Skip to content

Commit

Permalink
Merge pull request #125 from 0xPolygon/CDK-190-create-a-rpc-package-f…
Browse files Browse the repository at this point in the history
…or-fork-id-9-mainnet-for-astar

Retrieve and populate forkids table at boot
  • Loading branch information
vcastellm authored Apr 10, 2024
2 parents 5350426 + 99dcd67 commit 9aa12d6
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ func newState(ctx context.Context, c *config.Config, etherman *etherman.Client,
st.UpdateForkIDIntervalsInMemory(forkIDIntervals)

currentForkID := forkIDIntervals[len(forkIDIntervals)-1].ForkId
log.Infof("Fork ID read from POE SC = %v", forkIDIntervals[len(forkIDIntervals)-1].ForkId)
log.Infof("Fork ID read from POE SC = %v", currentForkID)

return st, currentForkID
}
Expand Down Expand Up @@ -763,14 +763,32 @@ func forkIDIntervals(ctx context.Context, st *state.State, etherman *etherman.Cl
}
forkIDIntervals = forkIntervals
} else {
log.Debug("Getting initial forkID")
forkIntervals, err := etherman.GetForks(ctx, genesisBlockNumber, genesisBlockNumber)
log.Debug("Getting all forkIDs")

// Get last L1 block number
bn, err := etherman.GetLatestBlockNumber(ctx)
if err != nil {
return []state.ForkIDInterval{}, fmt.Errorf("error getting latest block number. Error: %v", err)
}

// Get all forkIDs since genesis
forkIntervals, err := etherman.GetForks(ctx, genesisBlockNumber, bn)
if err != nil {
return []state.ForkIDInterval{}, fmt.Errorf("error getting forks. Please check the configuration. Error: %v", err)
} else if len(forkIntervals) == 0 {
return []state.ForkIDInterval{}, fmt.Errorf("error: no forkID received. It should receive at least one, please check the configuration...")
}
forkIDIntervals = forkIntervals

log.Debugf("Retrieved %d forkIDs", len(forkIDIntervals))

log.Debug("Adding forkIDs to db and memory")
for _, forkID := range forkIDIntervals {
err = st.AddForkIDInterval(ctx, forkID, nil)
if err != nil {
log.Fatal("error adding forkID to db. Error: ", err)
}
}
}
}
return forkIDIntervals, nil
Expand Down

0 comments on commit 9aa12d6

Please sign in to comment.