Skip to content

Commit

Permalink
fix to check if the generated channel ID is not already stored
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Dec 5, 2024
1 parent 61c65ec commit 93311b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions contracts/core/04-channel/IBCChannelHandshake.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
}

string memory channelId = generateChannelIdentifier();
ChannelStorage storage channelStorage = getChannelStorage()[msg_.portId][channelId];
if (channelStorage.channel.state != Channel.State.STATE_UNINITIALIZED_UNSPECIFIED) {
revert IBCChannelAlreadyChannelExists();
}
initializeSequences(msg_.portId, channelId);
emit GeneratedChannelIdentifier(channelId);

Expand Down Expand Up @@ -130,6 +134,10 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
);

string memory channelId = generateChannelIdentifier();
ChannelStorage storage channelStorage = getChannelStorage()[msg_.portId][channelId];
if (channelStorage.channel.state != Channel.State.STATE_UNINITIALIZED_UNSPECIFIED) {
revert IBCChannelAlreadyChannelExists();
}
initializeSequences(msg_.portId, channelId);
emit GeneratedChannelIdentifier(channelId);

Expand Down
2 changes: 2 additions & 0 deletions contracts/core/04-channel/IIBCChannelErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {Height} from "../../proto/Client.sol";
import {Channel} from "../../proto/Channel.sol";

interface IIBCChannelErrors {
error IBCChannelAlreadyChannelExists();

/// @param state channel state
error IBCChannelUnexpectedChannelState(Channel.State state);

Expand Down

0 comments on commit 93311b1

Please sign in to comment.