Skip to content

Commit

Permalink
fix(evm): portId not needed, only counterparty (#3135)
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-aitlahcen authored Oct 21, 2024
2 parents dd272af + 6d109de commit 3027e5f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 41 deletions.
48 changes: 20 additions & 28 deletions evm/contracts/core/04-channel/IBCChannel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
channel.connectionId = msg_.connectionId;
channel.ordering = msg_.ordering;
channel.version = msg_.version;
channel.portId = msg_.portId.toHexString();
channel.counterpartyPortId = msg_.counterpartyPortId;
initializeChannelSequences(channelId);
commitChannel(channelId, channel);
Expand All @@ -91,7 +90,7 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
msg_.relayer
);
emit IBCChannelLib.ChannelOpenInit(
channel.portId,
msg_.portId.toHexString(),
channelId,
channel.counterpartyPortId,
msg_.connectionId,
Expand Down Expand Up @@ -121,8 +120,7 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
ordering: msg_.channel.ordering,
counterpartyChannelId: 0,
connectionId: getCounterpartyConnection(msg_.channel.connectionId),
portId: msg_.channel.counterpartyPortId,
counterpartyPortId: msg_.channel.portId,
counterpartyPortId: msg_.portId.toHexString(),
version: msg_.counterpartyVersion
});
if (
Expand All @@ -140,9 +138,8 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
channels[channelId] = msg_.channel;
initializeChannelSequences(channelId);
commitChannelCalldata(channelId, msg_.channel);
address portId = Hex.hexToAddress(msg_.channel.portId);
claimChannel(portId, channelId);
IIBCModule(portId).onChanOpenTry(
claimChannel(msg_.portId, channelId);
IIBCModule(msg_.portId).onChanOpenTry(
msg_.channel.ordering,
msg_.channel.connectionId,
channelId,
Expand All @@ -152,7 +149,7 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
msg_.relayer
);
emit IBCChannelLib.ChannelOpenTry(
msg_.channel.portId,
msg_.portId.toHexString(),
channelId,
msg_.channel.counterpartyPortId,
msg_.channel.counterpartyChannelId,
Expand All @@ -173,13 +170,13 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
revert IBCErrors.ErrInvalidChannelState();
}
uint32 clientId = ensureConnectionState(channel.connectionId);
address portId = channelOwner[msg_.channelId];
IBCChannel memory expectedChannel = IBCChannel({
state: IBCChannelState.TryOpen,
ordering: channel.ordering,
counterpartyChannelId: msg_.channelId,
connectionId: getCounterpartyConnection(channel.connectionId),
portId: channel.counterpartyPortId,
counterpartyPortId: channel.portId,
counterpartyPortId: portId.toHexString(),
version: msg_.counterpartyVersion
});
if (
Expand All @@ -197,14 +194,14 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
channel.version = msg_.counterpartyVersion;
channel.counterpartyChannelId = msg_.counterpartyChannelId;
commitChannel(msg_.channelId, channel);
IIBCModule(Hex.hexToAddress(channel.portId)).onChanOpenAck(
IIBCModule(portId).onChanOpenAck(
msg_.channelId,
msg_.counterpartyChannelId,
msg_.counterpartyVersion,
msg_.relayer
);
emit IBCChannelLib.ChannelOpenAck(
channel.portId,
portId.toHexString(),
msg_.channelId,
channel.counterpartyPortId,
msg_.counterpartyChannelId,
Expand All @@ -223,13 +220,13 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
revert IBCErrors.ErrInvalidChannelState();
}
uint32 clientId = ensureConnectionState(channel.connectionId);
address portId = channelOwner[msg_.channelId];
IBCChannel memory expectedChannel = IBCChannel({
state: IBCChannelState.Open,
ordering: channel.ordering,
counterpartyChannelId: msg_.channelId,
connectionId: getCounterpartyConnection(channel.connectionId),
portId: channel.counterpartyPortId,
counterpartyPortId: channel.portId,
counterpartyPortId: portId.toHexString(),
version: channel.version
});
if (
Expand All @@ -245,11 +242,9 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
}
channel.state = IBCChannelState.Open;
commitChannel(msg_.channelId, channel);
IIBCModule(Hex.hexToAddress(channel.portId)).onChanOpenConfirm(
msg_.channelId, msg_.relayer
);
IIBCModule(portId).onChanOpenConfirm(msg_.channelId, msg_.relayer);
emit IBCChannelLib.ChannelOpenConfirm(
channel.portId,
portId.toHexString(),
msg_.channelId,
channel.counterpartyPortId,
channel.counterpartyChannelId,
Expand All @@ -270,11 +265,10 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
ensureConnectionState(channel.connectionId);
channel.state = IBCChannelState.Closed;
commitChannel(msg_.channelId, channel);
IIBCModule(Hex.hexToAddress(channel.portId)).onChanCloseInit(
msg_.channelId, msg_.relayer
);
address portId = channelOwner[msg_.channelId];
IIBCModule(portId).onChanCloseInit(msg_.channelId, msg_.relayer);
emit IBCChannelLib.ChannelCloseInit(
channel.portId,
portId.toHexString(),
msg_.channelId,
channel.counterpartyPortId,
channel.counterpartyChannelId
Expand All @@ -293,13 +287,13 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
revert IBCErrors.ErrInvalidChannelState();
}
uint32 clientId = ensureConnectionState(channel.connectionId);
address portId = channelOwner[msg_.channelId];
IBCChannel memory expectedChannel = IBCChannel({
state: IBCChannelState.Closed,
ordering: channel.ordering,
counterpartyChannelId: msg_.channelId,
connectionId: getCounterpartyConnection(channel.connectionId),
portId: channel.counterpartyPortId,
counterpartyPortId: channel.portId,
counterpartyPortId: portId.toHexString(),
version: channel.version
});
if (
Expand All @@ -315,11 +309,9 @@ abstract contract IBCChannelImpl is IBCStore, IIBCChannel {
}
channel.state = IBCChannelState.Closed;
commitChannel(msg_.channelId, channel);
IIBCModule(Hex.hexToAddress(channel.portId)).onChanCloseConfirm(
msg_.channelId, msg_.relayer
);
IIBCModule(portId).onChanCloseConfirm(msg_.channelId, msg_.relayer);
emit IBCChannelLib.ChannelCloseConfirm(
channel.portId,
portId.toHexString(),
msg_.channelId,
channel.counterpartyPortId,
channel.counterpartyChannelId
Expand Down
1 change: 1 addition & 0 deletions evm/contracts/core/25-handler/IBCMsgs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ library IBCMsgs {
}

struct MsgChannelOpenTry {
address portId;
IBCChannel channel;
string counterpartyVersion;
bytes proofInit;
Expand Down
1 change: 0 additions & 1 deletion evm/contracts/core/Types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ struct IBCChannel {
IBCChannelOrder ordering;
uint32 connectionId;
uint32 counterpartyChannelId;
string portId;
string counterpartyPortId;
string version;
}
Expand Down
22 changes: 10 additions & 12 deletions evm/tests/src/04-channel/IBCChannel.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ contract IBCChannelTests is Test {
ordering: IBCChannelOrder.Unordered,
connectionId: connectionId,
counterpartyChannelId: 0,
portId: address(module).toHexString(),
counterpartyPortId: COUNTERPARTY_PORT_ID,
version: version
});
Expand All @@ -133,12 +132,12 @@ contract IBCChannelTests is Test {
) public {
vm.pauseGasMetering();
IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({
portId: address(module),
channel: IBCChannel({
state: IBCChannelState.TryOpen,
ordering: IBCChannelOrder.Unordered,
connectionId: connectionId,
counterpartyChannelId: counterpartyChannelId,
portId: address(module).toHexString(),
counterpartyPortId: COUNTERPARTY_PORT_ID,
version: version
}),
Expand All @@ -150,7 +149,7 @@ contract IBCChannelTests is Test {
lightClient.pushValidMembership();
vm.expectEmit();
emit IBCChannelLib.ChannelOpenTry(
msg_.channel.portId,
msg_.portId.toHexString(),
0,
msg_.channel.counterpartyPortId,
msg_.channel.counterpartyChannelId,
Expand All @@ -168,12 +167,12 @@ contract IBCChannelTests is Test {
address relayer
) public {
IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({
portId: address(module),
channel: IBCChannel({
state: IBCChannelState.Unspecified,
connectionId: connectionId,
ordering: IBCChannelOrder.Unordered,
version: version,
portId: address(module).toHexString(),
counterpartyPortId: COUNTERPARTY_PORT_ID,
counterpartyChannelId: counterpartyChannelId
}),
Expand All @@ -193,12 +192,12 @@ contract IBCChannelTests is Test {
address relayer
) public {
IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({
portId: address(module),
channel: IBCChannel({
state: IBCChannelState.TryOpen,
connectionId: connectionId,
ordering: IBCChannelOrder.Unspecified,
version: version,
portId: address(module).toHexString(),
counterpartyPortId: COUNTERPARTY_PORT_ID,
counterpartyChannelId: counterpartyChannelId
}),
Expand All @@ -218,12 +217,12 @@ contract IBCChannelTests is Test {
address relayer
) public {
IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({
portId: address(module),
channel: IBCChannel({
state: IBCChannelState.TryOpen,
connectionId: connectionId,
ordering: IBCChannelOrder.Unordered,
version: version,
portId: address(module).toHexString(),
counterpartyPortId: COUNTERPARTY_PORT_ID,
counterpartyChannelId: counterpartyChannelId
}),
Expand All @@ -243,12 +242,12 @@ contract IBCChannelTests is Test {
address relayer
) public {
IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({
portId: address(module),
channel: IBCChannel({
state: IBCChannelState.TryOpen,
connectionId: connectionId,
ordering: IBCChannelOrder.Unordered,
version: version,
portId: address(module).toHexString(),
counterpartyPortId: COUNTERPARTY_PORT_ID,
counterpartyChannelId: counterpartyChannelId
}),
Expand All @@ -273,11 +272,11 @@ contract IBCChannelTests is Test {
connectionId: connectionId,
ordering: IBCChannelOrder.Unordered,
version: version,
portId: address(module).toHexString(),
counterpartyPortId: COUNTERPARTY_PORT_ID,
counterpartyChannelId: counterpartyChannelId
});
IBCMsgs.MsgChannelOpenTry memory msg_ = IBCMsgs.MsgChannelOpenTry({
portId: address(module),
channel: channel,
counterpartyVersion: counterpartyVersion,
proofInit: hex"",
Expand Down Expand Up @@ -358,7 +357,6 @@ contract IBCChannelTests is Test {
connectionId: connectionId,
ordering: IBCChannelOrder.Unordered,
version: version,
portId: address(module).toHexString(),
counterpartyPortId: COUNTERPARTY_PORT_ID,
counterpartyChannelId: counterpartyChannelId
});
Expand Down Expand Up @@ -397,12 +395,12 @@ contract IBCChannelTests is Test {
) public {
vm.pauseGasMetering();
IBCMsgs.MsgChannelOpenTry memory msgTry_ = IBCMsgs.MsgChannelOpenTry({
portId: address(module),
channel: IBCChannel({
state: IBCChannelState.TryOpen,
connectionId: connectionId,
ordering: IBCChannelOrder.Unordered,
version: version,
portId: address(module).toHexString(),
counterpartyPortId: COUNTERPARTY_PORT_ID,
counterpartyChannelId: counterpartyChannelId
}),
Expand All @@ -423,7 +421,7 @@ contract IBCChannelTests is Test {
lightClient.pushValidMembership();
vm.expectEmit();
emit IBCChannelLib.ChannelOpenConfirm(
msgTry_.channel.portId,
msgTry_.portId.toHexString(),
0,
msgTry_.channel.counterpartyPortId,
counterpartyChannelId,
Expand Down Expand Up @@ -460,11 +458,11 @@ contract IBCChannelTests is Test {
connectionId: connectionId,
ordering: IBCChannelOrder.Unordered,
version: version,
portId: address(module).toHexString(),
counterpartyPortId: COUNTERPARTY_PORT_ID,
counterpartyChannelId: counterpartyChannelId
});
IBCMsgs.MsgChannelOpenTry memory msgTry_ = IBCMsgs.MsgChannelOpenTry({
portId: address(module),
channel: channel,
counterpartyVersion: counterpartyVersion,
proofInit: hex"",
Expand Down

0 comments on commit 3027e5f

Please sign in to comment.