From 5643dff467a520c80aed8dba6e85e9d4c4fc25b5 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Tue, 2 Feb 2021 12:48:04 -0800 Subject: [PATCH] Give testnet internal node 70% voting power for stuck epochs (#3521) --- consensus/quorum/quorum.go | 5 +++-- consensus/votepower/roster.go | 3 ++- hmy/staking.go | 9 +++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/consensus/quorum/quorum.go b/consensus/quorum/quorum.go index 02e524dc6..128cde267 100644 --- a/consensus/quorum/quorum.go +++ b/consensus/quorum/quorum.go @@ -139,11 +139,12 @@ type Registry struct { Deciders map[string]Decider `json:"quorum-deciders"` ExternalCount int `json:"external-slot-count"` MedianStake numeric.Dec `json:"epos-median-stake"` + Epoch int `json:"epoch"` } // NewRegistry .. -func NewRegistry(extern int) Registry { - return Registry{map[string]Decider{}, extern, numeric.ZeroDec()} +func NewRegistry(extern int, epoch int) Registry { + return Registry{map[string]Decider{}, extern, numeric.ZeroDec(), epoch} } // Transition .. diff --git a/consensus/votepower/roster.go b/consensus/votepower/roster.go index 4f8530e32..736f3ebb8 100644 --- a/consensus/votepower/roster.go +++ b/consensus/votepower/roster.go @@ -184,7 +184,8 @@ func Compute(subComm *shard.Committee, epoch *big.Int) (*Roster, error) { // Testnet incident recovery // Make harmony nodes having 70% voting power for epoch 73314 - if nodeconfig.GetDefaultConfig().GetNetworkType() == nodeconfig.Testnet && epoch.Cmp(big.NewInt(73314)) == 0 { + if nodeconfig.GetDefaultConfig().GetNetworkType() == nodeconfig.Testnet && epoch.Cmp(big.NewInt(73305)) >= 0 && + epoch.Cmp(big.NewInt(73330)) <= 0 { harmonyPercent = numeric.MustNewDecFromStr("0.70") externalPercent = numeric.MustNewDecFromStr("0.30") } diff --git a/hmy/staking.go b/hmy/staking.go index ae094b8bb..d48f1ba92 100644 --- a/hmy/staking.go +++ b/hmy/staking.go @@ -66,6 +66,11 @@ func (hmy *Harmony) readAndUpdateRawStakes( func (hmy *Harmony) getSuperCommittees() (*quorum.Transition, error) { nowE := hmy.BlockChain.CurrentHeader().Epoch() + + if hmy.BlockChain.CurrentHeader().IsLastBlockInEpoch() { + // current epoch is current header epoch + 1 if the header was last block of prev epoch + nowE = new(big.Int).Add(nowE, common.Big1) + } thenE := new(big.Int).Sub(nowE, common.Big1) var ( @@ -86,8 +91,8 @@ func (hmy *Harmony) getSuperCommittees() (*quorum.Transition, error) { shard.ExternalSlotsAvailableForEpoch(thenE) then, now := - quorum.NewRegistry(stakedSlotsThen), - quorum.NewRegistry(stakedSlotsNow) + quorum.NewRegistry(stakedSlotsThen, int(thenE.Int64())), + quorum.NewRegistry(stakedSlotsNow, int(nowE.Int64())) rawStakes := []effective.SlotPurchase{} validatorSpreads := map[common.Address]numeric.Dec{}