From b47ee19dad4cb4e50e8a6a9448c0b09958d5581d Mon Sep 17 00:00:00 2001 From: Amir Deris Date: Tue, 7 Apr 2026 11:42:37 -0700 Subject: [PATCH] fixed some of static check warnings in sei-tendermint package --- sei-tendermint/crypto/tmhash/hash.go | 33 +------------- .../internal/consensus/reactor_test.go | 2 +- .../internal/consensus/state_test.go | 1 + .../internal/mempool/mempool_test.go | 1 - .../internal/p2p/peermanager_pool_test.go | 1 - sei-tendermint/internal/store/store.go | 1 + sei-tendermint/libs/cli/setup.go | 35 --------------- sei-tendermint/libs/json/decoder.go | 5 --- sei-tendermint/node/node.go | 1 - sei-tendermint/types/tx.go | 44 ------------------- sei-tendermint/types/validator_set_test.go | 14 +++--- 11 files changed, 11 insertions(+), 127 deletions(-) diff --git a/sei-tendermint/crypto/tmhash/hash.go b/sei-tendermint/crypto/tmhash/hash.go index 8a9fbcfe52..c889ccb4c5 100644 --- a/sei-tendermint/crypto/tmhash/hash.go +++ b/sei-tendermint/crypto/tmhash/hash.go @@ -6,8 +6,7 @@ import ( ) const ( - Size = sha256.Size - BlockSize = sha256.BlockSize + Size = sha256.Size ) // New returns a new hash.Hash. @@ -20,33 +19,3 @@ func Sum(bz []byte) []byte { h := sha256.Sum256(bz) return h[:] } - -//------------------------------------------------------------- - -const ( - TruncatedSize = 20 -) - -type sha256trunc struct { - sha256 hash.Hash -} - -func (h sha256trunc) Write(p []byte) (n int, err error) { - return h.sha256.Write(p) -} -func (h sha256trunc) Sum(b []byte) []byte { - shasum := h.sha256.Sum(b) - return shasum[:TruncatedSize] -} - -func (h sha256trunc) Reset() { - h.sha256.Reset() -} - -func (h sha256trunc) Size() int { - return TruncatedSize -} - -func (h sha256trunc) BlockSize() int { - return h.sha256.BlockSize() -} diff --git a/sei-tendermint/internal/consensus/reactor_test.go b/sei-tendermint/internal/consensus/reactor_test.go index d3c8d8c096..d7fab619e0 100644 --- a/sei-tendermint/internal/consensus/reactor_test.go +++ b/sei-tendermint/internal/consensus/reactor_test.go @@ -79,7 +79,7 @@ func setup( NopMetrics(), config.DefaultConfig(), ) - + require.NoError(t, err) blocksSub, err := state.eventBus.SubscribeWithArgs(ctx, tmpubsub.SubscribeArgs{ ClientID: testSubscriber, Query: types.EventQueryNewBlock, diff --git a/sei-tendermint/internal/consensus/state_test.go b/sei-tendermint/internal/consensus/state_test.go index 0836b4030c..30c6490d5a 100644 --- a/sei-tendermint/internal/consensus/state_test.go +++ b/sei-tendermint/internal/consensus/state_test.go @@ -2440,6 +2440,7 @@ func TestGossipTransactionKeyOnlyConfig(t *testing.T) { proposalMsg := ProposalMessage{&proposal} peerID, err := types.NewNodeID("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") + require.NoError(t, err) startTestRound(ctx, cs1, height, round) cs1.handleMsg(ctx, msgInfo{&proposalMsg, peerID, time.Now()}, false) rs := cs1.GetRoundState() diff --git a/sei-tendermint/internal/mempool/mempool_test.go b/sei-tendermint/internal/mempool/mempool_test.go index 39ca8146af..92fcccfdca 100644 --- a/sei-tendermint/internal/mempool/mempool_test.go +++ b/sei-tendermint/internal/mempool/mempool_test.go @@ -62,7 +62,6 @@ func (app *application) CheckTx(_ context.Context, req *abci.RequestCheckTxV2) ( // format is evm-sender-0=account=priority=nonce // split into respective vars parts := bytes.Split(req.Tx, []byte("=")) - sender = string(parts[0]) account := string(parts[1]) v, err := strconv.ParseInt(string(parts[2]), 10, 64) if err != nil { diff --git a/sei-tendermint/internal/p2p/peermanager_pool_test.go b/sei-tendermint/internal/p2p/peermanager_pool_test.go index 0fb24a559a..02a85117f0 100644 --- a/sei-tendermint/internal/p2p/peermanager_pool_test.go +++ b/sei-tendermint/internal/p2p/peermanager_pool_test.go @@ -46,7 +46,6 @@ func minBy[T any, I cmp.Ordered](vals iter.Seq[T], by func(T) I) utils.Option[T] // - no parallel upgrades allowed even if permit is provided. func TestPoolManager_TryStartDial_MaxOut(t *testing.T) { rng := utils.TestRng() - const maxIn = 0 const maxOut = 5 fixedAddrs := make([]NodeAddress, maxOut) want := map[types.NodeID][]NodeAddress{} diff --git a/sei-tendermint/internal/store/store.go b/sei-tendermint/internal/store/store.go index a94898820e..7fbb7864a6 100644 --- a/sei-tendermint/internal/store/store.go +++ b/sei-tendermint/internal/store/store.go @@ -657,6 +657,7 @@ func seenCommitKey() []byte { return key } +//lint:ignore U1000 Method retained for completeness func extCommitKey(height int64) []byte { key, err := orderedcode.Append(nil, prefixExtCommit, height) if err != nil { diff --git a/sei-tendermint/libs/cli/setup.go b/sei-tendermint/libs/cli/setup.go index 52f636a952..3bd172ffd9 100644 --- a/sei-tendermint/libs/cli/setup.go +++ b/sei-tendermint/libs/cli/setup.go @@ -132,38 +132,3 @@ func (e Executor) Execute() error { } return err } - -// Bind all flags and read the config into viper -func bindFlagsLoadViper(cmd *cobra.Command, args []string) error { - // cmd.Flags() includes flags from this command and all persistent flags from the parent - if err := viper.BindPFlags(cmd.Flags()); err != nil { - return err - } - - homeDir := viper.GetString(HomeFlag) - viper.Set(HomeFlag, homeDir) - viper.SetConfigName("config") // name of config file (without extension) - viper.AddConfigPath(homeDir) // search root directory - viper.AddConfigPath(filepath.Join(homeDir, "config")) // search root directory /config - - // If a config file is found, read it in. - if err := viper.ReadInConfig(); err == nil { - // stderr, so if we redirect output to json file, this doesn't appear - // fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed()) - } else if _, ok := err.(viper.ConfigFileNotFoundError); !ok { - // ignore not found error, return other errors - return err - } - return nil -} - -func validateOutput(cmd *cobra.Command, args []string) error { - // validate output format - output := viper.GetString(OutputFlag) - switch output { - case "text", "json": - default: - return fmt.Errorf("unsupported output format: %s", output) - } - return nil -} diff --git a/sei-tendermint/libs/json/decoder.go b/sei-tendermint/libs/json/decoder.go index ae516eefde..f973df8ccb 100644 --- a/sei-tendermint/libs/json/decoder.go +++ b/sei-tendermint/libs/json/decoder.go @@ -207,8 +207,3 @@ func decodeStdlib(bz []byte, rv reflect.Value) error { rv.Set(target.Elem()) return nil } - -type interfaceWrapper struct { - Type string `json:"type"` - Value json.RawMessage `json:"value"` -} diff --git a/sei-tendermint/node/node.go b/sei-tendermint/node/node.go index cf96b17ca3..fbc6bf0793 100644 --- a/sei-tendermint/node/node.go +++ b/sei-tendermint/node/node.go @@ -56,7 +56,6 @@ type nodeImpl struct { // network router *p2p.Router - routerRestartCh chan struct{} // Used to signal a restart the node on the application level ServiceRestartCh chan []string nodeInfo types.NodeInfo nodeKey types.NodeKey // our node privkey diff --git a/sei-tendermint/types/tx.go b/sei-tendermint/types/tx.go index ed66de4146..a8afa27069 100644 --- a/sei-tendermint/types/tx.go +++ b/sei-tendermint/types/tx.go @@ -5,7 +5,6 @@ import ( "crypto/sha256" "errors" "fmt" - "sort" "github.com/sei-protocol/sei-chain/sei-tendermint/crypto" "github.com/sei-protocol/sei-chain/sei-tendermint/crypto/merkle" @@ -93,49 +92,6 @@ func (txs Txs) ToSliceOfBytes() [][]byte { return txBzs } -func sortedCopy(txs Txs) Txs { - cp := make(Txs, len(txs)) - copy(cp, txs) - sort.Sort(cp) - return cp -} - -// containsAny checks that list a contains one of the transactions in list -// b. If a match is found, the index in b of the matching transaction is returned. -// Both lists must be sorted. -func containsAny(a, b []Tx) (int, bool) { - for i, cur := range b { - if _, ok := contains(a, cur); ok { - return i, true - } - } - return -1, false -} - -// containsAll checks that super contains all of the transactions in the sub -// list. If not all values in sub are present in super, the index in sub of the -// first Tx absent from super is returned. -func containsAll(super, sub Txs) (int, bool) { - for i, cur := range sub { - if _, ok := contains(super, cur); !ok { - return i, false - } - } - return -1, true -} - -// contains checks that the sorted list, set contains elem. If set does contain elem, then the -// index in set of elem is returned. -func contains(set []Tx, elem Tx) (int, bool) { - n := sort.Search(len(set), func(i int) bool { - return bytes.Compare(elem, set[i]) <= 0 - }) - if n == len(set) || !bytes.Equal(elem, set[n]) { - return -1, false - } - return n, true -} - // TxProof represents a Merkle proof of the presence of a transaction in the Merkle tree. type TxProof struct { RootHash tmbytes.HexBytes `json:"root_hash"` diff --git a/sei-tendermint/types/validator_set_test.go b/sei-tendermint/types/validator_set_test.go index 98e271421d..7a845c1a1d 100644 --- a/sei-tendermint/types/validator_set_test.go +++ b/sei-tendermint/types/validator_set_test.go @@ -34,13 +34,13 @@ func TestValidatorSetBasic(t *testing.T) { assert.EqualValues(t, vset, vset.Copy()) assert.False(t, vset.HasAddress([]byte("some val"))) - idx, val, ok := vset.GetByAddress([]byte("some val")) + _, _, ok := vset.GetByAddress([]byte("some val")) require.False(t, ok) - addr, val, ok := vset.GetByIndex(-100) + _, _, ok = vset.GetByIndex(-100) require.False(t, ok) - addr, val, ok = vset.GetByIndex(0) + _, _, ok = vset.GetByIndex(0) require.False(t, ok) - addr, val, ok = vset.GetByIndex(100) + _, _, ok = vset.GetByIndex(100) require.False(t, ok) assert.Zero(t, vset.Size()) assert.Equal(t, int64(0), vset.TotalVotingPower()) @@ -49,14 +49,14 @@ func TestValidatorSetBasic(t *testing.T) { 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}, vset.Hash()) // add - val = randModuloValidator(vset.TotalVotingPower()) + val := randModuloValidator(vset.TotalVotingPower()) assert.NoError(t, vset.UpdateWithChangeSet([]*Validator{val})) assert.True(t, vset.HasAddress(val.Address)) - idx, _, ok = vset.GetByAddress(val.Address) + idx, _, ok := vset.GetByAddress(val.Address) assert.True(t, ok) assert.EqualValues(t, 0, idx) - addr, _, ok = vset.GetByIndex(0) + addr, _, ok := vset.GetByIndex(0) assert.True(t, ok) assert.Equal(t, []byte(val.Address), addr) assert.Equal(t, 1, vset.Size())