diff --git a/eth/api.go b/eth/api.go index 1a14c555ae79..37a9730a138d 100644 --- a/eth/api.go +++ b/eth/api.go @@ -836,6 +836,19 @@ func (api *ScrollAPI) CalculateRowConsumptionByBlockNumber(ctx context.Context, // SetRollupEventSyncedL1Height sets the synced L1 height for rollup event synchronization func (api *ScrollAPI) SetRollupEventSyncedL1Height(height uint64) error { + prevHeightPtr := rawdb.ReadRollupEventSyncedL1BlockNumber(api.eth.ChainDb()) + + if prevHeightPtr == nil { + log.Warn("No previous rollup event synced L1 height found in database") + return fmt.Errorf("no previous rollup event synced L1 height found in database") + } + + prevHeight := *prevHeightPtr + if height >= prevHeight { + log.Warn("New rollup event synced L1 height is not lower than previous height", "newHeight", height, "prevHeight", prevHeight) + return fmt.Errorf("new rollup event synced L1 height (%d) is not lower than previous height (%d)", height, prevHeight) + } + log.Info("Setting rollup event synced L1 height", "height", height) rawdb.WriteRollupEventSyncedL1BlockNumber(api.eth.ChainDb(), height) return nil @@ -843,7 +856,20 @@ func (api *ScrollAPI) SetRollupEventSyncedL1Height(height uint64) error { // SetL1MessageSyncedL1Height sets the synced L1 height for L1 message synchronization func (api *ScrollAPI) SetL1MessageSyncedL1Height(height uint64) error { - rawdb.WriteSyncedL1BlockNumber(api.eth.ChainDb(), height) + prevHeightPtr := rawdb.ReadSyncedL1BlockNumber(api.eth.ChainDb()) + + if prevHeightPtr == nil { + log.Warn("No previous L1 message synced L1 height found in database") + return fmt.Errorf("no previous L1 message synced L1 height found in database") + } + + prevHeight := *prevHeightPtr + if height >= prevHeight { + log.Warn("New L1 message synced L1 height is not lower than previous height", "newHeight", height, "prevHeight", prevHeight) + return fmt.Errorf("new L1 message synced L1 height (%d) is not lower than previous height (%d)", height, prevHeight) + } + log.Info("Setting L1 message synced L1 height", "height", height) + rawdb.WriteSyncedL1BlockNumber(api.eth.ChainDb(), height) return nil }