Skip to content
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

Move IBC packet data interpretation to the application module #5890

Merged
merged 10 commits into from
Apr 1, 2020

Conversation

michaelfig
Copy link
Contributor

@michaelfig michaelfig commented Mar 30, 2020

Closes: #5870

Description

The main change is as the title: to move the IBC packet data interpretation to the application module to which it was routed. Notably, the TimeoutHeight is moved to PacketI and Data is a raw []byte again.

The tests pass for the entire x/ibc directory, but I'm unsure if I have covered all the corner cases.

I will need help from @jackzampolin and @cwgoes to get this over the finish line. Next comes testing in Agoric's Cosmos module.


For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@cwgoes
Copy link
Contributor

cwgoes commented Mar 30, 2020

Hmm, I actually would prefer that we just get rid of channelexported.PacketDataI altogether and have all packets use an opaque data field, which the modules themselves must unmarshal. Is there a strong reason not to do that?

@dtribble
Copy link

I'm in favor of that as well. Would we still have the PacketDataI type as the thing that the golang modules unmarshal to?

@michaelfig
Copy link
Contributor Author

Hmm, I actually would prefer that we just get rid of channelexported.PacketDataI altogether and have all packets use an opaque data field, which the modules themselves must unmarshal. Is there a strong reason not to do that?

No strong reason, so yes, I'll do that. I'm just getting my feet wet. 😄

Would we still have the PacketDataI type as the thing that the golang modules unmarshal to?

Probably an application-level interface (not exported by the channel) just to be able to specify the subset of codecs to use for the packet unmarshalling. I'll rename it just to prevent conflicts.

@cwgoes Should the IBC channel have a TimeoutHeight as part of the packet header (as it was before ADR-15)? It seems that this feature should be implemented in the channel, rather than the app module.

@cwgoes
Copy link
Contributor

cwgoes commented Mar 30, 2020

I'm in favor of that as well. Would we still have the PacketDataI type as the thing that the golang modules unmarshal to?

I don't think there needs to be a common interface if modules are decoding individually anyways.

No strong reason, so yes, I'll do that. I'm just getting my feet wet. smile

💯

Probably an application-level interface (not exported by the channel) just to be able to specify the subset of codecs to use for the packet unmarshalling. I'll rename it just to prevent conflicts.

Yes, exactly.

@cwgoes Should the IBC channel have a TimeoutHeight as part of the packet header (as it was before ADR-15)? It seems that this feature should be implemented in the channel, rather than the app module.

Yes, I think that makes sense, it should not be in each encoding separately for sure.

This also adds a channelexported.NewOpaquePacketData(rawBytes)
implementation to assist apps in being able to manipulate the
raw packet data using the codec layer.
@codecov
Copy link

codecov bot commented Mar 31, 2020

Codecov Report

Merging #5890 into ibc-alpha will decrease coverage by <.01%.
The diff coverage is 43.47%.

Impacted file tree graph

@@              Coverage Diff              @@
##           ibc-alpha    #5890      +/-   ##
=============================================
- Coverage      35.25%   35.25%   -0.01%     
=============================================
  Files            408      408              
  Lines          42411    42409       -2     
=============================================
- Hits           14952    14950       -2     
  Misses         26108    26108              
  Partials        1351     1351
Impacted Files Coverage Δ
x/ibc/04-channel/types/codec.go 100% <ø> (ø) ⬆️
x/ibc/04-channel/exported/exported.go 93.44% <ø> (ø) ⬆️
x/ibc/20-transfer/keeper/keeper.go 50% <0%> (ø) ⬆️
x/ibc/20-transfer/handler.go 35.59% <0%> (+1.16%) ⬆️
x/ibc/04-channel/keeper/packet.go 84.23% <100%> (-0.99%) ⬇️
x/ibc/20-transfer/keeper/relay.go 97.95% <100%> (+0.02%) ⬆️
x/ibc/04-channel/types/packet.go 66.66% <27.27%> (-0.65%) ⬇️
x/ibc/04-channel/types/msgs.go 76.37% <45.45%> (-1.7%) ⬇️
x/ibc/20-transfer/types/packet.go 51.61% <50%> (+6.87%) ⬆️
x/ibc/04-channel/keeper/timeout.go 78.57% <50%> (ø) ⬆️
... and 1 more

This one only has a GetBytes() method, which is implemented by
OpaquePacketData.
Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is exactly the right direction, I think we can fail even faster on the deserialisation.

docs/architecture/adr-015-ibc-packet-receiver.md Outdated Show resolved Hide resolved
x/ibc/04-channel/exported/opaque.go Outdated Show resolved Hide resolved
x/ibc/20-transfer/keeper/keeper.go Outdated Show resolved Hide resolved
No need to wrap the []byte packet.GetData().  If the caller wants
it, they can use it directly.
@michaelfig michaelfig requested a review from cwgoes March 31, 2020 15:30
Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

Copy link
Member

@AdityaSripal AdityaSripal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement! Main request is that the packet timeout is still committed correctly with these new changes

x/ibc/20-transfer/types/codec.go Outdated Show resolved Hide resolved
x/ibc/20-transfer/keeper/keeper.go Outdated Show resolved Hide resolved
x/ibc/04-channel/types/packet.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Pending @AdityaSripal's comments to be resolved

x/ibc/04-channel/types/msgs.go Outdated Show resolved Hide resolved
x/ibc/20-transfer/keeper/keeper.go Outdated Show resolved Hide resolved
@jackzampolin
Copy link
Member

Should we implement MsgSendPacketData as a generic msg and have MsgTransfer be a wrapper around MsgSendPacketData

x/ibc/20-transfer/handler.go Outdated Show resolved Hide resolved
x/ibc/20-transfer/handler.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one minor improvement

x/ibc/04-channel/types/packet.go Outdated Show resolved Hide resolved
x/ibc/04-channel/types/packet.go Outdated Show resolved Hide resolved
x/ibc/04-channel/types/packet.go Show resolved Hide resolved
Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
@michaelfig
Copy link
Contributor Author

@jackzampolin writes:

Should we implement MsgSendPacketData as a generic msg and have MsgTransfer be a wrapper around MsgSendPacketData

That's a terrific idea! Doing this would greatly simplify the ICS-20 implementation and make it much more understandable in intent. Do you want to take this to an issue?

@jackzampolin
Copy link
Member

Would like to see it impl in this PR tbh

@fedekunze
Copy link
Collaborator

Should we implement MsgSendPacketData as a generic msg and have MsgTransfer be a wrapper around MsgSendPacketData

This is a great idea but imo out of scope for this PR. If we get this in I can reduce the number of changes to the proto migration and I prefer not to be blocked 😄

Copy link
Member

@AdityaSripal AdityaSripal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants