From 30bcc5230af73719432439577b71f67cb45b826e Mon Sep 17 00:00:00 2001 From: Sergio Mena Date: Sat, 12 Nov 2022 14:04:45 +0100 Subject: [PATCH] monkey-see-monkey-do-fixes --- blocksync/pool.go | 2 +- consensus/reactor.go | 2 +- consensus/state.go | 4 ++-- types/block.go | 2 +- types/validation.go | 8 ++++---- types/vote.go | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/blocksync/pool.go b/blocksync/pool.go index 7f81344a5..b6a3f3db0 100644 --- a/blocksync/pool.go +++ b/blocksync/pool.go @@ -255,7 +255,7 @@ func (pool *BlockPool) RedoRequest(height int64) p2p.ID { // height of the extended commit and the height of the block do not match, we // do not add the block and return an error. // TODO: ensure that blocks come in order for each peer. -func (pool *BlockPool) AddBlock(peerID p2p.ID, block *types.Block, extCommit *types.ExtendedCommit, blockSize int) { +func (pool *BlockPool) AddBlock(peerID p2p.ID, block *types.Block, extCommit *types.ExtendedCommit, blockSize int) error { pool.mtx.Lock() defer pool.mtx.Unlock() diff --git a/consensus/reactor.go b/consensus/reactor.go index 7e66d2896..a027bac50 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -1691,7 +1691,7 @@ func (m *VoteMessage) ValidateBasic() error { // here. return m.Vote.ValidateWithExtension() } -g + // String returns a string representation. func (m *VoteMessage) String() string { return fmt.Sprintf("[Vote %v]", m.Vote) diff --git a/consensus/state.go b/consensus/state.go index 0513bc5a8..8526c87bf 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -2070,7 +2070,7 @@ func (cs *State) addVote(vote *types.Vote, peerID p2p.ID) (added bool, err error // Verify VoteExtension if precommit and not nil // https://github.com/tendermint/tendermint/issues/8487 - if vote.Type == tmproto.PrecommitType && !vote.BlockID.IsNil() { + if vote.Type == tmproto.PrecommitType && len(vote.BlockID.Hash) != 0 { if err = cs.blockExec.VerifyVoteExtension(vote); err != nil { return false, err } @@ -2237,7 +2237,7 @@ func (cs *State) signVote( BlockID: types.BlockID{Hash: hash, PartSetHeader: header}, } - if msgType == tmproto.PrecommitType && !vote.BlockID.IsNil() { + if msgType == tmproto.PrecommitType && len(vote.BlockID.Hash) != 0 { // if the signedMessage type is for a non-nil precommit, add // VoteExtension ext, err := cs.blockExec.ExtendVote(vote) diff --git a/types/block.go b/types/block.go index 687367928..de60f66ea 100644 --- a/types/block.go +++ b/types/block.go @@ -1121,7 +1121,7 @@ func (ec *ExtendedCommit) ValidateBasic() error { } if ec.Height >= 1 { - if ec.BlockID.IsNil() { + if len(ec.BlockID.Hash) == 0 { return errors.New("commit cannot be for nil block") } diff --git a/types/validation.go b/types/validation.go index 3601f0479..b62a2c8f1 100644 --- a/types/validation.go +++ b/types/validation.go @@ -34,10 +34,10 @@ func VerifyCommit(chainID string, vals *ValidatorSet, blockID BlockID, votingPowerNeeded := vals.TotalVotingPower() * 2 / 3 // ignore all absent signatures - ignore := func(c CommitSig) bool { return c.Absent() } + ignore := func(c CommitSig) bool { return c.BlockIDFlag == BlockIDFlagAbsent } // 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) { @@ -67,7 +67,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 } @@ -111,7 +111,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 } diff --git a/types/vote.go b/types/vote.go index d3e35eb1b..13053f14f 100644 --- a/types/vote.go +++ b/types/vote.go @@ -297,7 +297,7 @@ func (vote *Vote) ValidateBasic() error { // We should only ever see vote extensions in non-nil precommits, otherwise // this is a violation of the specification. // https://github.com/tendermint/tendermint/issues/8487 - if vote.Type != tmproto.PrecommitType || (vote.Type == tmproto.PrecommitType && vote.BlockID.IsNil()) { + if vote.Type != tmproto.PrecommitType || (vote.Type == tmproto.PrecommitType && len(vote.BlockID.Hash) == 0) { if len(vote.Extension) > 0 { return errors.New("unexpected vote extension") } @@ -318,7 +318,7 @@ func (vote *Vote) ValidateWithExtension() error { } // We should always see vote extension signatures in non-nil precommits - if vote.Type == tmproto.PrecommitType && !vote.BlockID.IsNil() { + if vote.Type == tmproto.PrecommitType && len(vote.BlockID.Hash) != 0 { if len(vote.ExtensionSignature) == 0 { return errors.New("vote extension signature is missing") }