From a96a211bbb537169869eb23403effca5e47e8469 Mon Sep 17 00:00:00 2001 From: Shane Bammel Date: Mon, 3 Oct 2022 22:19:05 -0500 Subject: [PATCH] Add support for PulseChain genesis --- core/genesis.go | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index d46471c4f..78c9af199 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -280,16 +280,25 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g } return genesis.Config, block.Hash(), nil } + // Assume mainnet chainId first + chainId := params.MainnetChainConfig.ChainID.Uint64() + // Note: The `genesis` argument will be one of: + // - nil: if running without the `init` command and without providing a network flag (--pulsechain, --ropsten, etc..) + // - defaulted: when a network flag is provided (--pulsechain, --ropsten, etc..), genesis will hold the defaults + // - custom: if running with the `init` command supplying a custom genesis.json file, genesis will hold the file contents // Check whether the genesis block is already written. if genesis != nil { applyOverrides(genesis.Config) + if genesis.Config.ChainID != nil { + chainId = genesis.Config.ChainID.Uint64() + } hash := genesis.ToBlock().Hash() if hash != stored { return genesis.Config, hash, &GenesisMismatchError{stored, hash} } } // Get the existing chain configuration. - newcfg := genesis.configOrDefault(stored) + newcfg := genesis.configOrDefault(stored, chainId) applyOverrides(newcfg) if err := newcfg.CheckConfigForkOrder(); err != nil { return newcfg, common.Hash{}, err @@ -306,7 +315,10 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g // chain config as that would be AllProtocolChanges (applying any new fork // on top of an existing private network genesis block). In that case, only // apply the overrides. - if genesis == nil && stored != params.MainnetGenesisHash { + // Added: support custom config for PrimordialPulse fork with mainnet genesis + // and non-standard chain id. + if genesis == nil && (storedcfg.PrimordialPulseBlock != nil || + stored != params.MainnetGenesisHash) { newcfg = storedcfg applyOverrides(newcfg) } @@ -360,12 +372,19 @@ func LoadChainConfig(db ethdb.Database, genesis *Genesis) (*params.ChainConfig, return params.MainnetChainConfig, nil } -func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig { +func (g *Genesis) configOrDefault(ghash common.Hash, chainId uint64) *params.ChainConfig { switch { case g != nil: return g.Config case ghash == params.MainnetGenesisHash: - return params.MainnetChainConfig + switch chainId { + case params.PulseChainConfig.ChainID.Uint64(): + return params.PulseChainConfig + case params.PulseChainTestnetConfig.ChainID.Uint64(): + return params.PulseChainTestnetConfig + default: + return params.MainnetChainConfig + } case ghash == params.HoleskyGenesisHash: return params.HoleskyChainConfig case ghash == params.SepoliaGenesisHash: