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 channel back to counterparty #7842

Merged
merged 19 commits into from
Jan 17, 2025

Conversation

AdityaSripal
Copy link
Member

@AdityaSripal AdityaSripal commented Jan 13, 2025

Description

closes: #7739


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.

@AdityaSripal AdityaSripal changed the base branch from main to feat/ibc-eureka January 13, 2025 16:10
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.

Thanks! This is going to be very nice! 🙌

The general structure and logic seems straightforward and understandable. I have some questions on naming that I left in comments.

proto/ibc/core/client/v2/counterparty.proto Outdated Show resolved Hide resolved
// resolveV2Identifiers returns the client identifier and the counterpartyInfo for the client given the packetId
// Note: For fresh eureka channels, the client identifier and packet identifier are the same.
// For aliased channels, the packet identifier will be the original channel ID and the counterpartyInfo will be constructed from the channel
func (k *Keeper) resolveV2Identifiers(ctx context.Context, portId string, packetId string) (string, clienttypes.CounterpartyInfo, error) {
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 maybe the name could be better here. If I have to read the comment to understand what the function does for me, I consider it a code smell :)

Copy link
Contributor

Choose a reason for hiding this comment

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

After seeing it used further down I am even more confused. Is it taking in packetId or a client id?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea this was because it could also be an original channelID for aliasing, in which case I still need to retrieve the original clientiD

@@ -14,9 +14,9 @@ message Packet {
// with a later sequence number.
uint64 sequence = 1;
// identifies the sending chain.
string source_channel = 2;
string source_id = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

It will be the last time I bring this up (I hope), but what is the reason we don't want to name source and destination identifier client_id (as in source_client_id)? Can it be anything else?

return 0, "", errorsmod.Wrap(types.ErrChannelNotFound, sourceChannel)
}
// lookup counterparty and clientid from packet identifiers
clientID, counterparty, err := k.resolveV2Identifiers(ctx, payloads[0].SourcePort, sourceId)
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought this function was taking in a packet identifier? But it is taking in the source (client) identifier?

Comment on lines +596 to 597
transfertypes.NewHop(transfertypes.ModuleName, pathv2.EndpointB.ClientID),
transfertypes.NewHop(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID),
Copy link
Member Author

Choose a reason for hiding this comment

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

First hop used IBC Classic, second hop used IBC Eureka

return nil, status.Error(codes.InvalidArgument, err.Error())
}

if req.Sequence == 0 {
return nil, status.Error(codes.InvalidArgument, "packet sequence cannot be 0")
}

