ChainConfigForNetworkType → NetworkType.ChainConfig

Makes the call sites read more naturally.
pull/1939/head
Eugene Kim 5 years ago
parent a30be8fdd8
commit 15f08d6aad
  1. 2
      cmd/harmony/main.go
  2. 13
      internal/configs/node/config.go
  3. 13
      node/node.go

@ -459,7 +459,7 @@ func main() {
os.Exit(1)
}
// Use the number of shards as of staking epoch.
chainConfig := node.ChainConfigForNetworkType(nodeconfig.NetworkType(*networkType))
chainConfig := nodeconfig.NetworkType(*networkType).ChainConfig()
stakingEpochShardConfig := shard.Schedule.InstanceForEpoch(chainConfig.StakingEpoch)
numShardsBig := big.NewInt(int64(stakingEpochShardConfig.NumShards()))
shardIDBig := new(big.Int).Mod(blsPubKey.Big(), numShardsBig)

@ -10,6 +10,8 @@ import (
"github.com/harmony-one/bls/ffi/go/bls"
p2p_crypto "github.com/libp2p/go-libp2p-crypto"
"github.com/harmony-one/harmony/internal/params"
)
// Role defines a role of a node.
@ -241,3 +243,14 @@ func SetPublicRPC(v bool) {
func GetPublicRPC() bool {
return publicRPC
}
func (t NetworkType) ChainConfig() params.ChainConfig {
switch t {
case Mainnet:
return *params.MainnetChainConfig
case Pangaea:
return *params.PangaeaChainConfig
default:
return *params.TestnetChainConfig
}
}

@ -408,7 +408,7 @@ func New(host p2p.Host, consensusObj *consensus.Consensus,
}
networkType := node.NodeConfig.GetNetworkType()
chainConfig := ChainConfigForNetworkType(networkType)
chainConfig := networkType.ChainConfig()
node.chainConfig = chainConfig
collection := shardchain.NewCollection(
@ -483,17 +483,6 @@ func New(host p2p.Host, consensusObj *consensus.Consensus,
return &node
}
func ChainConfigForNetworkType(t nodeconfig.NetworkType) params.ChainConfig {
switch t {
case nodeconfig.Mainnet:
return *params.MainnetChainConfig
case nodeconfig.Pangaea:
return *params.PangaeaChainConfig
default:
return *params.TestnetChainConfig
}
}
// InitConsensusWithValidators initialize shard state from latest epoch and update committee pub
// keys for consensus and drand
func (node *Node) InitConsensusWithValidators() (err error) {

Loading…
Cancel
Save