Skip to content

Commit 95aeea4

Browse files
committed
syncing: fallback to catchup on subscribe failure
1 parent 7bd2c8e commit 95aeea4

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

block/internal/syncing/syncer.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,9 @@ func (s *Syncer) runFollowMode() {
440440
err := s.subscribeAndFollow()
441441
if err != nil && !errors.Is(err, context.Canceled) {
442442
s.metrics.SubscribeErrors.Add(1)
443-
s.logger.Warn().Err(err).Msg("subscribe failed, falling back to catchup")
444-
// Don't sleep - go straight to catchup mode to recover
443+
s.logger.Warn().Err(err).Msg("subscribe failed, will retry via mode check")
444+
// No explicit catchup call needed - daWorkerLoop will call determineSyncMode()
445+
// which defaults to catchup on error or when behind
445446
}
446447
}
447448

@@ -977,25 +978,15 @@ func hashTx(tx []byte) string {
977978
}
978979

979980
// calculateBlockFullness returns a value between 0.0 and 1.0 indicating how full the block is.
980-
// It estimates fullness based on total data size.
981+
// It estimates fullness based on total data size relative to max blob size.
981982
// This is a heuristic - actual limits may vary by execution layer.
982983
func (s *Syncer) calculateBlockFullness(data *types.Data) float64 {
983-
const maxDataSize = common.DefaultMaxBlobSize
984-
985-
var fullness float64
986-
count := 0
987-
988-
// Check data size fullness
989-
dataSize := uint64(0)
984+
var dataSize uint64
990985
for _, tx := range data.Txs {
991986
dataSize += uint64(len(tx))
992987
}
993-
sizeFullness := float64(dataSize) / float64(maxDataSize)
994-
fullness += min(sizeFullness, 1.0)
995-
count++
996-
997-
// Return average fullness
998-
return fullness / float64(count)
988+
fullness := float64(dataSize) / float64(common.DefaultMaxBlobSize)
989+
return min(fullness, 1.0)
999990
}
1000991

1001992
// updateDynamicGracePeriod updates the grace period multiplier based on block fullness.

block/internal/syncing/syncer_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,30 @@ func TestSyncer_runCatchupMode(t *testing.T) {
831831
mockDA.AssertExpectations(t)
832832
}
833833

834+
func TestSyncer_runFollowMode_SubscribeFailureReturnsForModeCheck(t *testing.T) {
835+
mockDA := testmocks.NewMockClient(t)
836+
namespace := []byte("namespace")
837+
mockDA.EXPECT().GetHeaderNamespace().Return(namespace).Once()
838+
mockDA.EXPECT().GetDataNamespace().Return(namespace).Once()
839+
mockDA.EXPECT().Subscribe(mock.Anything, namespace).
840+
Return(nil, errors.New("subscribe failed")).Once()
841+
842+
syncer := &Syncer{
843+
daClient: mockDA,
844+
daRetrieverHeight: &atomic.Uint64{},
845+
ctx: context.Background(),
846+
logger: zerolog.Nop(),
847+
metrics: common.NopMetrics(),
848+
}
849+
syncer.daRetrieverHeight.Store(100)
850+
851+
// runFollowMode should return after subscribe failure,
852+
// allowing daWorkerLoop to call determineSyncMode() next iteration
853+
syncer.runFollowMode()
854+
855+
mockDA.AssertExpectations(t)
856+
}
857+
834858
func TestSyncer_modeSwitching(t *testing.T) {
835859
// Test that mode switches are tracked correctly
836860
mockDA := testmocks.NewMockClient(t)

0 commit comments

Comments
 (0)