Skip to content

Commit 141a8df

Browse files
authored
fix(rollup verifier): nil pointer due to missing CommittedBatchMeta (#1188)
* fix nil pointer due to CommittedBatchMeta not being found in the DB and add rewind of L1 sync height to recover from missing CommittedBatchMeta * chore: auto version bump [bot] * formatting * increase rewindL1height to 100 * make sure no underflow
1 parent c66a003 commit 141a8df

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 5 // Major version component of the current release
2626
VersionMinor = 8 // Minor version component of the current release
27-
VersionPatch = 48 // Patch version component of the current release
27+
VersionPatch = 49 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

rollup/rollup_sync_service/rollup_sync_service.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ const (
4242

4343
// defaultLogInterval is the frequency at which we print the latest processed block.
4444
defaultLogInterval = 5 * time.Minute
45+
46+
// rewindL1Height is the number of blocks to rewind the L1 sync height when a missing batch event is detected.
47+
rewindL1Height = 100
4548
)
4649

4750
var (
4851
finalizedBlockGauge = metrics.NewRegisteredGauge("chain/head/finalized", nil)
4952
ErrShouldResetSyncHeight = errors.New("ErrShouldResetSyncHeight")
53+
ErrMissingBatchEvent = errors.New("ErrMissingBatchEvent")
5054
)
5155

5256
// RollupSyncService collects ScrollChain batch commit/revert/finalize events and stores metadata into db.
@@ -223,6 +227,22 @@ func (s *RollupSyncService) fetchRollupEvents() error {
223227

224228
return nil
225229
}
230+
if errors.Is(err, ErrMissingBatchEvent) {
231+
// make sure no underflow
232+
var rewindTo uint64
233+
if prevL1Height > rewindL1Height {
234+
rewindTo = prevL1Height - rewindL1Height
235+
}
236+
237+
// If there's a missing batch event, rewind the L1 sync height by some blocks to re-fetch from L1 RPC and
238+
// replay creating corresponding CommittedBatchMeta in local DB.
239+
// This happens recursively until the missing event has been recovered as we will call fetchRollupEvents again
240+
// with the `L1Height = prevL1Height - rewindL1Height`.
241+
s.callDataBlobSource.SetL1Height(rewindTo)
242+
243+
return fmt.Errorf("missing batch event, rewinding L1 sync height by %d blocks to %d: %w", rewindL1Height, rewindTo, err)
244+
}
245+
226246
// Reset the L1 height to the previous value to retry fetching the same data.
227247
s.callDataBlobSource.SetL1Height(prevL1Height)
228248
return fmt.Errorf("failed to parse and update rollup event logs: %w", err)
@@ -297,12 +317,18 @@ func (s *RollupSyncService) updateRollupEvents(daEntries da.Entries) error {
297317
var err error
298318
if index > 0 {
299319
if parentCommittedBatchMeta, err = rawdb.ReadCommittedBatchMeta(s.db, index-1); err != nil {
300-
return fmt.Errorf("failed to read parent committed batch meta, batch index: %v, err: %w", index-1, err)
320+
return fmt.Errorf("failed to read parent committed batch meta, batch index: %v, err: %w", index-1, errors.Join(ErrMissingBatchEvent, err))
321+
}
322+
if parentCommittedBatchMeta == nil {
323+
return fmt.Errorf("parent committed batch meta = nil, batch index: %v, err: %w", index-1, ErrMissingBatchEvent)
301324
}
302325
}
303326
committedBatchMeta, err := rawdb.ReadCommittedBatchMeta(s.db, index)
304327
if err != nil {
305-
return fmt.Errorf("failed to read committed batch meta, batch index: %v, err: %w", index, err)
328+
return fmt.Errorf("failed to read committed batch meta, batch index: %v, err: %w", index, errors.Join(ErrMissingBatchEvent, err))
329+
}
330+
if committedBatchMeta == nil {
331+
return fmt.Errorf("committed batch meta = nil, batch index: %v, err: %w", index, ErrMissingBatchEvent)
306332
}
307333

308334
chunks, err := s.getLocalChunksForBatch(committedBatchMeta.ChunkBlockRanges)
@@ -447,7 +473,10 @@ func (s *RollupSyncService) getCommittedBatchMeta(commitedBatch da.EntryWithBloc
447473
if commitedBatch.Version() == encoding.CodecV7 {
448474
parentCommittedBatchMeta, err := rawdb.ReadCommittedBatchMeta(s.db, commitedBatch.BatchIndex()-1)
449475
if err != nil {
450-
return nil, fmt.Errorf("failed to read parent committed batch meta, batch index: %v, err: %w", commitedBatch.BatchIndex()-1, err)
476+
return nil, fmt.Errorf("failed to read parent committed batch meta, batch index: %v, err: %w", commitedBatch.BatchIndex()-1, errors.Join(ErrMissingBatchEvent, err))
477+
}
478+
if parentCommittedBatchMeta == nil {
479+
return nil, fmt.Errorf("parent committed batch meta = nil, batch index: %v, err: %w", commitedBatch.BatchIndex()-1, ErrMissingBatchEvent)
451480
}
452481

453482
// If parent batch has a lower version this means this is the first batch of CodecV7.

0 commit comments

Comments
 (0)