From accba4774d7425ae1627e180ccaf26464db3c1e9 Mon Sep 17 00:00:00 2001 From: Thane Thomson Date: Sat, 7 May 2022 10:11:01 -0400 Subject: [PATCH] Remove CommigSig.ForBlock helper Signed-off-by: Thane Thomson --- internal/consensus/state.go | 2 +- types/block.go | 5 ----- types/evidence.go | 6 +++--- types/validation.go | 6 +++--- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/internal/consensus/state.go b/internal/consensus/state.go index f5e44a9b5..c6ffb031e 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -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)) diff --git a/types/block.go b/types/block.go index 099c1ddca..e2354479b 100644 --- a/types/block.go +++ b/types/block.go @@ -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 diff --git a/types/evidence.go b/types/evidence.go index aed954a93..c5b5b6223 100644 --- a/types/evidence.go +++ b/types/evidence.go @@ -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 } diff --git a/types/validation.go b/types/validation.go index 21c8730f5..a422f72ab 100644 --- a/types/validation.go +++ b/types/validation.go @@ -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 }