if !q.HasChannel(ctx, req.ChannelId) {
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 was a pain to find the analog of especially in a world with aliasing. Just decided to remove it since if client (or aliased client) doesn't exist, none of these other auxilliary state will exist either

}
},
status.Error(codes.InvalidArgument, "packet sequence cannot be 0"),
},
{
"channel not found",
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed these cases. They still error but now equivalent to the queried key not existing

// NextSequenceSend returns the next send sequence for a given channel.
rpc NextSequenceSend(QueryNextSequenceSendRequest) returns (QueryNextSequenceSendResponse) {
option (google.api.http).get = "/ibc/core/channel/v2/channels/{channel_id}/next_sequence_send";
option (google.api.http).get = "/ibc/core/channel/v2/clients/{client_id}/next_sequence_send";
Copy link
Member Author

Choose a reason for hiding this comment

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

There rpc urls are very ugly since they still contain channel/v2. Should we pull this whole thing back out to its own package packetserver? 🫣

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 be cleaner, yes.

Copy link
Member

Choose a reason for hiding this comment

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

I don't mind the urls but up to you

// CounterpartyInfo defines the key that the counterparty will use to message our client
message CounterpartyInfo {
// merkle prefix key is the prefix that ics provable keys are stored under
repeated bytes merkle_prefix = 1;
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 decided to just make this repeated bytes rather than importing ics23.commitment MerklePath

I think the inclusion of ics23 into the required external structs has caused more confusion than anything else. It is also an unnecessary import here

I convert to ics23 commitment MerklePath internally

Copy link
Member

Choose a reason for hiding this comment

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

I think it is ok to have this be ics23.commitment.MerklePath but use repeated bytes in MsgRegisterCounterparty since CounterpartyInfo is used internally anyway?

But this is also good :)

@AdityaSripal AdityaSripal marked this pull request as ready for review January 16, 2025 11:47
@AdityaSripal AdityaSripal requested a review from srdtrk as a code owner January 16, 2025 11:47
@AdityaSripal
Copy link
Member Author

Now that we have channel completely removed should we move channel/v2 into a different package? Perhaps back to packetserver

@gjermundgaraba
Copy link
Contributor

Now that we have channel completely removed should we move channel/v2 into a different package? Perhaps back to packetserver

I think that would make sense and keep things much cleaner. Not sure what the best name is, but separate package for sure.

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 like where this is going! Left some mostly nit comments :)

// NextSequenceSend returns the next send sequence for a given channel.
rpc NextSequenceSend(QueryNextSequenceSendRequest) returns (QueryNextSequenceSendResponse) {
option (google.api.http).get = "/ibc/core/channel/v2/channels/{channel_id}/next_sequence_send";
option (google.api.http).get = "/ibc/core/channel/v2/clients/{client_id}/next_sequence_send";
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 be cleaner, yes.

// identifies the receiving chain.
string destination_channel = 3;
// identifies the sending client on the sending chain.
string source_client = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: but why not source_client_id? Since we use client_id everywhere else?

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 will leave this out for now, since this is analogous to what has existed in ibc-go forever. We can make a decision to change in a different PR/issue

Copy link
Contributor

Choose a reason for hiding this comment

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

Created an issue to track this here #7854

func() {},
func() {
packet.SourceChannel = ibctesting.InvalidID
packet.SourceClient = ibctesting.InvalidID
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit of a nit, but I don't get why we don't just add the ID to all these names? If we're dealing with the ID, and we use that name in most other contexts, why not keep it consistent and always refer to it as SourceClientID and so on?

@@ -19,50 +20,40 @@ import (
// in order for the packet to be sent to the counterparty.
func (k *Keeper) sendPacket(
ctx context.Context,
sourceChannel string,
sourceClient string,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here with the naming. It's a bit of a nit, but the more I see it, the more I feel like we should just use ClientID in all names where it that is really what it is.

modules/core/04-channel/v2/keeper/packet.go Outdated Show resolved Hide resolved
modules/core/04-channel/v2/keeper/packet.go Outdated Show resolved Hide resolved
modules/core/04-channel/v2/keeper/packet.go Outdated Show resolved Hide resolved
Copy link
Member

@srdtrk srdtrk left a comment

Choose a reason for hiding this comment

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

lgtm. Surprised so many lines were deleted. This is the right way it seems.

modules/core/02-client/keeper/keeper.go Show resolved Hide resolved
modules/core/02-client/keeper/keeper.go Show resolved Hide resolved
modules/core/02-client/types/counterparty.go Show resolved Hide resolved
modules/core/02-client/types/keys.go Show resolved Hide resolved
modules/core/02-client/types/keys.go Show resolved Hide resolved
modules/core/02-client/types/keys.go Show resolved Hide resolved
modules/core/04-channel/v2/client/cli/cli.go Outdated Show resolved Hide resolved
// it must be called by the same relayer that called CreateClient
func (k *Keeper) RegisterCounterparty(ctx context.Context, msg *clienttypes.MsgRegisterCounterparty) (*clienttypes.MsgRegisterCounterpartyResponse, error) {
creator := k.ClientKeeper.GetClientCreator(ctx, msg.ClientId)
if !creator.Equals(sdk.AccAddress(msg.Signer)) {
Copy link
Member

Choose a reason for hiding this comment

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

Should you instead have the creator become a string? Should be consistent with how we do these comparisons elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Left as is now, since it that case, we may as well just have the keeper return a string. Maybe we can do later as a small followup if really necessary

// NextSequenceSend returns the next send sequence for a given channel.
rpc NextSequenceSend(QueryNextSequenceSendRequest) returns (QueryNextSequenceSendResponse) {
option (google.api.http).get = "/ibc/core/channel/v2/channels/{channel_id}/next_sequence_send";
option (google.api.http).get = "/ibc/core/channel/v2/clients/{client_id}/next_sequence_send";
Copy link
Member

Choose a reason for hiding this comment

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

I don't mind the urls but up to you

// CounterpartyInfo defines the key that the counterparty will use to message our client
message CounterpartyInfo {
// merkle prefix key is the prefix that ics provable keys are stored under
repeated bytes merkle_prefix = 1;
Copy link
Member

Choose a reason for hiding this comment

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

I think it is ok to have this be ics23.commitment.MerklePath but use repeated bytes in MsgRegisterCounterparty since CounterpartyInfo is used internally anyway?

But this is also good :)

Copy link

@AdityaSripal AdityaSripal merged commit b3184b4 into feat/ibc-eureka Jan 17, 2025
67 checks passed
@AdityaSripal AdityaSripal deleted the aditya/back-to-counterparty branch January 17, 2025 16:19
@AdityaSripal AdityaSripal mentioned this pull request Jan 20, 2025
10 tasks
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.

3 participants