diff options
Diffstat (limited to 'cmd/utils/flags.go')
-rw-r--r-- | cmd/utils/flags.go | 107 |
1 files changed, 68 insertions, 39 deletions
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 14898b987..de379f84f 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -126,10 +126,6 @@ var ( Name: "dev", Usage: "Developer mode: pre-configured private network with several debugging flags", } - GenesisFileFlag = cli.StringFlag{ - Name: "genesis", - Usage: "Insert/overwrite the genesis block (JSON format)", - } IdentityFlag = cli.StringFlag{ Name: "identity", Usage: "Custom node name", @@ -161,6 +157,15 @@ var ( Name: "lightkdf", Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength", } + // Fork settings + SupportDAOFork = cli.BoolFlag{ + Name: "support-dao-fork", + Usage: "Updates the chain rules to support the DAO hard-fork", + } + OpposeDAOFork = cli.BoolFlag{ + Name: "oppose-dao-fork", + Usage: "Updates the chain rules to oppose the DAO hard-fork", + } // Miner settings // TODO: refactor CPU vs GPU mining flags MiningEnabledFlag = cli.BoolFlag{ @@ -534,20 +539,6 @@ func MakeWSRpcHost(ctx *cli.Context) string { return ctx.GlobalString(WSListenAddrFlag.Name) } -// MakeGenesisBlock loads up a genesis block from an input file specified in the -// command line, or returns the empty string if none set. -func MakeGenesisBlock(ctx *cli.Context) string { - genesis := ctx.GlobalString(GenesisFileFlag.Name) - if genesis == "" { - return "" - } - data, err := ioutil.ReadFile(genesis) - if err != nil { - Fatalf("Failed to load custom genesis file: %v", err) - } - return string(data) -} - // MakeDatabaseHandles raises out the number of allowed file handles per process // for Geth and returns half of the allowance to assign to the database. func MakeDatabaseHandles() int { @@ -689,7 +680,6 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ethConf := ð.Config{ ChainConfig: MustMakeChainConfig(ctx), - Genesis: MakeGenesisBlock(ctx), FastSync: ctx.GlobalBool(FastSyncFlag.Name), BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name), DatabaseCache: ctx.GlobalInt(CacheFlag.Name), @@ -722,17 +712,13 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte, if !ctx.GlobalIsSet(NetworkIdFlag.Name) { ethConf.NetworkId = 1 } - if !ctx.GlobalIsSet(GenesisFileFlag.Name) { - ethConf.Genesis = core.OlympicGenesisBlock() - } + ethConf.Genesis = core.OlympicGenesisBlock() case ctx.GlobalBool(TestNetFlag.Name): if !ctx.GlobalIsSet(NetworkIdFlag.Name) { ethConf.NetworkId = 2 } - if !ctx.GlobalIsSet(GenesisFileFlag.Name) { - ethConf.Genesis = core.TestNetGenesisBlock() - } + ethConf.Genesis = core.TestNetGenesisBlock() state.StartingNonce = 1048576 // (2**20) case ctx.GlobalBool(DevModeFlag.Name): @@ -747,9 +733,7 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte, stackConf.ListenAddr = ":0" } // Override the Ethereum protocol configs - if !ctx.GlobalIsSet(GenesisFileFlag.Name) { - ethConf.Genesis = core.OlympicGenesisBlock() - } + ethConf.Genesis = core.OlympicGenesisBlock() if !ctx.GlobalIsSet(GasPriceFlag.Name) { ethConf.GasPrice = new(big.Int) } @@ -763,6 +747,13 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte, if err != nil { Fatalf("Failed to create the protocol stack: %v", err) } + + if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { + return accman, nil + }); err != nil { + Fatalf("Failed to register the account manager service: %v", err) + } + if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { return eth.New(ctx, ethConf) }); err != nil { @@ -806,24 +797,62 @@ func MustMakeChainConfig(ctx *cli.Context) *core.ChainConfig { // MustMakeChainConfigFromDb reads the chain configuration from the given database. func MustMakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainConfig { - genesis := core.GetBlock(db, core.GetCanonicalHash(db, 0), 0) + // If the chain is already initialized, use any existing chain configs + config := new(core.ChainConfig) + genesis := core.GetBlock(db, core.GetCanonicalHash(db, 0), 0) if genesis != nil { - // Existing genesis block, use stored config if available. storedConfig, err := core.GetChainConfig(db, genesis.Hash()) - if err == nil { - return storedConfig - } else if err != core.ChainConfigNotFoundErr { + switch err { + case nil: + config = storedConfig + case core.ChainConfigNotFoundErr: + // No configs found, use empty, will populate below + default: Fatalf("Could not make chain configuration: %v", err) } } - var homesteadBlockNo *big.Int - if ctx.GlobalBool(TestNetFlag.Name) { - homesteadBlockNo = params.TestNetHomesteadBlock - } else { - homesteadBlockNo = params.MainNetHomesteadBlock + // Set any missing fields due to them being unset or system upgrade + if config.HomesteadBlock == nil { + if ctx.GlobalBool(TestNetFlag.Name) { + config.HomesteadBlock = params.TestNetHomesteadBlock + } else { + config.HomesteadBlock = params.MainNetHomesteadBlock + } + } + if config.DAOForkBlock == nil { + if ctx.GlobalBool(TestNetFlag.Name) { + config.DAOForkBlock = params.TestNetDAOForkBlock + } else { + config.DAOForkBlock = params.MainNetDAOForkBlock + } + config.DAOForkSupport = true } - return &core.ChainConfig{HomesteadBlock: homesteadBlockNo} + // Force override any existing configs if explicitly requested + switch { + case ctx.GlobalBool(SupportDAOFork.Name): + config.DAOForkSupport = true + case ctx.GlobalBool(OpposeDAOFork.Name): + config.DAOForkSupport = false + } + // Temporarilly display a proper message so the user knows which fork its on + if !ctx.GlobalBool(TestNetFlag.Name) && (genesis == nil || genesis.Hash() == common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")) { + choice := "SUPPORT" + if !config.DAOForkSupport { + choice = "OPPOSE" + } + current := fmt.Sprintf("Geth is currently configured to %s the DAO hard-fork!", choice) + howtoswap := fmt.Sprintf("You can change your choice prior to block #%v with --support-dao-fork or --oppose-dao-fork.", config.DAOForkBlock) + howtosync := fmt.Sprintf("After the hard-fork block #%v passed, changing chains requires a resync from scratch!", config.DAOForkBlock) + separator := strings.Repeat("-", len(howtoswap)) + + glog.V(logger.Warn).Info(separator) + glog.V(logger.Warn).Info(current) + glog.V(logger.Warn).Info(howtoswap) + glog.V(logger.Warn).Info(howtosync) + glog.V(logger.Warn).Info(separator) + } + return config } // MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails. |