#1667·fiber

A dual-funded UDT channel fails to open with partial funding by the acceptor

Author: sunchengzhuCreated Sep 25, 2026Updated Sep 25, 2026

English | 中文

Summary

In a dual-funded UDT channel, an acceptor that contributes only part of its balance can have the funding collaboration fail. When the selected UDT inputs exceed the contribution, the acceptor creates a UDT change output and places it at outputs[1], which shifts the outputs the initiator already put in place. The initiator's update_for_peer compares existing outputs by position and rejects the update as an invalid funding transaction.

In the tested single-cell balance layout, an acceptor contribution of 3000 (against 10000 held) failed this way at fee rates 1000 and 2000. A contribution of 10000 — the whole balance, so no change output — passed the positional check, and with funding_fee_rate 2000 the channel opened and reached ChannelReady. The initiator contributed 5000 and had its own UDT change output in all four cases. The successful fourth group shows that the initiator's change alone does not trigger this positional failure; the 1000-fee-rate 10000 group fails later, on the separate fee issue in #1663.

Environment

Item Value
FNN fnn Fiber v0.9.1 (9a561b3), observed on macOS arm64.
CKB 0.208.0 devnet, tx_pool.min_fee_rate = 1000.
Nodes Two connected FNN nodes with different secp funding locks.
UDT xUDT from the devnet system cell; each account holds 10000 units in a single cell.

The channel initiator opens with 5000 xUDT from its own lock, at the fee rate under test:

json
{
  "pubkey": "<acceptor_pubkey>",
  "funding_amount": "0x1388",
  "funding_fee_rate": "0x3e8",
  "funding_udt_type_script": {
    "code_hash": "0x1a1e4fef34f5982906f745b048fe7b1089647e82346074e0f32c2ece26cf6b1e",
    "hash_type": "type",
    "args": "0x4472b33b4e1845ebe82f2ce5f511bbe012f144c5f3d7b539909adffc83ccda61"
  }
}

The acceptor then calls accept_channel with its own contribution from its own lock. In this setup a positive contribution below 10000 leaves the acceptor with a UDT change output.

Both funding accounts also hold at least 1000 CKB in ordinary cells without a type script. Both nodes configure the matching UDT whitelist entry and valid cell dependencies, with auto_accept_amount unset, so the channel is accepted by hand. Wait until the funding cells are confirmed and visible to the indexer.

Actual and expected results

Expected: with sufficient UDT and CKB and valid channel parameters, a legitimate UDT change output should not make funding collaboration fail.

Actual, with the acceptor contributing 3000:

DEBUG fnn::ckb::funding::funding_tx: Verifying peer funding tx update: local_tx_hash=Byte32(0x3b6c238a...), remote_tx_hash=Byte32(0x60cf1b45...), local_inputs=2, remote_inputs=4, local_outputs=3, remote_outputs=5
DEBUG fnn::ckb::funding::funding_tx: invalid funding tx (outputs[1]): remote=CellOutput { capacity: JsonUint(14200000000), lock: Script { ... args: JsonBytes(b"\x96e\xe6\xbc...") }, ... } local=CellOutput { capacity: JsonUint(14200000000), lock: Script { ... args: JsonBytes(b"\xe6_\x82;...") }, ... }
DEBUG fnn::ckb::actor: [ckb] VerifyFundingTx failed for remote_tx_hash=Byte32(0x60cf1b45...): Peer sent us an invalid funding tx
ERROR fnn::fiber::channel: fails to verify the TxUpdate message from the peer: Peer sent us an invalid funding tx
DEBUG fnn::fiber::channel: ChannelActor stopped: Hash256(0x1365b5c9...) with reason: AbortFundingWithDetail("Peer sent us an invalid funding tx")

Log excerpts; ... marks omitted fields or abbreviated values. Both capacities and the differing lock-argument prefixes are retained.

The two cells reported at outputs[1] have the same capacity and the same UDT type script, but different locks — one per account. The log prints the lock arguments as escaped byte strings; the same bytes in hex:

Output at outputs[1] capacity type lock.args
acceptor's transaction (remote=) 142 CKB UDT 0x9665e6bc1966ec2bfcca4f11782d2b906f38438f
initiator's transaction (local=) 142 CKB UDT 0xe65f823bc5a48a38515690604e503dba4eb15d61

The counts also show that these are not the same output list: the initiator has 3 outputs and the acceptor's updated transaction has 5.

Measured results (initiator contributes 5000 in all four groups, xUDT)

Acceptor contribution funding_fee_rate Acceptor change output Result
3000 (partial) 1000 yes rejected: invalid funding tx (outputs[1])
3000 (partial) 2000 yes rejected at the same positional check
10000 (whole balance) 1000 no positional check passes; the transaction is then rejected by CKB for the minimum fee
10000 (whole balance) 2000 no ChannelReady, balances [5000, 10000]

