Skip to content

Commit

Permalink
Fix calculation when no power in support
Browse files Browse the repository at this point in the history
  • Loading branch information
anorth committed Jun 7, 2024
1 parent 696b632 commit 1e8667b
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions gpbft/gpbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ func (i *instance) tryPrepare() error {
proposalKey := i.proposal.Key()
foundQuorum := prepared.HasStrongQuorumFor(proposalKey)
timedOut := atOrAfter(i.participant.host.Time(), i.phaseTimeout) && prepared.ReceivedFromStrongQuorum()
quorumNotPossible := !prepared.mayHaveStrongQuorumFor(proposalKey)
quorumNotPossible := !prepared.couldReachStrongQuorumFor(proposalKey)

if foundQuorum {
i.value = i.proposal
Expand Down Expand Up @@ -1087,22 +1087,19 @@ func (q *quorumState) HasStrongQuorumFor(key ChainKey) bool {
return ok && supportForChain.hasStrongQuorum
}

// mayHaveStrongQuorumFor checks whether the given chain can possibly reach
// couldReachStrongQuorumFor checks whether the given chain can possibly reach
// strong quorum.
func (q *quorumState) mayHaveStrongQuorumFor(key ChainKey) bool {
supportForChain, found := q.chainSupport[key]
if !found {
// There is no support for given chain. Strong quorum is only possible if the
// aggregate power of voted participants dos not exceed ⅔ of total power.
return !q.ReceivedFromStrongQuorum()
func (q *quorumState) couldReachStrongQuorumFor(key ChainKey) bool {
supportingPower := new(big.Int)
if supportForChain, found := q.chainSupport[key]; found {
supportingPower.Set(supportForChain.power)
}

// A strong quorum is only feasible when the total support for the given chain,
// combined with the aggregate power of not yet voted participants, exceeds ⅔ of
// total power.
nonSendersTotalPower := NewStoragePower(0).Sub(q.powerTable.Total, q.sendersTotalPower)
strongQuorumThreshold := NewStoragePower(0).Add(nonSendersTotalPower, supportForChain.power)
return IsStrongQuorum(strongQuorumThreshold, q.powerTable.Total)
unvotedPower := NewStoragePower(0).Sub(q.powerTable.Total, q.sendersTotalPower)
possibleSupport := NewStoragePower(0).Add(supportingPower, unvotedPower)
return IsStrongQuorum(possibleSupport, q.powerTable.Total)
}

type QuorumResult struct {
Expand Down

0 comments on commit 1e8667b

Please sign in to comment.