Skip to content

Commit

Permalink
refactor: remove collections.ErrInvalidIterator when unecessary (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Aug 11, 2023
1 parent 66d9be0 commit 77be10b
Show file tree
Hide file tree
Showing 30 changed files with 50 additions and 82 deletions.
4 changes: 1 addition & 3 deletions simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package simapp

import (
"encoding/json"
"errors"
"fmt"
"log"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"

"cosmossdk.io/collections"
storetypes "cosmossdk.io/store/types"

servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand Down Expand Up @@ -243,7 +241,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
}
return false, nil
})
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}
}
2 changes: 1 addition & 1 deletion simapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.20
require (
cosmossdk.io/api v0.7.0
cosmossdk.io/client/v2 v2.0.0-20230630094428-02b760776860
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68
cosmossdk.io/core v0.9.0
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/log v1.2.0
Expand Down Expand Up @@ -38,6 +37,7 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.1 // indirect
cloud.google.com/go/storage v1.31.0 // indirect
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 // indirect
cosmossdk.io/errors v1.0.0 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/staking/keeper/validator_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper_test

import (
"bytes"
"errors"
"fmt"
"testing"

Expand Down Expand Up @@ -176,7 +175,7 @@ func updateValidatorDelegations(f *fixture, existingValAddr, newValAddr sdk.ValA

return false, nil
})
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}
}
6 changes: 2 additions & 4 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package keeper

import (
"context"
"errors"
"fmt"

"cosmossdk.io/collections"
"cosmossdk.io/core/store"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log"
Expand Down Expand Up @@ -258,7 +256,7 @@ func (k BaseKeeper) IterateAllDenomMetaData(ctx context.Context, cb func(types.M
err := k.BaseViewKeeper.DenomMetadata.Walk(ctx, nil, func(_ string, metadata types.Metadata) (stop bool, err error) {
return cb(metadata), nil
})
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}
}
Expand Down Expand Up @@ -479,7 +477,7 @@ func (k BaseViewKeeper) IterateTotalSupply(ctx context.Context, cb func(sdk.Coin
err := k.Supply.Walk(ctx, nil, func(s string, m math.Int) (bool, error) {
return cb(sdk.NewCoin(s, m)), nil
})
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}
}
2 changes: 1 addition & 1 deletion x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func (k BaseSendKeeper) IterateSendEnabledEntries(ctx context.Context, cb func(d
err := k.SendEnabled.Walk(ctx, nil, func(key string, value bool) (stop bool, err error) {
return cb(key, value), nil
})
if err != nil && !errorsmod.IsOf(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}
}
Expand Down
6 changes: 2 additions & 4 deletions x/bank/keeper/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"fmt"

"github.com/cockroachdb/errors"

"cosmossdk.io/collections"
"cosmossdk.io/collections/indexes"
"cosmossdk.io/core/store"
Expand Down Expand Up @@ -158,7 +156,7 @@ func (k BaseViewKeeper) IterateAccountBalances(ctx context.Context, addr sdk.Acc
err := k.Balances.Walk(ctx, collections.NewPrefixedPairRange[sdk.AccAddress, string](addr), func(key collections.Pair[sdk.AccAddress, string], value math.Int) (stop bool, err error) {
return cb(sdk.NewCoin(key.K2(), value)), nil
})
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}
}
Expand All @@ -170,7 +168,7 @@ func (k BaseViewKeeper) IterateAllBalances(ctx context.Context, cb func(sdk.AccA
err := k.Balances.Walk(ctx, nil, func(key collections.Pair[sdk.AccAddress, string], value math.Int) (stop bool, err error) {
return cb(key.K1(), sdk.NewCoin(key.K2(), value)), nil
})
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/circuit/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
cosmossdk.io/api v0.7.0
cosmossdk.io/collections v0.3.0
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68
cosmossdk.io/core v0.9.0
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/errors v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions x/circuit/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4=
cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M=
cosmossdk.io/collections v0.3.0 h1:v0eEqLBxebAV+t+Ahwf9tSJOu95HVLINwROXx2TTZ08=
cosmossdk.io/collections v0.3.0/go.mod h1:CHE1+niUElL9ikCpevRZcp0yqQ4TU0TrEEGirN0mvIg=
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 h1:aFHpJtJgdqBH8kRvD86Rl92rvd1+JFpaUpj+5NZNodg=
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68/go.mod h1:OK08xZu8fxXLoQcFIfkBDayo2aRokLfC3vVcXX0MB8E=
cosmossdk.io/core v0.9.0 h1:30ScAOHDIUOCg1DKAwqkho9wuQJnu7GUrMcg0XLioic=
cosmossdk.io/core v0.9.0/go.mod h1:NFgl5r41Q36+RixTvyrfsS6qQ65agCbZ1FTpnN7/G1Y=
cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc=
Expand Down
6 changes: 2 additions & 4 deletions x/circuit/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package keeper
import (
context "context"

"cosmossdk.io/collections"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/x/circuit/types"
)

Expand All @@ -27,15 +25,15 @@ func (k *Keeper) ExportGenesis(ctx context.Context) (data *types.GenesisState) {
})
return false, nil
})
if err != nil && !errorsmod.IsOf(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}

err = k.DisableList.Walk(ctx, nil, func(msgUrl string) (stop bool, err error) {
disabledMsgs = append(disabledMsgs, msgUrl)
return false, nil
})
if err != nil && !errorsmod.IsOf(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}

