From 108a98a86530aee9878c049794471dcdfc8acec8 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 7 Jun 2022 17:25:01 +0200 Subject: [PATCH 1/2] remove direct reliance on staking from slashing --- go.mod | 1 - go.sum | 2 -- x/slashing/module.go | 5 ++--- x/slashing/simulation/operations.go | 8 ++++---- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index b99ce2b1e7f4..598eea06d7ba 100644 --- a/go.mod +++ b/go.mod @@ -78,7 +78,6 @@ require ( github.com/cenkalti/backoff/v4 v4.1.1 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect - github.com/cosmos/cosmos-sdk/store/tools/ics23 v0.0.0-20220603170123-fc0238903061 // indirect github.com/cosmos/ledger-go v0.9.2 // indirect github.com/creachadair/taskgroup v0.3.2 // indirect github.com/danieljoos/wincred v1.0.2 // indirect diff --git a/go.sum b/go.sum index 05f371d31db0..2d67e65fb362 100644 --- a/go.sum +++ b/go.sum @@ -291,8 +291,6 @@ github.com/cosmos/btcutil v1.0.4 h1:n7C2ngKXo7UC9gNyMNLbzqz7Asuf+7Qv4gnX/rOdQ44= github.com/cosmos/btcutil v1.0.4/go.mod h1:Ffqc8Hn6TJUdDgHBwIZLtrLQC1KdJ9jGJl/TvgUaxbU= github.com/cosmos/cosmos-proto v1.0.0-alpha7 h1:yqYUOHF2jopwZh4dVQp3xgqwftE5/2hkrwIV6vkUbO0= github.com/cosmos/cosmos-proto v1.0.0-alpha7/go.mod h1:dosO4pSAbJF8zWCzCoTWP7nNsjcvSUBQmniFxDg5daw= -github.com/cosmos/cosmos-sdk/store/tools/ics23 v0.0.0-20220603170123-fc0238903061 h1:ERjwnZ8dFB+78pNDPoplaYJ+wdzc4Z0v+CcBS1ehalY= -github.com/cosmos/cosmos-sdk/store/tools/ics23 v0.0.0-20220603170123-fc0238903061/go.mod h1:EOXK+a/6yV5rT46k8UaI56UwE+AU1uq712wy6IbG5+E= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/iavl v0.18.0 h1:02ur4vnalMR2GuWCFNkuseUcl/BCVmg9tOeHOGiZOkE= diff --git a/x/slashing/module.go b/x/slashing/module.go index 47ab5e56d3b3..47f2aec83872 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -20,7 +20,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/slashing/keeper" "github.com/cosmos/cosmos-sdk/x/slashing/simulation" "github.com/cosmos/cosmos-sdk/x/slashing/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) var ( @@ -91,11 +90,11 @@ type AppModule struct { keeper keeper.Keeper accountKeeper types.AccountKeeper bankKeeper types.BankKeeper - stakingKeeper *stakingkeeper.Keeper + stakingKeeper types.StakingKeeper } // NewAppModule creates a new AppModule object -func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper, sk *stakingkeeper.Keeper) AppModule { +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper, sk types.StakingKeeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{cdc: cdc}, keeper: keeper, diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 1aaf4387f702..c6de169b2a89 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -24,7 +24,7 @@ const ( // WeightedOperations returns all the operations from the module with their respective weights func WeightedOperations( appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, - bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper, + bk types.BankKeeper, k keeper.Keeper, sk types.StakingKeeper, ) simulation.WeightedOperations { var weightMsgUnjail int appParams.GetOrGenerate(cdc, OpWeightMsgUnjail, &weightMsgUnjail, nil, @@ -36,18 +36,18 @@ func WeightedOperations( return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgUnjail, - SimulateMsgUnjail(ak, bk, k, sk), + SimulateMsgUnjail(ak, bk, k, sk.(*stakingkeeper.Keeper)), ), } } // SimulateMsgUnjail generates a MsgUnjail with random values -func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simtypes.Operation { +func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk types.StakingKeeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - validator, ok := stakingkeeper.RandomValidator(r, sk, ctx) + validator, ok := stakingkeeper.RandomValidator(r, sk.(*stakingkeeper.Keeper), ctx) if !ok { return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "validator is not ok"), nil, nil // skip } From f576ecd3c9beb1b8dbef493d295286a891ead8df Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 7 Jun 2022 17:51:10 +0200 Subject: [PATCH 2/2] remove reliance in distribution --- x/distribution/module.go | 5 ++--- x/distribution/simulation/operations.go | 10 ++++++---- x/slashing/simulation/operations.go | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/x/distribution/module.go b/x/distribution/module.go index be0e92d1e9cb..dc54a64a9b77 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -20,7 +20,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/distribution/keeper" "github.com/cosmos/cosmos-sdk/x/distribution/simulation" "github.com/cosmos/cosmos-sdk/x/distribution/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) var ( @@ -89,13 +88,13 @@ type AppModule struct { keeper keeper.Keeper accountKeeper types.AccountKeeper bankKeeper types.BankKeeper - stakingKeeper *stakingkeeper.Keeper + stakingKeeper types.StakingKeeper } // NewAppModule creates a new AppModule object func NewAppModule( cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.AccountKeeper, - bankKeeper types.BankKeeper, stakingKeeper *stakingkeeper.Keeper, + bankKeeper types.BankKeeper, stakingKeeper types.StakingKeeper, ) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{cdc: cdc}, diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index ba21eb7828a9..67f130b3c75c 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -24,7 +24,7 @@ const ( ) // WeightedOperations returns all the operations from the module with their respective weights -func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simulation.WeightedOperations { +func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk types.StakingKeeper) simulation.WeightedOperations { var weightMsgSetWithdrawAddress int appParams.GetOrGenerate(cdc, OpWeightMsgSetWithdrawAddress, &weightMsgSetWithdrawAddress, nil, func(_ *rand.Rand) { @@ -53,6 +53,8 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty }, ) + stakeKeeper := sk.(*stakingkeeper.Keeper) + return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgSetWithdrawAddress, @@ -60,15 +62,15 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty ), simulation.NewWeightedOperation( weightMsgWithdrawDelegationReward, - SimulateMsgWithdrawDelegatorReward(ak, bk, k, sk), + SimulateMsgWithdrawDelegatorReward(ak, bk, k, stakeKeeper), ), simulation.NewWeightedOperation( weightMsgWithdrawValidatorCommission, - SimulateMsgWithdrawValidatorCommission(ak, bk, k, sk), + SimulateMsgWithdrawValidatorCommission(ak, bk, k, stakeKeeper), ), simulation.NewWeightedOperation( weightMsgFundCommunityPool, - SimulateMsgFundCommunityPool(ak, bk, k, sk), + SimulateMsgFundCommunityPool(ak, bk, k, stakeKeeper), ), } } diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index c6de169b2a89..93f494360cfa 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -42,12 +42,12 @@ func WeightedOperations( } // SimulateMsgUnjail generates a MsgUnjail with random values -func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk types.StakingKeeper) simtypes.Operation { +func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk *stakingkeeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - validator, ok := stakingkeeper.RandomValidator(r, sk.(*stakingkeeper.Keeper), ctx) + validator, ok := stakingkeeper.RandomValidator(r, sk, ctx) if !ok { return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "validator is not ok"), nil, nil // skip }