Remove CommigSig.ForBlock helper

Signed-off-by: Thane Thomson <connect@thanethomson.com>
This commit is contained in:
Thane Thomson
2022-05-07 10:11:01 -04:00
parent 630ec2591d
commit accba4774d
4 changed files with 7 additions and 12 deletions
+1 -1
View File
@@ -2032,7 +2032,7 @@ func (cs *State) RecordMetrics(height int64, block *types.Block) {
"validator_address", val.Address.String(),
}
cs.metrics.ValidatorPower.With(label...).Set(float64(val.VotingPower))
if commitSig.ForBlock() {
if commitSig.BlockIDFlag == types.BlockIDFlagCommit {
cs.metrics.ValidatorLastSignedHeight.With(label...).Set(float64(height))
} else {
cs.metrics.ValidatorMissedBlocks.With(label...).Add(float64(1))
-5
View File
@@ -622,11 +622,6 @@ func NewCommitSigAbsent() CommitSig {
}
}
// ForBlock returns true if CommitSig is for the block.
func (cs CommitSig) ForBlock() bool {
return cs.BlockIDFlag == BlockIDFlagCommit
}
// Absent returns true if CommitSig is absent.
func (cs CommitSig) Absent() bool {
return cs.BlockIDFlag == BlockIDFlagAbsent
+3 -3
View File
@@ -309,7 +309,7 @@ func (l *LightClientAttackEvidence) GetByzantineValidators(commonVals *Validator
// validators who are in the commonVals and voted for the lunatic header
if l.ConflictingHeaderIsInvalid(trusted.Header) {
for _, commitSig := range l.ConflictingBlock.Commit.Signatures {
if !commitSig.ForBlock() {
if commitSig.BlockIDFlag != BlockIDFlagCommit {
continue
}
@@ -329,12 +329,12 @@ func (l *LightClientAttackEvidence) GetByzantineValidators(commonVals *Validator
// only need a single loop to find the validators that voted twice.
for i := 0; i < len(l.ConflictingBlock.Commit.Signatures); i++ {
sigA := l.ConflictingBlock.Commit.Signatures[i]
if !sigA.ForBlock() {
if sigA.BlockIDFlag != BlockIDFlagCommit {
continue
}
sigB := trusted.Commit.Signatures[i]
if !sigB.ForBlock() {
if sigB.BlockIDFlag != BlockIDFlagCommit {
continue
}
+3 -3
View File
@@ -39,7 +39,7 @@ func VerifyCommit(chainID string, vals *ValidatorSet, blockID BlockID,
ignore := func(c CommitSig) bool { return c.Absent() }
// only count the signatures that are for the block
count := func(c CommitSig) bool { return c.ForBlock() }
count := func(c CommitSig) bool { return c.BlockIDFlag == BlockIDFlagCommit }
// attempt to batch verify
if shouldBatchVerify(vals, commit) {
@@ -69,7 +69,7 @@ func VerifyCommitLight(chainID string, vals *ValidatorSet, blockID BlockID,
votingPowerNeeded := vals.TotalVotingPower() * 2 / 3
// ignore all commit signatures that are not for the block
ignore := func(c CommitSig) bool { return !c.ForBlock() }
ignore := func(c CommitSig) bool { return c.BlockIDFlag != BlockIDFlagCommit }
// count all the remaining signatures
count := func(c CommitSig) bool { return true }
@@ -113,7 +113,7 @@ func VerifyCommitLightTrusting(chainID string, vals *ValidatorSet, commit *Commi
votingPowerNeeded := totalVotingPowerMulByNumerator / int64(trustLevel.Denominator)
// ignore all commit signatures that are not for the block
ignore := func(c CommitSig) bool { return !c.ForBlock() }
ignore := func(c CommitSig) bool { return c.BlockIDFlag != BlockIDFlagCommit }
// count all the remaining signatures
count := func(c CommitSig) bool { return true }