From 472953335af88caefedef935af3c36c542376dbd Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Mon, 14 Dec 2020 14:08:29 -0800 Subject: [PATCH] config: allow for configurable chain id (#157) * config: allow for configurable chain id * compile: fix * geth: add chain id flag --- cmd/geth/main.go | 1 + cmd/geth/usage.go | 1 + cmd/utils/flags.go | 14 +++++++++++++- console/console_test.go | 2 +- core/genesis.go | 6 +++++- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 27934d77d262..c185a3e3add8 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -138,6 +138,7 @@ var ( utils.GoerliFlag, utils.VMEnableDebugFlag, utils.NetworkIdFlag, + utils.ChainIdFlag, utils.EthStatsURLFlag, utils.FakePoWFlag, utils.NoCompactionFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 6753e05ecc65..f89bed1b660d 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -92,6 +92,7 @@ var AppHelpFlagGroups = []flagGroup{ utils.NoUSBFlag, utils.SmartCardDaemonPathFlag, utils.NetworkIdFlag, + utils.ChainIdFlag, utils.TestnetFlag, utils.RinkebyFlag, utils.GoerliFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 1f5f4020064d..8dd93fc4f712 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -169,6 +169,11 @@ var ( Value: eth.DefaultConfig.NetworkId, EnvVar: "NETWORK_ID", } + ChainIdFlag = cli.Uint64Flag{ + Name: "chainid", + Usage: "Chain ID identifier", + EnvVar: "CHAIN_ID", + } TestnetFlag = cli.BoolFlag{ Name: "testnet", Usage: "Ropsten network: pre-configured proof-of-work test network", @@ -1713,10 +1718,17 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { } log.Info("Using developer account", "address", developer.Address) + // Allow for a configurable chain id + var chainID *big.Int + if ctx.GlobalIsSet(ChainIdFlag.Name) { + id := ctx.GlobalUint64(ChainIdFlag.Name) + chainID = new(big.Int).SetUint64(id) + } + xdomainAddress := cfg.Rollup.L1CrossDomainMessengerAddress addrManagerOwnerAddress := cfg.Rollup.AddressManagerOwnerAddress stateDumpPath := cfg.Rollup.StateDumpPath - cfg.Genesis = core.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address, xdomainAddress, addrManagerOwnerAddress, stateDumpPath) + cfg.Genesis = core.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address, xdomainAddress, addrManagerOwnerAddress, stateDumpPath, chainID) if !ctx.GlobalIsSet(MinerGasPriceFlag.Name) && !ctx.GlobalIsSet(MinerLegacyGasPriceFlag.Name) { cfg.Miner.GasPrice = big.NewInt(1) } diff --git a/console/console_test.go b/console/console_test.go index de1a478dc42f..8bd93ed05ae0 100644 --- a/console/console_test.go +++ b/console/console_test.go @@ -98,7 +98,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester { t.Fatalf("failed to create node: %v", err) } ethConf := ð.Config{ - Genesis: core.DeveloperGenesisBlock(15, common.Address{}, common.Address{}, common.Address{}, ""), + Genesis: core.DeveloperGenesisBlock(15, common.Address{}, common.Address{}, common.Address{}, "", nil), Miner: miner.Config{ Etherbase: common.HexToAddress(testAddress), }, diff --git a/core/genesis.go b/core/genesis.go index cbbcc593d674..fe7e93dd0cb6 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -436,11 +436,15 @@ func DefaultGoerliGenesisBlock() *Genesis { } // DeveloperGenesisBlock returns the 'geth --dev' genesis block. -func DeveloperGenesisBlock(period uint64, faucet, xDomainMessengerAddress, addrManagerOwnerAddress common.Address, stateDumpPath string) *Genesis { +func DeveloperGenesisBlock(period uint64, faucet, xDomainMessengerAddress, addrManagerOwnerAddress common.Address, stateDumpPath string, chainID *big.Int) *Genesis { // Override the default period to the user requested one config := *params.AllCliqueProtocolChanges config.Clique.Period = period + if chainID != nil { + config.ChainID = chainID + } + stateDump := dump.OvmDump{} if vm.UsingOVM { // Fetch the state dump from the state dump path