進階
Feature Bits 功能位
了解閃電網路節點如何通過功能位協商支援的功能,實現協議的向前兼容和功能演進。
10 分鐘
什麼是功能位?
功能位(Feature Bits)是閃電網路節點用來宣告和協商所支援功能的機制。 每個功能用一對位元表示:偶數位表示強制(compulsory),奇數位表示可選(optional)。 這種設計允許網路平滑升級,同時保持向後兼容。
功能協商: 節點在建立連接、開通道、發送發票時交換功能位。 雙方只使用共同支援的功能。
功能位結構
Feature Bit Encoding Rules Each feature uses a consecutive pair of bits: Bit 2N (even): Compulsory support -> If peer doesn't support, must disconnect Bit 2N+1 (odd): Optional support -> If peer doesn't support, can still connect Example: data_loss_protect (feature 0/1) Bit 0 (even) set to 1: • Means: I require this feature • Result: Peer must support, otherwise disconnect Bit 1 (odd) set to 1: • Means: I optionally support this feature • Result: Use if peer also supports Feature Bit Vector (from low to high bits): | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| ... |-------|-------|-------|-------|-------|-------| |Feat 0 |Feat 1 |Feat 2 |Feat 3 |Feat 4 |Feat 5 | ...
功能位使用場景
Feature Bits Appear in Different Contexts Context | Message/Location | Usage ------------|------------------------|------------------ init (I) | init message | Node connection node (N) | node_announcement | Network gossip channel (C) | channel_announcement | Channel gossip invoice (9) | BOLT 11 invoice | Payment request bolt12 (B) | BOLT 12 offer/invoice | Offer system Different contexts have different feature subsets: • init: All node features • node: Features to announce for node • channel: Channel-specific features • invoice: Payment-related features • bolt12: Offer-related features
已定義的功能
BOLT 9 定義的功能列表: 位元 名稱 上下文 狀態 ───────────────────────────────────────────────────────── 0/1 option_data_loss_protect IN 已棄用(v0.1) 4/5 option_upfront_shutdown_script IN 6/7 gossip_queries IN 8/9 var_onion_optin IN9 必須(v0.1) 10/11 gossip_queries_ex IN 12/13 option_static_remotekey IN 已棄用(v0.1) 14/15 payment_secret IN9 必須(v0.1) 16/17 basic_mpp IN9 18/19 option_support_large_channel IN 20/21 option_anchor_outputs IN 已棄用 22/23 option_anchors_zero_fee_htlc_tx IN 24/25 option_route_blinding IN9 26/27 option_shutdown_anysegwit IN 28/29 option_dual_fund IN 30/31 option_amp IN9 38/39 option_onion_messages IN 44/45 option_channel_type IN 46/47 option_scid_alias IN 48/49 option_payment_metadata 9 50/51 option_zeroconf IN 52/53 option_trampoline_routing IN9 54/55 option_simple_close IN
重要功能詳解
var_onion_optin (8/9)
TLV 格式的洋蔥 payload,替代固定格式。 現在是必須功能,所有現代節點都支援。
payment_secret (14/15)
防止支付探測攻擊,接收者驗證 payment_secret。 現在是必須功能。
basic_mpp (16/17)
支援基本多路徑支付。允許將一筆支付拆分成多個 HTLC, 通過不同路徑發送。
option_anchor_outputs (20/21)
錨點輸出,允許使用 CPFP 提升承諾交易費用。 已被 zero_fee_htlc_tx 版本取代。
option_route_blinding (24/25)
盲化路由,接收者可以隱藏自己的位置。 發送者只看到入口節點,不知道最終目的地。
option_dual_fund (28/29)
雙向注資通道,雙方都可以在開通道時投入資金。 支援互動式交易構建協議。
option_scid_alias (46/47)
短通道 ID 別名,增強隱私。 允許使用任意 SCID 而非真實的區塊位置。
option_zeroconf (50/51)
零確認通道,注資交易未確認就可使用。 需要信任對方不會雙花。
功能協商流程
Feature Negotiation on Connection Alice Bob | | |-------- init --------------------->| | features: 0x02aaa2 | | | |<------- init ----------------------| | features: 0x028a2a | | | | [Calculate commonly supported] | | | Feature Bit Comparison: Alice: 0x02aaa2 = 0000 0010 1010 1010 1010 0010 Bob: 0x028a2a = 0000 0010 1000 1010 0010 1010 Analysis: • Feature 0/1 (data_loss_protect): Both support • Feature 4/5 (upfront_shutdown): Alice has, Bob doesn't • Feature 8/9 (var_onion): Both support • ... Result: Use mutually supported features Compulsory Feature Check: • If peer lacks our required compulsory feature (even bit): -> Disconnect • If peer has compulsory feature we don't recognize (even bit): -> Disconnect • Optional feature (odd bit) mismatch: -> Continue connection, but don't use that feature
查看節點功能
查看節點支援的功能:
LND:
# 查看本地節點功能
lncli getinfo | jq '.features'
# 查看遠端節點功能
lncli getnodeinfo <pubkey> | jq '.node.features'
CLN:
# 查看本地節點
lightning-cli getinfo | jq '.our_features'
# 查看遠端節點
lightning-cli listnodes <node_id> | jq '.[0].features'
輸出示例:
{
"0": { "name": "data-loss-protect", "is_required": false, "is_known": true },
"5": { "name": "upfront-shutdown-script", "is_required": false, "is_known": true },
"9": { "name": "var-onion-optin", "is_required": false, "is_known": true },
"15": { "name": "payment-addr", "is_required": false, "is_known": true },
"17": { "name": "multi-path-payments", "is_required": false, "is_known": true },
"23": { "name": "anchors-zero-fee-htlc-tx", "is_required": false, "is_known": true },
"45": { "name": "explicit-channel-type", "is_required": false, "is_known": true }
} 通道類型功能
option_channel_type (44/45) Problem: Implicit channel type negotiation may cause inconsistency Solution: Explicitly specify channel type when opening channel channel_type in open_channel message: channel_type TLV: -> Contains feature bit vector for channel to use Example channel types: • Basic channel: No special features • static_remotekey: option_static_remotekey • anchor: option_anchors_zero_fee_htlc_tx • anchors+scid_alias: above + option_scid_alias • Zero-conf anchor: + option_zeroconf Negotiation flow: 1. Initiator proposes channel_type in open_channel 2. Receiver confirms or proposes alternative in accept_channel 3. Both agree, then use that type 4. Type doesn't change during channel lifetime
發票中的功能
BOLT 11 Invoice Feature Bits Invoices can include "9" tag to specify feature requirements: lnbc... 9 = feature bits Common invoice features: • var_onion_optin (8/9): Must use TLV onion • payment_secret (14/15): Must include payment_secret • basic_mpp (16/17): Accept MPP • amp (30/31): Accept AMP Sender handling: • Check invoice feature bits • If unrecognized compulsory feature -> Cannot pay • If supports optional feature -> Use that feature • Build payment conforming to feature requirements
兼容性提示: 新增功能時總是使用奇數(可選)位。只有在功能已被廣泛採用後才升級為偶數(強制)位。 這樣可以避免破壞與舊節點的兼容性。
相關資源
下一步: 了解 節點運營 的最佳實踐。
已複製連結