From 129221efecec7a5bcb1df5379a791943bdf63144 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 1 Dec 2020 09:40:50 +0100 Subject: [PATCH 1/3] cmd/geth: added --mainnet flag --- cmd/geth/chaincmd.go | 2 ++ cmd/geth/main.go | 1 + cmd/geth/usage.go | 1 + cmd/utils/flags.go | 6 +++++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 6418f909579a..f53932265492 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -159,6 +159,7 @@ The export-preimages command export hash preimages to an RLP encoded stream`, utils.CacheFlag, utils.SyncModeFlag, utils.FakePoWFlag, + utils.MainnetFlag, utils.RopstenFlag, utils.RinkebyFlag, utils.TxLookupLimitFlag, @@ -210,6 +211,7 @@ Use "ethereum dump 0" to dump the genesis block.`, utils.DataDirFlag, utils.AncientFlag, utils.CacheFlag, + utils.MainnetFlag, utils.RopstenFlag, utils.RinkebyFlag, utils.GoerliFlag, diff --git a/cmd/geth/main.go b/cmd/geth/main.go index e587a5f86dd6..91eef08a3f92 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -139,6 +139,7 @@ var ( utils.NodeKeyFileFlag, utils.NodeKeyHexFlag, utils.DNSDiscoveryFlag, + utils.MainnetFlag, utils.DeveloperFlag, utils.DeveloperPeriodFlag, utils.LegacyTestnetFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 0e70451ed385..2f37a2ac998c 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -40,6 +40,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{ utils.NoUSBFlag, utils.SmartCardDaemonPathFlag, utils.NetworkIdFlag, + utils.MainnetFlag, utils.GoerliFlag, utils.RinkebyFlag, utils.YoloV2Flag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 0b1695d0a53a..ea62fb7756c9 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -131,6 +131,10 @@ var ( Usage: "Explicitly set network id (integer)(For testnets: use --ropsten, --rinkeby, --goerli instead)", Value: eth.DefaultConfig.NetworkId, } + MainnetFlag = cli.BoolFlag{ + Name: "mainnet", + Usage: "Ethereum network: main network of the ETH asset", + } GoerliFlag = cli.BoolFlag{ Name: "goerli", Usage: "Görli network: pre-configured proof-of-authority test network", @@ -1487,7 +1491,7 @@ func SetShhConfig(ctx *cli.Context, stack *node.Node) { // SetEthConfig applies eth-related command line flags to the config. func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { // Avoid conflicting network flags - CheckExclusive(ctx, DeveloperFlag, LegacyTestnetFlag, RopstenFlag, RinkebyFlag, GoerliFlag, YoloV2Flag) + CheckExclusive(ctx, MainnetFlag, DeveloperFlag, LegacyTestnetFlag, RopstenFlag, RinkebyFlag, GoerliFlag, YoloV2Flag) CheckExclusive(ctx, LegacyLightServFlag, LightServeFlag, SyncModeFlag, "light") CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer CheckExclusive(ctx, GCModeFlag, "archive", TxLookupLimitFlag) From ae00010b95b3c6c92eb34d55bdee139b54ef7f30 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 15 Dec 2020 10:31:35 +0100 Subject: [PATCH 2/3] cmd/utils: set default genesis if --mainnet is specified --- cmd/utils/flags.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index ea62fb7756c9..499f2ff8f4e8 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1606,6 +1606,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { } // Override any default configs for hard coded networks. switch { + case ctx.GlobalBool(MainnetFlag.Name): + if !ctx.GlobalIsSet(NetworkIdFlag.Name) { + cfg.NetworkId = 1 + } + cfg.Genesis = core.DefaultGenesisBlock() + SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash) case ctx.GlobalBool(LegacyTestnetFlag.Name) || ctx.GlobalBool(RopstenFlag.Name): if !ctx.GlobalIsSet(NetworkIdFlag.Name) { cfg.NetworkId = 3 @@ -1807,7 +1813,7 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database { } func MakeGenesis(ctx *cli.Context) *core.Genesis { - var genesis *core.Genesis + genesis := core.DefaultGenesisBlock() switch { case ctx.GlobalBool(LegacyTestnetFlag.Name) || ctx.GlobalBool(RopstenFlag.Name): genesis = core.DefaultRopstenGenesisBlock() From 6677f2d64acf4d6eebd6376d770c5fa68c0fb734 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 15 Dec 2020 11:05:09 +0100 Subject: [PATCH 3/3] cmd/utils: addressed comments --- cmd/utils/flags.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 499f2ff8f4e8..77b28527572c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -133,7 +133,7 @@ var ( } MainnetFlag = cli.BoolFlag{ Name: "mainnet", - Usage: "Ethereum network: main network of the ETH asset", + Usage: "Ethereum mainnet", } GoerliFlag = cli.BoolFlag{ Name: "goerli", @@ -1813,7 +1813,7 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database { } func MakeGenesis(ctx *cli.Context) *core.Genesis { - genesis := core.DefaultGenesisBlock() + var genesis *core.Genesis switch { case ctx.GlobalBool(LegacyTestnetFlag.Name) || ctx.GlobalBool(RopstenFlag.Name): genesis = core.DefaultRopstenGenesisBlock()