From 442edf5e0604448b3d2baae6091ed6113b911b8c Mon Sep 17 00:00:00 2001 From: olegshmuelov Date: Thu, 12 Feb 2026 16:07:28 +0200 Subject: [PATCH 1/2] fix: update validator_count in head sync path and add cluster update logging --- eth/syncer/syncer.go | 16 +++++++++++----- storage/storage.go | 2 ++ storage/storage_test.go | 8 ++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/eth/syncer/syncer.go b/eth/syncer/syncer.go index b723394..ec486ba 100644 --- a/eth/syncer/syncer.go +++ b/eth/syncer/syncer.go @@ -410,13 +410,16 @@ func (s *EventSyncer) SyncClustersToHead(ctx context.Context) error { return nil } + var updates int topics := EventTopics() // Filter by handled event signatures err = s.client.FetchLogs(ctx, s.ssvContract, fromBlock+1, headBlock, topics, func(batchEnd uint64, logs []execution.BlockLogs) error { for _, blockLogs := range logs { - if err := s.applyClusterUpdates(ctx, blockLogs); err != nil { + n, err := s.applyClusterUpdates(ctx, blockLogs) + if err != nil { return err } + updates += n } return nil }) @@ -424,11 +427,12 @@ func (s *EventSyncer) SyncClustersToHead(ctx context.Context) error { return err } - logger.Debugw("Clusters synced to head", "from", fromBlock+1, "to", headBlock) + logger.Debugw("Clusters synced to head", "from", fromBlock+1, "to", headBlock, "clusterUpdates", updates) return nil } -func (s *EventSyncer) applyClusterUpdates(ctx context.Context, blockLogs execution.BlockLogs) error { +func (s *EventSyncer) applyClusterUpdates(ctx context.Context, blockLogs execution.BlockLogs) (int, error) { + var count int for _, log := range blockLogs.Logs { _, eventData, err := s.parser.parseLog(&log) if err != nil { @@ -453,6 +457,7 @@ func (s *EventSyncer) applyClusterUpdates(ctx context.Context, blockLogs executi row := &storage.ClusterRow{ ClusterID: clusterID[:], + ValidatorCount: cluster.ValidatorCount, NetworkFeeIndex: cluster.NetworkFeeIndex, Index: cluster.Index, IsActive: cluster.Active, @@ -460,8 +465,9 @@ func (s *EventSyncer) applyClusterUpdates(ctx context.Context, blockLogs executi } if err := s.storage.UpdateClusterIfExists(ctx, row); err != nil { - return err + return 0, err } + count++ } - return nil + return count, nil } diff --git a/storage/storage.go b/storage/storage.go index c04a30c..6a67ff9 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -593,6 +593,7 @@ func (s *Storage) SetSyncMode(bulk bool) error { func (s *Storage) UpdateClusterIfExists(ctx context.Context, cluster *ClusterRow) error { query := ` UPDATE clusters SET + validator_count = ?, network_fee_index = ?, idx = ?, is_active = ?, @@ -600,6 +601,7 @@ func (s *Storage) UpdateClusterIfExists(ctx context.Context, cluster *ClusterRow WHERE cluster_id = ? ` _, err := s.db.ExecContext(ctx, query, + cluster.ValidatorCount, cluster.NetworkFeeIndex, cluster.Index, boolToInt(cluster.IsActive), diff --git a/storage/storage_test.go b/storage/storage_test.go index 14a163c..cf79acd 100644 --- a/storage/storage_test.go +++ b/storage/storage_test.go @@ -805,6 +805,7 @@ func TestStorage_UpdateClusterIfExists_Existing(t *testing.T) { // Now update using UpdateClusterIfExists updated := &ClusterRow{ ClusterID: clusterID, + ValidatorCount: 5, NetworkFeeIndex: 500, Index: 600, IsActive: false, @@ -825,6 +826,9 @@ func TestStorage_UpdateClusterIfExists_Existing(t *testing.T) { t.Fatal("Expected cluster, got nil") } + if got.ValidatorCount != 5 { + t.Errorf("ValidatorCount = %d, want 5", got.ValidatorCount) + } if got.NetworkFeeIndex != 500 { t.Errorf("NetworkFeeIndex = %d, want 500", got.NetworkFeeIndex) } @@ -837,10 +841,6 @@ func TestStorage_UpdateClusterIfExists_Existing(t *testing.T) { if got.Balance.Cmp(big.NewInt(9999)) != 0 { t.Errorf("Balance = %v, want 9999", got.Balance) } - // ValidatorCount should remain unchanged - if got.ValidatorCount != 1 { - t.Errorf("ValidatorCount = %d, want 1 (unchanged)", got.ValidatorCount) - } } func TestStorage_DecodeOperatorIDs_Malformed(t *testing.T) { From a17ab5c2a2ce376b09d3eb2fec48fb0028573b1c Mon Sep 17 00:00:00 2001 From: olegshmuelov Date: Thu, 12 Feb 2026 18:08:08 +0200 Subject: [PATCH 2/2] address PR review feedback --- eth/syncer/syncer.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/eth/syncer/syncer.go b/eth/syncer/syncer.go index ec486ba..ea7c8cd 100644 --- a/eth/syncer/syncer.go +++ b/eth/syncer/syncer.go @@ -432,7 +432,7 @@ func (s *EventSyncer) SyncClustersToHead(ctx context.Context) error { } func (s *EventSyncer) applyClusterUpdates(ctx context.Context, blockLogs execution.BlockLogs) (int, error) { - var count int + var updated int for _, log := range blockLogs.Logs { _, eventData, err := s.parser.parseLog(&log) if err != nil { @@ -465,9 +465,9 @@ func (s *EventSyncer) applyClusterUpdates(ctx context.Context, blockLogs executi } if err := s.storage.UpdateClusterIfExists(ctx, row); err != nil { - return 0, err + return updated, err } - count++ + updated++ } - return count, nil + return updated, nil }