Skip to content

Commit 4714ce9

Browse files
cmd/geth: added --mainnet flag (#21932)
* cmd/geth: added --mainnet flag * cmd/utils: set default genesis if --mainnet is specified * cmd/utils: addressed comments
1 parent eb2a1df commit 4714ce9

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

cmd/geth/chaincmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ The export-preimages command export hash preimages to an RLP encoded stream`,
159159
utils.CacheFlag,
160160
utils.SyncModeFlag,
161161
utils.FakePoWFlag,
162+
utils.MainnetFlag,
162163
utils.RopstenFlag,
163164
utils.RinkebyFlag,
164165
utils.TxLookupLimitFlag,
@@ -210,6 +211,7 @@ Use "ethereum dump 0" to dump the genesis block.`,
210211
utils.DataDirFlag,
211212
utils.AncientFlag,
212213
utils.CacheFlag,
214+
utils.MainnetFlag,
213215
utils.RopstenFlag,
214216
utils.RinkebyFlag,
215217
utils.GoerliFlag,

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ var (
140140
utils.NodeKeyFileFlag,
141141
utils.NodeKeyHexFlag,
142142
utils.DNSDiscoveryFlag,
143+
utils.MainnetFlag,
143144
utils.DeveloperFlag,
144145
utils.DeveloperPeriodFlag,
145146
utils.LegacyTestnetFlag,

cmd/geth/usage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
4040
utils.USBFlag,
4141
utils.SmartCardDaemonPathFlag,
4242
utils.NetworkIdFlag,
43+
utils.MainnetFlag,
4344
utils.GoerliFlag,
4445
utils.RinkebyFlag,
4546
utils.YoloV2Flag,

cmd/utils/flags.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ var (
135135
Usage: "Explicitly set network id (integer)(For testnets: use --ropsten, --rinkeby, --goerli instead)",
136136
Value: eth.DefaultConfig.NetworkId,
137137
}
138+
MainnetFlag = cli.BoolFlag{
139+
Name: "mainnet",
140+
Usage: "Ethereum mainnet",
141+
}
138142
GoerliFlag = cli.BoolFlag{
139143
Name: "goerli",
140144
Usage: "Görli network: pre-configured proof-of-authority test network",
@@ -1494,7 +1498,7 @@ func SetShhConfig(ctx *cli.Context, stack *node.Node) {
14941498
// SetEthConfig applies eth-related command line flags to the config.
14951499
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
14961500
// Avoid conflicting network flags
1497-
CheckExclusive(ctx, DeveloperFlag, LegacyTestnetFlag, RopstenFlag, RinkebyFlag, GoerliFlag, YoloV2Flag)
1501+
CheckExclusive(ctx, MainnetFlag, DeveloperFlag, LegacyTestnetFlag, RopstenFlag, RinkebyFlag, GoerliFlag, YoloV2Flag)
14981502
CheckExclusive(ctx, LegacyLightServFlag, LightServeFlag, SyncModeFlag, "light")
14991503
CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
15001504
CheckExclusive(ctx, GCModeFlag, "archive", TxLookupLimitFlag)
@@ -1608,6 +1612,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
16081612
}
16091613
// Override any default configs for hard coded networks.
16101614
switch {
1615+
case ctx.GlobalBool(MainnetFlag.Name):
1616+
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
1617+
cfg.NetworkId = 1
1618+
}
1619+
cfg.Genesis = core.DefaultGenesisBlock()
1620+
SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)
16111621
case ctx.GlobalBool(LegacyTestnetFlag.Name) || ctx.GlobalBool(RopstenFlag.Name):
16121622
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
16131623
cfg.NetworkId = 3

0 commit comments

Comments
 (0)