Skip to content

Commit

Permalink
Add validation to ensure Cel2 chain has migrated data (#315)
Browse files Browse the repository at this point in the history
* Add error for no migrated data in bootstrapping

* Move migrated data existence check into backend and add a new condition for full sync node

* Improve error message for missing Celo1 blocks
  • Loading branch information
Kourin1996 authored and karlb committed Feb 3, 2025
1 parent 316f1ee commit 534e5ce
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,15 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if err != nil {
return nil, err
}
// Make sure Cel2 full sync node has migrated data from Celo1
currentBlock := eth.blockchain.CurrentBlock()
if config.SyncMode == downloader.FullSync && chainConfig.Cel2Time != nil && !chainConfig.IsCel2(currentBlock.Number.Uint64()) {
log.Error(fmt.Sprintf(
"Chaindata is missing blocks, Cel2 fork is at block %d, but the head block is %d. Pre Cel2 blocks must be migrated from"+
" Celo L1 chaindata, Celo L2 cannot generate pre Cel2 blocks. See migration instructions here - https://docs.celo.org/cel2/l2-operator-guide",
*chainConfig.Cel2Time, currentBlock.Number.Uint64()))
return nil, fmt.Errorf("missing migrated data")
}
if chainConfig := eth.blockchain.Config(); chainConfig.Optimism != nil { // config.Genesis.Config.ChainID cannot be used because it's based on CLI flags only, thus default to mainnet L1
config.NetworkId = chainConfig.ChainID.Uint64() // optimism defaults eth network ID to chain ID
eth.networkID = config.NetworkId
Expand Down

0 comments on commit 534e5ce

Please sign in to comment.