[votepower][quorum] Remove unused method, expose raw percent of vote power (#2383)

pull/2385/head
Edgar Aroutiounian 5 years ago committed by GitHub
parent 0185fef128
commit 82952fe866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      consensus/quorum/one-node-one-vote.go
  2. 29
      consensus/quorum/one-node-staked-vote.go
  3. 1
      consensus/quorum/quorum.go
  4. 8
      consensus/votepower/roster.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

@ -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

@ -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

@ -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)
}

Loading…
Cancel
Save