diff --git a/cmd/conf/init.go b/cmd/conf/init.go index f01d99f8b7..d54d35bf4e 100644 --- a/cmd/conf/init.go +++ b/cmd/conf/init.go @@ -25,6 +25,7 @@ type InitConfig struct { ImportWasm bool `koanf:"import-wasm"` AccountsPerSync uint `koanf:"accounts-per-sync"` ImportFile string `koanf:"import-file"` + GenesisJsonFile string `koanf:"genesis-json-file"` ThenQuit bool `koanf:"then-quit"` Prune string `koanf:"prune"` PruneBloomSize uint64 `koanf:"prune-bloom-size"` @@ -51,6 +52,7 @@ var InitConfigDefault = InitConfig{ Empty: false, ImportWasm: false, ImportFile: "", + GenesisJsonFile: "", AccountsPerSync: 100000, ThenQuit: false, Prune: "", @@ -79,6 +81,7 @@ func InitConfigAddOptions(prefix string, f *pflag.FlagSet) { f.Bool(prefix+".import-wasm", InitConfigDefault.ImportWasm, "if set, import the wasm directory when downloading a database (contains executable code - only use with highly trusted source)") f.Bool(prefix+".then-quit", InitConfigDefault.ThenQuit, "quit after init is done") f.String(prefix+".import-file", InitConfigDefault.ImportFile, "path for json data to import") + f.String(prefix+".genesis-json-file", InitConfigDefault.GenesisJsonFile, "path for genesis json file") f.Uint(prefix+".accounts-per-sync", InitConfigDefault.AccountsPerSync, "during init - sync database every X accounts. Lower value for low-memory systems. 0 disables.") f.String(prefix+".prune", InitConfigDefault.Prune, "pruning for a given use: \"full\" for full nodes serving RPC requests, or \"validator\" for validators") f.Uint64(prefix+".prune-bloom-size", InitConfigDefault.PruneBloomSize, "the amount of memory in megabytes to use for the pruning bloom filter (higher values prune better)") diff --git a/cmd/nitro/init.go b/cmd/nitro/init.go index f0b303817c..a5a6ec4ca8 100644 --- a/cmd/nitro/init.go +++ b/cmd/nitro/init.go @@ -687,6 +687,36 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo var chainConfig *params.ChainConfig + if config.Init.GenesisJsonFile != "" { + if initDataReader != nil { + return chainDb, nil, errors.New("multiple init methods supplied") + } + genesisJson, err := os.ReadFile(config.Init.GenesisJsonFile) + if err != nil { + return chainDb, nil, err + } + var gen core.Genesis + if err := json.Unmarshal(genesisJson, &gen); err != nil { + return chainDb, nil, err + } + var accounts []statetransfer.AccountInitializationInfo + for address, account := range gen.Alloc { + accounts = append(accounts, statetransfer.AccountInitializationInfo{ + Addr: address, + EthBalance: account.Balance, + Nonce: account.Nonce, + ContractInfo: &statetransfer.AccountInitContractInfo{ + Code: account.Code, + ContractStorage: account.Storage, + }, + }) + } + initDataReader = statetransfer.NewMemoryInitDataReader(&statetransfer.ArbosInitializationInfo{ + Accounts: accounts, + }) + chainConfig = gen.Config + } + var l2BlockChain *core.BlockChain txIndexWg := sync.WaitGroup{} if initDataReader == nil { @@ -712,9 +742,11 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo if err != nil { return chainDb, nil, err } - chainConfig, err = chaininfo.GetChainConfig(new(big.Int).SetUint64(config.Chain.ID), config.Chain.Name, genesisBlockNr, config.Chain.InfoFiles, config.Chain.InfoJson) - if err != nil { - return chainDb, nil, err + if chainConfig == nil { + chainConfig, err = chaininfo.GetChainConfig(new(big.Int).SetUint64(config.Chain.ID), config.Chain.Name, genesisBlockNr, config.Chain.InfoFiles, config.Chain.InfoJson) + if err != nil { + return chainDb, nil, err + } } testUpdateTxIndex(chainDb, chainConfig, &txIndexWg) ancients, err := chainDb.Ancients()