From 0c03fff891760321908289da31a50a80aeef8498 Mon Sep 17 00:00:00 2001 From: Goran Rojovic Date: Thu, 20 Jun 2024 11:50:50 +0200 Subject: [PATCH] lint fix --- core/helpers_test.go | 2 +- core/mock_test.go | 5 +---- core/rapid_test.go | 3 +++ messages/helpers.go | 40 ++++++++++++++++++++++++++++++++-------- messages/proto/helper.go | 14 ++++++++++++-- 5 files changed, 49 insertions(+), 15 deletions(-) diff --git a/core/helpers_test.go b/core/helpers_test.go index 76efe83..fbbcde7 100644 --- a/core/helpers_test.go +++ b/core/helpers_test.go @@ -184,7 +184,7 @@ func (c *cluster) runSequences(ctx context.Context, height uint64) error { // wait for the worker threads to return <-sequenceDone - return errors.New("timeout") + return errors.New("timeout") //nolint:err113 } } diff --git a/core/mock_test.go b/core/mock_test.go index e012d42..1f453a6 100644 --- a/core/mock_test.go +++ b/core/mock_test.go @@ -532,10 +532,7 @@ func (m *mockCluster) awaitNCompletions( for { select { case <-ctx.Done(): - return fmt.Errorf( - "await exceeded timeout for %d nodes", - count, - ) + return fmt.Errorf("await exceeded timeout for %d nodes", count) //nolint:err113 default: if m.wg.getDone() >= count { return nil diff --git a/core/rapid_test.go b/core/rapid_test.go index 1fb69a0..620568e 100644 --- a/core/rapid_test.go +++ b/core/rapid_test.go @@ -358,11 +358,14 @@ func TestProperty(t *testing.T) { // Make sure we have inserted blocks >= quorum per round. lastRound := setup.lastRound(height) badNodes := lastRound.badNodes() + var proposalsNumber int + for nodeID, proposalMap := range insertedProposals.proposals { if nodeID >= int(badNodes) { // Only one inserted block per valid round assert.LessOrEqual(t, len(proposalMap), 1) + proposalsNumber++ // Make sure inserted block value is correct diff --git a/messages/helpers.go b/messages/helpers.go index 89a2424..5b201f3 100644 --- a/messages/helpers.go +++ b/messages/helpers.go @@ -36,7 +36,10 @@ func ExtractCommittedSeals(commitMessages []*proto.IbftMessage) ([]*CommittedSea // ExtractCommittedSeal extracts the committed seal from the passed in message func ExtractCommittedSeal(commitMessage *proto.IbftMessage) *CommittedSeal { - commitData, _ := commitMessage.Payload.(*proto.IbftMessage_CommitData) + commitData, ok := commitMessage.Payload.(*proto.IbftMessage_CommitData) + if !ok { + return nil + } return &CommittedSeal{ Signer: commitMessage.From, @@ -50,7 +53,10 @@ func ExtractCommitHash(commitMessage *proto.IbftMessage) []byte { return nil } - commitData, _ := commitMessage.Payload.(*proto.IbftMessage_CommitData) + commitData, ok := commitMessage.Payload.(*proto.IbftMessage_CommitData) + if !ok { + return nil + } return commitData.CommitData.ProposalHash } @@ -61,7 +67,10 @@ func ExtractProposal(proposalMessage *proto.IbftMessage) *proto.Proposal { return nil } - preprepareData, _ := proposalMessage.Payload.(*proto.IbftMessage_PreprepareData) + preprepareData, ok := proposalMessage.Payload.(*proto.IbftMessage_PreprepareData) + if !ok { + return nil + } return preprepareData.PreprepareData.Proposal } @@ -72,7 +81,10 @@ func ExtractProposalHash(proposalMessage *proto.IbftMessage) []byte { return nil } - preprepareData, _ := proposalMessage.Payload.(*proto.IbftMessage_PreprepareData) + preprepareData, ok := proposalMessage.Payload.(*proto.IbftMessage_PreprepareData) + if !ok { + return nil + } return preprepareData.PreprepareData.ProposalHash } @@ -83,7 +95,10 @@ func ExtractRoundChangeCertificate(proposalMessage *proto.IbftMessage) *proto.Ro return nil } - preprepareData, _ := proposalMessage.Payload.(*proto.IbftMessage_PreprepareData) + preprepareData, ok := proposalMessage.Payload.(*proto.IbftMessage_PreprepareData) + if !ok { + return nil + } return preprepareData.PreprepareData.Certificate } @@ -94,7 +109,10 @@ func ExtractPrepareHash(prepareMessage *proto.IbftMessage) []byte { return nil } - prepareData, _ := prepareMessage.Payload.(*proto.IbftMessage_PrepareData) + prepareData, ok := prepareMessage.Payload.(*proto.IbftMessage_PrepareData) + if !ok { + return nil + } return prepareData.PrepareData.ProposalHash } @@ -105,7 +123,10 @@ func ExtractLatestPC(roundChangeMessage *proto.IbftMessage) *proto.PreparedCerti return nil } - rcData, _ := roundChangeMessage.Payload.(*proto.IbftMessage_RoundChangeData) + rcData, ok := roundChangeMessage.Payload.(*proto.IbftMessage_RoundChangeData) + if !ok { + return nil + } return rcData.RoundChangeData.LatestPreparedCertificate } @@ -116,7 +137,10 @@ func ExtractLastPreparedProposal(roundChangeMessage *proto.IbftMessage) *proto.P return nil } - rcData, _ := roundChangeMessage.Payload.(*proto.IbftMessage_RoundChangeData) + rcData, ok := roundChangeMessage.Payload.(*proto.IbftMessage_RoundChangeData) + if !ok { + return nil + } return rcData.RoundChangeData.LastPreparedProposal } diff --git a/messages/proto/helper.go b/messages/proto/helper.go index 90ee97a..59de2a8 100644 --- a/messages/proto/helper.go +++ b/messages/proto/helper.go @@ -1,11 +1,21 @@ // Package proto defines the code for protocol buffer package proto -import "google.golang.org/protobuf/proto" +import ( + "errors" + + "google.golang.org/protobuf/proto" +) + +var errNotIbftMessage = errors.New("not an Ibft message") // PayloadNoSig returns marshaled message without signature func (m *IbftMessage) PayloadNoSig() ([]byte, error) { - mm, _ := proto.Clone(m).(*IbftMessage) + mm, ok := proto.Clone(m).(*IbftMessage) + if !ok { + return nil, errNotIbftMessage + } + mm.Signature = nil raw, err := proto.Marshal(mm)