Skip to content

Commit 93311b1

Browse files
committed
fix to check if the generated channel ID is not already stored
Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
1 parent 61c65ec commit 93311b1

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

contracts/core/04-channel/IBCChannelHandshake.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
5555
}
5656

5757
string memory channelId = generateChannelIdentifier();
58+
ChannelStorage storage channelStorage = getChannelStorage()[msg_.portId][channelId];
59+
if (channelStorage.channel.state != Channel.State.STATE_UNINITIALIZED_UNSPECIFIED) {
60+
revert IBCChannelAlreadyChannelExists();
61+
}
5862
initializeSequences(msg_.portId, channelId);
5963
emit GeneratedChannelIdentifier(channelId);
6064

@@ -130,6 +134,10 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
130134
);
131135

132136
string memory channelId = generateChannelIdentifier();
137+
ChannelStorage storage channelStorage = getChannelStorage()[msg_.portId][channelId];
138+
if (channelStorage.channel.state != Channel.State.STATE_UNINITIALIZED_UNSPECIFIED) {
139+
revert IBCChannelAlreadyChannelExists();
140+
}
133141
initializeSequences(msg_.portId, channelId);
134142
emit GeneratedChannelIdentifier(channelId);
135143

contracts/core/04-channel/IIBCChannelErrors.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {Height} from "../../proto/Client.sol";
55
import {Channel} from "../../proto/Channel.sol";
66

77
interface IIBCChannelErrors {
8+
error IBCChannelAlreadyChannelExists();
9+
810
/// @param state channel state
911
error IBCChannelUnexpectedChannelState(Channel.State state);
1012

0 commit comments

Comments
 (0)