From 92c44afb204e39faa3f6ca038879304942961bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20Vi=E1=BB=87t=20Ho=C3=A0ng?= Date: Tue, 30 Jan 2024 22:43:02 +0700 Subject: [PATCH] exported.PacketI to concrete type (#5755) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * exported.PacketI to concrete type * lint * unused --------- Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- .../controller/keeper/events.go | 3 ++- .../27-interchain-accounts/host/keeper/events.go | 3 ++- modules/core/04-channel/keeper/events.go | 12 ++++++------ modules/core/04-channel/keeper/packet.go | 6 +++--- modules/core/04-channel/keeper/packet_test.go | 6 +++--- modules/core/04-channel/keeper/timeout.go | 6 +++--- modules/core/04-channel/types/packet.go | 4 +--- modules/core/04-channel/types/packet_test.go | 2 +- testing/chain.go | 3 ++- 9 files changed, 23 insertions(+), 22 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/events.go b/modules/apps/27-interchain-accounts/controller/keeper/events.go index afcc8b5598a..95390538783 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/events.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/events.go @@ -6,12 +6,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" "github.com/cosmos/ibc-go/v8/modules/core/exported" ) // EmitAcknowledgementEvent emits an event signalling a successful or failed acknowledgement and including the error // details if any. -func EmitAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI, ack exported.Acknowledgement, err error) { +func EmitAcknowledgementEvent(ctx sdk.Context, packet channeltypes.Packet, ack exported.Acknowledgement, err error) { attributes := []sdk.Attribute{ sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName), sdk.NewAttribute(icatypes.AttributeKeyControllerChannelID, packet.GetDestChannel()), diff --git a/modules/apps/27-interchain-accounts/host/keeper/events.go b/modules/apps/27-interchain-accounts/host/keeper/events.go index 3bfe7759670..3c5b4e0971f 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/events.go +++ b/modules/apps/27-interchain-accounts/host/keeper/events.go @@ -6,12 +6,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" "github.com/cosmos/ibc-go/v8/modules/core/exported" ) // EmitAcknowledgementEvent emits an event signalling a successful or failed acknowledgement and including the error // details if any. -func EmitAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI, ack exported.Acknowledgement, err error) { +func EmitAcknowledgementEvent(ctx sdk.Context, packet channeltypes.Packet, ack exported.Acknowledgement, err error) { attributes := []sdk.Attribute{ sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName), sdk.NewAttribute(icatypes.AttributeKeyHostChannelID, packet.GetDestChannel()), diff --git a/modules/core/04-channel/keeper/events.go b/modules/core/04-channel/keeper/events.go index a536ae848ae..3a9bd673f43 100644 --- a/modules/core/04-channel/keeper/events.go +++ b/modules/core/04-channel/keeper/events.go @@ -121,7 +121,7 @@ func emitChannelCloseConfirmEvent(ctx sdk.Context, portID string, channelID stri // emitSendPacketEvent emits an event with packet data along with other packet information for relayer // to pick up and relay to other chain -func emitSendPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel, timeoutHeight exported.Height) { +func emitSendPacketEvent(ctx sdk.Context, packet types.Packet, channel types.Channel, timeoutHeight exported.Height) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeSendPacket, @@ -149,7 +149,7 @@ func emitSendPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types // emitRecvPacketEvent emits a receive packet event. It will be emitted both the first time a packet // is received for a certain sequence and for all duplicate receives. -func emitRecvPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel) { +func emitRecvPacketEvent(ctx sdk.Context, packet types.Packet, channel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeRecvPacket, @@ -176,7 +176,7 @@ func emitRecvPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types } // emitWriteAcknowledgementEvent emits an event that the relayer can query for -func emitWriteAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel, acknowledgement []byte) { +func emitWriteAcknowledgementEvent(ctx sdk.Context, packet types.Packet, channel types.Channel, acknowledgement []byte) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeWriteAck, @@ -205,7 +205,7 @@ func emitWriteAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI, cha // emitAcknowledgePacketEvent emits an acknowledge packet event. It will be emitted both the first time // a packet is acknowledged for a certain sequence and for all duplicate acknowledgements. -func emitAcknowledgePacketEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel) { +func emitAcknowledgePacketEvent(ctx sdk.Context, packet types.Packet, channel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeAcknowledgePacket, @@ -231,7 +231,7 @@ func emitAcknowledgePacketEvent(ctx sdk.Context, packet exported.PacketI, channe // emitTimeoutPacketEvent emits a timeout packet event. It will be emitted both the first time a packet // is timed out for a certain sequence and for all duplicate timeouts. -func emitTimeoutPacketEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel) { +func emitTimeoutPacketEvent(ctx sdk.Context, packet types.Packet, channel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeTimeoutPacket, @@ -253,7 +253,7 @@ func emitTimeoutPacketEvent(ctx sdk.Context, packet exported.PacketI, channel ty } // emitChannelClosedEvent emits a channel closed event. -func emitChannelClosedEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel) { +func emitChannelClosedEvent(ctx sdk.Context, packet types.Packet, channel types.Channel) { ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeChannelClosed, diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index 794590cfad9..a5bdac63dfc 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -109,7 +109,7 @@ func (k Keeper) SendPacket( func (k Keeper) RecvPacket( ctx sdk.Context, chanCap *capabilitytypes.Capability, - packet exported.PacketI, + packet types.Packet, proof []byte, proofHeight exported.Height, ) error { @@ -337,7 +337,7 @@ func (k Keeper) WriteAcknowledgement( "dst_channel", packet.GetDestChannel(), ) - emitWriteAcknowledgementEvent(ctx, packet, channel, bz) + emitWriteAcknowledgementEvent(ctx, packet.(types.Packet), channel, bz) return nil } @@ -351,7 +351,7 @@ func (k Keeper) WriteAcknowledgement( func (k Keeper) AcknowledgePacket( ctx sdk.Context, chanCap *capabilitytypes.Capability, - packet exported.PacketI, + packet types.Packet, acknowledgement []byte, proof []byte, proofHeight exported.Height, diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index 6e9f471d3c4..d6a38311c7c 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -285,7 +285,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { func (suite *KeeperTestSuite) TestRecvPacket() { var ( path *ibctesting.Path - packet exported.PacketI + packet types.Packet channelCap *capabilitytypes.Capability ) @@ -434,7 +434,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - err = path.EndpointB.RecvPacket(packet.(types.Packet)) + err = path.EndpointB.RecvPacket(packet) suite.Require().NoError(err) }, types.ErrNoOpMsg, @@ -449,7 +449,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - err = path.EndpointB.RecvPacket(packet.(types.Packet)) + err = path.EndpointB.RecvPacket(packet) suite.Require().NoError(err) }, types.ErrNoOpMsg, diff --git a/modules/core/04-channel/keeper/timeout.go b/modules/core/04-channel/keeper/timeout.go index 15a7091ac09..05c3f1738d6 100644 --- a/modules/core/04-channel/keeper/timeout.go +++ b/modules/core/04-channel/keeper/timeout.go @@ -24,7 +24,7 @@ import ( // ante handler. func (k Keeper) TimeoutPacket( ctx sdk.Context, - packet exported.PacketI, + packet types.Packet, proof []byte, proofHeight exported.Height, nextSequenceRecv uint64, @@ -133,7 +133,7 @@ func (k Keeper) TimeoutPacket( func (k Keeper) TimeoutExecuted( ctx sdk.Context, chanCap *capabilitytypes.Capability, - packet exported.PacketI, + packet types.Packet, ) error { channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) if !found { @@ -206,7 +206,7 @@ func (k Keeper) TimeoutExecuted( func (k Keeper) TimeoutOnClose( ctx sdk.Context, chanCap *capabilitytypes.Capability, - packet exported.PacketI, + packet types.Packet, proof, closedProof []byte, proofHeight exported.Height, diff --git a/modules/core/04-channel/types/packet.go b/modules/core/04-channel/types/packet.go index a39ffe06692..76a8b35a34a 100644 --- a/modules/core/04-channel/types/packet.go +++ b/modules/core/04-channel/types/packet.go @@ -17,7 +17,7 @@ import ( // sha256_hash(timeout_timestamp + timeout_height.RevisionNumber + timeout_height.RevisionHeight + sha256_hash(data)) // from a given packet. This results in a fixed length preimage. // NOTE: sdk.Uint64ToBigEndian sets the uint64 to a slice of length 8. -func CommitPacket(cdc codec.BinaryCodec, packet exported.PacketI) []byte { +func CommitPacket(cdc codec.BinaryCodec, packet Packet) []byte { timeoutHeight := packet.GetTimeoutHeight() buf := sdk.Uint64ToBigEndian(packet.GetTimeoutTimestamp()) @@ -41,8 +41,6 @@ func CommitAcknowledgement(data []byte) []byte { return hash[:] } -var _ exported.PacketI = (*Packet)(nil) - // NewPacket creates a new Packet instance. It panics if the provided // packet data interface is not registered. func NewPacket( diff --git a/modules/core/04-channel/types/packet_test.go b/modules/core/04-channel/types/packet_test.go index 0bbcc641b25..cb7e6701985 100644 --- a/modules/core/04-channel/types/packet_test.go +++ b/modules/core/04-channel/types/packet_test.go @@ -21,7 +21,7 @@ func TestCommitPacket(t *testing.T) { cdc := codec.NewProtoCodec(registry) - commitment := types.CommitPacket(cdc, &packet) + commitment := types.CommitPacket(cdc, packet) require.NotNil(t, commitment) } diff --git a/testing/chain.go b/testing/chain.go index 816b987419a..bac4b125e25 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -30,6 +30,7 @@ import ( capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" "github.com/cosmos/ibc-go/v8/modules/core/exported" @@ -433,7 +434,7 @@ func (chain *TestChain) GetValsAtHeight(trustedHeight int64) (*cmttypes.Validato // GetAcknowledgement retrieves an acknowledgement for the provided packet. If the // acknowledgement does not exist then testing will fail. -func (chain *TestChain) GetAcknowledgement(packet exported.PacketI) []byte { +func (chain *TestChain) GetAcknowledgement(packet channeltypes.Packet) []byte { ack, found := chain.App.GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement(chain.GetContext(), packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) require.True(chain.TB, found)