Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(driver): update l1Current check in ProcessL1Blocks (#340)
Browse files Browse the repository at this point in the history
Co-authored-by: jeff <[email protected]>
  • Loading branch information
davidtaikocha and cyberhorsey authored Aug 1, 2023
1 parent 221a3b9 commit d67f287
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,20 @@ func (s *Syncer) ProcessL1Blocks(ctx context.Context, l1End *types.Header) error
s.reorgDetectedFlag = false
firstTry = false

startHeight := s.state.GetL1Current().Number
startL1Current := s.state.GetL1Current()
// If there is a L1 reorg, sometimes this will happen.
if startHeight.Uint64() >= l1End.Number.Uint64() {
startHeight = new(big.Int).Sub(l1End.Number, common.Big1)
newL1Current, err := s.rpc.L1.HeaderByNumber(ctx, startHeight)
if startL1Current.Number.Uint64() >= l1End.Number.Uint64() && startL1Current.Hash() != l1End.Hash() {
newL1Current, err := s.rpc.L1.HeaderByNumber(ctx, new(big.Int).Sub(l1End.Number, common.Big1))
if err != nil {
return err
}

log.Info(
"Reorg detected",
"oldL1Current", s.state.GetL1Current().Number,
"newL1Current", startHeight,
"oldL1CurrentHeight", startL1Current.Number,
"oldL1CurrentHash", startL1Current.Hash(),
"newL1CurrentHeight", newL1Current.Number,
"newL1CurrentHash", newL1Current.Hash(),
"l1Head", l1End.Number,
)

Expand All @@ -103,7 +104,7 @@ func (s *Syncer) ProcessL1Blocks(ctx context.Context, l1End *types.Header) error
iter, err := eventIterator.NewBlockProposedIterator(ctx, &eventIterator.BlockProposedIteratorConfig{
Client: s.rpc.L1,
TaikoL1: s.rpc.TaikoL1,
StartHeight: startHeight,
StartHeight: s.state.GetL1Current().Number,
EndHeight: l1End.Number,
FilterQuery: nil,
OnBlockProposedEvent: s.onBlockProposed,
Expand Down

0 comments on commit d67f287

Please sign in to comment.