diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index 262ba79e44f..19763a326e6 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -8,8 +8,6 @@ import ( errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" @@ -157,8 +155,7 @@ func (k *Keeper) RecvPacket( } // check if packet timed out by comparing it with the latest height of the chain - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 - selfHeight, selfTimestamp := clienttypes.GetSelfHeight(sdkCtx), uint64(sdkCtx.BlockTime().UnixNano()) + selfHeight, selfTimestamp := clienttypes.GetSelfHeight(ctx), uint64(k.HeaderService.HeaderInfo(ctx).Time.UnixNano()) timeout := types.NewTimeout(packet.GetTimeoutHeight().(clienttypes.Height), packet.GetTimeoutTimestamp()) if timeout.Elapsed(selfHeight, selfTimestamp) { return "", errorsmod.Wrap(timeout.ErrTimeoutElapsed(selfHeight, selfTimestamp), "packet timeout elapsed") @@ -477,9 +474,8 @@ func (k *Keeper) AcknowledgePacket( func (k *Keeper) handleFlushState(ctx context.Context, packet types.Packet, channel types.Channel) { if counterpartyUpgrade, found := k.GetCounterpartyUpgrade(ctx, packet.GetSourcePort(), packet.GetSourceChannel()); found { timeout := counterpartyUpgrade.Timeout - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 - selfHeight, selfTimestamp := clienttypes.GetSelfHeight(sdkCtx), uint64(sdkCtx.BlockTime().UnixNano()) + selfHeight, selfTimestamp := clienttypes.GetSelfHeight(ctx), uint64(k.HeaderService.HeaderInfo(ctx).Time.UnixNano()) if timeout.Elapsed(selfHeight, selfTimestamp) { // packet flushing timeout has expired, abort the upgrade // committing an error receipt to state, deleting upgrade information and restoring the channel. diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index 53bb8dc8670..b2c28e37d5b 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -9,7 +9,6 @@ import ( errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/telemetry" - sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" @@ -341,9 +340,7 @@ func (k *Keeper) ChanUpgradeAck( } timeout := counterpartyUpgrade.Timeout - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 - selfHeight, selfTimestamp := clienttypes.GetSelfHeight(sdkCtx), uint64(sdkCtx.BlockTime().UnixNano()) - + selfHeight, selfTimestamp := clienttypes.GetSelfHeight(ctx), uint64(k.HeaderService.HeaderInfo(ctx).Time.UnixNano()) if timeout.Elapsed(selfHeight, selfTimestamp) { return types.NewUpgradeError(channel.UpgradeSequence, errorsmod.Wrap(timeout.ErrTimeoutElapsed(selfHeight, selfTimestamp), "counterparty upgrade timeout elapsed")) } @@ -464,9 +461,7 @@ func (k *Keeper) ChanUpgradeConfirm( } timeout := counterpartyUpgrade.Timeout - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 - selfHeight, selfTimestamp := clienttypes.GetSelfHeight(sdkCtx), uint64(sdkCtx.BlockTime().UnixNano()) - + selfHeight, selfTimestamp := clienttypes.GetSelfHeight(ctx), uint64(k.HeaderService.HeaderInfo(ctx).Time.UnixNano()) if timeout.Elapsed(selfHeight, selfTimestamp) { return types.NewUpgradeError(channel.UpgradeSequence, errorsmod.Wrap(timeout.ErrTimeoutElapsed(selfHeight, selfTimestamp), "counterparty upgrade timeout elapsed")) } @@ -885,8 +880,8 @@ func (k *Keeper) startFlushing(ctx context.Context, portID, channelID string, up // getAbsoluteUpgradeTimeout returns the absolute timeout for the given upgrade. func (k *Keeper) getAbsoluteUpgradeTimeout(ctx context.Context) types.Timeout { upgradeTimeout := k.GetParams(ctx).UpgradeTimeout - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223 - return types.NewTimeout(clienttypes.ZeroHeight(), uint64(sdkCtx.BlockTime().UnixNano())+upgradeTimeout.Timestamp) + blockTime := k.HeaderService.HeaderInfo(ctx).Time.UnixNano() + return types.NewTimeout(clienttypes.ZeroHeight(), uint64(blockTime)+upgradeTimeout.Timestamp) } // checkForUpgradeCompatibility checks performs stateful validation of self upgrade fields relative to counterparty upgrade. diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index 205282687dd..d9cbff138a4 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -1005,12 +1005,13 @@ func (suite *KeeperTestSuite) TestChannelUpgradeInit() { ) suite.chainA.GetSimApp().IBCMockModule.IBCApp.OnChanUpgradeInit = func(ctx context.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) (string, error) { - storeKey := suite.chainA.GetSimApp().GetKey(exported.ModuleName) - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - store := sdkCtx.KVStore(storeKey) - store.Set(ibcmock.TestKey, ibcmock.TestValue) + store := suite.chainA.GetSimApp().GetIBCKeeper().KVStoreService.OpenKVStore(ctx) + err := store.Set(ibcmock.TestKey, ibcmock.TestValue) + suite.Require().NoError(err) - sdkCtx.EventManager().EmitEvent(sdk.NewEvent(ibcmock.MockEventType)) + eventService := suite.chainA.GetSimApp().GetIBCKeeper().EventService + err = eventService.EventManager(ctx).EmitKV(ibcmock.MockEventType) + suite.Require().NoError(err) return ibcmock.UpgradeVersion, nil } }, @@ -1153,12 +1154,13 @@ func (suite *KeeperTestSuite) TestChannelUpgradeTry() { "ibc application does not commit state changes in callback", func() { suite.chainA.GetSimApp().IBCMockModule.IBCApp.OnChanUpgradeTry = func(ctx context.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, counterpartyVersion string) (string, error) { - storeKey := suite.chainA.GetSimApp().GetKey(exported.ModuleName) - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - store := sdkCtx.KVStore(storeKey) - store.Set(ibcmock.TestKey, ibcmock.TestValue) + store := suite.chainA.GetSimApp().GetIBCKeeper().KVStoreService.OpenKVStore(ctx) + err := store.Set(ibcmock.TestKey, ibcmock.TestValue) + suite.Require().NoError(err) - sdkCtx.EventManager().EmitEvent(sdk.NewEvent(ibcmock.MockEventType)) + eventService := suite.chainA.GetSimApp().GetIBCKeeper().EventService + err = eventService.EventManager(ctx).EmitKV(ibcmock.MockEventType) + suite.Require().NoError(err) return ibcmock.UpgradeVersion, nil } }, @@ -1361,9 +1363,9 @@ func (suite *KeeperTestSuite) TestChannelUpgradeAck() { ctx context.Context, portID, channelID, counterpartyVersion string, ) error { // set arbitrary value in store to mock application state changes - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - store := sdkCtx.KVStore(suite.chainA.GetSimApp().GetKey(exported.ModuleName)) - store.Set([]byte("foo"), []byte("bar")) + store := suite.chainA.GetSimApp().GetIBCKeeper().KVStoreService.OpenKVStore(ctx) + err := store.Set(ibcmock.TestKey, ibcmock.TestValue) + suite.Require().NoError(err) return fmt.Errorf("mock app callback failed") } }, @@ -1435,12 +1437,13 @@ func (suite *KeeperTestSuite) TestChannelUpgradeAck() { "ibc application does not commit state changes in callback", func() { suite.chainA.GetSimApp().IBCMockModule.IBCApp.OnChanUpgradeAck = func(ctx context.Context, portID, channelID, counterpartyVersion string) error { - storeKey := suite.chainA.GetSimApp().GetKey(exported.ModuleName) - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - store := sdkCtx.KVStore(storeKey) - store.Set(ibcmock.TestKey, ibcmock.TestValue) + store := suite.chainA.GetSimApp().GetIBCKeeper().KVStoreService.OpenKVStore(ctx) + err := store.Set(ibcmock.TestKey, ibcmock.TestValue) + suite.Require().NoError(err) - sdkCtx.EventManager().EmitEvent(sdk.NewEvent(ibcmock.MockEventType)) + eventService := suite.chainA.GetSimApp().GetIBCKeeper().EventService + err = eventService.EventManager(ctx).EmitKV(ibcmock.MockEventType) + suite.Require().NoError(err) return nil } },