From 1e8667b4dbf865078ce3bf3ec79622913067dab3 Mon Sep 17 00:00:00 2001 From: Alex North <445306+anorth@users.noreply.github.com> Date: Fri, 7 Jun 2024 12:19:31 +1200 Subject: [PATCH] Fix calculation when no power in support --- gpbft/gpbft.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/gpbft/gpbft.go b/gpbft/gpbft.go index 1bd94b11..6868c7c4 100644 --- a/gpbft/gpbft.go +++ b/gpbft/gpbft.go @@ -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 @@ -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 {