Skip to content

Commit

Permalink
config: allow for configurable chain id (ethereum#157)
Browse files Browse the repository at this point in the history
* config: allow for configurable chain id

* compile: fix

* geth: add chain id flag
  • Loading branch information
tynes authored Dec 14, 2020
1 parent 6a04e39 commit 4729533
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ var (
utils.GoerliFlag,
utils.VMEnableDebugFlag,
utils.NetworkIdFlag,
utils.ChainIdFlag,
utils.EthStatsURLFlag,
utils.FakePoWFlag,
utils.NoCompactionFlag,
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.NoUSBFlag,
utils.SmartCardDaemonPathFlag,
utils.NetworkIdFlag,
utils.ChainIdFlag,
utils.TestnetFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
Expand Down
14 changes: 13 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion console/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester {
t.Fatalf("failed to create node: %v", err)
}
ethConf := &eth.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),
},
Expand Down
6 changes: 5 additions & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4729533

Please sign in to comment.