-
Notifications
You must be signed in to change notification settings - Fork 751
feat(core): Wire packet handler to core message server #7091
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
Changes from all commits
3604406
12b7b5e
beb4569
9bfa118
1970edd
8ecfbbb
a0c1e05
830fcd1
2241c14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package keeper | ||
|
|
||
| import ( | ||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
|
||
| capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" | ||
| channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" | ||
| "github.com/cosmos/ibc-go/v9/modules/core/exported" | ||
| ) | ||
|
|
||
| type PacketHandler interface { | ||
| RecvPacket( | ||
| ctx sdk.Context, | ||
| chanCap *capabilitytypes.Capability, | ||
| packet channeltypes.Packet, | ||
| proof []byte, | ||
| proofHeight exported.Height) (string, error) | ||
|
|
||
| WriteAcknowledgement( | ||
| ctx sdk.Context, | ||
| chanCap *capabilitytypes.Capability, | ||
| packet exported.PacketI, | ||
| acknowledgement exported.Acknowledgement, | ||
| ) error | ||
|
|
||
| AcknowledgePacket( | ||
| ctx sdk.Context, | ||
| chanCap *capabilitytypes.Capability, | ||
| packet channeltypes.Packet, | ||
| acknowledgement []byte, | ||
| proof []byte, | ||
| proofHeight exported.Height, | ||
| ) (string, error) | ||
|
|
||
| TimeoutPacket( | ||
| ctx sdk.Context, | ||
| chanCap *capabilitytypes.Capability, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm if there wasn't originally a chanCapability in this signature why do we need to add it only to then remove it later?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because I inlined |
||
| packet channeltypes.Packet, | ||
| proof []byte, | ||
| proofHeight exported.Height, | ||
| nextSequenceRecv uint64, | ||
| ) (string, error) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,13 @@ package keeper | |
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| errorsmod "cosmossdk.io/errors" | ||
|
|
||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
|
||
| capabilitytypes "github.com/cosmos/ibc-go/modules/capability/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/keeper" | ||
|
|
@@ -460,6 +462,11 @@ func (k *Keeper) ChannelCloseConfirm(goCtx context.Context, msg *channeltypes.Ms | |
|
|
||
| // RecvPacket defines a rpc handler method for MsgRecvPacket. | ||
| func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacket) (*channeltypes.MsgRecvPacketResponse, error) { | ||
| var ( | ||
| packetHandler PacketHandler | ||
| module string | ||
| capability *capabilitytypes.Capability | ||
| ) | ||
| ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
|
||
| relayer, err := sdk.AccAddressFromBech32(msg.Signer) | ||
|
|
@@ -468,11 +475,22 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack | |
| return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") | ||
| } | ||
|
|
||
| // Lookup module by channel capability | ||
| module, capability, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.DestinationPort, msg.Packet.DestinationChannel) | ||
| if err != nil { | ||
| ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) | ||
| return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") | ||
| switch msg.Packet.ProtocolVersion { | ||
| case channeltypes.IBC_VERSION_UNSPECIFIED, channeltypes.IBC_VERSION_1: | ||
| packetHandler = k.ChannelKeeper | ||
|
|
||
| // Lookup module by channel capability | ||
| module, capability, err = k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.DestinationPort, msg.Packet.DestinationChannel) | ||
| if err != nil { | ||
| ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) | ||
| return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") | ||
| } | ||
|
|
||
| case channeltypes.IBC_VERSION_2: | ||
| packetHandler = k.PacketServerKeeper | ||
| module = msg.Packet.DestinationPort | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was not sure if we want to do fallback yet. can tweak and add tho |
||
| default: | ||
| panic(fmt.Errorf("unsupported protocol version %d", msg.Packet.ProtocolVersion)) | ||
| } | ||
|
|
||
| // Retrieve callbacks from router | ||
|
|
@@ -487,7 +505,7 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack | |
| // If the packet was already received, perform a no-op | ||
| // Use a cached context to prevent accidental state changes | ||
| cacheCtx, writeFn := ctx.CacheContext() | ||
| channelVersion, err := k.ChannelKeeper.RecvPacket(cacheCtx, capability, msg.Packet, msg.ProofCommitment, msg.ProofHeight) | ||
| channelVersion, err := packetHandler.RecvPacket(cacheCtx, capability, msg.Packet, msg.ProofCommitment, msg.ProofHeight) | ||
|
|
||
| switch err { | ||
| case nil: | ||
|
|
@@ -518,7 +536,7 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack | |
| // NOTE: IBC applications modules may call the WriteAcknowledgement asynchronously if the | ||
| // acknowledgement is nil. | ||
| if ack != nil { | ||
| if err := k.ChannelKeeper.WriteAcknowledgement(ctx, capability, msg.Packet, ack); err != nil { | ||
| if err := packetHandler.WriteAcknowledgement(ctx, capability, msg.Packet, ack); err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
@@ -532,6 +550,11 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack | |
|
|
||
| // Timeout defines a rpc handler method for MsgTimeout. | ||
| func (k *Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*channeltypes.MsgTimeoutResponse, error) { | ||
| var ( | ||
| packetHandler PacketHandler | ||
| module string | ||
| capability *capabilitytypes.Capability | ||
| ) | ||
| ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
|
||
| relayer, err := sdk.AccAddressFromBech32(msg.Signer) | ||
|
|
@@ -540,11 +563,22 @@ func (k *Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (* | |
| return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") | ||
| } | ||
|
|
||
| // Lookup module by channel capability | ||
| module, capability, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel) | ||
| if err != nil { | ||
| ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) | ||
| return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") | ||
| switch msg.Packet.ProtocolVersion { | ||
| case channeltypes.IBC_VERSION_UNSPECIFIED, channeltypes.IBC_VERSION_1: | ||
| packetHandler = k.ChannelKeeper | ||
|
|
||
| // Lookup module by channel capability | ||
| module, capability, err = k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel) | ||
| if err != nil { | ||
| ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) | ||
| return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") | ||
| } | ||
|
|
||
| case channeltypes.IBC_VERSION_2: | ||
| packetHandler = k.PacketServerKeeper | ||
| module = msg.Packet.SourcePort | ||
| default: | ||
| panic(fmt.Errorf("unsupported protocol version %d", msg.Packet.ProtocolVersion)) | ||
| } | ||
|
|
||
| // Retrieve callbacks from router | ||
|
|
@@ -559,7 +593,7 @@ func (k *Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (* | |
| // If the timeout was already received, perform a no-op | ||
| // Use a cached context to prevent accidental state changes | ||
| cacheCtx, writeFn := ctx.CacheContext() | ||
| channelVersion, err := k.ChannelKeeper.TimeoutPacket(cacheCtx, msg.Packet, msg.ProofUnreceived, msg.ProofHeight, msg.NextSequenceRecv) | ||
| channelVersion, err := packetHandler.TimeoutPacket(cacheCtx, capability, msg.Packet, msg.ProofUnreceived, msg.ProofHeight, msg.NextSequenceRecv) | ||
|
|
||
| switch err { | ||
| case nil: | ||
|
|
@@ -573,11 +607,6 @@ func (k *Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (* | |
| return nil, errorsmod.Wrap(err, "timeout packet verification failed") | ||
| } | ||
|
|
||
| // Delete packet commitment | ||
| if err = k.ChannelKeeper.TimeoutExecuted(ctx, capability, msg.Packet); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // Perform application logic callback | ||
| err = cbs.OnTimeoutPacket(ctx, channelVersion, msg.Packet, relayer) | ||
| if err != nil { | ||
|
|
@@ -635,11 +664,6 @@ func (k *Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTime | |
| return nil, errorsmod.Wrap(err, "timeout on close packet verification failed") | ||
| } | ||
|
|
||
| // Delete packet commitment | ||
| if err = k.ChannelKeeper.TimeoutExecuted(ctx, capability, msg.Packet); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // Perform application logic callback | ||
| // | ||
| // NOTE: MsgTimeout and MsgTimeoutOnClose use the same "OnTimeoutPacket" | ||
|
|
@@ -659,6 +683,11 @@ func (k *Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTime | |
|
|
||
| // Acknowledgement defines a rpc handler method for MsgAcknowledgement. | ||
| func (k *Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAcknowledgement) (*channeltypes.MsgAcknowledgementResponse, error) { | ||
| var ( | ||
| packetHandler PacketHandler | ||
| module string | ||
| capability *capabilitytypes.Capability | ||
| ) | ||
| ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
|
||
| relayer, err := sdk.AccAddressFromBech32(msg.Signer) | ||
|
|
@@ -667,11 +696,22 @@ func (k *Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAck | |
| return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") | ||
| } | ||
|
|
||
| // Lookup module by channel capability | ||
| module, capability, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel) | ||
| if err != nil { | ||
| ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) | ||
| return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") | ||
| switch msg.Packet.ProtocolVersion { | ||
| case channeltypes.IBC_VERSION_UNSPECIFIED, channeltypes.IBC_VERSION_1: | ||
| packetHandler = k.ChannelKeeper | ||
|
|
||
| // Lookup module by channel capability | ||
| module, capability, err = k.ChannelKeeper.LookupModuleByChannel(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel) | ||
| if err != nil { | ||
| ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) | ||
| return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") | ||
| } | ||
|
|
||
| case channeltypes.IBC_VERSION_2: | ||
| packetHandler = k.PacketServerKeeper | ||
| module = msg.Packet.SourcePort | ||
| default: | ||
| panic(fmt.Errorf("unsupported protocol version %d", msg.Packet.ProtocolVersion)) | ||
| } | ||
|
|
||
| // Retrieve callbacks from router | ||
|
|
@@ -686,7 +726,7 @@ func (k *Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAck | |
| // If the acknowledgement was already received, perform a no-op | ||
| // Use a cached context to prevent accidental state changes | ||
| cacheCtx, writeFn := ctx.CacheContext() | ||
| channelVersion, err := k.ChannelKeeper.AcknowledgePacket(cacheCtx, capability, msg.Packet, msg.Acknowledgement, msg.ProofAcked, msg.ProofHeight) | ||
| channelVersion, err := packetHandler.AcknowledgePacket(cacheCtx, capability, msg.Packet, msg.Acknowledgement, msg.ProofAcked, msg.ProofHeight) | ||
|
|
||
| switch err { | ||
| case nil: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.