Skip to content

Commit

Permalink
[votepower][quorum] Remove unused method, expose raw percent of vote …
Browse files Browse the repository at this point in the history
…power (#2383)
  • Loading branch information
fxfactorial authored Mar 5, 2020
1 parent 0185fef commit 82952fe
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
7 changes: 0 additions & 7 deletions consensus/quorum/one-node-one-vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
29 changes: 12 additions & 17 deletions consensus/quorum/one-node-staked-vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()

Expand All @@ -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)
Expand All @@ -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"`
}
Expand All @@ -217,6 +211,7 @@ func (v *stakedVoteWeight) MarshalJSON() ([]byte, error) {
voter.IsHarmonyNode,
common2.MustAddressToBech32(voter.EarningAccount),
identity.Hex(),
voter.RawPercent.String(),
voter.EffectivePercent.String(),
"",
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion consensus/quorum/quorum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions consensus/votepower/roster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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(),
}
Expand All @@ -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)
}

Expand Down

0 comments on commit 82952fe

Please sign in to comment.