概述
本标准文档规定了 IBC 实现必须实现的接口与状态机逻辑,以便现有通道能够在初始通道握手完成后进行升级。动机
随着新特性不断加入 IBC,链可能希望在不放弃现有通道已经积累的状态和网络效应的前提下,利用新的通道特性。所提出的升级协议将允许链重新协商一个现有通道,以利用新特性,而无需创建新通道,从而保留该通道上已处理的所有现有数据包状态。期望属性
- 双方链都 MUST 同意重新协商后的通道参数。
- 双方链上的通道状态与逻辑 SHOULD 要么使用旧参数,要么使用新参数,但 MUST NOT 处于中间状态。例如,MUST NOT 出现某个应用运行 v2 逻辑,而其对手方仍在运行 v1 逻辑的情况。
- 通道升级协议是原子的,即,
- 要么升级失败,此时通道 MUST 回退到原始通道参数;
- 要么升级成功,此时双方通道端 MUST 采用新的通道参数,应用必须据此正确处理数据包数据。
- 在先前协商参数下发送的数据包,必须按先前协商的参数处理;在新协商参数下发送的数据包,必须按新协商的参数处理。因此,在升级握手完成之前发送的传输中数据包将按照原始参数进行处理。
- 通道升级协议 MUST NOT 修改通道标识符。
技术规范
数据结构
ChannelState 和 ChannelEnd 定义于 ICS-4 中,此处为了便于读者阅读而再次列出。FLUSHING 和 FLUSHCOMPLETE 是为支持升级功能而新增的状态。
ChannelState
- 在
ChanUpgradeInit中,提出升级的发起链应当存储通道升级信息。 - 执行
ChanUpgradeTry并接受升级的对手方链应当存储通道升级信息,将通道状态从OPEN设置为FLUSHING,并通过存储升级超时来启动 flush 计时器。 - 一旦发起链验证对手方处于
FLUSHING状态,它也必须切换到FLUSHING,除非其本端所有传输中数据包都已经 flush 完成,在这种情况下它必须直接切换到FLUSHCOMPLETE。发起方还将存储对手方超时信息,以确保在对手方超时过后不会切换到FLUSHCOMPLETE。 - 对手方链必须证明发起方同样处于
FLUSHING,或者已经在FLUSHCOMPLETE中完成 flush。对手方将存储发起方超时信息,以确保在发起方超时过后不会切换到FLUSHCOMPLETE。
FLUSHING 是一种“阻塞”状态,它会阻止通道端推进到 FLUSHCOMPLETE,除非该通道端上的传输中数据包已经 flush 完成,并且双方通道端都已经切换到 FLUSHING。一旦双方都切换到 FLUSHCOMPLETE,中继者便可通过 ChanUpgradeOpen 在两端证明这一点,从而以新参数在两端打开通道。
ChannelEnd
state:该状态由升级协议的握手步骤定义,并会在握手期间原地变更。当通道端正在 flush 传输中数据包时,它将处于FLUSHING模式。一旦不再存在传输中数据包,且 channelEnd 已准备好切换到OPEN,状态将变为FLUSHCOMPLETE。upgradeSequence:升级序列将在升级握手期间递增并达成一致,并会被原地更新。
OPEN 时,通道端上的字段将切换为 Upgrade 中指定的 UpgradeFields。
UpgradeFields
version:版本 MAY 由升级协议修改。初始通道握手中使用的相同版本协商机制也可以用于升级握手。ordering:排序方式 MAY 由升级协议修改,前提是底层连接支持新的排序方式。connectionHops:connectionHopsMAY 由升级协议修改。
counterpartyChannelIdentifier:对手方通道标识符 MUST NOT 由升级协议修改。counterpartyPortIdentifier:对手方端口标识符 MUST NOT 由升级协议修改。
ChannelEnd 增加了任何字段,则这些字段默认是可修改的,并且可以由有权限发起升级的 Actor(例如链治理)任意选择。
Timeout
timeoutHeight:超时高度表示对手方不得再继续执行升级握手的区块高度。此时双方链将保留其原始通道,并中止升级握手。timeoutTimestamp:超时时间戳表示在对手方链上的某个时间点之后,对手方不得再继续执行升级握手。此时双方链将保留其原始通道,并中止升级握手。
timeoutHeight 或 timeoutTimestamp 中至少有一个 MUST 为非零值。
Upgrade
升级类型表示通道端上的一次特定升级尝试。
nextSequenceSend 使对手方能够知道,在通道可以使用新协商参数重新打开之前,哪些数据包需要先被 flush。任何发送到该通道端且数据包序列大于或等于 nextSequenceSend 的数据包,在升级完成前都会被拒绝。nextSequenceSend 还将用于在对手方为新的升级重新打开时设置新的序列。
ErrorReceipt
sequence包含发生错误时的upgradeSequence。errorMsg包含一个任意字符串,链可用其提供升级为何被中止的附加信息。
存储路径
通道升级路径
链在发起升级时必须存储提议的升级内容。提议的升级必须存储在可证明存储中。一旦升级成功或已中止,该记录即可删除。CounterpartyUpgrade 路径
链必须在chanUpgradeAck 和 chanUpgradeConfirm 时存储对手方升级信息。该信息将存储在私有存储中的 counterpartyUpgrade 路径下。
升级错误路径
升级错误路径是一个公开路径,可在给定升级尝试中向对手方发出升级错误信号。在成功情况下它不会存储任何内容,但如果某条链不接受提议的升级,则会存储ErrorReceipt。
子协议
通道升级过程由以下子协议组成:initUpgradeHandshake、startFlushUpgradeHandshake、openUpgradeHandshake、cancelChannelUpgrade 和 timeoutChannelUpgrade。如果双方链都批准所提议的升级,则升级握手协议应成功完成,并且 ChannelEnd 应在 OPEN 状态下升级到新参数。
实用函数
initUpgradeHandshake 是一个子协议,用于为升级握手初始化通道端。它会校验升级参数并存储通道升级。所有数据包处理将继续按照原始通道参数进行,因为这是一种可以无限期保留的信号机制。新提议的升级将被存储在可证明存储中,供对手方验证。如果在握手开始前再次调用它,则当前提议的升级将被新的升级替换,并且通道升级序列将递增。
isCompatibleUpgradeFields 会在两个升级字段结构体作为对手方彼此兼容时返回 true,否则返回 false。第一个字段必须是执行链上的升级字段,第二个字段必须是对手方的升级字段。此函数还会检查提议的连接跳是否存在、是否为 OPEN,以及是否与对手方的连接跳相互兼容。
startFlushUpgradeHandshake 会阻止升级继续进行,直到所有传输中的数据包都已完成冲刷。它会将通道状态设置为 FLUSHING,并阻止 sendPacket。在此期间,receivePacket、acknowledgePacket 和 timeoutPacket 仍然被允许,并将按照原始通道参数进行处理。状态机会设置一个计时器,用于限制对端在完成冲刷并进入 FLUSHCOMPLETE 之前可花费的时间。新提议的升级将被存储在公共存储中,供对手方验证。
openUpgradeHandshake 会打开通道,并将现有通道参数切换为新达成一致的升级后通道字段。
restoreChannel 会在执行中的通道需要中止升级握手并返回原始参数时,写入一个 ErrorReceipt,将通道恢复到其原始状态,并删除升级信息。
pendingInflightPackets 将返回从该 ChannelEnd 发送的传输中数据包序列列表。由于数据包生命周期完成时会删除其数据包承诺,因此可以监控这一点。也就是说,如果发送方链上仍存在该数据包承诺,则说明该数据包生命周期尚未完成。本规范未提供伪代码,因为这将依赖于具体的状态机。ibc-go 实现将使用存储迭代器来实现该功能。函数签名如下:
isAuthorizedUpgrader 会在所提供地址被授权初始化、修改和取消升级时返回 true。链可以为一组地址授予权限,以表明通道愿意升级到哪一种升级方案。
getUpgradeTimeout 将返回为给定通道指定的升级超时时间。它可以是链范围参数,也可以是按通道选择的参数。这是一个实现层面的细节,因此这里只指定函数签名。注意,这应当为该通道获取某个已存储的超时增量,并将其加到当前高度和时间上,以得到绝对超时值。
升级握手
升级握手定义了七种数据报:ChanUpgradeInit、ChanUpgradeTry、ChanUpgradeAck、ChanUpgradeConfirm、ChanUpgradeOpen、ChanUpgradeTimeout 和 ChanUpgradeCancel 一次成功的协议执行流程如下(注意,所有调用都根据 ICS 25 通过模块进行):| 发起方 | 数据报 | 执行操作的链 | 先前状态 (A, B) | 后续状态 (A, B) |
|---|---|---|---|---|
| Actor | ChanUpgradeInit | A | (OPEN, OPEN) | (OPEN, OPEN) |
| Relayer | ChanUpgradeTry | B | (OPEN, OPEN) | (OPEN, FLUSHING) |
| Relayer | ChanUpgradeAck | A | (OPEN, FLUSHING) | (FLUSHING/FLUSHCOMPLETE, FLUSHING) |
| Relayer | ChanUpgradeConfirm | B | (FLUSHING/FLUSHCOMPLETE, FLUSHING) | (FLUSHING/FLUSHCOMPLETE, FLUSHING/FLUSHCOMPLETE/OPEN) |
OPEN。如果某一端在开始信道升级之前的前置状态不是 OPEN,则被授权的升级执行者会面临信道在升级过程中停滞的风险。
可参考下图了解一种可能的信道升级流程。在第 5 步和第 7 步中展示了多个信道状态,因为在执行握手后,信道端可能会进入这些可能状态之一。注意,在此示例中,链 B 上的信道端会在 ChanUpgradeConfirm(第 7 步)时使用新参数进入 OPEN。
一旦双方状态都进入 FLUSHING,并且双方都已存储对方的升级超时,双方即可通过清空其在途数据包进入 FLUSHCOMPLETE。一旦双方都完成清空,relayer 就可以向两端提交 ChanUpgradeOpen 数据报,并证明对手方也已完成清空,从而将 channelEnd 迁移到 OPEN。
只有当链 B 没有在 ChanUpgradeConfirm 时迁移到 OPEN 时,才需要在链 B 上调用 ChanUpgradeOpen;如果两端的所有数据包都已经清空,就可能发生这种情况。
在两个实现该子协议的链之间成功完成一次升级握手后,将满足以下属性:
- 每条链都在运行其新升级后的信道端,并根据升级后的参数处理升级后的逻辑与状态。
- 每条链都知晓并同意对手方升级后的信道参数。
- 所有在握手之前发送的数据包,都已使用旧参数被完全清空(已确认或已超时)。
- 所有在某个信道端迁移到 OPEN 之后发送的数据包,要么会在发送侧
channelEnd上使用新参数超时,要么会被对手方使用新参数接收。
ChannelEnd,它可以通过在 channelUpgradeErrorPath 写入一个 ErrorReceipt 并恢复原始信道来中止升级握手。该 ErrorReceipt 必须包含出错链的信道端上的当前升级序列。
channelUpgradeErrorPath(portID, channelID) => ErrorReceipt(sequence, msg)
随后,relayer 可以向对手方提交一个 ChanUpgradeCancel 数据报。链在收到该消息后,必须验证对手方是否已在其 channelUpgradeErrorPath 写入一个 ErrorReceipt,且其中的序列号大于或等于本方 ChannelEnd 的升级序列。如果验证成功,它也会恢复自己的原始信道,从而取消此次升级。
如果某条链未能在对手方指定的超时时间内达到 FLUSHCOMPLETE,那么它不得迁移到 FLUSHCOMPLETE,而应中止升级。relayer 可以在 ChanUpgradeTimeout 数据报中向对手方链提交这一事实的证明,使对手方也取消升级并恢复其原始信道。
chanUpgradeInit 函数提供访问控制,由具体实现自行决定。例如链上治理、许可参与者、DAO 等。
chanUpgradeAck 之后,chanUpgradeConfirm 会在处于 FLUSHING 状态的链上被调用。这会将对手链在 ACK 时设置的超时通知给 TRY 链。如果超时已经到期,我们将写入错误回执并恢复。如果两侧的数据包都已经完成冲刷且超时未到,那么我们就可以打开通道。否则,我们会在私有存储中设置对手链的超时,并等待数据包冲刷完成。
FLUSHCOMPLETE 后,才能调用 chanUpgradeOpen。如果握手进入 FLUSHING 模式时队列中仍存在未处理的数据包,那么数据包处理器必须在该通道端上的最后一个数据包处理完成后,将通道端迁移到 FLUSHCOMPLETE。
取消升级流程
在升级握手期间,链可以通过向升级错误路径写入错误回执并将原始通道恢复为OPEN 来取消升级。随后,对手方也必须将其通道恢复为 OPEN。中继者可以通过向处理器发送 ChanUpgradeCancel 数据报来促成这一过程:
升级超时流程
在尝试清空现有数据包时,通道升级过程可能会无限期停滞。为防止这种情况,每条链在进入FLUSHING 时都会设置一个超时。如果对手方未能在预期时间窗口内完成清空,则中继者可以提交一条超时消息,将通道按原始参数恢复为 OPEN。同时还会写入错误回执,以便尚未转入 FLUSHCOMPLETE 的对手方也能按原始参数将通道恢复为 OPEN。
FLUSHCOMPLETE。这将防止通道两端进入不兼容的状态。
注意事项
请注意,如果在途数据包无法被成功清理,通道升级握手可能永远无法成功完成。出现这种情况的原因可能是数据包的超时值过大、确认始终未到达,或者存在某个缺陷导致确认或超时一个数据包变得不可能。在这些情况下,必须由某种协议外机制(例如治理)介入,或许通过强制清除数据包承诺来“手动”清理数据包,然后再重新启动升级握手。迁移
链可能需要更新其内部状态,以与新的已升级通道保持一致。在这种情况下,迁移处理器应在升级流程开始前就已包含在链的二进制文件中,以便链在升级成功后能够正确迁移其状态。如果某次升级需要迁移处理器但该处理器不可用,则执行升级的链必须拒绝此次升级,以避免进入无效状态。该状态迁移不会由对手方验证,因为对手方只会假定:如果通道被升级到某个特定的通道版本,那么对手方上的辅助状态也会一并更新,以符合该通道版本的规范。迁移只能在升级成功完成且新通道处于OPEN 后运行(即在 ChanUpgradeConfirm 或 ChanUpgradeOpen 上)。
示例实现
- Go 语言中的通道升级实现可在 ibc-go 仓库 中找到。
历史
2024 年 2 月 1 日 - 按 ibc-go 中的实现编写的规范 2024 年 7 月 24 日 - 在chanUpgradeConfirm 中添加升级兼容性检查
版权
此处所有内容均采用 Apache 2.0 许可。Synopsis
This standard document specifies the interfaces and state machine logic that IBC implementations must implement in order to enable existing channels to upgrade after the initial channel handshake.Motivation
As new features get added to IBC, chains may wish to take advantage of new channel features without abandoning the accumulated state and network effect(s) of an already existing channel. The upgrade protocol proposed would allow chains to renegotiate an existing channel to take advantage of new features without having to create a new channel, thus preserving all existing packet state processed on the channel.Desired Properties
- Both chains MUST agree to the renegotiated channel parameters.
- Channel state and logic on both chains SHOULD either be using the old parameters or the new parameters, but MUST NOT be in an in-between state, e.g., it MUST NOT be possible for an application to run v2 logic, while its counterparty is still running v1 logic.
- The channel upgrade protocol is atomic, i.e.,
- either it is unsuccessful and then the channel MUST fall-back to the original channel parameters;
- or it is successful and then both channel ends MUST adopt the new channel parameters and the applications must process packet data appropriately.
- Packets sent under the previously negotiated parameters must be processed under the previously negotiated parameters, packets sent under the newly negotiated parameters must be processed under the newly negotiated parameters. Thus, in-flight packets sent before the upgrade handshake is complete will be processed according to the original parameters.
- The channel upgrade protocol MUST NOT modify the channel identifiers.
Technical Specification
Data Structures
TheChannelState and ChannelEnd are defined in ICS-4, they are reproduced here for the reader’s convenience. FLUSHING and FLUSHCOMPLETE are additional states added to enable the upgrade feature.
ChannelState
- In
ChanUpgradeInit, the initializing chain that is proposing the upgrade should store the channel upgrade. - The counterparty chain executing
ChanUpgradeTrythat accepts the upgrade should store the channel upgrade, set the channel state fromOPENtoFLUSHING, and start the flushing timer by storing an upgrade timeout. - Once the initiating chain verifies the counterparty is in
FLUSHING, it must also move toFLUSHINGunless all in-flight packets are already flushed on its end, in which case it must move directly toFLUSHCOMPLETE. The initiator will also store the counterparty timeout to ensure it does not move toFLUSHCOMPLETEafter the counterparty timeout has passed. - The counterparty chain must prove that the initiator is also in
FLUSHINGor completed flushing inFLUSHCOMPLETE. The counterparty will store the initiator timeout to ensure it does not move toFLUSHCOMPLETEafter the initiator timeout has passed.
FLUSHING is a “blocking” state that prevents a channel end from advancing to FLUSHCOMPLETE unless the in-flight packets on its channel end are flushed and both channel ends have already moved to FLUSHING. Once both sides have moved to FLUSHCOMPLETE, a relayer can prove this on both ends with ChanUpgradeOpen to open the channel on both sides with the new parameters.
ChannelEnd
state: The state is specified by the handshake steps of the upgrade protocol and will be mutated in place during the handshake. It will be inFLUSHINGmode when the channel end is flushing in-flight packets. The state will change toFLUSHCOMPLETEonce there are no in-flight packets left and the channelEnd is ready to move toOPEN.upgradeSequence: The upgrade sequence will be incremented and agreed upon during the upgrade handshake and will be mutated in place.
OPEN on a successful upgrade handshake, the fields on the channel end will be switched over to the UpgradeFields specified in the Upgrade.
UpgradeFields
version: The version MAY be modified by the upgrade protocol. The same version negotiation that happens in the initial channel handshake can be employed for the upgrade handshake.ordering: The ordering MAY be modified by the upgrade protocol so long as the new ordering is supported by underlying connection.connectionHops: The connectionHops MAY be modified by the upgrade protocol.
counterpartyChannelIdentifier: The counterparty channel identifier MUST NOT be modified by the upgrade protocol.counterpartyPortIdentifier: The counterparty port identifier MUST NOT be modified by the upgrade protocol
ChannelEnd these are by default modifiable, and can be arbitrarily chosen by an Actor (e.g. chain governance) which has permission to initiate the upgrade.
Timeout
timeoutHeight: Timeout height indicates the height at which the counterparty must no longer proceed with the upgrade handshake. The chains will then preserve their original channel and the upgrade handshake is aborted.timeoutTimestamp: Timeout timestamp indicates the time on the counterparty at which the counterparty must no longer proceed with the upgrade handshake. The chains will then preserve their original channel and the upgrade handshake is aborted.
timeoutHeight or timeoutTimestamp MUST be non-zero.
Upgrade
The upgrade type will represent a particular upgrade attempt on a channel end.
nextSequenceSend allows the counterparty to know which packets need to be flushed before the channel can reopen with the newly negotiated parameters. Any packet sent to the channel end with a packet sequence greater than or equal to the nextSequenceSend will be rejected until the upgrade is complete. The nextSequenceSend will also be used to set the new sequences for the counterparty when it opens for a new upgrade.
ErrorReceipt
sequencecontains theupgradeSequenceat which the error occurred.errorMsgcontains an arbitrary string which chains may use to provide additional information as to why the upgrade was aborted.
Store Paths
Channel Upgrade Path
The chain must store the proposed upgrade upon initiating an upgrade. The proposed upgrade must be stored in the provable store. It may be deleted once the upgrade is successful or has been aborted.CounterpartyUpgrade Path
The chain must store the counterparty upgrade onchanUpgradeAck and chanUpgradeConfirm. This will be stored in the counterpartyUpgrade path on the private store.
Upgrade Error Path
The upgrade error path is a public path that can signal an error of the upgrade to the counterparty for the given upgrade attempt. It does not store anything in the successful case, but it will store theErrorReceipt in the case that a chain does not accept the proposed upgrade.
Sub-Protocols
The channel upgrade process consists of the following sub-protocols:initUpgradeHandshake, startFlushUpgradeHandshake, openUpgradeHandshake, cancelChannelUpgrade, and timeoutChannelUpgrade. In the case where both chains approve of the proposed upgrade, the upgrade handshake protocol should complete successfully and the ChannelEnd should upgrade to the new parameters in OPEN state.
Utility Functions
initUpgradeHandshake is a sub-protocol that will initialize the channel end for the upgrade handshake. It will validate the upgrade parameters and store the channel upgrade. All packet processing will continue according to the original channel parameters, as this is a signalling mechanism that can remain indefinitely. The new proposed upgrade will be stored in the provable store for counterparty verification. If it is called again before the handshake starts, then the current proposed upgrade will be replaced with the new one and the channel upgrade sequence will be incremented.
isCompatibleUpgradeFields will return true if two upgrade field structs are mutually compatible as counterparties, and false otherwise. The first field must be the upgrade fields on the executing chain, the second field must be the counterparty upgrade fields. This function will also check that the proposed connection hops exists, is OPEN, and is mutually compatible with the counterparty connection hops.
startFlushUpgradeHandshake will block the upgrade from continuing until all in-flight packets have been flushed. It will set the channel state to FLUSHING and block sendPacket. During this time; receivePacket, acknowledgePacket and timeoutPacket will still be allowed and processed according to the original channel parameters. The state machine will set a timer for how long the other side can take before it completes flushing and moves to FLUSHCOMPLETE. The new proposed upgrade will be stored in the public store for counterparty verification.
openUpgradeHandshake will open the channel and switch the existing channel parameters to the newly agreed-upon upgraded channel fields.
restoreChannel will write an ErrorReceipt, set the channel back to its original state and delete upgrade information when the executing channel needs to abort the upgrade handshake and return to the original parameters.
pendingInflightPackets will return the list of in-flight packet sequences sent from this ChannelEnd. This can be monitored since the packet commitments are deleted when the packet lifecycle is complete. Thus if the packet commitment exists on the sender chain, the packet lifecycle is incomplete. The pseudocode is not provided in this spec since it will be dependent on the state machine in-question. The ibc-go implementation will use the store iterator to implement this functionality. The function signature is provided below:
isAuthorizedUpgrader will return true if the provided address is authorized to initialize, modify, and cancel upgrades. Chains may permission a set of addresses that can signal which upgrade a channel is willing to upgrade to.
getUpgradeTimeout will return the upgrade timeout specified for the given channel. This may be a chain-wide parameter, or it can be a parameter chosen per channel. This is an implementation-level detail, so only the function signature is specified here. Note this should retrieve some stored timeout delta for the channel and add it to the current height and time to get the absolute timeout values.
Upgrade Handshake
The upgrade handshake defines seven datagrams: ChanUpgradeInit, ChanUpgradeTry, ChanUpgradeAck, ChanUpgradeConfirm, ChanUpgradeOpen, ChanUpgradeTimeout, and ChanUpgradeCancel A successful protocol execution flows as follows (note that all calls are made through modules per ICS 25):| Initiator | Datagram | Chain acted upon | Prior state (A, B) | Posterior state (A, B) |
|---|---|---|---|---|
| Actor | ChanUpgradeInit | A | (OPEN, OPEN) | (OPEN, OPEN) |
| Relayer | ChanUpgradeTry | B | (OPEN, OPEN) | (OPEN, FLUSHING) |
| Relayer | ChanUpgradeAck | A | (OPEN, FLUSHING) | (FLUSHING/FLUSHCOMPLETE, FLUSHING) |
| Relayer | ChanUpgradeConfirm | B | (FLUSHING/FLUSHCOMPLETE, FLUSHING) | (FLUSHING/FLUSHCOMPLETE, FLUSHING/FLUSHCOMPLETE/OPEN) |
OPEN. Authorized upgraders are at risk of having the channel halt during the upgrade process if the prior state before channel upgrades on one of the ends is not OPEN.
Refer to the diagram below for a possible channel upgrade flow. Multiple channel states are shown on steps 5 and 7 where the channel end can move to either one of those possible states upon executing the handshake. Note that in this example, the channel end on chain B moves to OPEN with the new parameters on ChanUpgradeConfirm (step 7).
Once both states are in FLUSHING and both sides have stored each others upgrade timeouts, both sides can move to FLUSHCOMPLETE by clearing their in-flight packets. Once both sides have complete flushing, a relayer may submit a ChanUpgradeOpen datagram to both ends proving that the counterparty has also completed flushing in order to move the channelEnd to OPEN.
ChanUpgradeOpen is only necessary to call on chain B if the chain was not moved to OPEN on ChanUpgradeConfirm which may happen if all packets on both ends are already flushed.
At the end of a successful upgrade handshake between two chains implementing the sub-protocol, the following properties hold:
- Each chain is running their new upgraded channel end and is processing upgraded logic and state according to the upgraded parameters.
- Each chain has knowledge of and has agreed to the counterparty’s upgraded channel parameters.
- All packets sent before the handshake have been completely flushed (acked or timed out) with the old parameters.
- All packets sent after a channel end moves to OPEN will either timeout using new parameters on sending channelEnd or will be received by the counterparty using new parameters.
ChannelEnd, it may abort the upgrade handshake by writing an ErrorReceipt into the channelUpgradeErrorPath and restoring the original channel. The ErrorReceipt must contain the current upgrade sequence on the erroring chain’s channel end.
channelUpgradeErrorPath(portID, channelID) => ErrorReceipt(sequence, msg)
A relayer may then submit a ChanUpgradeCancel datagram to the counterparty. Upon receiving this message a chain must verify that the counterparty wrote an ErrorReceipt into its channelUpgradeErrorPath with a sequence greater than or equal to its own ChannelEnd’s upgrade sequence. If successful, it will restore its original channel as well, thus cancelling the upgrade.
If a chain does not reach FLUSHCOMPLETE within the counterparty specified timeout, then it MUST NOT move to FLUSHCOMPLETE and should instead abort the upgrade. A relayer may submit a proof of this to the counterparty chain in a ChanUpgradeTimeout datagram so that counterparty cancels the upgrade and restores its original channel as well.
chanUpgradeInit function. E.g. chain governance, permissioned actor, DAO, etc.
ChanUpgradeInit with mutually compatible parameters in order for ChanUpgradeTry to succeed. Implementations that want to be permissive towards counterparty-initiated upgrades may allow moving from OPEN to FLUSHING without having an upgrade previously stored on the executing chain.
chanUpgradeConfirm is called on the chain which is on FLUSHING after chanUpgradeAck is called on the counterparty. This will inform the TRY chain of the timeout set on ACK by the counterparty. If the timeout has already exceeded, we will write an error receipt and restore. If packets on both sides have already been flushed and timeout is not exceeded, then we can open the channel. Otherwise, we set the counterparty timeout in the private store and wait for packet flushing to complete.
chanUpgradeOpen may only be called once both sides have moved to FLUSHCOMPLETE. If there exists unprocessed packets in the queue when the handshake goes into FLUSHING mode, then the packet handlers must move the channel end to FLUSHCOMPLETE once the last packet on the channel end has been processed.
Cancel Upgrade Process
During the upgrade handshake a chain may cancel the upgrade by writing an error receipt into the upgrade error path and restoring the original channel toOPEN. The counterparty must then restore its channel to OPEN as well. A relayer can facilitate this by sending ChanUpgradeCancel datagram to the handler:
Timeout Upgrade Process
It is possible for the channel upgrade process to stall indefinitely while trying to flush the existing packets. To protect against this, each chain sets a timeout when it moves intoFLUSHING. If the counterparty has not completed flushing within the expected time window, then the relayer can submit a timeout message to restore the channel to OPEN with the original parameters. It will also write an error receipt so that the counterparty which has not moved to FLUSHCOMPLETE can also restore channel to OPEN with the original parameters.
FLUSHCOMPLETE if the counterparty upgrade timeout has already passed. This will prevent the channel ends from reaching incompatible states.
Considerations
Note that a channel upgrade handshake may never complete successfully if the in-flight packets cannot successfully be cleared. This can happen if the timeout value of a packet is too large, or an acknowledgement never arrives, or if there is a bug that makes acknowledging or timing out a packet impossible. In these cases, some out-of-protocol mechanism (e.g. governance) must step in to clear the packets “manually” perhaps by forcefully clearing the packet commitments before restarting the upgrade handshake.Migrations
A chain may have to update its internal state to be consistent with the new upgraded channel. In this case, a migration handler should be a part of the chain binary before the upgrade process so that the chain can properly migrate its state once the upgrade is successful. If a migration handler is necessary for a given upgrade but is not available, then the executing chain must reject the upgrade so as not to enter into an invalid state. This state migration will not be verified by the counterparty since it will just assume that if the channel is upgraded to a particular channel version, then the auxiliary state on the counterparty will also be updated to match the specification for the given channel version. The migration must only run once the upgrade has successfully completed and the new channel isOPEN (ie. on ChanUpgradeConfirm or ChanUpgradeOpen).
Example Implementations
- Implementation of channel upgrade in Go can be found in ibc-go repository.
History
Feb 1, 2024 - Spec as implemented in ibc-go Jul 24, 2024 - Add upgrade compatibility check inchanUpgradeConfirm