Add partner config

* Add partner config to main.go
* Add partner config internals
* Refactor and add partner logic to genesis node
pull/2453/head
Daniel Van Der Maden 5 years ago
parent 304cf10007
commit 6d9a2e39a0
  1. 1
      block/factory/factory.go
  2. 2
      cmd/harmony/main.go
  3. 3
      internal/configs/node/config.go
  4. 2
      internal/configs/node/group.go
  5. 1
      internal/configs/sharding/instance.go
  6. 84
      internal/configs/sharding/partner.go
  7. 12
      internal/params/config.go
  8. 2
      internal/wallet/configfile.go
  9. 15
      node/node_genesis.go

@ -49,6 +49,7 @@ var (
ForTestnet = NewFactory(params.TestnetChainConfig)
ForMainnet = NewFactory(params.MainnetChainConfig)
ForPangaea = NewFactory(params.PangaeaChainConfig)
ForPartner = NewFactory(params.PartnerChainConfig)
)
// NewTestHeader creates a new, empty header object for epoch 0 using the test

@ -613,6 +613,8 @@ func main() {
shard.Schedule = shardingconfig.PangaeaSchedule
case nodeconfig.Localnet:
shard.Schedule = shardingconfig.LocalnetSchedule
case nodeconfig.Partner:
shard.Schedule = shardingconfig.PartnerSchedule
case nodeconfig.Devnet:
if *devnetHarmonySize < 0 {
*devnetHarmonySize = *devnetShardSize

@ -54,6 +54,7 @@ const (
Mainnet = "mainnet"
Testnet = "testnet"
Pangaea = "pangaea"
Partner = "partner"
Devnet = "devnet"
Localnet = "localnet"
)
@ -320,6 +321,8 @@ func (t NetworkType) ChainConfig() params.ChainConfig {
return *params.MainnetChainConfig
case Pangaea:
return *params.PangaeaChainConfig
case Partner:
return *params.PartnerChainConfig
case Localnet:
return *params.LocalnetChainConfig
default:

@ -41,6 +41,8 @@ func getNetworkPrefix(shardID ShardID) (netPre string) {
netPre = "hmy/testnet"
case Pangaea:
netPre = "hmy/pangaea"
case Partner:
netPre = "hmy/partner"
case Devnet:
netPre = "hmy/devnet"
case Localnet:

@ -16,6 +16,7 @@ const (
TestNet
LocalNet
Pangaea
Partner
DevNet
)

@ -0,0 +1,84 @@
package shardingconfig
import (
"math/big"
"github.com/harmony-one/harmony/internal/genesis"
"github.com/harmony-one/harmony/internal/params"
)
// PartnerSchedule is the long-running public partner sharding
// configuration schedule.
var PartnerSchedule partnerSchedule
type partnerSchedule struct{}
const (
// 10 minutes per epoch (at 8s/block)
partnerBlocksPerEpoch = 75
partnerVdfDifficulty = 10000 // This takes about 20s to finish the vdf
// PartnerHTTPPattern is the http pattern for partner.
PartnerHTTPPattern = "https://api.s%d.ps.hmny.io"
// PartnerWSPattern is the websocket pattern for partner.
PartnerWSPattern = "wss://ws.s%d.ps.hmny.io"
)
func (partnerSchedule) InstanceForEpoch(epoch *big.Int) Instance {
switch {
case epoch.Cmp(params.PartnerChainConfig.StakingEpoch) >= 0:
return partnerV1
default: // genesis
return partnerV0
}
}
func (partnerSchedule) BlocksPerEpoch() uint64 {
return partnerBlocksPerEpoch
}
func (ts partnerSchedule) CalcEpochNumber(blockNum uint64) *big.Int {
epoch := blockNum / ts.BlocksPerEpoch()
return big.NewInt(int64(epoch))
}
func (ts partnerSchedule) IsLastBlock(blockNum uint64) bool {
return (blockNum+1)%ts.BlocksPerEpoch() == 0
}
func (ts partnerSchedule) EpochLastBlock(epochNum uint64) uint64 {
return ts.BlocksPerEpoch()*(epochNum+1) - 1
}
func (ts partnerSchedule) VdfDifficulty() int {
return partnerVdfDifficulty
}
// ConsensusRatio ratio of new nodes vs consensus total nodes
func (ts partnerSchedule) ConsensusRatio() float64 {
return mainnetConsensusRatio
}
// TODO: remove it after randomness feature turned on mainnet
//RandonnessStartingEpoch returns starting epoch of randonness generation
func (ts partnerSchedule) RandomnessStartingEpoch() uint64 {
return mainnetRandomnessStartingEpoch
}
func (ts partnerSchedule) GetNetworkID() NetworkID {
return Partner
}
// GetShardingStructure is the sharding structure for partner.
func (ts partnerSchedule) GetShardingStructure(numShard, shardID int) []map[string]interface{} {
return genShardingStructure(numShard, shardID, PartnerHTTPPattern, PartnerWSPattern)
}
var partnerReshardingEpoch = []*big.Int{
big.NewInt(0),
params.TestnetChainConfig.StakingEpoch,
}
var partnerV0 = MustNewInstance(2, 10, 10, genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, partnerReshardingEpoch, PartnerSchedule.BlocksPerEpoch())
var partnerV1 = MustNewInstance(2, 20, 10, genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, partnerReshardingEpoch, PartnerSchedule.BlocksPerEpoch())

@ -12,6 +12,7 @@ var (
MainnetChainID = big.NewInt(1)
TestnetChainID = big.NewInt(2)
PangaeaChainID = big.NewInt(3)
PartnerChainID = big.NewInt(4)
TestChainID = big.NewInt(99) // not a real network
AllProtocolChangesChainID = big.NewInt(100) // not a real network
)
@ -58,6 +59,17 @@ var (
ReceiptLogEpoch: big.NewInt(0),
}
PartnerChainConfig = &ChainConfig{
ChainID: PartnerChainID,
CrossTxEpoch: big.NewInt(0),
CrossLinkEpoch: big.NewInt(2),
StakingEpoch: big.NewInt(2),
PreStakingEpoch: big.NewInt(1),
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
ReceiptLogEpoch: big.NewInt(0),
}
// LocalnetChainConfig contains the chain parameters to run for local development.
LocalnetChainConfig = &ChainConfig{
ChainID: TestnetChainID,

@ -58,6 +58,8 @@ func ReadProfile(iniBytes []byte, profile string) (*Profile, error) {
config.ChainID = params.MainnetChainID.String()
case "pangaea":
config.ChainID = params.PangaeaChainID.String()
case "partner":
config.ChainID = params.PartnerChainID.String()
default:
config.ChainID = params.TestnetChainID.String()
}

@ -74,10 +74,12 @@ func (node *Node) SetupGenesisBlock(db ethdb.Database, shardID uint32, myShardSt
// Initialize genesis block and blockchain
genesisAlloc := make(core.GenesisAlloc)
chainConfig := *params.TestnetChainConfig
chainConfig := params.ChainConfig{}
gasLimit := params.GenesisGasLimit
switch node.NodeConfig.GetNetworkType() {
netType := node.NodeConfig.GetNetworkType()
switch netType {
case nodeconfig.Mainnet:
chainConfig = *params.MainnetChainConfig
if shardID == 0 {
@ -86,9 +88,14 @@ func (node *Node) SetupGenesisBlock(db ethdb.Database, shardID uint32, myShardSt
}
case nodeconfig.Pangaea:
chainConfig = *params.PangaeaChainConfig
fallthrough // the rest is the same as testnet
case nodeconfig.Partner:
chainConfig = *params.PartnerChainConfig
default: // all other types share testnet config
// Test accounts
chainConfig = *params.TestChainConfig
}
// All non-mainnet chains get test accounts
if netType != nodeconfig.Mainnet {
node.AddTestingAddresses(genesisAlloc, TestAccountNumber)
gasLimit = params.TestGenesisGasLimit
// Smart contract deployer account used to deploy initial smart contract

Loading…
Cancel
Save