# Fiber Pre-Ready Channels Management ## Metadata **Status**:: #x **Zettel**:: #zettel/permanent **Created**:: [[2025-01-07]] **Topic**:: [[♯ CKB Fiber]] ## Memo Pre-Ready Channels Management - 没有签名过 funding tx 的 channels 可以直接关闭。重试的话先签名方需要签名、后签名方等待对方签名。 - 一旦自己签名过 funding tx,哪 怕还没有在 CKB 链上被确认,甚至没还有收到对方的签名,此时 funding tx 是否会上链已经不受 channel 双方可控制,必须监控 CKB chain 直到以下事件发生: - funding tx committed 且经过足够的确认数,则 channel 成功创建,变成 READY 状态 - 有任一 input cell 或者 dep cell 确认在链上已经被其它 txs 消费掉,此时可以认为 funding tx 不可能再上链。为了安全,这里的确认数可以用大一些。 - 有任一 input cell 或者 dep cell 是 unknow 且保持在 unknown 状态过去了足够的时间的,也可认为 funding tx 不可能再上链。这可能是因为发生了 reorg 导致原来的 input cell 无法上链。 - 因为 RBF,一个 Channel 可能会有多个 Funding Tx,只要本方签过名,哪怕对方没有签过,都有可能上链,所以所有的 Funding Tx 都需要监控。 - 为了简化 Funding Tx 管理,应该加一条规则,则一 Channel 的所有 Funding Txs 必须至少有一个共同的 input cell,这样只要有一个 Funding Tx 成功上链,其它的 Txs 都无效,就不需要再继续监控了。这条规则和 CKB RBF 的规则也是一致的。 - 而因为 double spent / unknown cell 而无效的的 Funding Tx 并不能认为 Channel 无法再创建成功了,只有所有本方签名名的 Funding Tx 全部无效了,才能安全的关闭 Channel。 - 对于有过本方签名过 Funding Tx 的 Channel,应该按照以下方法推进 Channel 创建的进程: 1. 重发所有有双方签名且有效的 Funding Tx 到 CKB 并持续监控所有有效的 Funding Tx 2. 如果当前的 Pending Funding Tx 还没有签名且已方应该先签名,则签名后发送给对方,并开始在 CKB 链上监控上链状态。 3. 如果当前的 Pending Funding Tx 自己还没有签名且轮到自己签名,则签名后发送给对方,并开始在 CKB 链上监控上链状态。 4. 如果当前的 Pending Funding Tx 自己已经签名但是对方还没有签名,则应该发送给对方,并开始在 CKB 链上监控上链状态。 ## Motivation A channel is ready after the funding transaction is committed in the CKB blockchain. In pre-ready channels management, two issues need attention: 1. The channel can get stuck in the pre-ready status if the workflow is interrupted, e.g., when nodes restart. 2. Funding transactions, once signed, can be committed at any time unless any inputs have been spent. To address issue 1, we have to resume the funding workflow and closely monitor all ongoing funding transactions to tackle issue 2. This document outlines the specifications of these mechanisms. ## Specification ### Funding Transaction RBF (Replace-By-Fee) Overlapping Inputs Requirement In the funding process described in [the p2p-message specification](https://github.com/nervosnetwork/fiber/blob/develop/docs/specs/p2p-message.md), participants have the option to replace pending funding transactions with new ones with a higher fee-rate. However, that specification lacks specific requirements for the new funding transactions, leading to potential complexity in managing them. This specification enforces a mandatory verification rule for funding transactions. Nodes are required to reject signing funding transactions that do not meet this verification rule. **Funding Transaction RBF Overlapping Inputs Requirement**: all funding transactions negotiated for the same channel must have a common transaction input. This verification rule ensues that once a funding transaction has been committed, all other funding transactions for the same channel are invalidated. So once the channel is ready, the channel participants do not need to worry that their assets will be locked by other funding transactions for the same channel. ### Pre-Ready Channel Status Management