From 8ea1819b1c05498068d32fd5d070093623accaa8 Mon Sep 17 00:00:00 2001 From: hacheigriega Date: Fri, 6 Dec 2024 11:22:49 -0500 Subject: [PATCH] fix(x/staking): fix cyclic dependence issue bw pubkey and staking keepers --- app/app.go | 10 +++++----- scripts/local_setup.sh | 7 ------- x/batching/keeper/integration_test.go | 4 ++-- x/pubkey/keeper/common_test.go | 4 ++-- x/pubkey/keeper/endblock_test.go | 7 ++++--- x/pubkey/keeper/grpc_query.go | 2 +- x/pubkey/keeper/msg_server.go | 4 ++-- x/pubkey/module.go | 4 ++-- x/staking/keeper/keeper.go | 7 +++++-- x/tally/keeper/integration_test.go | 7 ++++--- x/vesting/keeper/integration_test.go | 3 ++- 11 files changed, 29 insertions(+), 30 deletions(-) diff --git a/app/app.go b/app/app.go index d343de57..b8cec64b 100644 --- a/app/app.go +++ b/app/app.go @@ -261,7 +261,7 @@ type App struct { WasmStorageKeeper wasmstoragekeeper.Keeper TallyKeeper tallykeeper.Keeper DataProxyKeeper dataproxykeeper.Keeper - PubKeyKeeper pubkeykeeper.Keeper + PubKeyKeeper *pubkeykeeper.Keeper BatchingKeeper batchingkeeper.Keeper // App-level pre-blocker (Note this cannot change consensus parameters) @@ -429,8 +429,7 @@ func NewApp( ) app.StakingKeeper = stakingkeeper.NewKeeper( sdkStakingKeeper, - app.PubKeyKeeper, - app.AccountKeeper.AddressCodec(), + authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), ) app.FeeGrantKeeper = feegrantkeeper.NewKeeper( @@ -653,7 +652,7 @@ func NewApp( app.WasmKeeper, ) - app.PubKeyKeeper = *pubkeykeeper.NewKeeper( + app.PubKeyKeeper = pubkeykeeper.NewKeeper( appCodec, runtime.NewKVStoreService(keys[pubkeytypes.StoreKey]), app.StakingKeeper, @@ -661,6 +660,7 @@ func NewApp( authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) + app.StakingKeeper.SetPubKeyKeeper(app.PubKeyKeeper) app.DataProxyKeeper = *dataproxykeeper.NewKeeper( appCodec, @@ -911,9 +911,9 @@ func NewApp( slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, - crisistypes.ModuleName, pubkeytypes.ModuleName, // pubkey before genutil genutiltypes.ModuleName, + crisistypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, feegrant.ModuleName, diff --git a/scripts/local_setup.sh b/scripts/local_setup.sh index 6a913d22..dc69e38a 100755 --- a/scripts/local_setup.sh +++ b/scripts/local_setup.sh @@ -95,10 +95,3 @@ $BIN collect-gentxs # start the chain $BIN start --log_level debug 2>&1 | tee local_chain.log & -CHAIN_PID=$! - -# Wait until at least one block is produced -sleep 10 - -$BIN tx pubkey add-seda-keys --from satoshi --keyring-backend test --gas-prices 10000000000aseda --gas auto --gas-adjustment 2.0 --keyring-backend test --yes -wait $CHAIN_PID diff --git a/x/batching/keeper/integration_test.go b/x/batching/keeper/integration_test.go index efb6fdbd..732d7487 100644 --- a/x/batching/keeper/integration_test.go +++ b/x/batching/keeper/integration_test.go @@ -152,7 +152,6 @@ func initFixture(tb testing.TB) *fixture { ) stakingKeeper := stakingkeeper.NewKeeper( sdkStakingKeeper, - pubKeyKeeper, addresscodec.NewBech32Codec(params.Bech32PrefixValAddr), ) @@ -209,6 +208,7 @@ func initFixture(tb testing.TB) *fixture { addresscodec.NewBech32Codec(params.Bech32PrefixValAddr), authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) + stakingKeeper.SetPubKeyKeeper(pubKeyKeeper) batchingKeeper := batchingkeeper.NewKeeper( cdc, @@ -234,7 +234,7 @@ func initFixture(tb testing.TB) *fixture { stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper, pubKeyKeeper) wasmStorageModule := wasmstorage.NewAppModule(cdc, *wasmStorageKeeper) tallyModule := tally.NewAppModule(tallyKeeper) - pubKeyModule := pubkey.NewAppModule(cdc, *pubKeyKeeper) + pubKeyModule := pubkey.NewAppModule(cdc, pubKeyKeeper) batchingModule := batching.NewAppModule(cdc, batchingKeeper) integrationApp := integration.NewIntegrationApp(ctx, logger, keys, cdc, map[string]appmodule.AppModule{ diff --git a/x/pubkey/keeper/common_test.go b/x/pubkey/keeper/common_test.go index 203f9d08..2e898a8c 100644 --- a/x/pubkey/keeper/common_test.go +++ b/x/pubkey/keeper/common_test.go @@ -67,11 +67,11 @@ func (s *KeeperTestSuite) SetupTest() { s.cdc = encCfg.Codec s.serverCtx = server.NewDefaultContext() - msr := keeper.NewMsgServerImpl(*s.keeper) + msr := keeper.NewMsgServerImpl(s.keeper) s.msgSrvr = msr queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, encCfg.InterfaceRegistry) - querier := keeper.Querier{Keeper: *s.keeper} + querier := keeper.Querier{Keeper: s.keeper} types.RegisterQueryServer(queryHelper, querier) s.queryClient = types.NewQueryClient(queryHelper) } diff --git a/x/pubkey/keeper/endblock_test.go b/x/pubkey/keeper/endblock_test.go index 23dd9b85..dcd4d7f8 100644 --- a/x/pubkey/keeper/endblock_test.go +++ b/x/pubkey/keeper/endblock_test.go @@ -129,7 +129,7 @@ func initFixture(tb testing.TB) *fixture { var pubKeyKeeper *pubkeykeeper.Keeper sdkStakingKeeper := sdkstakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[sdkstakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(params.Bech32PrefixValAddr), addresscodec.NewBech32Codec(params.Bech32PrefixConsAddr)) - stakingKeeper := stakingkeeper.NewKeeper(sdkStakingKeeper, pubKeyKeeper, addresscodec.NewBech32Codec(params.Bech32PrefixValAddr)) + stakingKeeper := stakingkeeper.NewKeeper(sdkStakingKeeper, addresscodec.NewBech32Codec(params.Bech32PrefixValAddr)) stakingParams := sdkstakingtypes.DefaultParams() stakingParams.BondDenom = bondDenom @@ -152,11 +152,12 @@ func initFixture(tb testing.TB) *fixture { addresscodec.NewBech32Codec(params.Bech32PrefixValAddr), authtypes.NewModuleAddress("gov").String(), ) + stakingKeeper.SetPubKeyKeeper(pubKeyKeeper) authModule := auth.NewAppModule(cdc, accountKeeper, app.RandomGenesisAccounts, nil) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil) stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper, pubKeyKeeper) - pubkeyModule := pubkey.NewAppModule(cdc, *pubKeyKeeper) + pubkeyModule := pubkey.NewAppModule(cdc, pubKeyKeeper) integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, map[string]appmodule.AppModule{ authtypes.ModuleName: authModule, @@ -165,7 +166,7 @@ func initFixture(tb testing.TB) *fixture { types.ModuleName: pubkeyModule, }) - types.RegisterMsgServer(integrationApp.MsgServiceRouter(), keeper.NewMsgServerImpl(*pubKeyKeeper)) + types.RegisterMsgServer(integrationApp.MsgServiceRouter(), keeper.NewMsgServerImpl(pubKeyKeeper)) sdkStakingMsgServer := sdkstakingkeeper.NewMsgServerImpl(sdkStakingKeeper) stakingMsgServer := stakingkeeper.NewMsgServerImpl(sdkStakingMsgServer, stakingKeeper) stakingtypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), stakingMsgServer) diff --git a/x/pubkey/keeper/grpc_query.go b/x/pubkey/keeper/grpc_query.go index 426aeaa1..52e67ef8 100644 --- a/x/pubkey/keeper/grpc_query.go +++ b/x/pubkey/keeper/grpc_query.go @@ -11,7 +11,7 @@ import ( var _ types.QueryServer = Querier{} type Querier struct { - Keeper + *Keeper } func (q Querier) ValidatorKeys(ctx context.Context, req *types.QueryValidatorKeysRequest) (*types.QueryValidatorKeysResponse, error) { diff --git a/x/pubkey/keeper/msg_server.go b/x/pubkey/keeper/msg_server.go index d60a19d8..2e3fd139 100644 --- a/x/pubkey/keeper/msg_server.go +++ b/x/pubkey/keeper/msg_server.go @@ -11,14 +11,14 @@ import ( ) type msgServer struct { - Keeper + *Keeper } var _ types.MsgServer = msgServer{} // NewMsgServerImpl returns an implementation of the MsgServer interface // for the provided Keeper. -func NewMsgServerImpl(keeper Keeper) types.MsgServer { +func NewMsgServerImpl(keeper *Keeper) types.MsgServer { return &msgServer{Keeper: keeper} } diff --git a/x/pubkey/module.go b/x/pubkey/module.go index 9a52ac5d..6c4a12d6 100644 --- a/x/pubkey/module.go +++ b/x/pubkey/module.go @@ -99,10 +99,10 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { // AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement type AppModule struct { AppModuleBasic - keeper keeper.Keeper + keeper *keeper.Keeper } -func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { +func NewAppModule(cdc codec.Codec, keeper *keeper.Keeper) AppModule { return AppModule{ AppModuleBasic: NewAppModuleBasic(cdc), keeper: keeper, diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 516fbccb..28a3fe9c 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -21,10 +21,9 @@ type Keeper struct { validatorAddressCodec addresscodec.Codec } -func NewKeeper(sdkStakingKeeper *sdkkeeper.Keeper, pubKeyKeeper types.PubKeyKeeper, valAddrCdc addresscodec.Codec) *Keeper { +func NewKeeper(sdkStakingKeeper *sdkkeeper.Keeper, valAddrCdc addresscodec.Codec) *Keeper { return &Keeper{ Keeper: sdkStakingKeeper, - pubKeyKeeper: pubKeyKeeper, validatorAddressCodec: valAddrCdc, } } @@ -33,6 +32,10 @@ func (k *Keeper) SetHooks(sh sdktypes.StakingHooks) { k.Keeper.SetHooks(sh) } +func (k *Keeper) SetPubKeyKeeper(pubKeyKeeper types.PubKeyKeeper) { + k.pubKeyKeeper = pubKeyKeeper +} + // NOTE: This code was taken from // https://github.com/agoric-labs/cosmos-sdk/blob/f42d86980ddfc07869846c391a03622cbd7e9188/x/staking/keeper/delegation.go#L701 // with slight modifications. diff --git a/x/tally/keeper/integration_test.go b/x/tally/keeper/integration_test.go index 690ce970..7e47af73 100644 --- a/x/tally/keeper/integration_test.go +++ b/x/tally/keeper/integration_test.go @@ -137,9 +137,8 @@ func initFixture(tb testing.TB) *fixture { log.NewNopLogger(), ) - var pubKeyKeeper *pubkeykeeper.Keeper sdkStakingKeeper := sdkstakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[sdkstakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(params.Bech32PrefixValAddr), addresscodec.NewBech32Codec(params.Bech32PrefixConsAddr)) - stakingKeeper := stakingkeeper.NewKeeper(sdkStakingKeeper, pubKeyKeeper, addresscodec.NewBech32Codec(params.Bech32PrefixValAddr)) + stakingKeeper := stakingkeeper.NewKeeper(sdkStakingKeeper, addresscodec.NewBech32Codec(params.Bech32PrefixValAddr)) stakingParams := sdkstakingtypes.DefaultParams() stakingParams.BondDenom = bondDenom @@ -192,7 +191,7 @@ func initFixture(tb testing.TB) *fixture { authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - pubKeyKeeper = pubkeykeeper.NewKeeper( + pubKeyKeeper := pubkeykeeper.NewKeeper( cdc, runtime.NewKVStoreService(keys[pubkeytypes.StoreKey]), stakingKeeper, @@ -200,6 +199,8 @@ func initFixture(tb testing.TB) *fixture { addresscodec.NewBech32Codec(params.Bech32PrefixValAddr), authtypes.NewModuleAddress("gov").String(), ) + stakingKeeper.SetPubKeyKeeper(pubKeyKeeper) + batchingKeeper := batchingkeeper.NewKeeper( cdc, runtime.NewKVStoreService(keys[batchingtypes.StoreKey]), diff --git a/x/vesting/keeper/integration_test.go b/x/vesting/keeper/integration_test.go index 5061989b..ad033906 100644 --- a/x/vesting/keeper/integration_test.go +++ b/x/vesting/keeper/integration_test.go @@ -122,7 +122,7 @@ func initFixture(tb testing.TB) *fixture { var pubKeyKeeper *pubkeykeeper.Keeper sdkStakingKeeper := sdkstakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[sdkstakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(params.Bech32PrefixValAddr), addresscodec.NewBech32Codec(params.Bech32PrefixConsAddr)) - stakingKeeper := stakingkeeper.NewKeeper(sdkStakingKeeper, pubKeyKeeper, addresscodec.NewBech32Codec(params.Bech32PrefixValAddr)) + stakingKeeper := stakingkeeper.NewKeeper(sdkStakingKeeper, addresscodec.NewBech32Codec(params.Bech32PrefixValAddr)) stakingParams := sdkstakingtypes.DefaultParams() stakingParams.BondDenom = bondDenom @@ -145,6 +145,7 @@ func initFixture(tb testing.TB) *fixture { addresscodec.NewBech32Codec(params.Bech32PrefixValAddr), authtypes.NewModuleAddress("gov").String(), ) + stakingKeeper.SetPubKeyKeeper(pubKeyKeeper) authModule := auth.NewAppModule(cdc, accountKeeper, app.RandomGenesisAccounts, nil) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil)