Feature: last signing power. (#4584)

* Signing power without leader.

* Fixed shard id.

* Removed debug info.
pull/4596/head
Konstantin 11 months ago committed by GitHub
parent 9a5ba3cc0b
commit 556444cea5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      consensus/quorum/one-node-staked-vote.go
  2. 1
      hmy/hmy.go
  3. 28
      node/api.go
  4. 7
      rpc/private_debug.go

@ -98,19 +98,19 @@ func (v *stakedVoteWeight) AddNewVote(
additionalVotePower = additionalVotePower.Add(votingPower)
}
tallyQuorum := func() *tallyAndQuorum {
var tallyQuorum *tallyAndQuorum
switch p {
case Prepare:
return v.voteTally.Prepare
tallyQuorum = v.voteTally.Prepare
case Commit:
return v.voteTally.Commit
tallyQuorum = v.voteTally.Commit
case ViewChange:
return v.voteTally.ViewChange
tallyQuorum = v.voteTally.ViewChange
default:
// Should not happen
return nil
return nil, errors.New("stakedVoteWeight not cache this phase")
}
}()
tallyQuorum.tally = tallyQuorum.tally.Add(additionalVotePower)
t := v.QuorumThreshold()
@ -163,20 +163,6 @@ func (v *stakedVoteWeight) IsQuorumAchievedByMask(mask *bls_cosi.Mask) bool {
return (*currentTotalPower).GT(threshold)
}
func (v *stakedVoteWeight) currentTotalPower(p Phase) (*numeric.Dec, error) {
switch p {
case Prepare:
return &v.voteTally.Prepare.tally, nil
case Commit:
return &v.voteTally.Commit.tally, nil
case ViewChange:
return &v.voteTally.ViewChange.tally, nil
default:
// Should not happen
return nil, errors.New("wrong phase is provided")
}
}
// ComputeTotalPowerByMask computes the total power indicated by bitmap mask
func (v *stakedVoteWeight) computeTotalPowerByMask(mask *bls_cosi.Mask) *numeric.Dec {
currentTotal := numeric.ZeroDec()

@ -120,6 +120,7 @@ type NodeAPI interface {
GetConfig() commonRPC.Config
ShutDown()
GetLastSigningPower() (float64, error)
GetLastSigningPower2() (float64, error)
}
// New creates a new Harmony object (including the

@ -2,7 +2,9 @@ package node
import (
"github.com/harmony-one/harmony/consensus/quorum"
"github.com/harmony-one/harmony/consensus/votepower"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/crypto/bls"
"github.com/harmony-one/harmony/eth/rpc"
"github.com/harmony-one/harmony/hmy"
"github.com/harmony-one/harmony/internal/tikv"
@ -183,3 +185,29 @@ func (node *Node) GetLastSigningPower() (float64, error) {
round := float64(power.MulInt64(10000).RoundInt64()) / 10000
return round, nil
}
func (node *Node) GetLastSigningPower2() (float64, error) {
bc := node.Consensus.Blockchain()
cur := bc.CurrentBlock()
ss, err := bc.ReadShardState(cur.Epoch())
if err != nil {
return 0, err
}
roster, err := votepower.Compute(&ss.Shards[bc.ShardID()], cur.Epoch())
if err != nil {
return 0, err
}
blsPubKeys, err := ss.Shards[bc.ShardID()].BLSPublicKeys()
if err != nil {
return 0, err
}
mask := bls.NewMask(blsPubKeys)
err = mask.SetMask(cur.Header().LastCommitBitmap())
if err != nil {
return 0, err
}
power := roster.VotePowerByMask(mask)
round := float64(power.MulInt64(10000).RoundInt64()) / 10000
return round, nil
}

@ -65,3 +65,10 @@ func (s *PrivateDebugService) GetLastSigningPower(
) (float64, error) {
return s.hmy.NodeAPI.GetLastSigningPower()
}
// GetLastSigningPower2 get last signed power
func (s *PrivateDebugService) GetLastSigningPower2(
ctx context.Context,
) (float64, error) {
return s.hmy.NodeAPI.GetLastSigningPower2()
}

Loading…
Cancel
Save