Skip to content

Commit

Permalink
fix(x/staking): fix cyclic dependence issue bw pubkey and staking kee…
Browse files Browse the repository at this point in the history
…pers
  • Loading branch information
hacheigriega committed Dec 6, 2024
1 parent 7147bbc commit 8ea1819
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 30 deletions.
10 changes: 5 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -653,14 +652,15 @@ func NewApp(
app.WasmKeeper,
)

app.PubKeyKeeper = *pubkeykeeper.NewKeeper(
app.PubKeyKeeper = pubkeykeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[pubkeytypes.StoreKey]),
app.StakingKeeper,
app.SlashingKeeper,
authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.StakingKeeper.SetPubKeyKeeper(app.PubKeyKeeper)

app.DataProxyKeeper = *dataproxykeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions scripts/local_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions x/batching/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ func initFixture(tb testing.TB) *fixture {
)
stakingKeeper := stakingkeeper.NewKeeper(
sdkStakingKeeper,
pubKeyKeeper,
addresscodec.NewBech32Codec(params.Bech32PrefixValAddr),
)

Expand Down Expand Up @@ -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,
Expand All @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions x/pubkey/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 4 additions & 3 deletions x/pubkey/keeper/endblock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/pubkey/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions x/pubkey/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Expand Down
4 changes: 2 additions & 2 deletions x/pubkey/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions x/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand All @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions x/tally/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -192,14 +191,16 @@ func initFixture(tb testing.TB) *fixture {
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

pubKeyKeeper = pubkeykeeper.NewKeeper(
pubKeyKeeper := pubkeykeeper.NewKeeper(
cdc,
runtime.NewKVStoreService(keys[pubkeytypes.StoreKey]),
stakingKeeper,
slashingKeeper,
addresscodec.NewBech32Codec(params.Bech32PrefixValAddr),
authtypes.NewModuleAddress("gov").String(),
)
stakingKeeper.SetPubKeyKeeper(pubKeyKeeper)

batchingKeeper := batchingkeeper.NewKeeper(
cdc,
runtime.NewKVStoreService(keys[batchingtypes.StoreKey]),
Expand Down
3 changes: 2 additions & 1 deletion x/vesting/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 8ea1819

Please sign in to comment.