Group 2 shows that raising funding_fee_rate does not avoid this failure: the transaction is rejected before broadcast, at the same output position.

The "minimum fee" outcome in group 3 is a separate issue, reported in #1663, and the two differ in both stage and mechanism:

  • This report: the initiator rejects the acceptor's funding transaction during TxUpdate validation, before broadcast. It happens at both fee rates tested.
  • #1663: the funding transaction is broadcast and then rejected by CKB because the fee was calculated without reserving all required signature space.

Changing the acceptor contribution also changes the funding amount and the transaction structure. The failure log identifies the positional output check specifically; the later contribution checks are not reached.

Cause

The acceptor inserts its UDT change at outputs[1] and then copies the initiator's existing non-funding outputs in their original order. With the initiator contributing 5000 and the acceptor 3000, the two transactions are:

Index Initiator's initial transaction (3 outputs) Acceptor's updated transaction (5 outputs)
0 funding: 5000 xUDT / 180 CKB funding: 8000 xUDT / 360 CKB
1 initiator's change: 5000 xUDT acceptor's change: 7000 xUDT
2 initiator's CKB change initiator's change: 5000 xUDT
3 — initiator's CKB change
4 — acceptor's CKB change

Extracted from the transaction JSON in both nodes' logs; the xUDT amounts are read from outputs_data.

The acceptor's new UDT change occupies index 1, pushing the initiator's existing outputs from index 1 and 2 to 2 and 3, which violates the requirement that existing non-funding outputs keep their original positions.

This positional check only fails when the initiator's transaction already carries a non-funding output that can be shifted. If the initial transaction held nothing but the funding output, an acceptor change output would not collide with an existing position.

A UDT change output is created only when the selected UDT inputs exceed the contribution; an account whose contribution exactly matches the selected inputs produces none. Each account here holds its 10000 units in one available cell, so in this layout any positive contribution below 10000 creates change.

Location What happens
build_udt_inputs_outputs, L382–L499 Collects UDT cells for the local contribution; when the collected amount exceeds it, appends a change output owned by the local account (outputs.push(change_output) at L473).
build_base_from_funding_cell, L501–L550 Writes the funding cell, appends the locally built UDT outputs, then appends the outputs already present in the peer's transaction (L525–L527).
update_for_peer, L813–L1025 Preserves the positions and contents of existing non-funding outputs (and their data). Output 0 is handled separately, and new outputs may be appended. The outputs comparison runs at L943–L949.

The same construction code serves other UDT scripts; the same ordering problem was also seen with SUDT, so it is not specific to xUDT.


中文版

双向注资的 UDT 通道在接受方部分出资时无法开通

双向注资的 UDT 通道中,接受方只出资一部分时,共同构造资金交易可能失败。接受方选中的 UDT 输入超过其出资额时会创建一笔 UDT 找零,并把它放在 outputs[1],使发起方已经写好的输出整体后移;发起方的 update_for_peer 按位置比对已有输出,随即判定这笔资金交易无效。

在本次单 cell 余额布局下,接受方出资 3000(账户持有 10000)在费率 1000 和 2000 下都以此方式失败;接受方出资 10000(全额出资、不产生找零)则通过该项位置校验,并且在 funding_fee_rate 为 2000 时成功开通、达到 ChannelReady。四组中发起方均出资 5000 并产生本方 UDT 找零。第 4 组成功开通说明发起方的找零本身不会触发本次位置冲突;费率 1000、出资 10000 的那一组则是随后被 #1663 描述的手续费问题拦下。

测试环境

项目 值
FNN fnn Fiber v0.9.1 (9a561b3),macOS arm64 上观察。
CKB 0.208.0 本地 devnet,tx_pool.min_fee_rate = 1000。
节点 两个已互联的 FNN 节点,各使用不同的 secp 资金锁。
UDT 取自 devnet 系统 cell 的 xUDT,每个账户的 10000 单位位于单个 cell 内。

发起方以本方锁出资 5000 xUDT,费率按被测组别取值,参数见上方英文部分的 JSON。接受方随后调用 accept_channel,同样以本方锁出资。在该布局下,正数出资额小于 10000 即产生一笔 UDT 找零。

双方资金账户各另有至少 1000 CKB 位于不带 type script 的普通 cell 中。两端配置匹配的 UDT 白名单和有效 cell dependencies,并且不设置 auto_accept_amount,通道由人工手动接受。等待资金 cell 确认并可被索引器查询后再继续。

预期与实际结果

预期:在 UDT、CKB 充足且通道参数有效时,合法的 UDT 找零不应导致共同构造资金交易失败。

实际,接受方出资 3000 时:

