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

refactor: change counterparty structure. #7328

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
@@ -148,7 +148,7 @@ func (k *Keeper) IBCSoftwareUpgrade(goCtx context.Context, msg *clienttypes.MsgI
func (k *Keeper) ProvideCounterparty(goCtx context.Context, msg *packetservertypes.MsgProvideCounterparty) (*packetservertypes.MsgProvideCounterpartyResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

creator, found := k.ClientKeeper.GetCreator(ctx, msg.ClientId)
Copy link
Contributor

Choose a reason for hiding this comment

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

My preference/recommendation would be to use the authority naming rather than "creator"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wouldn't that be more confusing? If used I'd assume the module's authority address should be what we're comparing with after (instead of msg.Signer). Either case, happy if issue is opened and discussed afterwards?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe its confusing intertwine terminology used for module permissions and client creation.

The way I thought about it was: msg.Signer creates a client, thus they have the authority to bind a counterparty to it.

Copy link
Contributor

Choose a reason for hiding this comment

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

i.e. SetClientAuthority(ctx, clientID, msg.Signer) && GetClientAuthority(ctx, clientID)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no issue with me, if your pref is strong, I say we open issue and slam it through in follow up.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not quite sure how strong my pref is! 😆

Copy link
Member

Choose a reason for hiding this comment

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

I find creator clearer personally. but maybe that's my own mental model. Don't have a strong preference

creator, found := k.ClientKeeper.GetCreator(ctx, msg.Counterparty.ClientId)
if !found {
return nil, errorsmod.Wrap(ibcerrors.ErrUnauthorized, "client creator must be set")
}
@@ -157,13 +157,13 @@ func (k *Keeper) ProvideCounterparty(goCtx context.Context, msg *packetservertyp
return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "client creator (%s) must match signer (%s)", creator, msg.Signer)
}

if _, ok := k.PacketServerKeeper.GetCounterparty(ctx, msg.ClientId); ok {
return nil, errorsmod.Wrapf(packetservertypes.ErrInvalidCounterparty, "counterparty already exists for client %s", msg.ClientId)
if _, ok := k.PacketServerKeeper.GetCounterparty(ctx, msg.ChannelId); ok {
return nil, errorsmod.Wrapf(packetservertypes.ErrInvalidCounterparty, "counterparty already exists for client %s", msg.ChannelId)
}

k.PacketServerKeeper.SetCounterparty(ctx, msg.ClientId, msg.Counterparty)
k.PacketServerKeeper.SetCounterparty(ctx, msg.ChannelId, msg.Counterparty)
// Delete client creator from state as it is not needed after this point.
k.ClientKeeper.DeleteCreator(ctx, msg.ClientId)
k.ClientKeeper.DeleteCreator(ctx, msg.Counterparty.ClientId)

return &packetservertypes.MsgProvideCounterpartyResponse{}, nil
}
4 changes: 2 additions & 2 deletions modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
@@ -1222,7 +1222,7 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() {
{
"failure: unknown client identifier",
func() {
msg.ClientId = ibctesting.InvalidID
msg.Counterparty.ClientId = ibctesting.InvalidID
},
ibcerrors.ErrUnauthorized,
},
@@ -1237,7 +1237,7 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() {
"failure: counterparty already exists",
func() {
// set it before handler
suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetCounterparty(suite.chainA.GetContext(), msg.ClientId, msg.Counterparty)
suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetCounterparty(suite.chainA.GetContext(), msg.ChannelId, msg.Counterparty)
},
packetservertypes.ErrInvalidCounterparty,
},
2 changes: 1 addition & 1 deletion modules/core/packet-server/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ The [counterparty-merkle-path-prefix] is a comma-separated list of hex-encoded s

counterparty := types.NewCounterparty(counterpartyClientIdentifier, counterpartyMerklePathPrefix)
msg := types.MsgProvideCounterparty{
ClientId: clientIdentifier,
ChannelId: clientIdentifier,
Counterparty: counterparty,
Signer: clientCtx.GetFromAddress().String(),
}
102 changes: 79 additions & 23 deletions modules/core/packet-server/types/counterparty.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions modules/core/packet-server/types/msgs.go
Original file line number Diff line number Diff line change
@@ -16,12 +16,12 @@ var (
)

// NewMsgProvideCounterparty creates a new MsgProvideCounterparty instance
func NewMsgProvideCounterparty(signer, clientID, counterpartyID string, merklePathPrefix commitmenttypes.MerklePath) *MsgProvideCounterparty {
func NewMsgProvideCounterparty(signer, channelID, counterpartyID string, merklePathPrefix commitmenttypes.MerklePath) *MsgProvideCounterparty {
counterparty := NewCounterparty(counterpartyID, merklePathPrefix)

return &MsgProvideCounterparty{
Signer: signer,
ClientId: clientID,
ChannelId: channelID,
Counterparty: counterparty,
}
}
@@ -32,7 +32,7 @@ func (msg *MsgProvideCounterparty) ValidateBasic() error {
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err)
}

if err := host.ClientIdentifierValidator(msg.ClientId); err != nil {
if err := host.ClientIdentifierValidator(msg.ChannelId); err != nil {
return err
}

2 changes: 1 addition & 1 deletion modules/core/packet-server/types/msgs_test.go
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ func (s *TypesTestSuite) TestMsgProvideCounterpartyValidateBasic() {
{
"failure: invalid client ID",
func() {
msg.ClientId = ""
msg.ChannelId = ""
},
host.ErrInvalidID,
},
50 changes: 25 additions & 25 deletions modules/core/packet-server/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions proto/ibc/core/packetserver/v1/counterparty.proto
Original file line number Diff line number Diff line change
@@ -9,8 +9,12 @@ import "ibc/core/commitment/v2/commitment.proto";

// Counterparty defines the counterparty for a light client to implement IBC eureka protocol
message Counterparty {
// the client identifier of the counterparty chain
// the client identifier of the light client representing the counterparty chain
string client_id = 1;
// the merkle path that all ICS24 paths will be stored under
ibc.core.commitment.v2.MerklePath merkle_path_prefix = 2 [(gogoproto.nullable) = false];
// the counterparty identifier that must be used by the packet
string counterparty_channel = 2;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ditto for counterparty_id here though in this case, this will always be one of channel-{N} or client-{N} (correct me if wrong)

Copy link
Contributor

Choose a reason for hiding this comment

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

would definitely make sure any ids are suffixed with _id anyways

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doing this rename atm

// the key path used to store packet flow messages that the counterparty
// will use to send to us. In backwards compatible cases, we will append the channelID and sequence in order to create
// the final path.
ibc.core.commitment.v2.MerklePath merkle_path_prefix = 3 [(gogoproto.nullable) = false];
Copy link
Contributor

Choose a reason for hiding this comment

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

Was there a reason that MerklePrefix wasn't used here? cc @AdityaSripal

}
4 changes: 2 additions & 2 deletions proto/ibc/core/packetserver/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -25,8 +25,8 @@ message MsgProvideCounterparty {

option (gogoproto.goproto_getters) = false;

// client unique identifier
string client_id = 1;
// unique identifier we will use to write all packet messages sent to counterparty
string channel_id = 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Colin suggested id here (considering this key would either be channel-{N} or client-{N}. If we go with generating a channel identifier (e.g {channelV2-{N}) for eureka, keeping as is might be fine?

Copy link
Contributor

Choose a reason for hiding this comment

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

what about source_id?

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 think talking about source and dest makes sense outside the context of a packet

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that makes sense

// counterparty client
Counterparty counterparty = 2 [(gogoproto.nullable) = false];
// signer address