Skip to content

Commit

Permalink
exported.PacketI to concrete type (cosmos#5755)
Browse files Browse the repository at this point in the history
* exported.PacketI to concrete type

* lint

* unused

---------

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
  • Loading branch information
hoangdv2429 and colin-axner authored Jan 30, 2024
1 parent ffd91be commit 92c44af
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
3 changes: 2 additions & 1 deletion modules/apps/27-interchain-accounts/host/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
12 changes: 6 additions & 6 deletions modules/core/04-channel/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions modules/core/04-channel/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions modules/core/04-channel/keeper/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions modules/core/04-channel/keeper/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions modules/core/04-channel/types/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion modules/core/04-channel/types/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 92c44af

Please sign in to comment.