types: VerifyCommitX return when +2/3 sigs are verified (#4445)

Closes #4417
This commit is contained in:
Alessio Treglia
2020-02-25 10:04:24 +01:00
committed by GitHub
parent f934ca82fc
commit 25d92d05f8
2 changed files with 16 additions and 12 deletions
+14 -12
View File
@@ -636,6 +636,7 @@ func (vals *ValidatorSet) VerifyCommit(chainID string, blockID BlockID,
}
talliedVotingPower := int64(0)
votingPowerNeeded := vals.TotalVotingPower() * 2 / 3
for idx, commitSig := range commit.Signatures {
if commitSig.Absent() {
continue // OK, some signatures can be absent.
@@ -658,13 +659,15 @@ func (vals *ValidatorSet) VerifyCommit(chainID string, blockID BlockID,
// It's OK that the BlockID doesn't match. We include stray
// signatures (~votes for nil) to measure validator availability.
// }
// return as soon as +2/3 of the signatures are verified
if talliedVotingPower > votingPowerNeeded {
return nil
}
}
if got, needed := talliedVotingPower, vals.TotalVotingPower()*2/3; got <= needed {
return ErrNotEnoughVotingPowerSigned{Got: got, Needed: needed}
}
return nil
// talliedVotingPower <= needed, thus return error
return ErrNotEnoughVotingPowerSigned{Got: talliedVotingPower, Needed: votingPowerNeeded}
}
// VerifyFutureCommit will check to see if the set would be valid with a different
@@ -762,6 +765,7 @@ func (vals *ValidatorSet) VerifyCommitTrusting(chainID string, blockID BlockID,
var (
talliedVotingPower int64
seenVals = make(map[int]int, len(commit.Signatures)) // validator index -> commit index
votingPowerNeeded = (vals.TotalVotingPower() * trustLevel.Numerator) / trustLevel.Denominator
)
for idx, commitSig := range commit.Signatures {
@@ -795,16 +799,14 @@ func (vals *ValidatorSet) VerifyCommitTrusting(chainID string, blockID BlockID,
// It's OK that the BlockID doesn't match. We include stray
// signatures (~votes for nil) to measure validator availability.
// }
if talliedVotingPower > votingPowerNeeded {
return nil
}
}
}
got := talliedVotingPower
needed := (vals.TotalVotingPower() * trustLevel.Numerator) / trustLevel.Denominator
if got <= needed {
return ErrNotEnoughVotingPowerSigned{Got: got, Needed: needed}
}
return nil
return ErrNotEnoughVotingPowerSigned{Got: talliedVotingPower, Needed: votingPowerNeeded}
}
func verifyCommitBasic(commit *Commit, height int64, blockID BlockID) error {