Browse Source

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

Closes #4417
anca/fix_TestReactorTerminationScenarios
Alessio Treglia 5 years ago
committed by GitHub
parent
commit
25d92d05f8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 11 deletions
  1. +2
    -0
      CHANGELOG_PENDING.md
  2. +13
    -11
      types/validator_set.go

+ 2
- 0
CHANGELOG_PENDING.md View File

@ -19,6 +19,8 @@ program](https://hackerone.com/tendermint).
### IMPROVEMENTS: ### IMPROVEMENTS:
- [types] [\#4417](https://github.com/tendermint/tendermint/issues/4417) VerifyCommitX() functions should return as soon as +2/3 threashold is reached.
### BUG FIXES: ### BUG FIXES:
- [rpc] [\#4437](https://github.com/tendermint/tendermint/pull/4437) Fix tx_search pagination with ordered results (@erikgrinaker) - [rpc] [\#4437](https://github.com/tendermint/tendermint/pull/4437) Fix tx_search pagination with ordered results (@erikgrinaker)


+ 13
- 11
types/validator_set.go View File

@ -636,6 +636,7 @@ func (vals *ValidatorSet) VerifyCommit(chainID string, blockID BlockID,
} }
talliedVotingPower := int64(0) talliedVotingPower := int64(0)
votingPowerNeeded := vals.TotalVotingPower() * 2 / 3
for idx, commitSig := range commit.Signatures { for idx, commitSig := range commit.Signatures {
if commitSig.Absent() { if commitSig.Absent() {
continue // OK, some signatures can be 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 // It's OK that the BlockID doesn't match. We include stray
// signatures (~votes for nil) to measure validator availability. // signatures (~votes for nil) to measure validator availability.
// } // }
}
if got, needed := talliedVotingPower, vals.TotalVotingPower()*2/3; got <= needed {
return ErrNotEnoughVotingPowerSigned{Got: got, Needed: needed}
// return as soon as +2/3 of the signatures are verified
if talliedVotingPower > votingPowerNeeded {
return nil
}
} }
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 // 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 ( var (
talliedVotingPower int64 talliedVotingPower int64
seenVals = make(map[int]int, len(commit.Signatures)) // validator index -> commit index 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 { 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 // It's OK that the BlockID doesn't match. We include stray
// signatures (~votes for nil) to measure validator availability. // signatures (~votes for nil) to measure validator availability.
// } // }
}
}
got := talliedVotingPower
needed := (vals.TotalVotingPower() * trustLevel.Numerator) / trustLevel.Denominator
if got <= needed {
return ErrNotEnoughVotingPowerSigned{Got: got, Needed: needed}
if talliedVotingPower > votingPowerNeeded {
return nil
}
}
} }
return nil
return ErrNotEnoughVotingPowerSigned{Got: talliedVotingPower, Needed: votingPowerNeeded}
} }
func verifyCommitBasic(commit *Commit, height int64, blockID BlockID) error { func verifyCommitBasic(commit *Commit, height int64, blockID BlockID) error {


Loading…
Cancel
Save