@@ -20,11 +20,14 @@ import {IBCChannelLib} from "./IBCChannelLib.sol";
20
20
contract IBCChannelHandshake is IBCModuleManager , IIBCChannelHandshake , IIBCChannelErrors {
21
21
using IBCHeight for Height.Data;
22
22
23
+ // ------------- IIBCChannelHandshake implementation ------------------- //
24
+
23
25
/**
24
26
* @dev channelOpenInit is called by a module to initiate a channel opening handshake with a module on another chain.
25
27
*/
26
28
function channelOpenInit (IIBCChannelHandshake.MsgChannelOpenInit calldata msg_ )
27
- external
29
+ public
30
+ override
28
31
returns (string memory , string memory )
29
32
{
30
33
if (msg_.channel.connection_hops.length != 1 ) {
@@ -52,6 +55,7 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
52
55
53
56
string memory channelId = generateChannelIdentifier ();
54
57
initializeSequences (msg_.portId, channelId);
58
+ emit GeneratedChannelIdentifier (channelId);
55
59
56
60
IIBCModule module = lookupModuleByPort (msg_.portId);
57
61
string memory version = module.onChanOpenInit (
@@ -74,15 +78,15 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
74
78
msg_.channel.connection_hops,
75
79
version
76
80
);
77
- emit GeneratedChannelIdentifier (channelId);
78
81
return (channelId, version);
79
82
}
80
83
81
84
/**
82
85
* @dev channelOpenTry is called by a module to accept the first step of a channel opening handshake initiated by a module on another chain.
83
86
*/
84
87
function channelOpenTry (IIBCChannelHandshake.MsgChannelOpenTry calldata msg_ )
85
- external
88
+ public
89
+ override
86
90
returns (string memory , string memory )
87
91
{
88
92
if (msg_.channel.connection_hops.length != 1 ) {
@@ -127,6 +131,7 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
127
131
128
132
string memory channelId = generateChannelIdentifier ();
129
133
initializeSequences (msg_.portId, channelId);
134
+ emit GeneratedChannelIdentifier (channelId);
130
135
131
136
IIBCModule module = lookupModuleByPort (msg_.portId);
132
137
string memory version = module.onChanOpenTry (
@@ -149,14 +154,13 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
149
154
msg_.channel.connection_hops,
150
155
version
151
156
);
152
- emit GeneratedChannelIdentifier (channelId);
153
157
return (channelId, version);
154
158
}
155
159
156
160
/**
157
161
* @dev channelOpenAck is called by the handshake-originating module to acknowledge the acceptance of the initial request by the counterparty module on the other chain.
158
162
*/
159
- function channelOpenAck (IIBCChannelHandshake.MsgChannelOpenAck calldata msg_ ) external {
163
+ function channelOpenAck (IIBCChannelHandshake.MsgChannelOpenAck calldata msg_ ) public override {
160
164
Channel.Data storage channel = channels[msg_.portId][msg_.channelId];
161
165
if (channel.state != Channel.State.STATE_INIT) {
162
166
revert IBCChannelUnexpectedChannelState (channel.state);
@@ -195,7 +199,7 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
195
199
/**
196
200
* @dev channelOpenConfirm is called by the counterparty module to close their end of the channel, since the other end has been closed.
197
201
*/
198
- function channelOpenConfirm (IIBCChannelHandshake.MsgChannelOpenConfirm calldata msg_ ) external {
202
+ function channelOpenConfirm (IIBCChannelHandshake.MsgChannelOpenConfirm calldata msg_ ) public override {
199
203
Channel.Data storage channel = channels[msg_.portId][msg_.channelId];
200
204
if (channel.state != Channel.State.STATE_TRYOPEN) {
201
205
revert IBCChannelUnexpectedChannelState (channel.state);
@@ -227,7 +231,7 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
227
231
/**
228
232
* @dev channelCloseInit is called by either module to close their end of the channel. Once closed, channels cannot be reopened.
229
233
*/
230
- function channelCloseInit (IIBCChannelHandshake.MsgChannelCloseInit calldata msg_ ) external {
234
+ function channelCloseInit (IIBCChannelHandshake.MsgChannelCloseInit calldata msg_ ) public override {
231
235
Channel.Data storage channel = channels[msg_.portId][msg_.channelId];
232
236
if (channel.state == Channel.State.STATE_UNINITIALIZED_UNSPECIFIED) {
233
237
revert IBCChannelChannelNotFound (msg_.portId, msg_.channelId);
@@ -249,7 +253,7 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
249
253
* @dev channelCloseConfirm is called by the counterparty module to close their end of the
250
254
* channel, since the other end has been closed.
251
255
*/
252
- function channelCloseConfirm (IIBCChannelHandshake.MsgChannelCloseConfirm calldata msg_ ) external {
256
+ function channelCloseConfirm (IIBCChannelHandshake.MsgChannelCloseConfirm calldata msg_ ) public override {
253
257
Channel.Data storage channel = channels[msg_.portId][msg_.channelId];
254
258
if (channel.state == Channel.State.STATE_UNINITIALIZED_UNSPECIFIED) {
255
259
revert IBCChannelChannelNotFound (msg_.portId, msg_.channelId);
@@ -285,6 +289,8 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
285
289
);
286
290
}
287
291
292
+ // ------------- Private functions ------------------- //
293
+
288
294
/**
289
295
* @dev writeChannel writes a channel which has successfully passed the OpenInit or OpenTry handshake step.
290
296
*/
@@ -296,7 +302,7 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
296
302
ChannelCounterparty.Data calldata counterparty ,
297
303
string [] calldata connectionHops ,
298
304
string memory version
299
- ) internal {
305
+ ) private {
300
306
Channel.Data storage channel = channels[portId][channelId];
301
307
channel.state = state;
302
308
channel.ordering = order;
@@ -309,13 +315,20 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
309
315
updateChannelCommitment (portId, channelId);
310
316
}
311
317
318
+ function initializeSequences (string memory portId , string memory channelId ) internal {
319
+ nextSequenceSends[portId][channelId] = 1 ;
320
+ nextSequenceRecvs[portId][channelId] = 1 ;
321
+ nextSequenceAcks[portId][channelId] = 1 ;
322
+ recvStartSequences[portId][channelId].sequence = 1 ;
323
+ commitments[IBCCommitment.nextSequenceRecvCommitmentKey (portId, channelId)] =
324
+ keccak256 (abi.encodePacked ((bytes8 (uint64 (1 )))));
325
+ }
326
+
312
327
function updateChannelCommitment (string memory portId , string memory channelId ) private {
313
328
commitments[IBCCommitment.channelCommitmentKey (portId, channelId)] =
314
329
keccak256 (Channel.encode (channels[portId][channelId]));
315
330
}
316
331
317
- /* Verification functions */
318
-
319
332
function verifyChannelState (
320
333
ConnectionEnd.Data storage connection ,
321
334
Height.Data calldata height ,
@@ -345,17 +358,6 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
345
358
);
346
359
}
347
360
348
- /* Internal functions */
349
-
350
- function initializeSequences (string memory portId , string memory channelId ) internal {
351
- nextSequenceSends[portId][channelId] = 1 ;
352
- nextSequenceRecvs[portId][channelId] = 1 ;
353
- nextSequenceAcks[portId][channelId] = 1 ;
354
- recvStartSequences[portId][channelId].sequence = 1 ;
355
- commitments[IBCCommitment.nextSequenceRecvCommitmentKey (portId, channelId)] =
356
- keccak256 (abi.encodePacked ((bytes8 (uint64 (1 )))));
357
- }
358
-
359
361
function getCounterpartyHops (string memory connectionId ) internal view returns (string [] memory hops ) {
360
362
hops = new string [](1 );
361
363
hops[0 ] = connections[connectionId].counterparty.connection_id;
0 commit comments