aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-07-08 23:48:17 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-07-15 21:52:55 +0800
commita87089fd2dc08a69a4a4f1ef93db9a2871d819a3 (patch)
treeb1634faefc24ee8b80b9ad9c06ac8df7f409558b /cmd/utils
parent1e24c2e4f428c85c2f83272af2696469cb8f5bed (diff)
downloadgo-tangerine-a87089fd2dc08a69a4a4f1ef93db9a2871d819a3.tar.gz
go-tangerine-a87089fd2dc08a69a4a4f1ef93db9a2871d819a3.tar.zst
go-tangerine-a87089fd2dc08a69a4a4f1ef93db9a2871d819a3.zip
cmd, core, miner: add extradata validation to consensus rules
Diffstat (limited to 'cmd/utils')
-rw-r--r--cmd/utils/flags.go53
1 files changed, 26 insertions, 27 deletions
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index b95f5159c..fae1647b3 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -798,43 +798,42 @@ 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 {
// If the chain is already initialized, use any existing chain configs
+ config := new(core.ChainConfig)
+
if genesis := core.GetBlock(db, core.GetCanonicalHash(db, 0), 0); genesis != nil {
storedConfig, err := core.GetChainConfig(db, genesis.Hash())
- if err == nil {
- // Force override any existing configs if explicitly requested
- switch {
- case storedConfig.DAOForkBlock == nil && ctx.GlobalBool(SupportDAOFork.Name) && ctx.GlobalBool(TestNetFlag.Name):
- storedConfig.DAOForkBlock = params.TestNetDAOForkBlock
- case storedConfig.DAOForkBlock == nil && ctx.GlobalBool(SupportDAOFork.Name):
- storedConfig.DAOForkBlock = params.MainNetDAOForkBlock
- case ctx.GlobalBool(OpposeDAOFork.Name):
- storedConfig.DAOForkBlock = 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)
}
}
- // If the chain is uninitialized nor no configs are present, create one
- var homesteadBlock *big.Int
- if ctx.GlobalBool(TestNetFlag.Name) {
- homesteadBlock = params.TestNetHomesteadBlock
- } else {
- homesteadBlock = 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 = new(big.Int).Set(params.TestNetHomesteadBlock)
+ } else {
+ config.HomesteadBlock = new(big.Int).Set(params.MainNetHomesteadBlock)
+ }
}
- var daoForkBlock *big.Int
+ if config.DAOForkBlock == nil {
+ if ctx.GlobalBool(TestNetFlag.Name) {
+ config.DAOForkBlock = new(big.Int).Set(params.TestNetDAOForkBlock)
+ } else {
+ config.DAOForkBlock = new(big.Int).Set(params.MainNetDAOForkBlock)
+ }
+ }
+ // Force override any existing configs if explicitly requested
switch {
- case ctx.GlobalBool(SupportDAOFork.Name) && ctx.GlobalBool(TestNetFlag.Name):
- daoForkBlock = params.TestNetDAOForkBlock
case ctx.GlobalBool(SupportDAOFork.Name):
- daoForkBlock = params.MainNetDAOForkBlock
+ config.DAOForkSupport = true
case ctx.GlobalBool(OpposeDAOFork.Name):
- daoForkBlock = nil
- }
- return &core.ChainConfig{
- HomesteadBlock: homesteadBlock,
- DAOForkBlock: daoForkBlock,
+ config.DAOForkSupport = false
}
+ return config
}
// MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.