diff --git a/core/genesis.go b/core/genesis.go index 2fe5a366bc..2339546ef7 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -373,6 +373,40 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen return newcfg, stored, nil } +// LoadChainConfig loads the stored chain config if it is already present in +// database, otherwise, return the config in the provided genesis specification. +// LG: this is replicated for now to satisfy the divergent interfaces between 1.11 and after +func LoadChainConfig(db ethdb.Database, genesis *Genesis) (*params.ChainConfig, error) { + // Load the stored chain config from the database. It can be nil + // in case the database is empty. Notably, we only care about the + // chain config corresponds to the canonical chain. + stored := rawdb.ReadCanonicalHash(db, 0) + if stored != (common.Hash{}) { + storedcfg := rawdb.ReadChainConfig(db, stored) + if storedcfg != nil { + return storedcfg, nil + } + } + // Load the config from the provided genesis specification + if genesis != nil { + // Reject invalid genesis spec without valid chain config + if genesis.Config == nil { + return nil, errGenesisNoConfig + } + // If the canonical genesis header is present, but the chain + // config is missing(initialize the empty leveldb with an + // external ancient chain segment), ensure the provided genesis + // is matched. + if stored != (common.Hash{}) && genesis.ToBlock().Hash() != stored { + return nil, &GenesisMismatchError{stored, genesis.ToBlock().Hash()} + } + return genesis.Config, nil + } + // There is no stored chain config and no new config provided, + // In this case the default chain config(mainnet) will be used + return params.MainnetChainConfig, nil +} + // LoadCliqueConfig loads the stored clique config if the chain config // is already present in database, otherwise, return the config in the // provided genesis specification. Note the returned clique config can diff --git a/eth/backend.go b/eth/backend.go index 0298dd19d7..1aa7212460 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -151,13 +151,20 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { return nil, err } + // Transfer mining-related config to the ethash config. + chainConfig, err := core.LoadChainConfig(chainDb, config.Genesis) + if err != nil { + return nil, err + } + engine := ethconfig.CreateConsensusEngine(stack, ðashConfig, cliqueConfig, config.Miner.Notify, config.Miner.Noverify, chainDb) + if err != nil { + return nil, err + } networkID := config.NetworkId if networkID == 0 { networkID = chainConfig.ChainID.Uint64() } - engine := ethconfig.CreateConsensusEngine(stack, ðashConfig, cliqueConfig, config.Miner.Notify, config.Miner.Noverify, chainDb) - eth := &Ethereum{ config: config, merger: consensus.NewMerger(chainDb),