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

feat: add acknowledgePacket handler to channel/v2 #7412

Open
wants to merge 7 commits into
base: feat/ibc-eureka
Choose a base branch
from

Conversation

damiannolan
Copy link
Member

Description

  • Adds acknowledgePacket handler to channel/v2
  • Refactored commitment funcs to commitment.go in channel/v2/types

closes: #7369


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.

Copy link
Member Author

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Leaving some comments for the reader! Tests come later, judging by the current structure of the package

@@ -199,3 +199,15 @@ func (k *Keeper) AliasV1Channel(ctx context.Context, portID, channelID string) (
}
return counterparty, true
}

// getV1Counterparty attempts to retrieve a v1 channel from the channel keeper if it exists, then converts it
Copy link
Member Author

Choose a reason for hiding this comment

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

moved from relay.go to keeper.go

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed relay.go to packet.go

Copy link
Member Author

Choose a reason for hiding this comment

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

created commitment.go to house commitment funcs

}

path := hostv2.PacketAcknowledgementKey(packet.DestinationId, sdk.Uint64ToBigEndian(packet.Sequence))
merklePath := types.BuildMerklePath(counterparty.MerklePathPrefix, path)
Copy link
Member Author

Choose a reason for hiding this comment

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

BuildMerklePath, used here and other funcs in this file is imported from the packet-server package.

We should move this to the channel/v2 types pkg afaik. We should not depend on anything in packet-server (which will ultimately be removed).

I'd also like some insight into the implementation of BuildMerklePath.
Some questions I have are:
Why are we not using the MerklePrefix type for the "ibc" prefix used by counterparties - instead we're using MerklePath.
Secondly, implementation looks complex and kinda funky, haven't stepped through to see exactly why that is, was hoping someone could explain it for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

re dependencies: I think we can do a pass at the end and make sure there is no dependency on v1 anything within the channel/v2 package.

func (k Keeper) acknowledgePacket(ctx context.Context, packet channeltypesv2.Packet, acknowledgement channeltypesv2.Acknowledgement, proof []byte, proofHeight exported.Height) error {
// Lookup counterparty associated with our channel and ensure
// that the packet was indeed sent by our counterparty.
counterparty, ok := k.GetCounterparty(ctx, packet.SourceId)
Copy link
Member Author

Choose a reason for hiding this comment

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

this will become a v2 channelEnd, and below clientID := counterparty.ClientID will read better... right now its slightly confusing.

The channelEnd.ClientID would suggest to me that it's the clientID of the client representing the counterparty state machine. Rather than a counterparty.ClientID which would suggest to me its the clientID on the counterparty which repesents this chain (self host where this code is being executed)

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah the naming is a bit all over the place at the moment with regards to counterparty/channel/ids etc, hopefully we'll be able to sort this out quite soon!

@damiannolan damiannolan marked this pull request as ready for review October 8, 2024 11:57
Comment on lines 214 to 216
k.Logger(ctx).Info("packet acknowledged", "sequence", strconv.FormatUint(packet.GetSequence(), 10), "source_id", packet.GetSourceId(), "destination_id", packet.GetDestinationId())

EmitAcknowledgePacketEvents(ctx, packet, acknowledgement)
Copy link
Member Author

Choose a reason for hiding this comment

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

I guess these logs and events should be at the msg server handler layer. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that would make the most sense yeah, can do in a follow up though I think!

Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

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

LGTM 🫡

modules/core/04-channel/v2/keeper/keeper.go Outdated Show resolved Hide resolved
func (k Keeper) acknowledgePacket(ctx context.Context, packet channeltypesv2.Packet, acknowledgement channeltypesv2.Acknowledgement, proof []byte, proofHeight exported.Height) error {
// Lookup counterparty associated with our channel and ensure
// that the packet was indeed sent by our counterparty.
counterparty, ok := k.GetCounterparty(ctx, packet.SourceId)
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah the naming is a bit all over the place at the moment with regards to counterparty/channel/ids etc, hopefully we'll be able to sort this out quite soon!

Comment on lines 214 to 216
k.Logger(ctx).Info("packet acknowledged", "sequence", strconv.FormatUint(packet.GetSequence(), 10), "source_id", packet.GetSourceId(), "destination_id", packet.GetDestinationId())

EmitAcknowledgePacketEvents(ctx, packet, acknowledgement)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that would make the most sense yeah, can do in a follow up though I think!

}

path := hostv2.PacketAcknowledgementKey(packet.DestinationId, sdk.Uint64ToBigEndian(packet.Sequence))
merklePath := types.BuildMerklePath(counterparty.MerklePathPrefix, path)
Copy link
Contributor

Choose a reason for hiding this comment

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

re dependencies: I think we can do a pass at the end and make sure there is no dependency on v1 anything within the channel/v2 package.

Copy link

sonarcloud bot commented Oct 9, 2024

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