package shardingconfig import ( "math/big" "github.com/harmony-one/harmony/internal/genesis" "github.com/harmony-one/harmony/internal/params" "github.com/harmony-one/harmony/numeric" ) // TestnetSchedule is the long-running public testnet sharding // configuration schedule. var TestnetSchedule testnetSchedule type testnetSchedule struct{} const ( // ~304 sec epochs for P2 of open staking testnetBlocksPerEpoch = 38 testnetVdfDifficulty = 10000 // This takes about 20s to finish the vdf // TestNetHTTPPattern is the http pattern for testnet. TestNetHTTPPattern = "https://api.s%d.b.hmny.io" // TestNetWSPattern is the websocket pattern for testnet. TestNetWSPattern = "wss://ws.s%d.b.hmny.io" testnetV2Epoch = 6050 // per shard, reduce internal node from 15 to 8, and external nodes from 5 to 22 ) func (ts testnetSchedule) InstanceForEpoch(epoch *big.Int) Instance { switch { case epoch.Cmp(big.NewInt(testnetV2Epoch)) >= 0: return testnetV2 case epoch.Cmp(params.TestnetChainConfig.StakingEpoch) >= 0: return testnetV1 default: // genesis return testnetV0 } } func (ts testnetSchedule) BlocksPerEpoch() uint64 { return testnetBlocksPerEpoch } func (ts testnetSchedule) CalcEpochNumber(blockNum uint64) *big.Int { epoch := blockNum / ts.BlocksPerEpoch() return big.NewInt(int64(epoch)) } func (ts testnetSchedule) IsLastBlock(blockNum uint64) bool { return (blockNum+1)%ts.BlocksPerEpoch() == 0 } func (ts testnetSchedule) EpochLastBlock(epochNum uint64) uint64 { return ts.BlocksPerEpoch()*(epochNum+1) - 1 } func (ts testnetSchedule) VdfDifficulty() int { return testnetVdfDifficulty } // ConsensusRatio ratio of new nodes vs consensus total nodes func (ts testnetSchedule) ConsensusRatio() float64 { return mainnetConsensusRatio } // TODO: remove it after randomness feature turned on mainnet //RandonnessStartingEpoch returns starting epoch of randonness generation func (ts testnetSchedule) RandomnessStartingEpoch() uint64 { return mainnetRandomnessStartingEpoch } func (ts testnetSchedule) GetNetworkID() NetworkID { return TestNet } // GetShardingStructure is the sharding structure for testnet. func (ts testnetSchedule) GetShardingStructure(numShard, shardID int) []map[string]interface{} { return genShardingStructure(numShard, shardID, TestNetHTTPPattern, TestNetWSPattern) } // IsSkippedEpoch returns if an epoch was skipped on shard due to staking epoch func (ts testnetSchedule) IsSkippedEpoch(shardID uint32, epoch *big.Int) bool { return false } var testnetReshardingEpoch = []*big.Int{ big.NewInt(0), params.TestnetChainConfig.StakingEpoch, } var testnetV0 = MustNewInstance(4, 16, 15, numeric.OneDec(), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, testnetReshardingEpoch, TestnetSchedule.BlocksPerEpoch()) var testnetV1 = MustNewInstance(4, 20, 15, numeric.MustNewDecFromStr("0.90"), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, testnetReshardingEpoch, TestnetSchedule.BlocksPerEpoch()) var testnetV2 = MustNewInstance(4, 30, 8, numeric.MustNewDecFromStr("0.90"), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, testnetReshardingEpoch, TestnetSchedule.BlocksPerEpoch())