mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
revert cleanup: harmonize old and new consensus engine creation
This commit is contained in:
parent
c01385e088
commit
20454fc435
2 changed files with 43 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Reference in a new issue