跳至主要內容
進階

Force Close 強制關閉

了解閃電網路通道的強制關閉(單方面關閉)機制,何時發生、如何處理及相關風險。

12 分鐘

什麼是強制關閉?

強制關閉(Force Close),也稱為單方面關閉(Unilateral Close),是指通道一方 在沒有對方配合的情況下,通過廣播承諾交易來關閉通道。這是閃電網路的安全逃生機制, 確保即使對方離線或不配合,你也能取回自己的資金。

成本較高: 強制關閉比協商關閉需要更多的鏈上交易和時間。應該優先嘗試協商關閉, 只有在必要時才使用強制關閉。

何時發生強制關閉

對方離線

對方節點長時間不可達,無法進行協商關閉。你需要資金但無法等待。

對方不配合

對方拒絕簽署協商關閉交易,或者對關閉條款有爭議無法達成一致。

HTLC 超時風險

有未結算的 HTLC 即將超時,必須上鏈解決以避免資金損失。

檢測到欺詐

對方廣播了舊的承諾交易(作弊),你需要廣播懲罰交易。

協議違規

對方發送無效訊息或違反協議規則,節點自動觸發強制關閉。

強制關閉流程

Force Close Transaction Structure:

Step 1: Broadcast Commitment Transaction
+-------------------------------------------------------+
| Commitment Transaction                                |
+-------------------------------------------------------+
| Input:                                                |
|   - Funding TX output (2-of-2 multisig)               |
+-------------------------------------------------------+
| Outputs:                                              |
|   - to_local (initiator balance, timelocked)          |
|   - to_remote (counterparty, immediately spendable)   |
|   - Offered HTLCs                                     |
|   - Received HTLCs                                    |
|   - Anchor outputs (if enabled)                       |
+-------------------------------------------------------+

Step 2: Wait for Confirmation
  - Commitment TX needs miner confirmation
  - Timelock starts after confirmation
  - Usually needs 1-6 confirmations

Step 3: Handle to_local Output
  to_local has to_self_delay timelock
  Example: 144 blocks = ~1 day

  Must wait for timelock to expire before spending.
  This gives counterparty time to detect and punish fraud.

Step 4: Handle HTLC Outputs
  - HTLC-Success TX: claim received HTLC with preimage
  - HTLC-Timeout TX: reclaim sent HTLC after timeout
  - These are second-level TXs requiring additional on-chain fees

時間鎖機制

to_self_delay Timelock:

Purpose:
  - Give counterparty time to detect fraud
  - If you broadcast old state
  - Counterparty can broadcast penalty TX in this window

Typical Settings:
  - Small channels: 144 blocks (~1 day)
  - Medium channels: 288 blocks (~2 days)
  - Large channels: 1008-2016 blocks (1-2 weeks)

Timeline Example:
  T0: You broadcast commitment TX
  T1: TX confirmed (T0 + ~10 min)
  T2: Timelock starts (T1)
  T3: Timelock ends (T1 + 144 blocks = T1 + ~1 day)
  T4: You can spend to_local output

If counterparty detects cheating (old state broadcast):
  - They broadcast penalty TX during T1-T3
  - Penalty TX has no timelock restriction
  - All your funds confiscated by counterparty

Honest close is fine:
  - You broadcast latest state
  - Waiting for timelock is just inconvenient
  - Funds settle correctly in the end

HTLC 處理

HTLC Handling During Force Close:

Scenario: Channel has pending HTLCs

Offered HTLC (you sent):
  You --HTLC--> Counterparty

  Possible outcomes:
    1. Counterparty knows preimage
       -> They claim with HTLC-Success TX
    2. HTLC times out
       -> You reclaim with HTLC-Timeout TX

  Note: HTLC-Timeout TX also has timelock!

Received HTLC (you received):
  Counterparty --HTLC--> You

  Possible outcomes:
    1. You know preimage
       -> You claim with HTLC-Success TX
    2. HTLC times out
       -> Counterparty reclaims with HTLC-Timeout TX

  Must claim with preimage before timeout!

Fee Considerations:
  - Each HTLC output needs separate TX to resolve
  - Small HTLCs may not be worth claiming due to fees
  - This is why HTLC dust limits exist

Anchor Outputs 的影響

沒有 Anchor 的問題

承諾交易費率在簽署時固定。如果網路擁堵,費率可能太低導致交易卡住, HTLC 可能超時,資金面臨風險。

有 Anchor 的優勢

使用 Anchor Outputs 可以通過 CPFP 動態調整費率,確保交易即時確認。需要維護額外的鏈上 UTXO。

強制關閉的成本

Force Close Cost Analysis:

1. Commitment TX Fee
   - Paid by initiator (from channel balance)
   - Fee rate fixed at signing (or adjusted with Anchor)
   - Typical size: 500-1000 vB

2. to_local Spending TX Fee
   - Another TX needed after timelock expires
   - Paid by you

3. HTLC Resolution Fees
   - Each HTLC needs separate second-level TX
   - HTLC-Success: ~150 vB
   - HTLC-Timeout: ~150 vB
   - Multiple HTLCs = cumulative fees

4. Time Cost
   - Wait for commitment TX confirmation
   - Wait for to_self_delay timelock
   - Funds locked and unusable

Cost Comparison (assuming 50 sat/vB):

Cooperative Close:
  - 1 TX ~350 vB = 17,500 sats
  - Immediate settlement

Force Close (no HTLC):
  - Commitment TX ~700 vB = 35,000 sats
  - to_local spend ~200 vB = 10,000 sats
  - Wait ~1 day
  - Total: 45,000 sats + time

Force Close (3 HTLCs):
  - Commitment TX ~1000 vB = 50,000 sats
  - 3 HTLC TXs ~450 vB = 22,500 sats
  - to_local spend ~200 vB = 10,000 sats
  - Total: 82,500 sats + time

最佳實踐

優先協商關閉

始終先嘗試協商關閉。等待對方上線,多次重試後再考慮強制關閉。

維護 Anchor UTXO

使用 Anchor Outputs 的通道需要維護用於 CPFP 的 UTXO。確保錢包有足夠的鏈上資金。

監控待處理 HTLC

在強制關閉前確認所有待處理 HTLC 的狀態和超時時間。確保有足夠時間處理。

使用 Watchtower

Watchtower 可以在你離線時監控並響應對方的強制關閉。

相關資源

下一步: 了解 協商關閉 如何更高效、更便宜地關閉通道。

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