進階
Channel Backup 通道備份
了解閃電網路通道備份的機制、風險和最佳實踐,保護你的資金免受硬件故障或數據丟失的影響。
12 分鐘
為什麼需要通道備份?
閃電網路的通道狀態存儲在本地,如果丟失這些數據(硬盤故障、軟件錯誤等), 你可能無法正確關閉通道並取回資金。更糟的是,使用過時的備份可能導致 你被對方懲罰,損失全部通道資金。
警告: 在 LN-Penalty 機制下,恢復過時的通道狀態等同於嘗試詐騙,會觸發對方的懲罰交易, 你可能損失通道中的全部資金。這就是所謂的「有毒備份」問題。
備份的挑戰
Dynamic Nature of Channel State:
Problem: Channel state keeps changing
Timeline:
T0: Open channel, state 0
Alice: 1 BTC, Bob: 0 BTC
T1: Backup state 0
T2: Pay 0.3 BTC to Bob, state 1
Alice: 0.7 BTC, Bob: 0.3 BTC
T3: Pay 0.2 BTC to Bob, state 2
Alice: 0.5 BTC, Bob: 0.5 BTC
T4: Disk failure!
What happens when restoring backup (state 0)?
Alice tries to broadcast commitment tx 0
-> Bob detects this is an old state
-> Bob broadcasts penalty transaction
-> Alice loses entire 1 BTC!
This is worse than losing the backup entirely! Static Channel Backup (SCB)
LND 引入的靜態通道備份是一種安全的恢復機制:
Static Channel Backup (SCB) Principle:
SCB does NOT contain channel state!
SCB Contents:
version: backup format version
channels: [
{
channel_point: funding txid:vout
remote_pubkey: peer node public key
capacity: channel capacity
addresses: peer node addresses
},
...
]
Recovery Flow:
1. Restore wallet using seed words
2. Import SCB file
3. Node connects to each channel peer
4. Request peer to initiate cooperative close
5. Peer uses latest state to close
6. Funds return on-chain
Key Points:
• Does not attempt to restore state (avoids toxic backup)
• Relies on peer's honest cooperation
• Funds will return, but must wait for on-chain confirmation Data Loss Protection (DLP)
option_data_loss_protect (BOLT feature):
Detects data loss when nodes reconnect:
Normal case:
Alice ---channel_reestablish---> Bob
my_current_per_commitment_point
your_last_per_commitment_secret
Alice <------------------------- Bob
If Alice loses data:
Alice (after recovery) sends outdated commitment point
----------------------------------> Bob
Bob detects mismatch!
Alice <-- sends latest per_commitment_secret
+ suggests closing channel
Bob's options:
1. Initiate cooperative close (friendly)
2. Force close (using latest state)
Alice can verify if Bob's state is newer than hers,
ensuring Bob isn't maliciously using an old state.
Feature bit: option_data_loss_protect (bit 0/1) option_static_remotekey
這個功能簡化了資金恢復:
option_static_remotekey: Traditional mode: to_remote output uses derived keys Key differs with each state update Recovery requires knowing exact state number static_remotekey mode: to_remote output uses fixed payment_basepoint Regardless of which state is broadcast, output is same address Benefits: Even if peer unilaterally closes channel, you only need seed words to spend to_remote output! Not required: • Knowing current state number • Saving any channel data • Peer cooperation Note: to_local and HTLCs still need extra data for recovery Feature bit: option_static_remotekey (bit 12/13)
各實現的備份機制
LND
-
•
channel.backup文件 - • 每次通道變更自動更新
- • 支持自動複製到遠程位置
-
•
lncli exportchanbackup
Core Lightning
-
•
hsm_secret是核心密鑰 - • 使用 PostgreSQL 後端可實現實時複製
-
•
emergency.recover文件 - • 依賴 option_static_remotekey
Eclair / Phoenix
- • 自動雲端備份(加密)
- • 種子詞 + 備份恢復通道
- • 專門優化的恢復流程
備份最佳實踐
應該做
- • 安全保存種子詞(離線)
- • 設置 SCB 自動備份
- • 使用支持 static_remotekey 的通道
- • 定期測試恢復流程
- • 使用可靠的存儲(RAID、雲端)
不應該做
- • 恢復過時的完整數據庫
- • 在多個節點使用同一個錢包
- • 忽略備份警告
- • 將種子詞存在線上
- • 假設對方會誠實合作
Watchtower 與備份
Watchtower as Backup Supplement: Scenario: You lose data, peer maliciously broadcasts old state Without Watchtower: • You cannot penalize (no revocation key) • Can only accept peer's claimed state • May lose funds With Watchtower: • Watchtower has penalty transactions stored • Even if you're offline/lost data • Watchtower can protect you However: • Watchtower needs new data uploaded on each update • Storage requirements can be large • Must trust Watchtower is online and reliable
Eltoo 的改進
Eltoo 將徹底解決備份問題:
當前(LN-Penalty)
- • 舊備份是「有毒」的
- • 需要存儲所有舊狀態
- • Watchtower 存儲需求大
- • 恢復複雜且有風險
未來(Eltoo)
- • 任何備份都安全
- • 只需存儲最新狀態
- • Watchtower 只需一份數據
- • 恢復簡單可靠
相關資源
- • LND 恢復規劃
- • Watchtowers
- • Eltoo
重要: 閃電網路資金的安全高度依賴正確的備份策略。在運行節點前,請確保你完全理解 備份機制和恢復流程。永遠不要在生產環境測試恢復!
已複製連結