進階
CLTV Expiry Delta 時間鎖設定
深入了解閃電網路的 CLTV 過期差值設定,如何影響路由安全性和支付成功率。
10 分鐘
什麼是 CLTV Expiry Delta?
CLTV Expiry Delta 是每個閃電節點設定的時間鎖差值。它決定了節點在轉發 HTLC 時 需要的時間緩衝,以確保有足夠時間在鏈上解決爭議。
安全參數: CLTV delta 是閃電網路安全的關鍵參數。設定太小可能導致資金損失, 設定太大可能使路由被拒絕。
CLTV Delta 工作原理
CLTV Delta in Routing: Multi-hop Payment Example (Alice -> Bob -> Carol -> Dave): Current block height: 800,000 Final expiry (Dave): 800,100 (+100 blocks) Bob's delta: 40 Carol's delta: 40 Dave's delta: 18 Alice ------> Bob ------> Carol ------> Dave | | | | | HTLC | HTLC | HTLC | | expiry: | expiry: | expiry: | | 800,180 | 800,140 | 800,100 | Calculation: Dave: 800,100 (min_final_cltv_expiry from invoice) Carol -> Dave: 800,100 (no delta needed, final node) Bob -> Carol: 800,100 + 40 = 800,140 Alice -> Bob: 800,140 + 40 = 800,180
為什麼需要 Delta?
Safety Time Window Provided by Delta: Scenario: Carol receives preimage but needs to settle with Bob Timeline (block height): 800,100 800,140 | | v v ---+===========+------------------------------------> | | | +-- Bob->Carol HTLC expires | +-- Carol->Dave HTLC expires Carol's 40-block window: • Block 800,100: Dave HTLC expires, Carol's last chance to get preimage • Blocks 800,100-800,140: Carol has time to submit preimage to Bob • Block 800,140: Bob HTLC expires, Carol's last chance to settle If delta is too small (e.g., 3 blocks): • May not broadcast in time during chain congestion • Miners may delay packaging • Carol could lose funds!
Delta 設定建議
Recommended CLTV Delta Settings: Defaults (different implementations): LND: • time_lock_delta: 40 (default) • Config: lnd.conf or updatechanpolicy Core Lightning: • cltv_delta: 34 (default) • Config: setchannel or config Eclair: • cltv-expiry-delta: 48 (default) • Config: eclair.conf Delta Selection Considerations: Larger Delta (e.g., 144 = ~1 day): [+] Safer, ample time to handle [+] Suitable for nodes not always online [-] Longer fund lock time [-] May be skipped by routing algorithms Smaller Delta (e.g., 18): [+] Shorter fund lock time [+] More attractive to payers [-] May be unsafe during chain congestion [-] Requires highly available node Balanced Recommendations: • Routing nodes: 40-80 (requires reliable monitoring) • Personal nodes: 80-144 (more conservative) • High-value channels: 144+ (maximum safety)
min_final_cltv_expiry
Final Expiry Settings in Invoices:
BOLT 11 Invoice Field:
min_final_cltv_expiry_delta (c):
• Type: varint
• Default: 18 (if not specified)
• Meaning: Minimum expiry delta required by final node
Example:
lnbc1u1p...c18... (number after 'c')
If current block height is 800,000:
Payer must set final HTLC expiry >= 800,018
Receiving Node Validation:
When HTLC received:
if htlc.cltv_expiry < current_height + min_final_cltv:
reject(INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS)
This ensures receiver has enough time to:
• Validate payment
• Decide whether to accept
• Settle on-chain if necessary 常見問題
CLTV-Related Errors and Issues: Error Types: INCORRECT_CLTV_EXPIRY: • Cause: Expiry value doesn't match expected • Sender set expiry too small • Solution: Retry with larger delta EXPIRY_TOO_SOON: • Cause: HTLC about to expire • Route too long causing excessive delta accumulation • Solution: Choose shorter route EXPIRY_TOO_FAR: • Cause: Expiry time too far (exceeds max_htlc_cltv) • Node has maximum expiry limit set • Solution: Choose route with smaller delta max_htlc_cltv Limit: Many nodes limit maximum CLTV: LND default: max_cltv = 2016 (~2 weeks) Reasons: • Avoid funds being locked for too long • Reduce wumbo attack vectors • Limit channel occupation time Long Route Problem: If route has 20 hops, each with delta=40: Total CLTV = 20 x 40 = 800 blocks ~ 5.5 days Plus min_final = 18, may approach limit
Shadow Route
添加額外的 CLTV 來隱藏真實目的地。 使路由長度更難推測。
Anchor Outputs
Anchor 輸出允許費用追加, 減少對大 delta 的依賴。
監控重要: 如果你運行路由節點,確保有系統監控即將過期的 HTLC。 錯過過期時間可能導致資金損失。
相關資源
- • BOLT 2 Peer Protocol
- • 時間鎖概述
- • HTLC 腳本
下一步: 了解 HTLC 腳本 中 CLTV 的具體實現。
已複製連結