diff --git a/consensus/quorum/one-node-one-vote.go b/consensus/quorum/one-node-one-vote.go index b865b3bc2e..93187196ce 100644 --- a/consensus/quorum/one-node-one-vote.go +++ b/consensus/quorum/one-node-one-vote.go @@ -5,7 +5,6 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" - "github.com/harmony-one/bls/ffi/go/bls" bls_cosi "github.com/harmony-one/harmony/crypto/bls" "github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/numeric" @@ -64,12 +63,6 @@ func (v *uniformVoteWeight) SetVoters(shard.SlotList) (*TallyResult, error) { return nil, nil } -// ToggleActive for uniform vote is a no-op, always says that voter is active -func (v *uniformVoteWeight) ToggleActive(*bls.PublicKey) bool { - // NO-OP do not add anything here - return true -} - // Award .. func (v *uniformVoteWeight) Award( // Here hook is the callback which gets the amount the earner is due in just reward diff --git a/consensus/quorum/one-node-staked-vote.go b/consensus/quorum/one-node-staked-vote.go index 87480ba151..2a05c0b6cb 100644 --- a/consensus/quorum/one-node-staked-vote.go +++ b/consensus/quorum/one-node-staked-vote.go @@ -3,7 +3,6 @@ package quorum import ( "encoding/json" - "github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/harmony/consensus/votepower" bls_cosi "github.com/harmony-one/harmony/crypto/bls" common2 "github.com/harmony-one/harmony/internal/common" @@ -159,7 +158,9 @@ var ( ) ) -func (v *stakedVoteWeight) SetVoters(staked shard.SlotList) (*TallyResult, error) { +func (v *stakedVoteWeight) SetVoters( + staked shard.SlotList, +) (*TallyResult, error) { v.ResetPrepareAndCommitVotes() v.ResetViewChangeVotes() @@ -170,19 +171,11 @@ func (v *stakedVoteWeight) SetVoters(staked shard.SlotList) (*TallyResult, error // Hold onto this calculation v.roster = *roster return &TallyResult{ - roster.OurVotingPowerTotalPercentage, roster.TheirVotingPowerTotalPercentage, + roster.OurVotingPowerTotalPercentage, + roster.TheirVotingPowerTotalPercentage, }, nil } -func (v *stakedVoteWeight) ToggleActive(k *bls.PublicKey) bool { - w := shard.BlsPublicKey{} - w.FromLibBLSPublicKey(k) - g := v.roster.Voters[w] - g.IsActive = !g.IsActive - v.roster.Voters[w] = g - return v.roster.Voters[w].IsActive -} - func (v *stakedVoteWeight) String() string { s, _ := json.Marshal(v) return string(s) @@ -195,6 +188,7 @@ func (v *stakedVoteWeight) MarshalJSON() ([]byte, error) { IsHarmony bool `json:"is-harmony-slot"` EarningAccount string `json:"earning-account"` Identity string `json:"bls-public-key"` + RawPercent string `json:"voting-power-unnormalized"` VotingPower string `json:"voting-power-%"` EffectiveStake string `json:"effective-stake,omitempty"` } @@ -217,6 +211,7 @@ func (v *stakedVoteWeight) MarshalJSON() ([]byte, error) { voter.IsHarmonyNode, common2.MustAddressToBech32(voter.EarningAccount), identity.Hex(), + voter.RawPercent.String(), voter.EffectivePercent.String(), "", } @@ -245,11 +240,11 @@ func (v *stakedVoteWeight) AmIMemberOfCommitee() bool { } identity, _ := pubKeyFunc() for _, key := range identity.PublicKey { - w := shard.BlsPublicKey{} - w.FromLibBLSPublicKey(key) - _, ok := v.roster.Voters[w] - if ok { - return true + if w := (shard.BlsPublicKey{}); w.FromLibBLSPublicKey(key) != nil { + _, ok := v.roster.Voters[w] + if ok { + return true + } } } return false diff --git a/consensus/quorum/quorum.go b/consensus/quorum/quorum.go index e24f777a5c..f6737769ee 100644 --- a/consensus/quorum/quorum.go +++ b/consensus/quorum/quorum.go @@ -110,7 +110,6 @@ type Decider interface { fmt.Stringer SignatureReader DependencyInjectionWriter - ToggleActive(*bls.PublicKey) bool SetVoters(shard.SlotList) (*TallyResult, error) Policy() Policy IsQuorumAchieved(Phase) bool diff --git a/consensus/votepower/roster.go b/consensus/votepower/roster.go index b2a22bd4b0..8eb90d191e 100644 --- a/consensus/votepower/roster.go +++ b/consensus/votepower/roster.go @@ -63,6 +63,7 @@ type stakedVoter struct { IsHarmonyNode bool `json:"is-harmony"` EarningAccount common.Address `json:"earning-account"` Identity shard.BlsPublicKey `json:"bls-public-key"` + RawPercent numeric.Dec `json:"voting-power-unnormalized"` EffectivePercent numeric.Dec `json:"voting"` EffectiveStake numeric.Dec `json:"effective-stake"` } @@ -176,6 +177,7 @@ func Compute(staked shard.SlotList) (*Roster, error) { IsHarmonyNode: true, EarningAccount: staked[i].EcdsaAddress, Identity: staked[i].BlsPublicKey, + RawPercent: numeric.ZeroDec(), EffectivePercent: numeric.ZeroDec(), EffectiveStake: numeric.ZeroDec(), } @@ -184,13 +186,13 @@ func Compute(staked shard.SlotList) (*Roster, error) { if staked[i].EffectiveStake != nil { member.IsHarmonyNode = false member.EffectiveStake = member.EffectiveStake.Add(*staked[i].EffectiveStake) - member.EffectivePercent = staked[i].EffectiveStake. - Quo(roster.RawStakedTotal). - Mul(StakersShare) + member.RawPercent = staked[i].EffectiveStake.Quo(roster.RawStakedTotal) + member.EffectivePercent = member.RawPercent.Mul(StakersShare) theirPercentage = theirPercentage.Add(member.EffectivePercent) lastStakedVoter = &member } else { // Our node member.EffectivePercent = HarmonysShare.Quo(ourCount) + member.RawPercent = member.EffectivePercent ourPercentage = ourPercentage.Add(member.EffectivePercent) }