Network type.

pull/4389/head
frozen 2 years ago committed by Casey Gardiner
parent 15885f4c9b
commit 5e1878aedc
  1. 3
      cmd/harmony/main.go
  2. 9
      core/genesis_initializer.go
  3. 7
      internal/shardchain/dbinit.go
  4. 12
      internal/shardchain/shardchains.go

@ -700,9 +700,8 @@ func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfi
chainDBFactory = &shardchain.LDBFactory{RootDir: nodeConfig.DBDir} chainDBFactory = &shardchain.LDBFactory{RootDir: nodeConfig.DBDir}
} }
chainConfig := nodeConfig.GetNetworkType().ChainConfig()
collection := shardchain.NewCollection( collection := shardchain.NewCollection(
&hc, chainDBFactory, &core.GenesisInitializer{NetworkType: nodeConfig.GetNetworkType()}, &chainConfig, &hc, chainDBFactory, &core.GenesisInitializer{}, nodeConfig.GetNetworkType(),
) )
for shardID, archival := range nodeConfig.ArchiveModes() { for shardID, archival := range nodeConfig.ArchiveModes() {
if archival { if archival {

@ -13,11 +13,10 @@ import (
// GenesisInitializer is a shardchain.DBInitializer adapter. // GenesisInitializer is a shardchain.DBInitializer adapter.
type GenesisInitializer struct { type GenesisInitializer struct {
NetworkType nodeconfig.NetworkType
} }
// InitChainDB sets up a new genesis block in the database for the given shard. // 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( shardState, _ := committee.WithStakingEnabled.Compute(
big.NewInt(GenesisEpoch), nil, 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}} shardState = &shard.State{Shards: []shard.Committee{*subComm}}
} }
gi.setupGenesisBlock(db, shardID, shardState) gi.setupGenesisBlock(db, shardID, shardState, networkType)
return nil return nil
} }
// SetupGenesisBlock sets up a genesis blockchain. // 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") 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.ShardStateHash = myShardState.Hash()
gspec.ShardState = *myShardState.DeepCopy() gspec.ShardState = *myShardState.DeepCopy()
// Store genesis block into db. // Store genesis block into db.

@ -1,8 +1,11 @@
package shardchain 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. // DBInitializer initializes a newly created chain database.
type DBInitializer interface { type DBInitializer interface {
InitChainDB(db ethdb.Database, shardID uint32) error InitChainDB(db ethdb.Database, networkType nodeconfig.NetworkType, shardID uint32) error
} }

@ -7,6 +7,7 @@ import (
"github.com/harmony-one/harmony/core/state" "github.com/harmony-one/harmony/core/state"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony" 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/internal/shardchain/tikv_manage"
"github.com/harmony-one/harmony/shard" "github.com/harmony-one/harmony/shard"
@ -16,7 +17,6 @@ import (
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/rawdb" "github.com/harmony-one/harmony/core/rawdb"
"github.com/harmony-one/harmony/core/vm" "github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/internal/params"
"github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/internal/utils"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -42,7 +42,7 @@ type CollectionImpl struct {
mtx sync.Mutex mtx sync.Mutex
pool map[uint32]core.BlockChain pool map[uint32]core.BlockChain
disableCache map[uint32]bool disableCache map[uint32]bool
chainConfig *params.ChainConfig networkType nodeconfig.NetworkType
harmonyconfig *harmonyconfig.HarmonyConfig harmonyconfig *harmonyconfig.HarmonyConfig
} }
@ -55,7 +55,7 @@ type CollectionImpl struct {
func NewCollection( func NewCollection(
harmonyconfig *harmonyconfig.HarmonyConfig, harmonyconfig *harmonyconfig.HarmonyConfig,
dbFactory DBFactory, dbInit DBInitializer, dbFactory DBFactory, dbInit DBInitializer,
chainConfig *params.ChainConfig, network nodeconfig.NetworkType,
) *CollectionImpl { ) *CollectionImpl {
return &CollectionImpl{ return &CollectionImpl{
harmonyconfig: harmonyconfig, harmonyconfig: harmonyconfig,
@ -63,7 +63,7 @@ func NewCollection(
dbInit: dbInit, dbInit: dbInit,
pool: make(map[uint32]core.BlockChain), pool: make(map[uint32]core.BlockChain),
disableCache: make(map[uint32]bool), 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(). utils.Logger().Info().
Uint32("shardID", shardID). Uint32("shardID", shardID).
Msg("initializing a new chain database") 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") 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 { 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 // For beacon chain inside a shard chain, need to reset the eth chainID to shard 0's eth chainID in the config

Loading…
Cancel
Save