VerifyCommitLightTrusting verifies that trustLevel of the validator set signed this commit. NOTE the given validators do not necessarily correspond to the validator set for this commit, but there may be some intersection. This method is primarily used by the light client and does not check all the
(chainID string, vals *ValidatorSet, commit *Commit, trustLevel tmmath.Fraction)
| 92 | // This method is primarily used by the light client and does not check all the |
| 93 | // signatures. |
| 94 | func VerifyCommitLightTrusting(chainID string, vals *ValidatorSet, commit *Commit, trustLevel tmmath.Fraction) error { |
| 95 | // sanity checks |
| 96 | if vals == nil { |
| 97 | return errors.New("nil validator set") |
| 98 | } |
| 99 | if trustLevel.Denominator == 0 { |
| 100 | return errors.New("trustLevel has zero Denominator") |
| 101 | } |
| 102 | if commit == nil { |
| 103 | return errors.New("nil commit") |
| 104 | } |
| 105 | |
| 106 | // safely calculate voting power needed. |
| 107 | totalVotingPowerMulByNumerator, overflow := safeMul(vals.TotalVotingPower(), int64(trustLevel.Numerator)) |
| 108 | if overflow { |
| 109 | return errors.New("int64 overflow while calculating voting power needed. please provide smaller trustLevel numerator") |
| 110 | } |
| 111 | votingPowerNeeded := totalVotingPowerMulByNumerator / int64(trustLevel.Denominator) |
| 112 | |
| 113 | // ignore all commit signatures that are not for the block |
| 114 | ignore := func(c CommitSig) bool { return !c.ForBlock() } |
| 115 | |
| 116 | // count all the remaining signatures |
| 117 | count := func(c CommitSig) bool { return true } |
| 118 | |
| 119 | // attempt to batch verify commit. As the validator set doesn't necessarily |
| 120 | // correspond with the validator set that signed the block we need to look |
| 121 | // up by address rather than index. |
| 122 | if shouldBatchVerify(vals, commit) { |
| 123 | return verifyCommitBatch(chainID, vals, commit, |
| 124 | votingPowerNeeded, ignore, count, false, false) |
| 125 | } |
| 126 | |
| 127 | // attempt with single verification |
| 128 | return verifyCommitSingle(chainID, vals, commit, votingPowerNeeded, |
| 129 | ignore, count, false, false) |
| 130 | } |
| 131 | |
| 132 | // ValidateHash returns an error if the hash is not empty, but its |
| 133 | // size != tmhash.Size. |
no test coverage detected
searching dependent graphs…