Skip to content

Commit

Permalink
cmd/geth: added --mainnet flag (ethereum#21932)
Browse files Browse the repository at this point in the history
* cmd/geth: added --mainnet flag

* cmd/utils: set default genesis if --mainnet is specified

* cmd/utils: addressed comments
  • Loading branch information
MariusVanDerWijden authored and iquidus committed Feb 22, 2021
1 parent a899229 commit 8d00cfb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ The export-preimages command export hash preimages to an RLP encoded stream`,
utils.CacheFlag,
utils.SyncModeFlag,
utils.FakePoWFlag,
utils.MainnetFlag,
utils.ClassicFlag,
utils.MordorFlag,
utils.KottiFlag,
Expand Down Expand Up @@ -220,6 +221,7 @@ Use "ethereum dump 0" to dump the genesis block.`,
utils.DataDirFlag,
utils.AncientFlag,
utils.CacheFlag,
utils.MainnetFlag,
utils.ClassicFlag,
utils.MordorFlag,
utils.KottiFlag,
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ var (
utils.NodeKeyHexFlag,
utils.DNSDiscoveryFlag,
utils.EthProtocolsFlag,
utils.MainnetFlag,
utils.DeveloperFlag,
utils.DeveloperPeriodFlag,
utils.DeveloperPoWFlag,
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.NoUSBFlag,
utils.SmartCardDaemonPathFlag,
utils.NetworkIdFlag,
utils.MainnetFlag,
utils.ClassicFlag,
utils.MordorFlag,
utils.KottiFlag,
Expand Down
14 changes: 12 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ var (
Name: "classic",
Usage: "Ethereum Classic network: pre-configured Ethereum Classic mainnet",
}
MainnetFlag = cli.BoolFlag{
Name: "mainnet",
Usage: "Ethereum mainnet: pre-configured Ethereum mainnet",
}
YoloV2Flag = cli.BoolFlag{
Name: "yolov2",
Usage: "YOLOv2 network: pre-configured proof-of-authority shortlived test network.",
Expand Down Expand Up @@ -1597,7 +1601,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, DeveloperPoWFlag, LegacyTestnetFlag, RopstenFlag, RinkebyFlag, GoerliFlag, YoloV2Flag, ClassicFlag, KottiFlag, MordorFlag)
CheckExclusive(ctx, DeveloperFlag, DeveloperPoWFlag, LegacyTestnetFlag, MainnetFlag, RopstenFlag, RinkebyFlag, GoerliFlag, YoloV2Flag, ClassicFlag, KottiFlag, MordorFlag)
CheckExclusive(ctx, LegacyLightServFlag, LightServeFlag, SyncModeFlag, "light")
CheckExclusive(ctx, DeveloperFlag, DeveloperPoWFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
CheckExclusive(ctx, GCModeFlag, "archive", TxLookupLimitFlag)
Expand Down Expand Up @@ -1759,8 +1763,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {

// Set DNS discovery defaults for hard coded networks with DNS defaults.
switch {
case ctx.GlobalBool(MainnetFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 1
}
SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)
case ctx.GlobalBool(LegacyTestnetFlag.Name) || ctx.GlobalBool(RopstenFlag.Name):
cfg.Genesis = params.DefaultRopstenGenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.RopstenGenesisHash)
case ctx.GlobalBool(RinkebyFlag.Name):
SetDNSDiscoveryDefaults(cfg, params.RinkebyGenesisHash)
Expand Down Expand Up @@ -1970,6 +1978,8 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database {
func genesisForCtxChainConfig(ctx *cli.Context) *genesisT.Genesis {
var genesis *genesisT.Genesis
switch {
case ctx.GlobalBool(MainnetFlag.Name):
genesis = params.DefaultGenesisBlock()
case ctx.GlobalBool(ClassicFlag.Name):
genesis = params.DefaultClassicGenesisBlock()
case ctx.GlobalBool(MordorFlag.Name):
Expand Down

0 comments on commit 8d00cfb

Please sign in to comment.