From 08b23db9889bd6f3136b1894a8b0a08ccc2a8368 Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Wed, 23 Oct 2024 14:22:34 +0800 Subject: [PATCH 1/4] chore: remove unused local variables --- .golangci.yml | 2 ++ schema/indexer/start.go | 2 +- simapp/export.go | 2 -- store/cachekv/store_test.go | 12 +++++------- types/mempool/priority_nonce_test.go | 1 + x/staking/keeper/query_utils.go | 3 --- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 9fa8a3398ac3..29c3e352b6ab 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -119,3 +119,5 @@ linters-settings: - regexpMust - appendAssign - ifElseChain + unused: + local-variables-are-used: false \ No newline at end of file diff --git a/schema/indexer/start.go b/schema/indexer/start.go index f675c2916026..cc5110046eee 100644 --- a/schema/indexer/start.go +++ b/schema/indexer/start.go @@ -120,7 +120,7 @@ func StartIndexing(opts IndexingOptions) (IndexingTarget, error) { targetCfg.Config, err = unmarshalIndexerCustomConfig(targetCfg.Config, init.ConfigType) if err != nil { - return IndexingTarget{}, fmt.Errorf("failed to unmarshal indexer config for target %q: %v", targetName, err) + return IndexingTarget{}, fmt.Errorf("failed to unmarshal indexer config for target %q: %w", targetName, err) } initRes, err := init.InitFunc(InitParams{ diff --git a/simapp/export.go b/simapp/export.go index 28d15f507a9b..9600132dfedf 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -216,7 +216,6 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] // update bond intra-tx counters. store := ctx.KVStore(app.GetKey(stakingtypes.StoreKey)) iter := storetypes.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) - counter := int16(0) for ; iter.Valid(); iter.Next() { addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key())) @@ -238,7 +237,6 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] if err = app.StakingKeeper.SetValidator(ctx, validator); err != nil { panic(err) } - counter++ } if err := iter.Close(); err != nil { diff --git a/store/cachekv/store_test.go b/store/cachekv/store_test.go index 2885e7125476..8df5c1cfb758 100644 --- a/store/cachekv/store_test.go +++ b/store/cachekv/store_test.go @@ -448,7 +448,7 @@ func TestIteratorDeadlock(t *testing.T) { defer it2.Close() } -//------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------- // do some random ops const ( @@ -527,7 +527,7 @@ func doRandomOp(t *testing.T, st types.CacheKVStore, truth corestore.KVStoreWith } } -//------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------- // iterate over whole domain func assertIterateDomain(t *testing.T, st types.KVStore, expectedN int) { @@ -552,7 +552,6 @@ func assertIterateDomainCheck(t *testing.T, st types.KVStore, mem corestore.KVSt require.NoError(t, err) krc := newKeyRangeCounter(r) - i := 0 for ; krc.valid(); krc.next() { require.True(t, itr.Valid()) @@ -569,7 +568,6 @@ func assertIterateDomainCheck(t *testing.T, st types.KVStore, mem corestore.KVSt itr.Next() itr2.Next() - i++ } require.False(t, itr.Valid()) @@ -604,7 +602,7 @@ func checkIterators(t *testing.T, itr, itr2 types.Iterator) { require.False(t, itr2.Valid()) } -//-------------------------------------------------------- +// -------------------------------------------------------- func setRange(t *testing.T, st types.KVStore, mem corestore.KVStoreWithBatch, start, end int) { t.Helper() @@ -624,7 +622,7 @@ func deleteRange(t *testing.T, st types.KVStore, mem corestore.KVStoreWithBatch, } } -//-------------------------------------------------------- +// -------------------------------------------------------- type keyRange struct { start int @@ -674,7 +672,7 @@ func (krc *keyRangeCounter) key() int { return thisKeyRange.start + krc.idx } -//-------------------------------------------------------- +// -------------------------------------------------------- func bz(s string) []byte { return []byte(s) } diff --git a/types/mempool/priority_nonce_test.go b/types/mempool/priority_nonce_test.go index 3bfd7e4ba86c..3a5bed96045b 100644 --- a/types/mempool/priority_nonce_test.go +++ b/types/mempool/priority_nonce_test.go @@ -588,6 +588,7 @@ func validateOrder(mtxs []sdk.Tx) error { } } } + _ = iterations // fmt.Printf("validation in iterations: %d\n", iterations) return nil } diff --git a/x/staking/keeper/query_utils.go b/x/staking/keeper/query_utils.go index 625984dbd44a..ee0b042b8433 100644 --- a/x/staking/keeper/query_utils.go +++ b/x/staking/keeper/query_utils.go @@ -65,12 +65,9 @@ func (k Keeper) GetDelegatorValidator( func (k Keeper) GetAllDelegatorDelegations(ctx context.Context, delegator sdk.AccAddress) ([]types.Delegation, error) { delegations := make([]types.Delegation, 0) - var i int64 rng := collections.NewPrefixedPairRange[sdk.AccAddress, sdk.ValAddress](delegator) err := k.Delegations.Walk(ctx, rng, func(key collections.Pair[sdk.AccAddress, sdk.ValAddress], del types.Delegation) (stop bool, err error) { delegations = append(delegations, del) - i++ - return false, nil }) if err != nil { From 1d804cc6425cfca9515d68d44e5ec9b1367c4959 Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Wed, 23 Oct 2024 14:27:01 +0800 Subject: [PATCH 2/4] revert --- store/cachekv/store_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/store/cachekv/store_test.go b/store/cachekv/store_test.go index 8df5c1cfb758..de03b04ba3fa 100644 --- a/store/cachekv/store_test.go +++ b/store/cachekv/store_test.go @@ -448,7 +448,7 @@ func TestIteratorDeadlock(t *testing.T) { defer it2.Close() } -// ------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------- // do some random ops const ( @@ -527,7 +527,7 @@ func doRandomOp(t *testing.T, st types.CacheKVStore, truth corestore.KVStoreWith } } -// ------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------- // iterate over whole domain func assertIterateDomain(t *testing.T, st types.KVStore, expectedN int) { @@ -602,7 +602,7 @@ func checkIterators(t *testing.T, itr, itr2 types.Iterator) { require.False(t, itr2.Valid()) } -// -------------------------------------------------------- +//-------------------------------------------------------- func setRange(t *testing.T, st types.KVStore, mem corestore.KVStoreWithBatch, start, end int) { t.Helper() @@ -622,7 +622,7 @@ func deleteRange(t *testing.T, st types.KVStore, mem corestore.KVStoreWithBatch, } } -// -------------------------------------------------------- +//-------------------------------------------------------- type keyRange struct { start int @@ -672,7 +672,7 @@ func (krc *keyRangeCounter) key() int { return thisKeyRange.start + krc.idx } -// -------------------------------------------------------- +//-------------------------------------------------------- func bz(s string) []byte { return []byte(s) } From c571f1355a934bb45eab5e2d5bde254a6fee3841 Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Wed, 23 Oct 2024 16:04:59 +0800 Subject: [PATCH 3/4] revert --- schema/indexer/start.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schema/indexer/start.go b/schema/indexer/start.go index cc5110046eee..f675c2916026 100644 --- a/schema/indexer/start.go +++ b/schema/indexer/start.go @@ -120,7 +120,7 @@ func StartIndexing(opts IndexingOptions) (IndexingTarget, error) { targetCfg.Config, err = unmarshalIndexerCustomConfig(targetCfg.Config, init.ConfigType) if err != nil { - return IndexingTarget{}, fmt.Errorf("failed to unmarshal indexer config for target %q: %w", targetName, err) + return IndexingTarget{}, fmt.Errorf("failed to unmarshal indexer config for target %q: %v", targetName, err) } initRes, err := init.InitFunc(InitParams{ From 16bfeddccc6b103d43453440a4643f2eb7e1ec1f Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Wed, 23 Oct 2024 16:14:20 +0800 Subject: [PATCH 4/4] remove comment --- types/mempool/priority_nonce_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/types/mempool/priority_nonce_test.go b/types/mempool/priority_nonce_test.go index 3a5bed96045b..73d61cb9c2e9 100644 --- a/types/mempool/priority_nonce_test.go +++ b/types/mempool/priority_nonce_test.go @@ -540,10 +540,8 @@ func (s *MempoolTestSuite) TestRandomTxOrderManyTimes() { // validateOrder checks that the txs are ordered by priority and nonce // in O(n^2) time by checking each tx against all the other txs func validateOrder(mtxs []sdk.Tx) error { - iterations := 0 var itxs []txSpec for i, mtx := range mtxs { - iterations++ tx := mtx.(testTx) itxs = append(itxs, txSpec{p: int(tx.priority), n: int(tx.nonce), a: tx.address, i: i}) } @@ -556,7 +554,6 @@ func validateOrder(mtxs []sdk.Tx) error { for _, a := range itxs { for _, b := range itxs { - iterations++ // when b is before a // when a is before b @@ -574,7 +571,6 @@ func validateOrder(mtxs []sdk.Tx) error { // find a tx with same sender as b and lower nonce found := false for _, c := range itxs { - iterations++ if c.a.Equals(b.a) && c.n < b.n && c.p <= a.p { found = true break @@ -588,8 +584,6 @@ func validateOrder(mtxs []sdk.Tx) error { } } } - _ = iterations - // fmt.Printf("validation in iterations: %d\n", iterations) return nil }