diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index d13ba266e..afffa1f3c 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -700,9 +700,8 @@ func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfi chainDBFactory = &shardchain.LDBFactory{RootDir: nodeConfig.DBDir} } - chainConfig := nodeConfig.GetNetworkType().ChainConfig() collection := shardchain.NewCollection( - &hc, chainDBFactory, &core.GenesisInitializer{NetworkType: nodeConfig.GetNetworkType()}, &chainConfig, + &hc, chainDBFactory, &core.GenesisInitializer{}, nodeConfig.GetNetworkType(), ) for shardID, archival := range nodeConfig.ArchiveModes() { if archival { diff --git a/core/genesis_initializer.go b/core/genesis_initializer.go index 04c6c85ed..87ddd5fff 100644 --- a/core/genesis_initializer.go +++ b/core/genesis_initializer.go @@ -13,11 +13,10 @@ import ( // GenesisInitializer is a shardchain.DBInitializer adapter. type GenesisInitializer struct { - NetworkType nodeconfig.NetworkType } // InitChainDB sets up a new genesis block in the database for the given shard. -func (gi *GenesisInitializer) InitChainDB(db ethdb.Database, shardID uint32) error { +func (gi *GenesisInitializer) InitChainDB(db ethdb.Database, networkType nodeconfig.NetworkType, shardID uint32) error { shardState, _ := committee.WithStakingEnabled.Compute( big.NewInt(GenesisEpoch), nil, ) @@ -34,14 +33,14 @@ func (gi *GenesisInitializer) InitChainDB(db ethdb.Database, shardID uint32) err } shardState = &shard.State{Shards: []shard.Committee{*subComm}} } - gi.setupGenesisBlock(db, shardID, shardState) + gi.setupGenesisBlock(db, shardID, shardState, networkType) return nil } // SetupGenesisBlock sets up a genesis blockchain. -func (gi *GenesisInitializer) setupGenesisBlock(db ethdb.Database, shardID uint32, myShardState *shard.State) { +func (gi *GenesisInitializer) setupGenesisBlock(db ethdb.Database, shardID uint32, myShardState *shard.State, networkType nodeconfig.NetworkType) { utils.Logger().Info().Interface("shardID", shardID).Msg("setting up a brand new chain database") - gspec := NewGenesisSpec(gi.NetworkType, shardID) + gspec := NewGenesisSpec(networkType, shardID) gspec.ShardStateHash = myShardState.Hash() gspec.ShardState = *myShardState.DeepCopy() // Store genesis block into db. diff --git a/internal/shardchain/dbinit.go b/internal/shardchain/dbinit.go index 4987a7886..b7b5d9e38 100644 --- a/internal/shardchain/dbinit.go +++ b/internal/shardchain/dbinit.go @@ -1,8 +1,11 @@ package shardchain -import "github.com/ethereum/go-ethereum/ethdb" +import ( + "github.com/ethereum/go-ethereum/ethdb" + nodeconfig "github.com/harmony-one/harmony/internal/configs/node" +) // DBInitializer initializes a newly created chain database. type DBInitializer interface { - InitChainDB(db ethdb.Database, shardID uint32) error + InitChainDB(db ethdb.Database, networkType nodeconfig.NetworkType, shardID uint32) error } diff --git a/internal/shardchain/shardchains.go b/internal/shardchain/shardchains.go index a0f0e40ea..957ba9150 100644 --- a/internal/shardchain/shardchains.go +++ b/internal/shardchain/shardchains.go @@ -7,6 +7,7 @@ import ( "github.com/harmony-one/harmony/core/state" harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony" + nodeconfig "github.com/harmony-one/harmony/internal/configs/node" "github.com/harmony-one/harmony/internal/shardchain/tikv_manage" "github.com/harmony-one/harmony/shard" @@ -16,7 +17,6 @@ import ( "github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core/rawdb" "github.com/harmony-one/harmony/core/vm" - "github.com/harmony-one/harmony/internal/params" "github.com/harmony-one/harmony/internal/utils" "github.com/pkg/errors" ) @@ -42,7 +42,7 @@ type CollectionImpl struct { mtx sync.Mutex pool map[uint32]core.BlockChain disableCache map[uint32]bool - chainConfig *params.ChainConfig + networkType nodeconfig.NetworkType harmonyconfig *harmonyconfig.HarmonyConfig } @@ -55,7 +55,7 @@ type CollectionImpl struct { func NewCollection( harmonyconfig *harmonyconfig.HarmonyConfig, dbFactory DBFactory, dbInit DBInitializer, - chainConfig *params.ChainConfig, + network nodeconfig.NetworkType, ) *CollectionImpl { return &CollectionImpl{ harmonyconfig: harmonyconfig, @@ -63,7 +63,7 @@ func NewCollection( dbInit: dbInit, pool: make(map[uint32]core.BlockChain), disableCache: make(map[uint32]bool), - chainConfig: chainConfig, + networkType: network, } } @@ -92,7 +92,7 @@ func (sc *CollectionImpl) ShardChain(shardID uint32, options ...core.Options) (c utils.Logger().Info(). Uint32("shardID", shardID). Msg("initializing a new chain database") - if err := sc.dbInit.InitChainDB(db, shardID); err != nil { + if err := sc.dbInit.InitChainDB(db, sc.networkType, shardID); err != nil { return nil, errors.Wrapf(err, "cannot initialize a new chain database") } } @@ -113,7 +113,7 @@ func (sc *CollectionImpl) ShardChain(shardID uint32, options ...core.Options) (c } } - chainConfig := *sc.chainConfig + chainConfig := sc.networkType.ChainConfig() if shardID == shard.BeaconChainShardID { // For beacon chain inside a shard chain, need to reset the eth chainID to shard 0's eth chainID in the config