mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
cmd/geth: add flag to override genesis
This commit is contained in:
parent
891bbad9ce
commit
b02b46dd5a
2 changed files with 19 additions and 1 deletions
|
|
@ -84,6 +84,7 @@ var (
|
||||||
utils.SyncModeFlag,
|
utils.SyncModeFlag,
|
||||||
utils.SyncTargetFlag,
|
utils.SyncTargetFlag,
|
||||||
utils.ExitWhenSyncedFlag,
|
utils.ExitWhenSyncedFlag,
|
||||||
|
utils.GenesisFlag,
|
||||||
utils.GCModeFlag,
|
utils.GCModeFlag,
|
||||||
utils.SnapshotFlag,
|
utils.SnapshotFlag,
|
||||||
utils.TxLookupLimitFlag, // deprecated
|
utils.TxLookupLimitFlag, // deprecated
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,11 @@ var (
|
||||||
Usage: "Exits after block synchronisation completes",
|
Usage: "Exits after block synchronisation completes",
|
||||||
Category: flags.EthCategory,
|
Category: flags.EthCategory,
|
||||||
}
|
}
|
||||||
|
GenesisFlag = &cli.StringFlag{
|
||||||
|
Name: "genesis",
|
||||||
|
Usage: "Load genesis block and configuration from file at this path.",
|
||||||
|
Category: flags.EthCategory,
|
||||||
|
}
|
||||||
|
|
||||||
// Dump command options.
|
// Dump command options.
|
||||||
IterativeOutputFlag = &cli.BoolFlag{
|
IterativeOutputFlag = &cli.BoolFlag{
|
||||||
|
|
@ -1593,7 +1598,7 @@ func setRequiredBlocks(ctx *cli.Context, cfg *ethconfig.Config) {
|
||||||
// SetEthConfig applies eth-related command line flags to the config.
|
// SetEthConfig applies eth-related command line flags to the config.
|
||||||
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
// Avoid conflicting network flags, don't allow network id override on preset networks
|
// Avoid conflicting network flags, don't allow network id override on preset networks
|
||||||
flags.CheckExclusive(ctx, MainnetFlag, DeveloperFlag, SepoliaFlag, HoleskyFlag, HoodiFlag, NetworkIdFlag)
|
flags.CheckExclusive(ctx, MainnetFlag, DeveloperFlag, SepoliaFlag, HoleskyFlag, HoodiFlag, NetworkIdFlag, GenesisFlag)
|
||||||
flags.CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
|
flags.CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
|
||||||
|
|
||||||
// Set configurations from CLI flags
|
// Set configurations from CLI flags
|
||||||
|
|
@ -1873,6 +1878,18 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
if !ctx.IsSet(MinerGasPriceFlag.Name) {
|
if !ctx.IsSet(MinerGasPriceFlag.Name) {
|
||||||
cfg.Miner.GasPrice = big.NewInt(1)
|
cfg.Miner.GasPrice = big.NewInt(1)
|
||||||
}
|
}
|
||||||
|
case ctx.String(GenesisFlag.Name) != "":
|
||||||
|
f, err := os.Open(ctx.String(GenesisFlag.Name))
|
||||||
|
if err != nil {
|
||||||
|
Fatalf("Failed to read genesis file: %v", err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
genesis := new(core.Genesis)
|
||||||
|
if err := json.NewDecoder(f).Decode(genesis); err != nil {
|
||||||
|
Fatalf("Invalid genesis file: %v", err)
|
||||||
|
}
|
||||||
|
cfg.Genesis = genesis
|
||||||
default:
|
default:
|
||||||
if cfg.NetworkId == 1 {
|
if cfg.NetworkId == 1 {
|
||||||
SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)
|
SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue