@@ -20,11 +20,14 @@ import {IBCChannelLib} from "./IBCChannelLib.sol";
2020contract IBCChannelHandshake is IBCModuleManager , IIBCChannelHandshake , IIBCChannelErrors {
2121 using IBCHeight for Height.Data;
2222
23+ // ------------- IIBCChannelHandshake implementation ------------------- //
24+
2325 /**
2426 * @dev channelOpenInit is called by a module to initiate a channel opening handshake with a module on another chain.
2527 */
2628 function channelOpenInit (IIBCChannelHandshake.MsgChannelOpenInit calldata msg_ )
27- external
29+ public
30+ override
2831 returns (string memory , string memory )
2932 {
3033 if (msg_.channel.connection_hops.length != 1 ) {
@@ -52,6 +55,7 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
5255
5356 string memory channelId = generateChannelIdentifier ();
5457 initializeSequences (msg_.portId, channelId);
58+ emit GeneratedChannelIdentifier (channelId);
5559
5660 IIBCModule module = lookupModuleByPort (msg_.portId);
5761 string memory version = module.onChanOpenInit (
@@ -74,15 +78,15 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
7478 msg_.channel.connection_hops,
7579 version
7680 );
77- emit GeneratedChannelIdentifier (channelId);
7881 return (channelId, version);
7982 }
8083
8184 /**
8285 * @dev channelOpenTry is called by a module to accept the first step of a channel opening handshake initiated by a module on another chain.
8386 */
8487 function channelOpenTry (IIBCChannelHandshake.MsgChannelOpenTry calldata msg_ )
85- external
88+ public
89+ override
8690 returns (string memory , string memory )
8791 {
8892 if (msg_.channel.connection_hops.length != 1 ) {
@@ -127,6 +131,7 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
127131
128132 string memory channelId = generateChannelIdentifier ();
129133 initializeSequences (msg_.portId, channelId);
134+ emit GeneratedChannelIdentifier (channelId);
130135
131136 IIBCModule module = lookupModuleByPort (msg_.portId);
132137 string memory version = module.onChanOpenTry (
@@ -149,14 +154,13 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
149154 msg_.channel.connection_hops,
150155 version
151156 );
152- emit GeneratedChannelIdentifier (channelId);
153157 return (channelId, version);
154158 }
155159
156160 /**
157161 * @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.
158162 */
159- function channelOpenAck (IIBCChannelHandshake.MsgChannelOpenAck calldata msg_ ) external {
163+ function channelOpenAck (IIBCChannelHandshake.MsgChannelOpenAck calldata msg_ ) public override {
160164 Channel.Data storage channel = channels[msg_.portId][msg_.channelId];
161165 if (channel.state != Channel.State.STATE_INIT) {
162166 revert IBCChannelUnexpectedChannelState (channel.state);
@@ -195,7 +199,7 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
195199 /**
196200 * @dev channelOpenConfirm is called by the counterparty module to close their end of the channel, since the other end has been closed.
197201 */
198- function channelOpenConfirm (IIBCChannelHandshake.MsgChannelOpenConfirm calldata msg_ ) external {
202+ function channelOpenConfirm (IIBCChannelHandshake.MsgChannelOpenConfirm calldata msg_ ) public override {
199203 Channel.Data storage channel = channels[msg_.portId][msg_.channelId];
200204 if (channel.state != Channel.State.STATE_TRYOPEN) {
201205 revert IBCChannelUnexpectedChannelState (channel.state);
@@ -227,7 +231,7 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
227231 /**
228232 * @dev channelCloseInit is called by either module to close their end of the channel. Once closed, channels cannot be reopened.
229233 */
230- function channelCloseInit (IIBCChannelHandshake.MsgChannelCloseInit calldata msg_ ) external {
234+ function channelCloseInit (IIBCChannelHandshake.MsgChannelCloseInit calldata msg_ ) public override {
231235 Channel.Data storage channel = channels[msg_.portId][msg_.channelId];
232236 if (channel.state == Channel.State.STATE_UNINITIALIZED_UNSPECIFIED) {
233237 revert IBCChannelChannelNotFound (msg_.portId, msg_.channelId);
@@ -249,7 +253,7 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
249253 * @dev channelCloseConfirm is called by the counterparty module to close their end of the
250254 * channel, since the other end has been closed.
251255 */
252- function channelCloseConfirm (IIBCChannelHandshake.MsgChannelCloseConfirm calldata msg_ ) external {
256+ function channelCloseConfirm (IIBCChannelHandshake.MsgChannelCloseConfirm calldata msg_ ) public override {
253257 Channel.Data storage channel = channels[msg_.portId][msg_.channelId];
254258 if (channel.state == Channel.State.STATE_UNINITIALIZED_UNSPECIFIED) {
255259 revert IBCChannelChannelNotFound (msg_.portId, msg_.channelId);
@@ -285,6 +289,8 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
285289 );
286290 }
287291
292+ // ------------- Private functions ------------------- //
293+
288294 /**
289295 * @dev writeChannel writes a channel which has successfully passed the OpenInit or OpenTry handshake step.
290296 */
@@ -296,7 +302,7 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
296302 ChannelCounterparty.Data calldata counterparty ,
297303 string [] calldata connectionHops ,
298304 string memory version
299- ) internal {
305+ ) private {
300306 Channel.Data storage channel = channels[portId][channelId];
301307 channel.state = state;
302308 channel.ordering = order;
@@ -309,13 +315,20 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
309315 updateChannelCommitment (portId, channelId);
310316 }
311317
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+
312327 function updateChannelCommitment (string memory portId , string memory channelId ) private {
313328 commitments[IBCCommitment.channelCommitmentKey (portId, channelId)] =
314329 keccak256 (Channel.encode (channels[portId][channelId]));
315330 }
316331
317- /* Verification functions */
318-
319332 function verifyChannelState (
320333 ConnectionEnd.Data storage connection ,
321334 Height.Data calldata height ,
@@ -345,17 +358,6 @@ contract IBCChannelHandshake is IBCModuleManager, IIBCChannelHandshake, IIBCChan
345358 );
346359 }
347360
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-
359361 function getCounterpartyHops (string memory connectionId ) internal view returns (string [] memory hops ) {
360362 hops = new string [](1 );
361363 hops[0 ] = connections[connectionId].counterparty.connection_id;
0 commit comments