Skip to content

Commit

Permalink
Add a check that the database chain id matches the config
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Jan 16, 2024
1 parent 7896f0d commit 44319b7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/nitro/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/offchainlabs/nitro/cmd/util"
"github.com/offchainlabs/nitro/execution/gethexec"
"github.com/offchainlabs/nitro/statetransfer"
"github.com/offchainlabs/nitro/util/arbmath"
)

func downloadInit(ctx context.Context, initConfig *conf.InitConfig) (string, error) {
Expand Down Expand Up @@ -163,6 +164,9 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo
if readOnlyDb, err := stack.OpenDatabaseWithFreezer("l2chaindata", 0, 0, "", "", true); err == nil {
if chainConfig := gethexec.TryReadStoredChainConfig(readOnlyDb); chainConfig != nil {
readOnlyDb.Close()
if !arbmath.BigEquals(chainConfig.ChainID, chainId) {
return nil, nil, fmt.Errorf("database has chain ID %v but config has chain ID %v (are you sure this database is for the right chain?)", chainConfig.ChainID, chainId)
}
chainDb, err := stack.OpenDatabaseWithFreezer("l2chaindata", config.Execution.Caching.DatabaseCache, config.Persistent.Handles, config.Persistent.Ancient, "", false)
if err != nil {
return chainDb, nil, err
Expand Down

0 comments on commit 44319b7

Please sign in to comment.