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

Ibcmodulev2 transfer application spike #7524

Merged

Conversation

bznein
Copy link
Contributor

@bznein bznein commented Oct 29, 2024

Description

This Spike was done by Cian & Nikolas to help inform the IBCModuleV2 interface definition and to get a PoC of what a transfer v2 module looks like and ensures that funigibility between v1 and v2 can be retained.

A few notes about what we did here before anything goes into the feature branch.

  • We created a new Keeper under transfer/v2. This keeper embeds the existing transfer/v1 keeper, and overrides functions required. E.g. the new OnRecv, Ack, Timeout etc.
  • Forwarding is not supported in this PoC. This will require further discussion and spec changes.
  • Some types/functions were made public to be accessible from the new transfer/v2 Keeper. This can be cleaned up / refactored before merging to not need to do this.
  • A new IBCModule (V2) implementation for transfer was created, and added to the V2 router in our testing simapp.
  • Events / telemetry currently disgregarded.
  • The sequence was added to the OnRecv application callback, as this can be required by some applications. I think we probably need to add this to Ack/Timeout as well, but for now have not done so.
  • We added some basic tests for all the new transfer module at the message server layer. A simple happy path test and some test cases where the transfer application fails.
  • We added a test which does the following
    • Sets up 3 chains
    • Sends tokens from A -> B using MsgTransfer (protocol v1)
    • Sends same tokens from B -> C using MsgSendPacket (protocol v2)
    • Sends tokens back from C -> B using MsgSendPacket (protocol v2)
    • Sends tokens from B -> A using MsgTransfer (protocol V1)

This test ensures that fungibility remains and tokens can be sent back and forth using either the v1 or v2 router.

Questions

  1. What does forwarding look like in transfer v2? In v1 we stored the forwarded packets in state, we no longer provide the entire packet to the application callbacks.
  2. Are we happy with the general idea of re-using the transfer keeper and extending/overriding with new logic where appropriate.
  3. If we are going to include the sequence, should we also include the timeout timestamp? Previously we included the full packet in the application callbacks, but now we are providing a subset of that information. Are there use cases where this extra info should be needed? I guess there is nothing stopping an application from including the timestamp in the packet data if required. I think it's probably fine to omit.

closes: #XXXX


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the 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 and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

@gjermundgaraba
Copy link
Contributor

Are we happy with the general idea of re-using the transfer keeper and extending/overriding with new logic where appropriate.

To me, this depends a lot on how long we expect v1 to live in our codebase. Short-term, this might be OK, I don't love the idea of a v2 depending on v1 and having these convoluted paths that might end up with weird bugs later. For one release, I might be OK :)

I guess there is nothing stopping an application from including the timestamp in the packet data if required. I think it's probably fine to omit.

But the application would not know if the timestamp is the same as in the packet, unless only the application is allowed to construct new packets on all implementations?

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.

I looked mainly at the high level interfaces. We want the sequence in ack and timeout as well.

@@ -27,6 +27,7 @@ type IBCModule interface {
ctx context.Context,
sourceChannel string,
destinationChannel string,
sequence uint64,
Copy link
Member

Choose a reason for hiding this comment

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

This should be added to OnAcknowledgementPacket and OnTimeoutPacket as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

yep makes sense!

@chatton
Copy link
Contributor

chatton commented Nov 4, 2024

Are we happy with the general idea of re-using the transfer keeper and extending/overriding with new logic where appropriate.

To me, this depends a lot on how long we expect v1 to live in our codebase. Short-term, this might be OK, I don't love the idea of a v2 depending on v1 and having these convoluted paths that might end up with weird bugs later. For one release, I might be OK :)

Thinking a bit more about this, I was thinking it might be possible to create some type that is a subset of of the transfer keeper that has all the functionality that is shared (e.g. code regarding denoms/ native vs ibc etc. )

Extracting some interfaces/ functions into a the transfer v1 module, then having (potentially a new go mod for) transfer v2 import from v1 the required components/functions and implement all the new logic in a new keeper while re-using a subset from v1.

Kind of similar to what is happening in this PR, but this is a bit messier just shoving it all in a sub directory.

@bznein bznein marked this pull request as ready for review November 15, 2024 12:18
@womensrights womensrights linked an issue Nov 15, 2024 that may be closed by this pull request
4 tasks
@gjermundgaraba
Copy link
Contributor

For some context: this PR is being split up in such a way that forwarding support will happen in a separate PR.

@bznein bznein changed the title [WIP] Ibcmodulev2 transfer application spike Ibcmodulev2 transfer application spike Nov 18, 2024
Copy link
Contributor

@gjermundgaraba gjermundgaraba left a comment

Choose a reason for hiding this comment

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

I think this looks good! And I've tested it e2e with solidity already, so happy path should be working at the very least :)

@@ -210,6 +210,8 @@ func (ftpd FungibleTokenPacketDataV2) HasForwarding() bool {
// UnmarshalPacketData attempts to unmarshal the provided packet data bytes into a FungibleTokenPacketDataV2.
// The version of ics20 should be provided and should be either ics20-1 or ics20-2.
func UnmarshalPacketData(bz []byte, ics20Version string) (FungibleTokenPacketDataV2, error) {
// TODO: in transfer ibc module V2, we need to respect he encoding value passed via the payload, some hard coded assumptions about
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have an issue created for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually have the commit ready to be added to this PR (if we want to!) or I can add it in a separate one! I just wanted to go over it w/ Cian before

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.

LGTM, i have a couple suggestions but not blocking ack. I'm also a bit confused with how the app encoding logic

// TODO: note, encoding field currently not respected in the implementation. encoding is determined by the version.
// ics20-v1 == json
// ics20-v2 == proto
payload = channeltypesv2.NewPayload(transfertypes.ModuleName, transfertypes.ModuleName, transfertypes.V2, "json", bz)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be "proto"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it should! I actually encountered some errors due to this while working on using the encoding! Not worth fixing it now since I have already a commit (which might end up here on in a separate PR) that fixes it

OnSendPacket func(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, payload channeltypesv2.Payload, signer sdk.AccAddress) error
OnRecvPacket func(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, payload channeltypesv2.Payload, relayer sdk.AccAddress) channeltypesv2.RecvPacketResult
OnTimeoutPacket func(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, payload channeltypesv2.Payload, relayer sdk.AccAddress) error
OnAcknowledgementPacket func(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, payload channeltypesv2.Payload, acknowledgement []byte, relayer sdk.AccAddress) error
Copy link
Member

Choose a reason for hiding this comment

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

This fn signature looks different than the fn outside the testing package

return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to send funds", signer)
}

data, err := transfertypes.UnmarshalPacketData(payload.Value, payload.Version)
Copy link
Member

Choose a reason for hiding this comment

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

Ahh because you aren't using the payload.Encoding here

Copy link

sonarcloud bot commented Nov 19, 2024

@bznein bznein merged commit 7ccd1c0 into feat/ibc-eureka Nov 19, 2024
64 of 65 checks passed
@bznein bznein deleted the cian/issue#7510-ibcmodulev2-transfer-application-spike branch November 19, 2024 09:16
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.

IBCModuleV2 Transfer Application Spike
4 participants