mirror of
https://github.com/tendermint/tendermint.git
synced 2026-04-20 15:50:31 +00:00
types: VerifyCommitX return when +2/3 sigs are verified (#4445)
Closes #4417
This commit is contained in:
@@ -19,6 +19,8 @@ program](https://hackerone.com/tendermint).
|
||||
|
||||
### IMPROVEMENTS:
|
||||
|
||||
- [types] [\#4417](https://github.com/tendermint/tendermint/issues/4417) VerifyCommitX() functions should return as soon as +2/3 threashold is reached.
|
||||
|
||||
### BUG FIXES:
|
||||
|
||||
- [rpc] [\#4437](https://github.com/tendermint/tendermint/pull/4437) Fix tx_search pagination with ordered results (@erikgrinaker)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user