Testnet reset (#4207)

* Revert "Increase voting power of harmony nodes in testnet to 0.7 (#4200)"
This reverts commit 20edef740b.
* RESET TESTNET
* fix vrf testcase
* reduce number of nodes required for reseting testnet
* use only harmony nodes before staking epoch
pull/4272/head
PeekPI 2 years ago committed by GitHub
parent 309d91f889
commit 914d7da0b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      consensus/quorum/one-node-one-vote.go
  2. 23
      consensus/quorum/one-node-staked-vote.go
  3. 2
      consensus/quorum/one-node-staked-vote_test.go
  4. 4
      consensus/quorum/quorum.go
  5. 13
      consensus/quorum/verifier.go
  6. 2
      consensus/validator.go
  7. 6
      consensus/view_change.go
  8. 2
      consensus/view_change_construct.go
  9. 14
      consensus/votepower/roster.go
  10. 2
      core/genesis.go
  11. 2
      internal/chain/engine.go
  12. 43
      internal/configs/sharding/testnet.go
  13. 44
      internal/params/config.go
  14. 2
      node/node_explorer.go
  15. 2
      staking/verify/verify.go

@ -56,7 +56,7 @@ func (v *uniformVoteWeight) IsQuorumAchieved(p Phase) bool {
}
// IsQuorumAchivedByMask ..
func (v *uniformVoteWeight) IsQuorumAchievedByMask(mask *bls_cosi.Mask, height uint64) bool {
func (v *uniformVoteWeight) IsQuorumAchievedByMask(mask *bls_cosi.Mask) bool {
if mask == nil {
return false
}
@ -74,10 +74,7 @@ func (v *uniformVoteWeight) IsQuorumAchievedByMask(mask *bls_cosi.Mask, height u
}
// QuorumThreshold ..
func (v *uniformVoteWeight) QuorumThreshold(height uint64) numeric.Dec {
if fixed := tryFixedThreshold(height); fixed != nil {
return *fixed
}
func (v *uniformVoteWeight) QuorumThreshold() numeric.Dec {
return numeric.NewDec(v.TwoThirdsSignersCount())
}

@ -9,8 +9,6 @@ import (
"github.com/harmony-one/harmony/internal/utils"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/ethereum/go-ethereum/common"
bls_core "github.com/harmony-one/bls/ffi/go/bls"
"github.com/pkg/errors"
@ -24,18 +22,8 @@ import (
var (
twoThird = numeric.NewDec(2).Quo(numeric.NewDec(3))
// fix testnet temporary
fixedThreshold = numeric.MustNewDecFromStr("0.51")
fixedThresholdHeight = uint64(26481647)
)
func tryFixedThreshold(height uint64) *numeric.Dec {
if nodeconfig.GetDefaultConfig().GetNetworkType() == nodeconfig.Testnet && height >= fixedThresholdHeight {
return &fixedThreshold
}
return nil
}
// TallyResult is the result of when we calculate voting power,
// recall that it happens to us at epoch change
type TallyResult struct {
@ -128,7 +116,7 @@ func (v *stakedVoteWeight) AddNewVote(
}()
tallyQuorum.tally = tallyQuorum.tally.Add(additionalVotePower)
t := v.QuorumThreshold(height)
t := v.QuorumThreshold()
msg := "[AddNewVote] New Vote Added!"
if !tallyQuorum.quorumAchieved {
@ -163,8 +151,8 @@ func (v *stakedVoteWeight) IsQuorumAchieved(p Phase) bool {
}
// IsQuorumAchivedByMask ..
func (v *stakedVoteWeight) IsQuorumAchievedByMask(mask *bls_cosi.Mask, height uint64) bool {
threshold := v.QuorumThreshold(height)
func (v *stakedVoteWeight) IsQuorumAchievedByMask(mask *bls_cosi.Mask) bool {
threshold := v.QuorumThreshold()
if mask == nil {
return false
}
@ -206,10 +194,7 @@ func (v *stakedVoteWeight) computeTotalPowerByMask(mask *bls_cosi.Mask) *numeric
}
// QuorumThreshold ..
func (v *stakedVoteWeight) QuorumThreshold(height uint64) numeric.Dec {
if fixed := tryFixedThreshold(height); fixed != nil {
return *fixed
}
func (v *stakedVoteWeight) QuorumThreshold() numeric.Dec {
return twoThird
}

@ -128,7 +128,7 @@ func TestPolicy(t *testing.T) {
func TestQuorumThreshold(t *testing.T) {
expectedThreshold := numeric.NewDec(2).Quo(numeric.NewDec(3))
quorumThreshold := basicDecider.QuorumThreshold(0)
quorumThreshold := basicDecider.QuorumThreshold()
if !expectedThreshold.Equal(quorumThreshold) {
t.Errorf("Expected: %s, Got: %s", expectedThreshold.String(), quorumThreshold.String())
}

@ -128,8 +128,8 @@ type Decider interface {
height, viewID uint64,
) (*votepower.Ballot, error)
IsQuorumAchieved(Phase) bool
IsQuorumAchievedByMask(mask *bls_cosi.Mask, height uint64) bool
QuorumThreshold(height uint64) numeric.Dec
IsQuorumAchievedByMask(mask *bls_cosi.Mask) bool
QuorumThreshold() numeric.Dec
AmIMemberOfCommitee() bool
IsAllSigsCollected() bool
ResetPrepareAndCommitVotes()

@ -13,7 +13,7 @@ import (
// Verifier is the interface to verify the whether the quorum is achieved by mask at each epoch.
// TODO: Add some unit tests to make sure Verifier get exactly the same result as Decider
type Verifier interface {
IsQuorumAchievedByMask(mask *bls_cosi.Mask, height uint64) bool
IsQuorumAchievedByMask(mask *bls_cosi.Mask) bool
}
// NewVerifier creates the quorum verifier for the given committee, epoch and whether the scenario
@ -43,18 +43,15 @@ func newStakeVerifier(committee *shard.Committee, epoch *big.Int) (*stakeVerifie
}
// IsQuorumAchievedByMask returns whether the quorum is achieved with the provided mask
func (sv *stakeVerifier) IsQuorumAchievedByMask(mask *bls_cosi.Mask, height uint64) bool {
func (sv *stakeVerifier) IsQuorumAchievedByMask(mask *bls_cosi.Mask) bool {
if mask == nil {
return false
}
vp := sv.r.VotePowerByMask(mask)
return vp.GT(sv.threshold(height))
return vp.GT(sv.threshold())
}
func (sv *stakeVerifier) threshold(height uint64) numeric.Dec {
if fixed := tryFixedThreshold(height); fixed != nil {
return *fixed
}
func (sv *stakeVerifier) threshold() numeric.Dec {
return twoThird
}
@ -75,7 +72,7 @@ func newUniformVerifier(committee *shard.Committee) (*uniformVerifier, error) {
// IsQuorumAchievedByMask returns whether the quorum is achieved with the provided mask,
// which is whether more than (2/3+1) nodes is included in mask.
func (uv *uniformVerifier) IsQuorumAchievedByMask(mask *bls_cosi.Mask, height uint64) bool {
func (uv *uniformVerifier) IsQuorumAchievedByMask(mask *bls_cosi.Mask) bool {
got := int64(len(mask.Publics))
exp := uv.thresholdKeyCount()
// Theoretically speaking, greater or equal will do the work. But current logic is more strict

@ -214,7 +214,7 @@ func (consensus *Consensus) onPrepared(recvMsg *FBFTMessage) {
consensus.getLogger().Error().Err(err).Msg("ReadSignatureBitmapPayload failed!")
return
}
if !consensus.Decider.IsQuorumAchievedByMask(mask, recvMsg.BlockNum) {
if !consensus.Decider.IsQuorumAchievedByMask(mask) {
consensus.getLogger().Warn().Msgf("[OnPrepared] Quorum Not achieved.")
return
}

@ -386,7 +386,7 @@ func (consensus *Consensus) onViewChange(recvMsg *FBFTMessage) {
return
}
if consensus.Decider.IsQuorumAchievedByMask(consensus.vc.GetViewIDBitmap(recvMsg.ViewID), recvMsg.BlockNum) {
if consensus.Decider.IsQuorumAchievedByMask(consensus.vc.GetViewIDBitmap(recvMsg.ViewID)) {
consensus.getLogger().Info().
Int64("have", consensus.Decider.SignersCount(quorum.ViewChange)).
Int64("need", consensus.Decider.TwoThirdsSignersCount()).
@ -428,7 +428,7 @@ func (consensus *Consensus) onViewChange(recvMsg *FBFTMessage) {
}
// received enough view change messages, change state to normal consensus
if consensus.Decider.IsQuorumAchievedByMask(consensus.vc.GetViewIDBitmap(recvMsg.ViewID), recvMsg.BlockNum) && consensus.IsViewChangingMode() {
if consensus.Decider.IsQuorumAchievedByMask(consensus.vc.GetViewIDBitmap(recvMsg.ViewID)) && consensus.IsViewChangingMode() {
// no previous prepared message, go straight to normal mode
// and start proposing new block
if consensus.vc.IsM1PayloadEmpty() {
@ -498,7 +498,7 @@ func (consensus *Consensus) onNewView(recvMsg *FBFTMessage) {
}
m3Mask := recvMsg.M3Bitmap
if !consensus.Decider.IsQuorumAchievedByMask(m3Mask, recvMsg.BlockNum) {
if !consensus.Decider.IsQuorumAchievedByMask(m3Mask) {
consensus.getLogger().Warn().
Msgf("[onNewView] Quorum Not achieved")
return

@ -274,7 +274,7 @@ func (vc *viewChange) ProcessViewChangeMsg(
return err
}
if !decider.IsQuorumAchievedByMask(mask, recvMsg.BlockNum) {
if !decider.IsQuorumAchievedByMask(mask) {
return errNoQuorum
}

@ -7,8 +7,6 @@ import (
"math/big"
"sort"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/harmony-one/harmony/shard"
"github.com/ethereum/go-ethereum/common"
@ -183,14 +181,6 @@ func Compute(subComm *shard.Committee, epoch *big.Int) (*Roster, error) {
harmonyPercent := shard.Schedule.InstanceForEpoch(epoch).HarmonyVotePercent()
externalPercent := shard.Schedule.InstanceForEpoch(epoch).ExternalVotePercent()
// Testnet incident recovery
// Make harmony nodes having 70% voting power for epoch 73314
if nodeconfig.GetDefaultConfig().GetNetworkType() == nodeconfig.Testnet && epoch.Cmp(big.NewInt(73305)) >= 0 &&
epoch.Cmp(big.NewInt(73490)) <= 0 {
harmonyPercent = numeric.MustNewDecFromStr("0.70")
externalPercent = numeric.MustNewDecFromStr("0.40") // Make sure consensus is always good.
}
for i := range staked {
member := AccommodateHarmonyVote{
PureStakedVote: PureStakedVote{
@ -225,9 +215,7 @@ func Compute(subComm *shard.Committee, epoch *big.Int) (*Roster, error) {
}
}
if !(nodeconfig.GetDefaultConfig().GetNetworkType() == nodeconfig.Testnet && epoch.Cmp(big.NewInt(73305)) >= 0 &&
epoch.Cmp(big.NewInt(73490)) <= 0) {
{
// NOTE Enforce voting power sums to one,
// give diff (expect tiny amt) to last staked voter
if diff := numeric.OneDec().Sub(

@ -105,6 +105,8 @@ func NewGenesisSpec(netType nodeconfig.NetworkType, shardID uint32) *Genesis {
foundationAddress := common.HexToAddress("0xE25ABC3f7C3d5fB7FB81EAFd421FF1621A61107c")
genesisAlloc[foundationAddress] = GenesisAccount{Balance: GenesisFund}
}
case nodeconfig.Testnet:
chainConfig = *params.TestnetChainConfig
case nodeconfig.Pangaea:
chainConfig = *params.PangaeaChainConfig
case nodeconfig.Partner:

@ -585,7 +585,7 @@ func (e *engineImpl) verifySignature(chain engine.ChainReader, pas payloadArgs,
if err != nil {
return errors.Wrap(err, "deserialize signature and bitmap")
}
if !qrVerifier.IsQuorumAchievedByMask(mask, pas.number) {
if !qrVerifier.IsQuorumAchievedByMask(mask) {
return errors.New("not enough signature collected")
}
commitPayload := pas.constructPayload(chain)

@ -27,40 +27,11 @@ const (
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
)
var (
harmonyVotePercentFix = numeric.MustNewDecFromStr("0.70")
// testnet failed to propose the last block of epoch 75893.
// it stopped at 26481646, and last block of epoch 75893 is 26481647.
harmonyVotePercentFixEpoch = big.NewInt(75894)
)
// isForked returns whether a fork scheduled at epoch s is active at the given head epoch.
func isForked(s, epoch *big.Int) bool {
if s == nil || epoch == nil {
return false
}
return s.Cmp(epoch) <= 0
}
func (ts testnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
switch {
case isForked(harmonyVotePercentFixEpoch, epoch):
return testnetV3_4
case params.TestnetChainConfig.IsAllowlistEpoch(epoch):
return testnetV3_3
case params.TestnetChainConfig.IsSlotsLimited(epoch):
return testnetV3_2
case params.TestnetChainConfig.IsSixtyPercent(epoch):
return testnetV3_1
case params.TestnetChainConfig.IsTwoSeconds(epoch):
return testnetV3
case epoch.Cmp(big.NewInt(testnetV2Epoch)) >= 0:
return testnetV2
case epoch.Cmp(params.TestnetChainConfig.StakingEpoch) >= 0:
case params.TestnetChainConfig.IsStaking(epoch):
return testnetV1
default: // genesis
return testnetV0
@ -135,11 +106,7 @@ var testnetReshardingEpoch = []*big.Int{
params.TestnetChainConfig.TwoSecondsEpoch,
}
var testnetV0 = MustNewInstance(4, 16, 15, 0, numeric.OneDec(), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, emptyAllowlist, testnetReshardingEpoch, TestnetSchedule.BlocksPerEpochOld())
var testnetV1 = MustNewInstance(4, 20, 15, 0, numeric.MustNewDecFromStr("0.90"), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, emptyAllowlist, testnetReshardingEpoch, TestnetSchedule.BlocksPerEpochOld())
var testnetV2 = MustNewInstance(4, 30, 8, 0, numeric.MustNewDecFromStr("0.90"), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, emptyAllowlist, testnetReshardingEpoch, TestnetSchedule.BlocksPerEpochOld())
var testnetV3 = MustNewInstance(4, 30, 8, 0, numeric.MustNewDecFromStr("0.90"), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, emptyAllowlist, testnetReshardingEpoch, TestnetSchedule.BlocksPerEpoch())
var testnetV3_1 = MustNewInstance(4, 30, 8, 0, numeric.MustNewDecFromStr("0.60"), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, emptyAllowlist, testnetReshardingEpoch, TestnetSchedule.BlocksPerEpoch())
var testnetV3_2 = MustNewInstance(4, 30, 8, 0.15, numeric.MustNewDecFromStr("0.60"), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, emptyAllowlist, testnetReshardingEpoch, TestnetSchedule.BlocksPerEpoch())
var testnetV3_3 = MustNewInstance(4, 30, 8, 0.15, numeric.MustNewDecFromStr("0.60"), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, testnetAllowlistV3_3, testnetReshardingEpoch, TestnetSchedule.BlocksPerEpoch())
var testnetV3_4 = MustNewInstance(4, 30, 8, 0.15, harmonyVotePercentFix, genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, testnetAllowlistV3_3, testnetReshardingEpoch, TestnetSchedule.BlocksPerEpoch())
var (
testnetV0 = MustNewInstance(4, 8, 8, 0, numeric.OneDec(), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, emptyAllowlist, testnetReshardingEpoch, TestnetSchedule.BlocksPerEpoch())
testnetV1 = MustNewInstance(4, 30, 8, 0.15, numeric.MustNewDecFromStr("0.70"), genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, emptyAllowlist, testnetReshardingEpoch, TestnetSchedule.BlocksPerEpoch())
)

@ -76,36 +76,36 @@ var (
ChainID: TestnetChainID,
EthCompatibleChainID: EthTestnetShard0ChainID,
EthCompatibleShard0ChainID: EthTestnetShard0ChainID,
EthCompatibleEpoch: big.NewInt(73290),
EthCompatibleEpoch: big.NewInt(0),
CrossTxEpoch: big.NewInt(0),
CrossLinkEpoch: big.NewInt(2),
AggregatedRewardEpoch: big.NewInt(74275),
AggregatedRewardEpoch: big.NewInt(2),
StakingEpoch: big.NewInt(2),
PreStakingEpoch: big.NewInt(1),
QuickUnlockEpoch: big.NewInt(0),
FiveSecondsEpoch: big.NewInt(16500),
TwoSecondsEpoch: big.NewInt(73000),
SixtyPercentEpoch: big.NewInt(73282),
RedelegationEpoch: big.NewInt(36500),
NoEarlyUnlockEpoch: big.NewInt(73580),
VRFEpoch: big.NewInt(73880),
PrevVRFEpoch: big.NewInt(74384),
MinDelegation100Epoch: big.NewInt(73880),
MinCommissionRateEpoch: big.NewInt(73880),
MinCommissionPromoPeriod: big.NewInt(10),
EPoSBound35Epoch: big.NewInt(73880),
FiveSecondsEpoch: big.NewInt(0),
TwoSecondsEpoch: big.NewInt(2),
SixtyPercentEpoch: big.NewInt(2),
RedelegationEpoch: big.NewInt(2),
NoEarlyUnlockEpoch: big.NewInt(2),
VRFEpoch: big.NewInt(2),
PrevVRFEpoch: big.NewInt(2),
MinDelegation100Epoch: big.NewInt(2),
MinCommissionRateEpoch: big.NewInt(2),
MinCommissionPromoPeriod: big.NewInt(2),
EPoSBound35Epoch: big.NewInt(2),
EIP155Epoch: big.NewInt(0),
S3Epoch: big.NewInt(0),
DataCopyFixEpoch: big.NewInt(74412),
IstanbulEpoch: big.NewInt(43800),
DataCopyFixEpoch: big.NewInt(0),
IstanbulEpoch: big.NewInt(0),
ReceiptLogEpoch: big.NewInt(0),
SHA3Epoch: big.NewInt(74570),
HIP6And8Epoch: big.NewInt(74570),
StakingPrecompileEpoch: big.NewInt(75175),
SlotsLimitedEpoch: big.NewInt(75684), // epoch to enable HIP-16, around Mon, 02 May 2022 08:18:45 UTC with 2s block time
ChainIdFixEpoch: big.NewInt(75907), // around Wed, 15 Jun 2022 22:58:03 GMT with average block time 2.0065s
CrossShardXferPrecompileEpoch: big.NewInt(75907), // around Wed, 15 Jun 2022 22:58:03 GMT with average block time 2.0065s
AllowlistEpoch: big.NewInt(75907), // around Wed, 15 Jun 2022 22:58:03 GMT with average block time 2.0065s
SHA3Epoch: big.NewInt(0),
HIP6And8Epoch: big.NewInt(2),
StakingPrecompileEpoch: big.NewInt(2),
SlotsLimitedEpoch: big.NewInt(2),
ChainIdFixEpoch: big.NewInt(0),
CrossShardXferPrecompileEpoch: big.NewInt(2),
AllowlistEpoch: big.NewInt(2),
}
// PangaeaChainConfig contains the chain parameters for the Pangaea network.

@ -53,7 +53,7 @@ func (node *Node) explorerMessageHandler(ctx context.Context, msg *msg_pb.Messag
return err
}
if !node.Consensus.Decider.IsQuorumAchievedByMask(mask, recvMsg.BlockNum) {
if !node.Consensus.Decider.IsQuorumAchievedByMask(mask) {
utils.Logger().Error().Msg("[Explorer] not have enough signature power")
return nil
}

@ -41,7 +41,7 @@ func AggregateSigForCommittee(
return err
}
if !decider.IsQuorumAchievedByMask(mask, blockNum) {
if !decider.IsQuorumAchievedByMask(mask) {
return errQuorumVerifyAggSign
}

Loading…
Cancel
Save