Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: context cleanup (4/n) #7217

Merged
merged 23 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ package keeper
*/

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"context"

icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types"
)

// GetAppMetadata is a wrapper around getAppMetadata to allow the function to be directly called in tests.
func (k Keeper) GetAppMetadata(ctx sdk.Context, portID, channelID string) (icatypes.Metadata, error) {
func (k Keeper) GetAppMetadata(ctx context.Context, portID, channelID string) (icatypes.Metadata, error) {
return k.getAppMetadata(ctx, portID, channelID)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

controllertypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types"
Expand All @@ -19,11 +21,12 @@ func NewMigrator(k *Keeper) Migrator {
}

// MigrateParams migrates the controller submodule's parameters from the x/params to self store.
func (m Migrator) MigrateParams(ctx sdk.Context) error {
func (m Migrator) MigrateParams(ctx context.Context) error {
if m.keeper != nil {
params := controllertypes.DefaultParams()
if m.keeper.legacySubspace != nil {
m.keeper.legacySubspace.GetParamSetIfExists(ctx, &params)
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223
m.keeper.legacySubspace.GetParamSetIfExists(sdkCtx, &params)
}
m.keeper.SetParams(ctx, params)
m.keeper.Logger(ctx).Info("successfully migrated ica/controller submodule to self-manage params")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
// Prior to v6.x.x of ibc-go, the controller module was only functional as middleware, with authentication performed
// by the underlying application. For a full summary of the changes in v6.x.x, please see ADR009.
// This API will be removed in later releases.
func (k Keeper) SendTx(ctx sdk.Context, _ *capabilitytypes.Capability, connectionID, portID string, icaPacketData icatypes.InterchainAccountPacketData, timeoutTimestamp uint64) (uint64, error) {
func (k Keeper) SendTx(ctx context.Context, _ *capabilitytypes.Capability, connectionID, portID string, icaPacketData icatypes.InterchainAccountPacketData, timeoutTimestamp uint64) (uint64, error) {
return k.sendTx(ctx, connectionID, portID, icaPacketData, timeoutTimestamp)
}

func (k Keeper) sendTx(ctx sdk.Context, connectionID, portID string, icaPacketData icatypes.InterchainAccountPacketData, timeoutTimestamp uint64) (uint64, error) {
func (k Keeper) sendTx(ctx context.Context, connectionID, portID string, icaPacketData icatypes.InterchainAccountPacketData, timeoutTimestamp uint64) (uint64, error) {
if !k.GetParams(ctx).ControllerEnabled {
return 0, types.ErrControllerSubModuleDisabled
}
Expand All @@ -38,7 +38,8 @@ func (k Keeper) sendTx(ctx sdk.Context, connectionID, portID string, icaPacketDa
return 0, errorsmod.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel on connection %s for port %s", connectionID, portID)
}

if uint64(ctx.BlockTime().UnixNano()) >= timeoutTimestamp {
sdkCtx := sdk.UnwrapSDKContext(ctx)
if uint64(sdkCtx.BlockTime().UnixNano()) >= timeoutTimestamp {
return 0, icatypes.ErrInvalidTimeoutTimestamp
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanUpgradeAck() {
}
}

func (suite *InterchainAccountsTestSuite) fundICAWallet(ctx sdk.Context, portID string, amount sdk.Coins) {
func (suite *InterchainAccountsTestSuite) fundICAWallet(ctx context.Context, portID string, amount sdk.Coins) {
interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(ctx, ibctesting.FirstConnectionID, portID)
suite.Require().True(found)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ package keeper
*/

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"context"

icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types"
)

// GetAppMetadata is a wrapper around getAppMetadata to allow the function to be directly called in tests.
func (k Keeper) GetAppMetadata(ctx sdk.Context, portID, channelID string) (icatypes.Metadata, error) {
func (k Keeper) GetAppMetadata(ctx context.Context, portID, channelID string) (icatypes.Metadata, error) {
return k.getAppMetadata(ctx, portID, channelID)
}

Expand Down
7 changes: 3 additions & 4 deletions modules/apps/27-interchain-accounts/host/keeper/genesis.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package keeper

import (
"context"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"

genesistypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/genesis/types"
icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
)

// InitGenesis initializes the interchain accounts host application state from a provided genesis state
func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.HostGenesisState) {
func InitGenesis(ctx context.Context, keeper Keeper, state genesistypes.HostGenesisState) {
keeper.setPort(ctx, state.Port)

// generate port capability if it does not already exist
Expand Down Expand Up @@ -40,7 +39,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.HostGenesisS
}

// ExportGenesis returns the interchain accounts host exported genesis
func ExportGenesis(ctx sdk.Context, keeper Keeper) genesistypes.HostGenesisState {
func ExportGenesis(ctx context.Context, keeper Keeper) genesistypes.HostGenesisState {
return genesistypes.NewHostGenesisState(
keeper.GetAllActiveChannels(ctx),
keeper.GetAllInterchainAccounts(ctx),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host/types"
Expand All @@ -19,11 +21,12 @@ func NewMigrator(k *Keeper) Migrator {
}

// MigrateParams migrates the host submodule's parameters from the x/params to self store.
func (m Migrator) MigrateParams(ctx sdk.Context) error {
func (m Migrator) MigrateParams(ctx context.Context) error {
if m.keeper != nil {
params := types.DefaultParams()
if m.keeper.legacySubspace != nil {
m.keeper.legacySubspace.GetParamSetIfExists(ctx, &params)
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: should we remove legacy migrations?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably, opened #7234

DimitrisJim marked this conversation as resolved.
Show resolved Hide resolved
m.keeper.legacySubspace.GetParamSetIfExists(sdkCtx, &params)
}
if err := params.Validate(); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/host/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (k Keeper) authenticateTx(ctx context.Context, msgs []sdk.Msg, connectionID

// Attempts to get the message handler from the router and if found will then execute the message.
// If the message execution is successful, the proto marshaled message response will be returned.
func (k Keeper) executeMsg(ctx sdk.Context, msg sdk.Msg) (*codectypes.Any, error) {
func (k Keeper) executeMsg(ctx sdk.Context, msg sdk.Msg) (*codectypes.Any, error) { // TODO: https://github.com/cosmos/ibc-go/issues/7223
handler := k.msgRouter.Handler(msg)
if handler == nil {
return nil, icatypes.ErrInvalidRoute
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
"context"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -886,7 +887,7 @@ func (suite *KeeperTestSuite) TestJSONOnRecvPacket() {
}
}

func (suite *KeeperTestSuite) fundICAWallet(ctx sdk.Context, portID string, amount sdk.Coins) {
func (suite *KeeperTestSuite) fundICAWallet(ctx context.Context, portID string, amount sdk.Coins) {
interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(ctx, ibctesting.FirstConnectionID, portID)
suite.Require().True(found)

Expand Down
6 changes: 3 additions & 3 deletions modules/apps/29-fee/keeper/genesis.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"context"

"github.com/cosmos/ibc-go/v9/modules/apps/29-fee/types"
)

// InitGenesis initializes the fee middleware application state from a provided genesis state
func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) {
func (k Keeper) InitGenesis(ctx context.Context, state types.GenesisState) {
for _, identifiedFees := range state.IdentifiedFees {
k.SetFeesInEscrow(ctx, identifiedFees.PacketId, types.NewPacketFees(identifiedFees.PacketFees))
}
Expand All @@ -30,7 +30,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) {
}

// ExportGenesis returns the fee middleware application exported genesis
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState {
return &types.GenesisState{
IdentifiedFees: k.GetAllIdentifiedPacketFees(ctx),
FeeEnabledChannels: k.GetAllFeeEnabledChannels(ctx),
Expand Down
1 change: 1 addition & 0 deletions modules/apps/29-fee/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func NewMigrator(keeper Keeper) Migrator {

// Migrate1to2 migrates ibc-fee module from ConsensusVersion 1 to 2
// by refunding leftover fees to the refund address.
// TODO: should this be removed?
damiannolan marked this conversation as resolved.
Show resolved Hide resolved
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
store := runtime.KVStoreAdapter(m.keeper.storeService.OpenKVStore(ctx))
iterator := storetypes.KVStorePrefixIterator(store, []byte(types.FeesInEscrowPrefix))
Expand Down
36 changes: 18 additions & 18 deletions modules/core/02-client/migrations/v7/solomachine.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package v7

import (
"context"
"errors"

storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/v9/modules/core/exported"
)
Expand Down Expand Up @@ -63,7 +63,7 @@ func (ClientState) GetLatestHeight() exported.Height {
}

// Status panics!
func (ClientState) Status(_ sdk.Context, _ storetypes.KVStore, _ codec.BinaryCodec) exported.Status {
func (ClientState) Status(_ context.Context, _ storetypes.KVStore, _ codec.BinaryCodec) exported.Status {
panic(errors.New("legacy solo machine is deprecated"))
}

Expand All @@ -73,59 +73,59 @@ func (ClientState) Validate() error {
}

// Initialize panics!
func (ClientState) Initialize(_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ConsensusState) error {
func (ClientState) Initialize(_ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ConsensusState) error {
panic(errors.New("legacy solo machine is deprecated"))
}

// CheckForMisbehaviour panics!
func (ClientState) CheckForMisbehaviour(_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage) bool {
func (ClientState) CheckForMisbehaviour(_ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage) bool {
panic(errors.New("legacy solo machine is deprecated"))
}

// UpdateStateOnMisbehaviour panics!
func (*ClientState) UpdateStateOnMisbehaviour(
_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage,
_ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage,
) {
panic(errors.New("legacy solo machine is deprecated"))
}

// VerifyClientMessage panics!
func (*ClientState) VerifyClientMessage(
_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage,
_ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage,
) error {
panic(errors.New("legacy solo machine is deprecated"))
}

// UpdateState panis!
func (*ClientState) UpdateState(_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage) []exported.Height {
func (*ClientState) UpdateState(_ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage) []exported.Height {
panic(errors.New("legacy solo machine is deprecated"))
}

// CheckHeaderAndUpdateState panics!
func (*ClientState) CheckHeaderAndUpdateState(
_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage,
_ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage,
) (exported.ClientState, exported.ConsensusState, error) {
panic(errors.New("legacy solo machine is deprecated"))
}

// CheckMisbehaviourAndUpdateState panics!
func (ClientState) CheckMisbehaviourAndUpdateState(
_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage,
_ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage,
) (exported.ClientState, error) {
panic(errors.New("legacy solo machine is deprecated"))
}

// CheckSubstituteAndUpdateState panics!
func (ClientState) CheckSubstituteAndUpdateState(
ctx sdk.Context, _ codec.BinaryCodec, _, _ storetypes.KVStore,
ctx context.Context, _ codec.BinaryCodec, _, _ storetypes.KVStore,
_ exported.ClientState,
) error {
panic(errors.New("legacy solo machine is deprecated"))
}

// VerifyUpgradeAndUpdateState panics!
func (ClientState) VerifyUpgradeAndUpdateState(
_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore,
_ context.Context, _ codec.BinaryCodec, _ storetypes.KVStore,
_ exported.ClientState, _ exported.ConsensusState, _, _ []byte,
) error {
panic(errors.New("legacy solo machine is deprecated"))
Expand All @@ -150,7 +150,7 @@ func (ClientState) VerifyClientConsensusState(

// VerifyPacketCommitment panics!
func (ClientState) VerifyPacketCommitment(
sdk.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height,
context.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height,
uint64, uint64, exported.Prefix, []byte,
string, string, uint64, []byte,
) error {
Expand All @@ -159,7 +159,7 @@ func (ClientState) VerifyPacketCommitment(

// VerifyPacketAcknowledgement panics!
func (ClientState) VerifyPacketAcknowledgement(
sdk.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height,
context.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height,
uint64, uint64, exported.Prefix, []byte,
string, string, uint64, []byte,
) error {
Expand All @@ -168,7 +168,7 @@ func (ClientState) VerifyPacketAcknowledgement(

// VerifyPacketReceiptAbsence panics!
func (ClientState) VerifyPacketReceiptAbsence(
sdk.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height,
context.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height,
uint64, uint64, exported.Prefix, []byte,
string, string, uint64,
) error {
Expand All @@ -177,7 +177,7 @@ func (ClientState) VerifyPacketReceiptAbsence(

// VerifyNextSequenceRecv panics!
func (ClientState) VerifyNextSequenceRecv(
sdk.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height,
context.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height,
uint64, uint64, exported.Prefix, []byte,
string, string, uint64,
) error {
Expand All @@ -186,14 +186,14 @@ func (ClientState) VerifyNextSequenceRecv(

// GetTimestampAtHeight panics!
func (ClientState) GetTimestampAtHeight(
sdk.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height,
context.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height,
) (uint64, error) {
panic(errors.New("legacy solo machine is deprecated"))
}

// VerifyMembership panics!
func (*ClientState) VerifyMembership(
ctx sdk.Context,
ctx context.Context,
clientStore storetypes.KVStore,
cdc codec.BinaryCodec,
height exported.Height,
Expand All @@ -208,7 +208,7 @@ func (*ClientState) VerifyMembership(

// VerifyNonMembership panics!
func (*ClientState) VerifyNonMembership(
ctx sdk.Context,
ctx context.Context,
clientStore storetypes.KVStore,
cdc codec.BinaryCodec,
height exported.Height,
Expand Down
6 changes: 3 additions & 3 deletions modules/core/03-connection/genesis.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package connection

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"context"

"github.com/cosmos/ibc-go/v9/modules/core/03-connection/keeper"
"github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
)

// InitGenesis initializes the ibc connection submodule's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k *keeper.Keeper, gs types.GenesisState) {
func InitGenesis(ctx context.Context, k *keeper.Keeper, gs types.GenesisState) {
for _, connection := range gs.Connections {
conn := types.NewConnectionEnd(connection.State, connection.ClientId, connection.Counterparty, connection.Versions, connection.DelayPeriod)
k.SetConnection(ctx, connection.Id, conn)
Expand All @@ -24,7 +24,7 @@ func InitGenesis(ctx sdk.Context, k *keeper.Keeper, gs types.GenesisState) {
}

// ExportGenesis returns the ibc connection submodule's exported genesis.
func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) types.GenesisState {
func ExportGenesis(ctx context.Context, k *keeper.Keeper) types.GenesisState {
return types.GenesisState{
Connections: k.GetAllConnections(ctx),
ClientConnectionPaths: k.GetAllClientConnectionPaths(ctx),
Expand Down
Loading
Loading