Channel Opening Handshake
The channel opening handshake is a 4-step process (see ICS-004 to learn more):
- Channel Open Init (source chain)
- Channel Open Try (destination chain)
- Channel Open Ack (source chain)
- Channel Open Confirm (destination chain)
Naturally, this contract only implements the first and third steps of the channel opening handshake, as the second and fourth steps are handled by the counterparty ICA host module.
loading...
Channel Open Init
Authorization
A channel open init message can be sent to any IBC module by any user, and it is up to the module to decide whether to accept the request or not.
In the case of cw-ica-controller
, only the contract itself can send a channel open init message. Since the sender of
MsgChannelOpenInit
is not passed to the contract (or any other IBC module), we enforce this by having a state
variable that keeps track of whether
or not to accept channel open init messages. This variable is only set to true by the contract itself right before
it is about to send a channel open init message in InstantiateMsg
or
ExecuteMsg::CreateChannel
.
loading...
Version Metadata and Ordering
Whenever a new channel is created, the submitter of MsgChannelOpenInit
must propose a version string and ordering.
In IBC, the version string is used to determine whether or not the two modules on either side of the channel are compatible. The two modules are compatible if and only if they both support and agree on the same version string. Moreover, the version string may carry arbitrary metadata encoded in JSON format. This metadata can be used to carry key information about the channel, such as the encoding format, the application version, etc.
The format of the version string for ICS-27 is specified here. The following rust code shows the version metadata struct used to encode the version string:
loading...
Since it is the contract itself that submits the MsgChannelOpenInit
, the contract constructs the version string
based on the channel_open_init_options
that are passed to it in InstantiateMsg
or ExecuteMsg::CreateChannel
.
loading...
The actual entry point for the MsgChannelOpenInit
only does validation checks on channel parameters. For example,
it checks that the channel is not already open.
loading...
Channel Open Ack
Unlike the MsgChannelOpenInit
, the MsgChannelOpenAck
is submitted by a relayer, and we do not need to worry about
authorization. This step comes after the MsgChannelOpenTry
is submitted by the counterparty ICA host module. In the
Try
step, the counterparty ICA host module may propose a different version string. Therefore, the contract must
validate the version string and channel parameters once again in the MsgChannelOpenAck
.
The interchain account address is passed to the contract in this step through the version string. In Init
step,
cw-ica-controller
leaves the interchain account address empty, and the counterparty ICA host module fills it in.
After validating the version string, the contract then stores the channel parameters in its state.
loading...