Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/ha/block_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ func (s *blockSyncerTestAggregatorRecordStorage) Count(context.Context) (int64,
return count, nil
}

func (s *blockSyncerTestAggregatorRecordStorage) EstimatedCount(ctx context.Context) (int64, error) {
return s.Count(ctx)
}

func (s *blockSyncerTestAggregatorRecordStorage) GetExistingStateIDs(_ context.Context, stateIDs []string) (map[string]bool, error) {
out := make(map[string]bool, len(stateIDs))
wanted := make(map[string]struct{}, len(stateIDs))
Expand Down
2 changes: 1 addition & 1 deletion internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ var (
SMTNodesPersistedTotal = promauto.NewGaugeFunc(
prometheus.GaugeOpts{
Name: "aggregator_smt_nodes_persisted_total",
Help: "Approximate persisted SMT node count from MongoDB EstimatedDocumentCount.",
Help: "Approximate finalized aggregator-record (SMT leaf) count per shard via Mongo EstimatedDocumentCount; a per-shard growth proxy (leaves, not RocksDB internal nodes).",
Comment thread
jait91 marked this conversation as resolved.
},
getSMTNodesPersistedCount,
)
Expand Down
4 changes: 4 additions & 0 deletions internal/round/disk_smt_startup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,10 @@ func (s *diskStartupAggregatorRecordStorage) Count(context.Context) (int64, erro
return int64(len(s.records)), nil
}

func (s *diskStartupAggregatorRecordStorage) EstimatedCount(context.Context) (int64, error) {
return int64(len(s.records)), nil
}

func (s *diskStartupAggregatorRecordStorage) GetExistingStateIDs(_ context.Context, stateIDs []string) (map[string]bool, error) {
existing := make(map[string]bool, len(stateIDs))
for _, stateID := range stateIDs {
Expand Down
6 changes: 4 additions & 2 deletions internal/round/round_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,11 @@ func NewRoundManagerWithBackend(
avgSMTUpdateTime: 5 * time.Millisecond, // Initial estimate per batch
}

if rm.storage != nil && rm.storage.SmtStorage() != nil {
// Count records (SMT leaves) in Mongo; disk-backed SMT nodes live in RocksDB,
// so the SMT collection reads ~0.
if rm.storage != nil && rm.storage.AggregatorRecordStorage() != nil {
metrics.SetSMTNodesPersistedCountFunc(func(countCtx context.Context) (int64, error) {
return rm.storage.SmtStorage().EstimatedCount(countCtx)
return rm.storage.AggregatorRecordStorage().EstimatedCount(countCtx)
})
}
if rm.commitmentQueue != nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,8 @@ func (s *testAggregatorRecordStorage) StoreBatch(context.Context, []*models.Aggr
func (s *testAggregatorRecordStorage) GetByBlockNumber(context.Context, *api.BigInt) ([]*models.AggregatorRecord, error) {
return nil, nil
}
func (s *testAggregatorRecordStorage) Count(context.Context) (int64, error) { return 0, nil }
func (s *testAggregatorRecordStorage) Count(context.Context) (int64, error) { return 0, nil }
func (s *testAggregatorRecordStorage) EstimatedCount(context.Context) (int64, error) { return 0, nil }
func (s *testAggregatorRecordStorage) GetExistingStateIDs(context.Context, []string) (map[string]bool, error) {
return nil, nil
}
Expand Down
3 changes: 3 additions & 0 deletions internal/storage/interfaces/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ type AggregatorRecordStorage interface {
// Count returns the total number of records
Count(ctx context.Context) (int64, error)

// EstimatedCount returns an approximate record count from collection metadata (O(1)).
EstimatedCount(ctx context.Context) (int64, error)
Comment thread
jait91 marked this conversation as resolved.

// GetExistingStateIDs returns which of the given state IDs already exist.
GetExistingStateIDs(ctx context.Context, stateIDs []string) (map[string]bool, error)
}
Expand Down
9 changes: 9 additions & 0 deletions internal/storage/mongodb/aggregator_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,15 @@ func (ars *AggregatorRecordStorage) Count(ctx context.Context) (int64, error) {
return count, nil
}

// EstimatedCount returns an approximate record count from collection metadata (O(1), unlike Count's scan).
func (ars *AggregatorRecordStorage) EstimatedCount(ctx context.Context) (int64, error) {
count, err := ars.collection.EstimatedDocumentCount(ctx)
if err != nil {
return 0, fmt.Errorf("failed to estimate aggregator record count: %w", err)
}
return count, nil
}

// CreateIndexes creates the necessary indexes needed by the submit, proof, and
// block-record lookup paths.
func (ars *AggregatorRecordStorage) CreateIndexes(ctx context.Context) error {
Expand Down
Loading