Skip to content

Commit

Permalink
add height validity check
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo committed Sep 18, 2024
1 parent 0751c86 commit 41ab50d
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,14 +836,40 @@ 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
}

// 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
}

0 comments on commit 41ab50d

Please sign in to comment.