From 5c624eae9d9c2a1d7e7db3909c9c8b6153bc8761 Mon Sep 17 00:00:00 2001 From: Sam Ricotta Date: Thu, 11 Aug 2022 10:26:23 +0200 Subject: [PATCH] review updates --- .golangci.yml | 2 +- blocksync/pool.go | 3 +-- config/config.go | 3 +-- consensus/byzantine_test.go | 2 +- consensus/msgs_test.go | 1 - consensus/replay_test.go | 1 - crypto/armor/armor.go | 2 +- crypto/merkle/proof_value.go | 4 ++-- crypto/secp256k1/secp256k1.go | 1 - evidence/reactor_test.go | 1 - evidence/verify.go | 3 +-- libs/clist/clist_test.go | 2 -- libs/log/tmfmt_logger_test.go | 1 - light/client.go | 6 +++--- light/rpc/client.go | 1 - privval/msgs_test.go | 1 - rpc/core/env.go | 1 - types/block_test.go | 2 +- types/event_bus.go | 1 - types/validator_set_test.go | 1 - 20 files changed, 12 insertions(+), 27 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ef8395a16..6136c8868 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,7 +21,7 @@ linters: # - nolintlint - prealloc - staticcheck - # - structcheck // to be fixed by golangci-lint + - structcheck - stylecheck - typecheck - unconvert diff --git a/blocksync/pool.go b/blocksync/pool.go index 1a89cbe7d..712b6d79a 100644 --- a/blocksync/pool.go +++ b/blocksync/pool.go @@ -410,8 +410,7 @@ func (pool *BlockPool) sendError(err error, peerID p2p.ID) { } // for debugging purposes -// -//nolint:unused + func (pool *BlockPool) debug() string { pool.mtx.Lock() defer pool.mtx.Unlock() diff --git a/config/config.go b/config/config.go index 3eea2b7b5..03c76591e 100644 --- a/config/config.go +++ b/config/config.go @@ -1117,11 +1117,10 @@ func TestStorageConfig() *StorageConfig { } } -// ----------------------------------------------------------------------------- // TxIndexConfig // Remember that Event has the following structure: // type: [ -// +// ... // key: value, // ... // diff --git a/consensus/byzantine_test.go b/consensus/byzantine_test.go index 75b69395a..d953ab34b 100644 --- a/consensus/byzantine_test.go +++ b/consensus/byzantine_test.go @@ -422,7 +422,7 @@ func TestByzantineConflictingProposalsWithPartition(t *testing.T) { // wait for someone in the big partition (B) to make a block <-blocksSubs[ind2].Out() - t.Logf("A block has been committed. Healing partition") + t.Log("A block has been committed. Healing partition") p2p.Connect2Switches(switches, ind0, ind1) p2p.Connect2Switches(switches, ind0, ind2) diff --git a/consensus/msgs_test.go b/consensus/msgs_test.go index 296f6b12a..e1ab4b2e2 100644 --- a/consensus/msgs_test.go +++ b/consensus/msgs_test.go @@ -314,7 +314,6 @@ func TestWALMsgProto(t *testing.T) { } } -//nolint:lll //ignore line length for tests func TestConsMsgsVectors(t *testing.T) { date := time.Date(2018, 8, 30, 12, 0, 0, 0, time.UTC) psh := types.PartSetHeader{ diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 9ca5f657e..d9ad60d18 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -291,7 +291,6 @@ func (w *crashingWAL) Start() error { return w.next.Start() } func (w *crashingWAL) Stop() error { return w.next.Stop() } func (w *crashingWAL) Wait() { w.next.Wait() } -// ------------------------------------------------------------------------------------------ type testSim struct { GenesisState sm.State Config *cfg.Config diff --git a/crypto/armor/armor.go b/crypto/armor/armor.go index 99e2c3b3a..5549d08ce 100644 --- a/crypto/armor/armor.go +++ b/crypto/armor/armor.go @@ -5,7 +5,7 @@ import ( "fmt" "io" - "golang.org/x/crypto/openpgp/armor" //nolint: staticcheck + "golang.org/x/crypto/openpgp/armor" ) func EncodeArmor(blockType string, headers map[string]string, data []byte) string { diff --git a/crypto/merkle/proof_value.go b/crypto/merkle/proof_value.go index 842dc8201..7e1420ab1 100644 --- a/crypto/merkle/proof_value.go +++ b/crypto/merkle/proof_value.go @@ -85,8 +85,8 @@ func (op ValueOp) Run(args [][]byte) ([][]byte, error) { bz := new(bytes.Buffer) // Wrap to hash the KVPair. - encodeByteSlice(bz, op.key) //nolint: errcheck // does not error - encodeByteSlice(bz, vhash) //nolint: errcheck // does not error + encodeByteSlice(bz, op.key) + encodeByteSlice(bz, vhash) kvhash := leafHash(bz.Bytes()) if !bytes.Equal(kvhash, op.Proof.LeafHash) { diff --git a/crypto/secp256k1/secp256k1.go b/crypto/secp256k1/secp256k1.go index 21073bea1..da21de1bb 100644 --- a/crypto/secp256k1/secp256k1.go +++ b/crypto/secp256k1/secp256k1.go @@ -15,7 +15,6 @@ import ( tmjson "github.com/tendermint/tendermint/libs/json" ) -// ------------------------------------- const ( PrivKeyName = "tendermint/PrivKeySecp256k1" PubKeyName = "tendermint/PubKeySecp256k1" diff --git a/evidence/reactor_test.go b/evidence/reactor_test.go index d4772b00c..ff6dd712d 100644 --- a/evidence/reactor_test.go +++ b/evidence/reactor_test.go @@ -367,7 +367,6 @@ func exampleVote(t byte) *types.Vote { } } -//nolint:lll //ignore line length for tests func TestEvidenceVectors(t *testing.T) { val := &types.Validator{ diff --git a/evidence/verify.go b/evidence/verify.go index c20cb0a2d..9a9193044 100644 --- a/evidence/verify.go +++ b/evidence/verify.go @@ -106,9 +106,8 @@ func (evpool *Pool) verify(evidence types.Evidence) error { // the conflicting header's commit // - 2/3+ of the conflicting validator set correctly signed the conflicting block // - the nodes trusted header at the same height as the conflicting header has a different hash -// + // CONTRACT: must run ValidateBasic() on the evidence before verifying -// // must check that the evidence has not expired (i.e. is outside the maximum age threshold) func VerifyLightClientAttack(e *types.LightClientAttackEvidence, commonHeader, trustedHeader *types.SignedHeader, commonVals *types.ValidatorSet, now time.Time, trustPeriod time.Duration) error { diff --git a/libs/clist/clist_test.go b/libs/clist/clist_test.go index 7b10478fd..e2fc577a6 100644 --- a/libs/clist/clist_test.go +++ b/libs/clist/clist_test.go @@ -68,8 +68,6 @@ func TestSmall(t *testing.T) { // This test is quite hacky because it relies on SetFinalizer // which isn't guaranteed to run at all. - -//nolint:unused,deadcode func _TestGCFifo(t *testing.T) { if runtime.GOARCH != "amd64" { t.Skipf("Skipping on non-amd64 machine") diff --git a/libs/log/tmfmt_logger_test.go b/libs/log/tmfmt_logger_test.go index c9a6deff4..d607e0d83 100644 --- a/libs/log/tmfmt_logger_test.go +++ b/libs/log/tmfmt_logger_test.go @@ -83,7 +83,6 @@ func benchmarkRunnerKitlog(b *testing.B, logger kitlog.Logger, f func(kitlog.Log } } -// nolint: errcheck // ignore errors var ( baseMessage = func(logger kitlog.Logger) { logger.Log("foo_key", "foo_value") } withMessage = func(logger kitlog.Logger) { kitlog.With(logger, "a", "b").Log("d", "f") } diff --git a/light/client.go b/light/client.go index 8d478e69c..3d26d1b0b 100644 --- a/light/client.go +++ b/light/client.go @@ -284,16 +284,16 @@ func (c *Client) restoreTrustedLightBlock() error { // if options.Height: // -// 1. ahead of trustedLightBlock.Height => fetch light blocks (same height as +// 1) ahead of trustedLightBlock.Height => fetch light blocks (same height as // trustedLightBlock) from primary provider and check it's hash matches the // trustedLightBlock's hash (if not, remove trustedLightBlock and all the light blocks // before) // -// 2. equals trustedLightBlock.Height => check options.Hash matches the +// 2) equals trustedLightBlock.Height => check options.Hash matches the // trustedLightBlock's hash (if not, remove trustedLightBlock and all the light blocks // before) // -// 3. behind trustedLightBlock.Height => remove all the light blocks between +// 3) behind trustedLightBlock.Height => remove all the light blocks between // options.Height and trustedLightBlock.Height, update trustedLightBlock, then // check options.Hash matches the trustedLightBlock's hash (if not, remove // trustedLightBlock and all the light blocks before) diff --git a/light/rpc/client.go b/light/rpc/client.go index 4a845a5da..6fc1adbca 100644 --- a/light/rpc/client.go +++ b/light/rpc/client.go @@ -27,7 +27,6 @@ var errNegOrZeroHeight = errors.New("negative or zero height") type KeyPathFunc func(path string, key []byte) (merkle.KeyPath, error) // LightClient is an interface that contains functionality needed by Client from the light client. -// //go:generate ../../scripts/mockery_generate.sh LightClient type LightClient interface { ChainID() string diff --git a/privval/msgs_test.go b/privval/msgs_test.go index afefa0e77..053e9bcc6 100644 --- a/privval/msgs_test.go +++ b/privval/msgs_test.go @@ -57,7 +57,6 @@ func exampleProposal() *types.Proposal { } } -//nolint:lll // ignore line length for tests func TestPrivvalVectors(t *testing.T) { pk := ed25519.GenPrivKeyFromSecret([]byte("it's a secret")).PubKey() ppk, err := cryptoenc.PubKeyToProto(pk) diff --git a/rpc/core/env.go b/rpc/core/env.go index e92319937..d28bedd7a 100644 --- a/rpc/core/env.go +++ b/rpc/core/env.go @@ -69,7 +69,6 @@ type peers interface { Peers() p2p.IPeerSet } -// ---------------------------------------------- // Environment contains objects and interfaces used by the RPC. It is expected // to be setup once during startup. type Environment struct { diff --git a/types/block_test.go b/types/block_test.go index dc0579fec..2355cb0f1 100644 --- a/types/block_test.go +++ b/types/block_test.go @@ -200,7 +200,7 @@ func makeBlockID(hash []byte, partSetSize uint32, partSetHash []byte) BlockID { var nilBytes []byte -// This follows RFC-6962, i.e. `echo -n ” | sha256sum` +// This follows RFC-6962, i.e. `echo -n '' | sha256sum` var emptyBytes = []byte{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55} diff --git a/types/event_bus.go b/types/event_bus.go index af5b2df05..b44d5143f 100644 --- a/types/event_bus.go +++ b/types/event_bus.go @@ -227,7 +227,6 @@ func (b *EventBus) PublishEventValidatorSetUpdates(data EventDataValidatorSetUpd return b.Publish(EventValidatorSetUpdates, data) } -// ----------------------------------------------------------------------------- type NopEventBus struct{} func (NopEventBus) Subscribe( diff --git a/types/validator_set_test.go b/types/validator_set_test.go index d9283001c..7f501b844 100644 --- a/types/validator_set_test.go +++ b/types/validator_set_test.go @@ -1680,7 +1680,6 @@ func (tvals testValsByVotingPower) Swap(i, j int) { tvals[i], tvals[j] = tvals[j], tvals[i] } -// ------------------------------------- // Benchmark tests func BenchmarkUpdates(b *testing.B) { const (