跳至主要內容
入門

Cooperative Close 協商關閉

了解閃電網路通道的協商關閉機制,如何與對方合作以最低成本和最快速度關閉通道。

8 分鐘

什麼是協商關閉?

協商關閉(Cooperative Close),也稱為相互關閉(Mutual Close),是通道雙方 合作創建一筆最終結算交易來關閉通道的過程。這是關閉通道的首選方式,因為它比強制關閉 更便宜、更快速,且雙方可以立即使用結算後的資金。

推薦方式: 協商關閉沒有時間鎖限制,交易更小費用更低,結算後雙方立即獲得資金。 始終應該優先嘗試協商關閉。

協商 vs 強制關閉

Comparison Table:

Feature                 Cooperative     Force Close
-------------------------------------------------------
Requires cooperation    Yes             No
Transaction size        ~350 vB         ~700+ vB
Fee                     Low             High
Timelock                None            1 day - 2 weeks
HTLC handling           Off-chain       On-chain TX
Fund availability       Immediate       Delayed
Secondary TX            None            May need

Fee Example (50 sat/vB):
  - Cooperative close: ~17,500 sats
  - Force close (no HTLC): ~45,000 sats
  - Force close (with HTLC): ~80,000+ sats

協商關閉流程

Message Flow:

Alice                              Bob
  |                                 |
  |───── shutdown ─────────────────>|  Alice initiates
  |      (scriptpubkey_a)           |
  |                                 |
  |<──── shutdown ──────────────────|  Bob agrees
  |      (scriptpubkey_b)           |
  |                                 |
  | (Both stop accepting new HTLCs) |
  | (Wait for existing HTLCs)       |
  |                                 |
  |<──── closing_signed ────────────|  Bob proposes fee
  |      (fee_satoshis, signature)  |
  |                                 |
  |───── closing_signed ───────────>|  Alice accepts/counters
  |      (fee_satoshis, signature)  |
  |                                 |
  | (Repeat until fee agreed)       |
  |                                 |
  | [Broadcast closing transaction] |
  |                                 |

Closing Transaction Structure:
+-------------------------------------------------------+
| Closing Transaction                                   |
+-------------------------------------------------------+
| Input:                                                |
|   - Funding TX output (2-of-2 multisig)               |
|   - Signatures: Alice + Bob                           |
+-------------------------------------------------------+
| Outputs:                                              |
|   - Alice's output: scriptpubkey_a (no timelock)      |
|   - Bob's output: scriptpubkey_b (no timelock)        |
+-------------------------------------------------------+

Note: No to_local timelock restriction!

費用協商

Fee Negotiation:

Rules:
  - Fee paid by initiator (deducted from their balance)
  - Both parties must agree on fee rate
  - Uses binary search convergence

Example:
  Bob proposes: fee = 10,000 sats
  Alice counters: fee = 5,000 sats
  Bob counters: fee = 7,500 sats
  Alice accepts: fee = 7,500 sats
  -> Agreement reached, broadcast TX

BOLT Recommendation:
  If fee difference < 10% of counterparty's proposal,
  the receiver should accept.

  Example:
    Bob proposes: 10,000 sats
    Alice proposes: 9,500 sats
    Difference: 5% < 10%
    -> Alice should accept Bob's 10,000

Fee Range Limits:
  - Minimum: dust_limit (avoid dust outputs)
  - Maximum: cannot make either balance dust
  - Must be within reasonable range

HTLC 處理

關閉前結算

shutdown 訊息發送後,雙方停止接受新 HTLC,但現有 HTLC 仍正常處理。 必須等所有 HTLC 結算後才能完成關閉。

不需要鏈上處理

與強制關閉不同,協商關閉時 HTLC 在鏈下結算。不需要 HTLC-Success 或 HTLC-Timeout 交易,節省大量費用。

輸出地址

Scriptpubkey in shutdown message:

Allowed script types:
  - P2PKH: OP_DUP OP_HASH160 <20 bytes> OP_EQUALVERIFY OP_CHECKSIG
  - P2SH: OP_HASH160 <20 bytes> OP_EQUAL
  - P2WPKH: OP_0 <20 bytes>
  - P2WSH: OP_0 <32 bytes>
  - P2TR: OP_1 <32 bytes> (if option_shutdown_anysegwit)

upfront_shutdown_script:

  Can pre-set close address when opening channel.

  In open_channel/accept_channel:
    upfront_shutdown_script: <preset_address>

  Benefits:
    - Prevents funds sent to wrong address
    - Protects funds even if node compromised
    - Forces funds to preset address only

  If upfront_shutdown_script is set:
    shutdown scriptpubkey must match

常見問題

對方不回應怎麼辦?

如果發送 shutdown 後對方長時間不回應,可能需要強制關閉。 但建議先多等待一段時間,對方可能只是暫時離線。

費用談不攏怎麼辦?

如果雙方對費用分歧太大無法達成一致,任一方可以選擇強制關閉。 但這通常意味著更高的總成本。

還有未結算的 HTLC?

必須等待所有 HTLC 結算。如果有卡住的 HTLC,可能需要等待超時或獲得 preimage。 極端情況可能需要強制關閉。

實現命令

發起協商關閉:

LND:
lncli closechannel --chan_point <funding_txid:output_index>

# 指定目標確認區塊數(影響費用)
lncli closechannel --chan_point <txid:index> --conf_target 6

# 指定關閉地址
lncli closechannel --chan_point <txid:index> \
  --delivery_address bc1q...

CLN:
lightning-cli close <channel_id>

# 指定超時(秒),超時後強制關閉
lightning-cli close <channel_id> 300

# 指定目標費率
lightning-cli close <channel_id> null 10000perkb

Eclair:
eclair-cli close --channelId <channel_id>

相關資源

下一步: 了解 通道管理 的完整生命週期。

已複製連結
已複製到剪貼簿