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

ics20-tao-v2-support #1157

Merged
merged 16 commits into from
Nov 6, 2024
Merged

ics20-tao-v2-support #1157

merged 16 commits into from
Nov 6, 2024

Conversation

sangier
Copy link
Contributor

@sangier sangier commented Oct 31, 2024

This PR introduces IBC v2 TAO support for the ics20 v1 and v2 trying to capture all the internal discussions.

Closes #1141

@sangier sangier marked this pull request as ready for review October 31, 2024 17:04
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.

Nice start! The ics20-v1 spec looks correct, but there are some mistakes on the ics20-v2 side

): bool {

// the decode function must check the payload.encoding is among those supported
success,appData=decode(payload.encoding,payload.appData)
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 also take in the version so that we decode into v1 or v2 appData

var tokens []Token
var sender string
var receiver string // address to send tokens to on this chain
var finalReceiver string // final intended address in forwarding case

if transferVersion == "ics20-1" {
FungibleTokenPacketData data = json.unmarshal(packet.data)
FungibleTokenPacketData data = payload.encoding.unmarshal(payload.appData)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
FungibleTokenPacketData data = payload.encoding.unmarshal(payload.appData)
FungibleTokenPacketData data = unmarshal(payload.encoding, payload.version, payload.appData)

Copy link
Member

Choose a reason for hiding this comment

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

payload.encoding is just a string

currentTime() + DefaultHopTimeoutPeriod,
forwardingPayload
)
// store packet for future sending ack
Copy link
Member

Choose a reason for hiding this comment

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

Fix comment

packet: Packet,
acknowledgement: bytes) {
sourceChannelId: bytes,
destChannelId: bytes, // Can be nullable
Copy link
Member

Choose a reason for hiding this comment

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

Why would this be nullable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, here what I wanted to express is that we call the onAckPacket with the parameters specified in the ics04, but, actually, we don't use all of them. Indeed, while all parameters are necessary for ics20v2 onAckPacket logic, destChannelId and sequence are not used in the ics20v1 onAckPacket.

So the question is how do we want to handle this difference in the interfaces?

  1. Do we want to have a standard way to call applications on the core side?
  2. Do we let the core understand how to call the specific app callback retrieving from the router the callback signature?

Option 2 should provide more flexibility and seems ok. What do you think?

spec/app/ics-020-fungible-token-transfer/README.md Outdated Show resolved Hide resolved
spec/app/ics-020-fungible-token-transfer/README.md Outdated Show resolved Hide resolved
if acknowledgement.success {
FungibleTokenPacketAcknowledgement ack = FungibleTokenPacketAcknowledgement{true, "forwarded packet succeeded"}
handler.writeAcknowledgement(
prevPacket,
destChannelId,
Copy link
Member

Choose a reason for hiding this comment

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

We aren't using the destChannelId here. We need the dest channel of the previous packet

If its not available here then we need to store it along with the previous sequence.

// write error acknowledgement
FungibleTokenPacketAcknowledgement ack = FungibleTokenPacketAcknowledgement{false, "forwarded packet failed"}
handler.writeAcknowledgement(
prevPacket,
destChannelId,
Copy link
Member

Choose a reason for hiding this comment

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

ditto

// the forwarded packet has failed, thus the funds have been refunded to the forwarding address.
// we must revert the changes that came from successfully receiving the tokens on our chain
// before propogating the error acknowledgement back to original sender chain
revertInFlightChanges(packet, prevPacket)
revertInFlightChanges(destChannelId, payload)
// write error acknowledgement
FungibleTokenPacketAcknowledgement ack = FungibleTokenPacketAcknowledgement{false, "forwarded packet timed out"}
handler.writeAcknowledgement(
Copy link
Member

Choose a reason for hiding this comment

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

This needs to change to not have prevPacket in argument

function revertInFlightChanges(sentPacket: Packet, receivedPacket: Packet) {
forwardingAddress = channelForwardingAddress[receivedPacket.destChannel]
reverseEscrow = channelEscrowAddresses[receivedPacket.destChannel]
function revertInFlightChanges(
Copy link
Member

Choose a reason for hiding this comment

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

This function was incorrectly converted. Note that it originally took in two different packets and now you only have a single destChannelId and payload. You need to still take in the forwarded packet info and the original received packet info

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.

Excellent work! Everything looks good now, will commit the small fixes and then merge

var tokens []Token
var sender string
var receiver string // address to send tokens to on this chain
var finalReceiver string // final intended address in forwarding case

if transferVersion == "ics20-1" {
FungibleTokenPacketData data = json.unmarshal(packet.data)
FungibleTokenPacketData data = payload.encoding.unmarshal(payload.appData)
Copy link
Member

Choose a reason for hiding this comment

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

payload.encoding is just a string

spec/app/ics-020-fungible-token-transfer/README.md Outdated Show resolved Hide resolved
spec/app/ics-020-fungible-token-transfer/README.md Outdated Show resolved Hide resolved
@AdityaSripal AdityaSripal merged commit af15ac1 into feat/v2-spec Nov 6, 2024
2 checks passed
@AdityaSripal AdityaSripal deleted the stefano/1141-ic20-tao-v2 branch November 6, 2024 18:27
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.

2 participants