-
Notifications
You must be signed in to change notification settings - Fork 586
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
imp: add UnmarshalPacketData interface function #3353
Changes from all commits
bf93c0e
8c16e8d
3500d06
89f608c
b77cfe6
1db4626
32b74ec
f8298da
f826ddd
ca33576
6bf400e
19ab301
1a1a082
07cc36a
9d9e33a
882dc95
bfb359d
27f2447
d80eb6f
16a8e84
c4987af
d4bae04
9919cb1
06916c5
bec5a03
6781f20
1f04b6d
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 |
---|---|---|
|
@@ -15,7 +15,10 @@ import ( | |
"github.com/cosmos/ibc-go/v7/modules/core/exported" | ||
) | ||
|
||
var _ porttypes.Middleware = &IBCMiddleware{} | ||
var ( | ||
_ porttypes.Middleware = &IBCMiddleware{} | ||
_ porttypes.PacketDataUnmarshaler = &IBCMiddleware{} | ||
) | ||
|
||
// IBCMiddleware implements the ICS26 callbacks for the fee middleware given the | ||
// fee keeper and the underlying application. | ||
|
@@ -347,3 +350,15 @@ func (im IBCMiddleware) WriteAcknowledgement( | |
func (im IBCMiddleware) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) { | ||
return im.keeper.GetAppVersion(ctx, portID, channelID) | ||
} | ||
|
||
// UnmarshalPacketData attempts to use the underlying app to unmarshal the packet data. | ||
// If the underlying app does not support the PacketDataUnmarshaler interface, an error is returned. | ||
// This function implements the optional PacketDataUnmarshaler interface required for ADR 008 support. | ||
func (im IBCMiddleware) UnmarshalPacketData(bz []byte) (interface{}, error) { | ||
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. this is only necessary if the ADR 8 implementation is higher than ICS 29, which should not be the case. I added the function anyways so we could discuss here whether to keep it or not 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, I guess its best to keep it? 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. Agree that it should be kept. Let's remove ordering requirements from our stack whenever possible |
||
unmarshaler, ok := im.app.(porttypes.PacketDataUnmarshaler) | ||
if !ok { | ||
return nil, errorsmod.Wrapf(types.ErrUnsupportedAction, "underlying app does not implement PacketDataUnmarshaler") | ||
} | ||
|
||
return unmarshaler.UnmarshalPacketData(bz) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ var ( | |
ErrFeeNotEnabled = errorsmod.Register(ModuleName, 9, "fee module is not enabled for this channel. If this error occurs after channel setup, fee module may not be enabled") | ||
ErrRelayerNotFoundForAsyncAck = errorsmod.Register(ModuleName, 10, "relayer address must be stored for async WriteAcknowledgement") | ||
ErrFeeModuleLocked = errorsmod.Register(ModuleName, 11, "the fee module is currently locked, a severe bug has been detected") | ||
ErrUnsupportedAction = errorsmod.Register(ModuleName, 12, "unsupported action") | ||
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. nit: maybe this go into feel free to ignore 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. I decided to ignore, only because in a world where ics29 becomes it's own go.mod, this change might become reverted. I think it makes sense to keep it in ics29 unless we added it to the ibc errors which are exported outside of ibc-go |
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,11 @@ import ( | |
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" | ||
) | ||
|
||
var ( | ||
_ porttypes.IBCModule = IBCModule{} | ||
_ porttypes.PacketDataUnmarshaler = IBCModule{} | ||
) | ||
|
||
// IBCModule implements the ICS26 interface for transfer given the transfer keeper. | ||
type IBCModule struct { | ||
keeper keeper.Keeper | ||
|
@@ -300,3 +305,15 @@ func (im IBCModule) OnTimeoutPacket( | |
|
||
return nil | ||
} | ||
|
||
// UnmarshalPacketData attempts to unmarshal the provided packet data bytes | ||
// into a FungibleTokenPacketData. This function implements the optional | ||
// PacketDataUnmarshaler interface required for ADR 008 support. | ||
func (im IBCModule) UnmarshalPacketData(bz []byte) (interface{}, error) { | ||
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. do we have a e.g. something like type PacketData interface {
GetBytes() []byte
ValidateBasic() error
} 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. We could do this, but it wouldn't provide any functional benefits, would just clean up the API slightly. It would be an API breaking change to add which is why we have avoided it for now. I believe the interface would likely become unnecessary in the existence of a flat map packet data |
||
var packetData types.FungibleTokenPacketData | ||
if err := types.ModuleCdc.UnmarshalJSON(bz, &packetData); err != nil { | ||
return nil, err | ||
} | ||
|
||
return packetData, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,3 +138,9 @@ type Middleware interface { | |
IBCModule | ||
ICS4Wrapper | ||
} | ||
|
||
// PacketDataUnmarshaler defines an optional interface which allows a middleware to | ||
// request the packet data to be unmarshaled by the base application. | ||
type PacketDataUnmarshaler interface { | ||
UnmarshalPacketData([]byte) (interface{}, error) | ||
} | ||
Comment on lines
+144
to
+146
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. I looked very briefly into what this could look like with generics as I think it would be nice to be able to specify the data type that will be unmarshalled, but things get a little tricky with middleware! 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. 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. I think the solution with generics that could potentially work here is to change the interface function from Happy to review a follow pr if someone wanted to explore that solution |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️