DEBUG fnn::ckb::funding::funding_tx: Verifying peer funding tx update: local_tx_hash=Byte32(0x3b6c238a...), remote_tx_hash=Byte32(0x60cf1b45...), local_inputs=2, remote_inputs=4, local_outputs=3, remote_outputs=5
DEBUG fnn::ckb::funding::funding_tx: invalid funding tx (outputs[1]): remote=CellOutput { capacity: JsonUint(14200000000), lock: Script { ... args: JsonBytes(b"\x96e\xe6\xbc...") }, ... } local=CellOutput { capacity: JsonUint(14200000000), lock: Script { ... args: JsonBytes(b"\xe6_\x82;...") }, ... }
DEBUG fnn::ckb::actor: [ckb] VerifyFundingTx failed for remote_tx_hash=Byte32(0x60cf1b45...): Peer sent us an invalid funding tx
ERROR fnn::fiber::channel: fails to verify the TxUpdate message from the peer: Peer sent us an invalid funding tx
DEBUG fnn::fiber::channel: ChannelActor stopped: Hash256(0x1365b5c9...) with reason: AbortFundingWithDetail("Peer sent us an invalid funding tx")

以下为日志节选,... 表示省略的字段或缩写的取值;两边的 capacity 和不同的 lock args 前缀均予以保留。

日志里 outputs[1] 两个 cell 的 capacity 与 UDT type script 相同,lock 不同,分属两个账户。日志把 lock args 打印为转义字节串,同样的字节用十六进制表示为:

outputs[1] 的输出 capacity type lock.args
接受方交易(remote=) 142 CKB UDT 0x9665e6bc1966ec2bfcca4f11782d2b906f38438f
发起方交易(local=) 142 CKB UDT 0xe65f823bc5a48a38515690604e503dba4eb15d61

数量也说明两者并非同一份输出列表:发起方为 3 个输出,接受方更新后的交易为 5 个。

实测结果(四组的发起方均出资 5000,xUDT)

接受方出资 funding_fee_rate 是否产生找零 结果
3000(部分出资) 1000 有 被拒:invalid funding tx (outputs[1])
3000(部分出资) 2000 有 在同一处位置校验被拒
10000(全额出资) 1000 无 通过该项位置校验,但交易随后因手续费不足被 CKB 拒绝
10000(全额出资) 2000 无 ChannelReady,余额 [5000, 10000]

第 2 组说明提高 funding_fee_rate 不能避开该失败:交易在广播前、在同一个输出位置就被拒绝。

第 3 组的“手续费不足”是 #1663 已报告的问题,两者在失败阶段和机制上都不同:

  • 本问题:发起方在 TxUpdate 校验阶段拒绝接受方的资金交易,发生在广播之前,且在测试的两个费率下都会发生。
  • #1663:交易已经广播,因估费时未预留全部签名空间,被 CKB 以最低手续费不足拒收。

改变接受方出资额也会改变 funding 金额和交易结构。失败日志具体指向的是输出的位置校验,后续关于出资是否充足的检查尚未执行。

问题原因

接受方先把本方 UDT 找零放到 outputs[1],再按原顺序复制发起方已有的非 funding 输出。在发起方出资 5000、接受方出资 3000 的情况下,两笔交易分别是:

索引 发起方初始交易(3 个输出) 接受方更新交易(5 个输出)
0 funding:5000 xUDT/180 CKB funding:8000 xUDT/360 CKB
1 发起方找零:5000 xUDT 接受方找零:7000 xUDT
2 发起方 CKB 找零 发起方找零:5000 xUDT
3 — 发起方 CKB 找零
4 — 接受方 CKB 找零

根据两端日志中的交易 JSON 提取,xUDT 金额取自 outputs_data。

接受方新增的 UDT 找零占据索引 1,使发起方原有输出从索引 1、2 后移至 2、3,因此违反了“已有非 funding 输出必须保持原位置”这一校验要求。

只有当发起方的交易里已经有可被后移的非 funding 输出时,这项位置校验才会失败。若初始交易仅有 funding 输出,接受方的找零不会与已有位置冲突。

此外,仅当选中的输入 UDT 总量超过出资额时才会创建找零;出资额与选中输入恰好相等则不产生找零。本次每个账户的 10000 单位都在单个可用 cell 内,因此该布局下任何小于 10000 的正数出资都会产生找零。

位置 做了什么
build_udt_inputs_outputs,L382–L499 按本方出资额收集 UDT cell;收集到的数量超过出资额时,追加一笔本账户的找零(L473 outputs.push(change_output))。
build_base_from_funding_cell,L501–L550 先写入 funding cell,再追加本方构造的 UDT 输出,最后追加对端交易中已有的输出(L525–L527)。
update_for_peer,L813–L1025 要求已有非 funding 输出及其数据保持原位置和内容;索引 0 的 funding 输出单独校验,并允许在末尾追加新输出。outputs 的比较位于 L943–L949。

同一段构造代码也用于其他 UDT 脚本;同样的顺序问题在 SUDT 上也观察到过,因此并非 xUDT 所特有。