Skip to content

Commit

Permalink
Merge pull request #81 from 0xPolygon/release/v0.5.12+cdk
Browse files Browse the repository at this point in the history
Fix initial sync
  • Loading branch information
arnaubennassar authored Feb 22, 2024
2 parents 023710f + 756f798 commit 80c8ad6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ func (etherMan *Client) GetForks(ctx context.Context, genBlockNumber uint64, las
log.Debug("Getting forkIDs from blockNumber: ", genBlockNumber)
start := time.Now()
var logs []types.Log

if lastL1BlockSynced < genBlockNumber {
lastL1BlockSynced = genBlockNumber
}

log.Debug("Using ForkIDChunkSize: ", etherMan.cfg.ForkIDChunkSize)
for i := genBlockNumber; i <= lastL1BlockSynced; i = i + etherMan.cfg.ForkIDChunkSize + 1 {
final := i + etherMan.cfg.ForkIDChunkSize
Expand Down
3 changes: 2 additions & 1 deletion synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (s *ClientSynchronizer) Sync() error {
// Sync events from RollupManager that happen before rollup creation
log.Info("synchronizing events from RollupManager that happen before rollup creation")
for i := s.genesis.RollupManagerBlockNumber; true; i += s.cfg.SyncChunkSize {
toBlock := min(i+s.cfg.SyncChunkSize, s.genesis.RollupBlockNumber-1)
toBlock := min(i+s.cfg.SyncChunkSize-1, s.genesis.RollupBlockNumber-1)
blocks, order, err := s.etherMan.GetRollupInfoByBlockRange(s.ctx, i, &toBlock)
if err != nil {
log.Error("error getting rollupInfoByBlockRange before rollup genesis: ", err)
Expand All @@ -242,6 +242,7 @@ func (s *ClientSynchronizer) Sync() error {
break
}
}

header, err := s.etherMan.HeaderByNumber(s.ctx, big.NewInt(0).SetUint64(s.genesis.RollupBlockNumber))
if err != nil {
log.Errorf("error getting l1 block header for block %d. Error: %v", s.genesis.RollupBlockNumber, err)
Expand Down

0 comments on commit 80c8ad6

Please sign in to comment.