Expand Down
4 changes: 1 addition & 3 deletions x/circuit/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package keeper
import (
"context"

"cosmossdk.io/collections"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/x/circuit/types"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -72,7 +70,7 @@ func (qs QueryServer) DisabledList(ctx context.Context, req *types.QueryDisabled
msgs = append(msgs, msgUrl)
return false, nil
})
if err != nil && !errorsmod.IsOf(err, collections.ErrInvalidIterator) {
if err != nil {
return nil, err
}

Expand Down
4 changes: 1 addition & 3 deletions x/distribution/keeper/delegation_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper_test

import (
"errors"
"testing"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
Expand Down Expand Up @@ -118,8 +117,7 @@ func getValHistoricalReferenceCount(k keeper.Keeper, ctx sdk.Context) int {
return false, nil
},
)

if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}

Expand Down
15 changes: 7 additions & 8 deletions x/distribution/keeper/genesis.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper

import (
"errors"
"fmt"

"cosmossdk.io/collections"
Expand Down Expand Up @@ -166,7 +165,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
})
return false, nil
})
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}

Expand All @@ -185,7 +184,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
return false, nil
},
)
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}

Expand All @@ -197,7 +196,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
})
return false, nil
})
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}

Expand All @@ -212,7 +211,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
return false, nil
},
)
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}

Expand All @@ -226,7 +225,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
return false, nil
},
)
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}

Expand All @@ -239,7 +238,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
})
return false, nil
})
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}

Expand All @@ -258,7 +257,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
},
)

if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}

Expand Down
9 changes: 4 additions & 5 deletions x/distribution/keeper/invariants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper

import (
"errors"
"fmt"

"cosmossdk.io/collections"
Expand Down Expand Up @@ -57,7 +56,7 @@ func NonNegativeOutstandingInvariant(k Keeper) sdk.Invariant {
}
return false, nil
})
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
return sdk.FormatInvariant(types.ModuleName, "nonnegative outstanding", err.Error()), true
}
broken := count != 0
Expand Down Expand Up @@ -152,7 +151,7 @@ func ReferenceCountInvariant(k Keeper) sdk.Invariant {
},
)

if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}

Expand All @@ -167,7 +166,7 @@ func ReferenceCountInvariant(k Keeper) sdk.Invariant {
},
)

if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}

Expand All @@ -189,7 +188,7 @@ func ModuleAccountInvariant(k Keeper) sdk.Invariant {
expectedCoins = expectedCoins.Add(rewards.Rewards...)
return false, nil
})
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
return sdk.FormatInvariant(types.ModuleName, "module account coins", err.Error()), true
}

Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (k Keeper) GetTotalRewards(ctx context.Context) (totalRewards sdk.DecCoins)
return false, nil
},
)
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}

Expand Down
3 changes: 1 addition & 2 deletions x/distribution/keeper/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ func (k Keeper) IterateValidatorSlashEventsBetween(ctx context.Context, val sdk.
}
return false, nil
})

if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
return err
}

Expand Down
4 changes: 1 addition & 3 deletions x/evidence/genesis.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package evidence

import (
"errors"
"fmt"

"cosmossdk.io/collections"
"cosmossdk.io/x/evidence/exported"
"cosmossdk.io/x/evidence/keeper"
"cosmossdk.io/x/evidence/types"
Expand Down Expand Up @@ -46,7 +44,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
gs.Evidence = append(gs.Evidence, anyEvi)
return false, nil
})
if err != nil && !errors.Is(err, collections.ErrInvalidIterator) {
if err != nil {
panic(err)
}
return gs
Expand Down
3 changes: 1 addition & 2 deletions x/evidence/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"cosmossdk.io/collections"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
"cosmossdk.io/x/evidence"
Expand Down Expand Up @@ -96,7 +95,7 @@ func (suite *GenesisTestSuite) TestInitGenesis() {
false,
func() {
_, err := suite.keeper.Evidences.Iterate(suite.ctx, nil)
suite.Require().ErrorIs(err, collections.ErrInvalidIterator)
suite.Require().NoError(err)
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion x/evidence/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
cosmossdk.io/api v0.7.0
cosmossdk.io/collections v0.3.0
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68
cosmossdk.io/core v0.9.0
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/errors v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions x/evidence/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4=
cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M=
cosmossdk.io/collections v0.3.0 h1:v0eEqLBxebAV+t+Ahwf9tSJOu95HVLINwROXx2TTZ08=
cosmossdk.io/collections v0.3.0/go.mod h1:CHE1+niUElL9ikCpevRZcp0yqQ4TU0TrEEGirN0mvIg=
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 h1:aFHpJtJgdqBH8kRvD86Rl92rvd1+JFpaUpj+5NZNodg=
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68/go.mod h1:OK08xZu8fxXLoQcFIfkBDayo2aRokLfC3vVcXX0MB8E=
cosmossdk.io/core v0.9.0 h1:30ScAOHDIUOCg1DKAwqkho9wuQJnu7GUrMcg0XLioic=
cosmossdk.io/core v0.9.0/go.mod h1:NFgl5r41Q36+RixTvyrfsS6qQ65agCbZ1FTpnN7/G1Y=
cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc=
Expand Down
Loading

0 comments on commit 77be10b

Please sign in to comment.