Skip to content

Commit 366fce0

Browse files
add hardfork epoch to use GT for check Quorum in uniformVoteWeight
1 parent 5cef50c commit 366fce0

11 files changed

+27
-24
lines changed

cmd/harmony/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,8 @@ func setupChain(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfig.ConfigTyp
705705
}
706706

707707
func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfig.ConfigType, registry *registry.Registry) *node.Node {
708-
decider := quorum.NewDecider(quorum.SuperMajorityVote, uint32(hc.General.ShardID))
708+
useGT := registry.GetBlockchain().Config().IsLeaderRotationV2Epoch(registry.GetBlockchain().CurrentBlock().Epoch())
709+
decider := quorum.NewDecider(quorum.SuperMajorityVote, uint32(hc.General.ShardID), useGT)
709710

710711
// Parse minPeers from harmonyconfig.HarmonyConfig
711712
var minPeers int

consensus/consensus_service.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ func (consensus *Consensus) updateConsensusInformation(reason string) Mode {
373373

374374
// Only happens once, the flip-over to a new Decider policy
375375
if isFirstTimeStaking || haventUpdatedDecider {
376-
decider := quorum.NewDecider(quorum.SuperMajorityStake, consensus.ShardID)
376+
useGT := consensus.Blockchain().Config().IsLeaderRotationV2Epoch(consensus.Blockchain().CurrentBlock().Epoch())
377+
decider := quorum.NewDecider(quorum.SuperMajorityStake, consensus.ShardID, useGT)
377378
consensus.decider = decider
378379
}
379380

consensus/consensus_service_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestSignAndMarshalConsensusMessage(t *testing.T) {
2626
if err != nil {
2727
t.Fatalf("newhost failure: %v", err)
2828
}
29-
decider := quorum.NewDecider(quorum.SuperMajorityVote, shard.BeaconChainShardID)
29+
decider := quorum.NewDecider(quorum.SuperMajorityVote, shard.BeaconChainShardID, false)
3030
blsPriKey := bls.RandPrivateKey()
3131
reg := registry.New()
3232
consensus, err := New(host, shard.BeaconChainShardID, multibls.GetPrivateKeys(blsPriKey), reg, decider, 3, false)
@@ -58,7 +58,7 @@ func TestSetViewID(t *testing.T) {
5858
t.Fatalf("newhost failure: %v", err)
5959
}
6060
decider := quorum.NewDecider(
61-
quorum.SuperMajorityVote, shard.BeaconChainShardID,
61+
quorum.SuperMajorityVote, shard.BeaconChainShardID, false,
6262
)
6363
blsPriKey := bls.RandPrivateKey()
6464
reg := registry.New()

consensus/consensus_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func GenerateConsensusForTesting() (p2p.Host, multibls.PrivateKeys, *Consensus,
7979
return nil, nil, nil, nil, err
8080
}
8181

82-
decider := quorum.NewDecider(quorum.SuperMajorityVote, shard.BeaconChainShardID)
82+
decider := quorum.NewDecider(quorum.SuperMajorityVote, shard.BeaconChainShardID, false)
8383
multiBLSPrivateKey := multibls.GetPrivateKeys(bls.RandPrivateKey())
8484

8585
consensus, err := New(host, shard.BeaconChainShardID, multiBLSPrivateKey, registry.New(), decider, 3, false)

consensus/construct_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestConstructAnnounceMessage(test *testing.T) {
3737
test.Fatalf("newhost failure: %v", err)
3838
}
3939
decider := quorum.NewDecider(
40-
quorum.SuperMajorityVote, shard.BeaconChainShardID,
40+
quorum.SuperMajorityVote, shard.BeaconChainShardID, false,
4141
)
4242
blsPriKey := bls.RandPrivateKey()
4343
reg := registry.New()
@@ -70,7 +70,7 @@ func TestConstructPreparedMessage(test *testing.T) {
7070
test.Fatalf("newhost failure: %v", err)
7171
}
7272
decider := quorum.NewDecider(
73-
quorum.SuperMajorityVote, shard.BeaconChainShardID,
73+
quorum.SuperMajorityVote, shard.BeaconChainShardID, false,
7474
)
7575
blsPriKey := bls.RandPrivateKey()
7676
reg := registry.New()
@@ -150,7 +150,7 @@ func TestConstructPrepareMessage(test *testing.T) {
150150
priKeyWrapper2 := bls.PrivateKeyWrapper{Pri: blsPriKey2, Pub: &pubKeyWrapper2}
151151

152152
decider := quorum.NewDecider(
153-
quorum.SuperMajorityStake, shard.BeaconChainShardID,
153+
quorum.SuperMajorityStake, shard.BeaconChainShardID, false,
154154
)
155155

156156
consensus, err := New(
@@ -242,7 +242,7 @@ func TestConstructCommitMessage(test *testing.T) {
242242
priKeyWrapper2 := bls.PrivateKeyWrapper{Pri: blsPriKey2, Pub: &pubKeyWrapper2}
243243

244244
decider := quorum.NewDecider(
245-
quorum.SuperMajorityStake, shard.BeaconChainShardID,
245+
quorum.SuperMajorityStake, shard.BeaconChainShardID, false,
246246
)
247247

248248
consensus, err := New(host, shard.BeaconChainShardID, multibls.GetPrivateKeys(blsPriKey1), registry.New(), decider, 3, false)
@@ -324,7 +324,7 @@ func TestPopulateMessageFields(t *testing.T) {
324324
}
325325
blsPriKey := bls.RandPrivateKey()
326326
decider := quorum.NewDecider(
327-
quorum.SuperMajorityVote, shard.BeaconChainShardID,
327+
quorum.SuperMajorityVote, shard.BeaconChainShardID, false,
328328
)
329329
consensus, err := New(
330330
host, shard.BeaconChainShardID, multibls.GetPrivateKeys(blsPriKey), registry.New(), decider, 3, false,

consensus/quorum/one-node-staked-vote.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (v *stakedVoteWeight) IsQuorumAchievedByMask(mask *bls_cosi.Mask) bool {
160160
const msg = "[IsQuorumAchievedByMask] Voting power: need %+v, have %+v"
161161
utils.Logger().Debug().
162162
Msgf(msg, threshold, currentTotalPower)
163-
return (*currentTotalPower).GTE(threshold)
163+
return (*currentTotalPower).GT(threshold)
164164
}
165165

166166
func (v *stakedVoteWeight) ComputeTotalPowerByMask(mask *bls_cosi.Mask) numeric.Dec {

consensus/quorum/one-node-staked-vote_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var (
3434
type secretKeyMap map[bls.SerializedPublicKey]bls_core.SecretKey
3535

3636
func init() {
37-
basicDecider = NewDecider(SuperMajorityStake, shard.BeaconChainShardID)
37+
basicDecider = NewDecider(SuperMajorityStake, shard.BeaconChainShardID, false)
3838
shard.Schedule = shardingconfig.LocalnetSchedule
3939
}
4040

@@ -71,7 +71,7 @@ func setupBaseCase() (Decider, *TallyResult, shard.SlotList, map[string]secretKe
7171
pubKeys = append(pubKeys, wrapper)
7272
}
7373

74-
decider := NewDecider(SuperMajorityStake, shard.BeaconChainShardID)
74+
decider := NewDecider(SuperMajorityStake, shard.BeaconChainShardID, false)
7575
decider.UpdateParticipants(pubKeys, []bls.PublicKeyWrapper{})
7676
tally, err := decider.SetVoters(&shard.Committee{
7777
ShardID: shard.BeaconChainShardID, Slots: slotList,
@@ -100,7 +100,7 @@ func setupEdgeCase() (Decider, *TallyResult, shard.SlotList, secretKeyMap) {
100100
pubKeys = append(pubKeys, wrapper)
101101
}
102102

103-
decider := NewDecider(SuperMajorityStake, shard.BeaconChainShardID)
103+
decider := NewDecider(SuperMajorityStake, shard.BeaconChainShardID, false)
104104
decider.UpdateParticipants(pubKeys, []bls.PublicKeyWrapper{})
105105
tally, err := decider.SetVoters(&shard.Committee{
106106
ShardID: shard.BeaconChainShardID, Slots: slotList,

consensus/quorum/quorom_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestPolicyStrings(t *testing.T) {
5353
}
5454

5555
func TestAddingQuoromParticipants(t *testing.T) {
56-
decider := NewDecider(SuperMajorityVote, shard.BeaconChainShardID)
56+
decider := NewDecider(SuperMajorityVote, shard.BeaconChainShardID, false)
5757

5858
assert.Equal(t, int64(0), decider.ParticipantsCount())
5959

@@ -77,7 +77,7 @@ func TestSubmitVote(test *testing.T) {
7777
viewID := uint64(2)
7878

7979
decider := NewDecider(
80-
SuperMajorityStake, shard.BeaconChainShardID,
80+
SuperMajorityStake, shard.BeaconChainShardID, false,
8181
)
8282

8383
message := "test string"
@@ -131,7 +131,7 @@ func TestSubmitVoteAggregateSig(test *testing.T) {
131131
viewID := uint64(2)
132132

133133
decider := NewDecider(
134-
SuperMajorityStake, shard.BeaconChainShardID,
134+
SuperMajorityStake, shard.BeaconChainShardID, false,
135135
)
136136

137137
blsPriKey1 := bls.RandPrivateKey()
@@ -203,7 +203,7 @@ func TestAddNewVote(test *testing.T) {
203203
viewID := uint64(2)
204204

205205
decider := NewDecider(
206-
SuperMajorityStake, shard.BeaconChainShardID,
206+
SuperMajorityStake, shard.BeaconChainShardID, false,
207207
)
208208

209209
slotList := shard.SlotList{}
@@ -305,7 +305,7 @@ func TestAddNewVoteAggregateSig(test *testing.T) {
305305
viewID := uint64(2)
306306

307307
decider := NewDecider(
308-
SuperMajorityStake, shard.BeaconChainShardID,
308+
SuperMajorityStake, shard.BeaconChainShardID, false,
309309
)
310310

311311
slotList := shard.SlotList{}
@@ -386,7 +386,7 @@ func TestAddNewVoteInvalidAggregateSig(test *testing.T) {
386386
viewID := uint64(2)
387387

388388
decider := NewDecider(
389-
SuperMajorityStake, shard.BeaconChainShardID,
389+
SuperMajorityStake, shard.BeaconChainShardID, false,
390390
)
391391

392392
slotList := shard.SlotList{}

consensus/quorum/quorum.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,13 @@ func newBallotsBackedSignatureReader() *cIdentities {
483483
}
484484

485485
// NewDecider ..
486-
func NewDecider(p Policy, shardID uint32) Decider {
486+
func NewDecider(p Policy, shardID uint32, useGTforQuorumChecking bool) Decider {
487487
switch p {
488488
case SuperMajorityVote:
489489
return &uniformVoteWeight{
490490
SignatureReader: newBallotsBackedSignatureReader(),
491491
lastPowerSignersCountCache: make(map[Phase]int64),
492+
useGTforQuorumChecking: useGTforQuorumChecking,
492493
}
493494
case SuperMajorityStake:
494495
return &stakedVoteWeight{

core_test/shardchain_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestAddNewBlock(t *testing.T) {
4141
nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, engine, &chainconfig,
4242
)
4343
decider := quorum.NewDecider(
44-
quorum.SuperMajorityVote, shard.BeaconChainShardID,
44+
quorum.SuperMajorityVote, shard.BeaconChainShardID, false,
4545
)
4646
blockchain, err := collection.ShardChain(shard.BeaconChainShardID)
4747
if err != nil {

hmy/staking.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (hmy *Harmony) getSuperCommittees() (*quorum.Transition, error) {
9696
rawStakes := []effective.SlotPurchase{}
9797
validatorSpreads := map[common.Address]numeric.Dec{}
9898
for _, comm := range prevCommittee.Shards {
99-
decider := quorum.NewDecider(quorum.SuperMajorityStake, comm.ShardID)
99+
decider := quorum.NewDecider(quorum.SuperMajorityStake, comm.ShardID, false)
100100
// before staking skip computing
101101
if hmy.BlockChain.Config().IsStaking(prevCommittee.Epoch) {
102102
if _, err := decider.SetVoters(&comm, prevCommittee.Epoch); err != nil {
@@ -111,7 +111,7 @@ func (hmy *Harmony) getSuperCommittees() (*quorum.Transition, error) {
111111
rawStakes = []effective.SlotPurchase{}
112112
validatorSpreads = map[common.Address]numeric.Dec{}
113113
for _, comm := range nowCommittee.Shards {
114-
decider := quorum.NewDecider(quorum.SuperMajorityStake, comm.ShardID)
114+
decider := quorum.NewDecider(quorum.SuperMajorityStake, comm.ShardID, false)
115115
if _, err := decider.SetVoters(&comm, nowCommittee.Epoch); err != nil {
116116
return nil, errors.Wrapf(
117117
err,

0 commit comments

Comments
 (0)