Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Synchronizer accept forkids that are the same as in database #3452

Merged
merged 7 commits into from
Mar 13, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions synchronizer/actions/incaberry/processor_l1_forkid.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ func (p *ProcessorForkId) Process(ctx context.Context, order etherman.Order, l1B
return p.processForkID(ctx, l1Block.ForkIDs[order.Pos], l1Block.BlockNumber, dbTx)
}

func getForkdFromSlice(fIds []state.ForkIDInterval, forkId uint64) (bool, state.ForkIDInterval) {
if len(fIds) == 0 {
return false, state.ForkIDInterval{}
}
for _, f := range fIds {
if f.ForkId == forkId {
return true, f
}
}
return false, state.ForkIDInterval{}
}

func isForksEquals(f1, f2 state.ForkIDInterval) bool {
return f1.ForkId == f2.ForkId && f1.FromBatchNumber == f2.FromBatchNumber && f1.Version == f2.Version && f1.BlockNumber == f2.BlockNumber
}

func (s *ProcessorForkId) processForkID(ctx context.Context, forkID etherman.ForkID, blockNumber uint64, dbTx pgx.Tx) error {
fID := state.ForkIDInterval{
FromBatchNumber: forkID.BatchNumber + 1,
Expand All @@ -68,8 +84,14 @@ func (s *ProcessorForkId) processForkID(ctx context.Context, forkID etherman.For
}
return err
}
if len(fIds) != 0 && fIds[len(fIds)-1].ForkId == fID.ForkId { // If the forkID reset was already done
return nil
if found, dbForkID := getForkdFromSlice(fIds, fID.ForkId); found {
if isForksEquals(fID, dbForkID) {
log.Infof("ForkID: %d, already in the state. Skipping . ForkID: %+v.", fID.ForkId, fID)
return nil
}
err = fmt.Errorf("ForkID: %d, already in the state but with different values. DB ForkID: %+v. New ForkID: %+v", fID.ForkId, dbForkID, fID)
log.Error(err.Error())
return err
}
//If the forkID.batchnumber is a future batch
latestBatchNumber, err := s.state.GetLastBatchNumber(ctx, dbTx)
Expand Down
Loading