進階
Channel Update Gossip 通道更新廣播
深入了解閃電網路的 channel_update 訊息,如何傳播通道費用和策略變更。
10 分鐘
什麼是 Channel Update?
Channel Update 是閃電網路節點用來廣播通道策略變更的訊息。 它包含費用設定、HTLC 限制和通道狀態,是路由決策的關鍵資訊。
BOLT 7 定義: channel_update 訊息在 BOLT 7 中規範。每個通道方向 可以獨立設定策略,因此一個通道可能有兩個不同的 update。
訊息結構
channel_update Message Format: Field Definitions: signature: 64 bytes Schnorr/ECDSA signature of entire message chain_hash: 32 bytes Blockchain identifier (Bitcoin mainnet/testnet) short_channel_id: 8 bytes Channel identifier (block_height:tx_index:output_index) timestamp: 4 bytes Unix timestamp for ordering updates message_flags: 1 byte • bit 0: must_be_one (compatibility) • Other bits reserved channel_flags: 1 byte • bit 0: direction (0=node1->node2, 1=node2->node1) • bit 1: disable (1=channel temporarily disabled) cltv_expiry_delta: 2 bytes CLTV delta required for forwarding HTLCs htlc_minimum_msat: 8 bytes Minimum accepted HTLC amount fee_base_msat: 4 bytes Base fee (millisatoshis) fee_proportional_millionths: 4 bytes Proportional fee (per million) htlc_maximum_msat: 8 bytes (optional, if message_flags bit 0) Maximum accepted HTLC amount
費用計算
Routing Fee Formula:
fee = fee_base_msat + (amount_msat * fee_proportional_millionths / 1,000,000)
Example:
Channel Policy:
• fee_base_msat: 1000 (1 sat)
• fee_proportional_millionths: 100 (0.01%)
Forwarding 1,000,000 msat (1000 sats):
fee = 1000 + (1,000,000 * 100 / 1,000,000)
= 1000 + 100
= 1100 msat (1.1 sats)
Forwarding 10,000,000 msat (10,000 sats):
fee = 1000 + (10,000,000 * 100 / 1,000,000)
= 1000 + 1000
= 2000 msat (2 sats)
Common Fee Settings:
1. Zero-fee Channel:
• base: 0, ppm: 0
• Used for connections between own nodes
2. Low-fee Node:
• base: 0-10, ppm: 1-10
• Prioritizes routing volume
3. Standard Node:
• base: 1000, ppm: 100-500
• Balances revenue and routing volume
4. High-fee Node:
• base: 1000+, ppm: 1000+
• Popular routes or scarce liquidity 方向性
Channel Update Directions:
One channel, two directions, two updates:
Node A (pubkey: 02aa...) Node B (pubkey: 03bb...)
| |
| short_channel_id: 700000x1x0
| |
|---- channel_update (dir=0) ----|
| A's policy for A->B |
| fee_base: 1000 |
| fee_ppm: 100 |
| |
|---- channel_update (dir=1) ----|
| B's policy for B->A |
| fee_base: 500 |
| fee_ppm: 50 |
Direction Determination (channel_flags bit 0):
direction = 0:
Publisher is node1 (smaller pubkey)
Defines policy from node1 to node2
direction = 1:
Publisher is node2 (larger pubkey)
Defines policy from node2 to node1
Determining node1/node2:
if pubkey_a < pubkey_b:
node1 = A, node2 = B
else:
node1 = B, node2 = A Gossip 傳播
Channel Update Propagation:
Broadcast Flow:
1. Node updates channel policy
lncli updatechanpolicy --base_fee_msat 1000 ...
2. Node creates and signs channel_update
timestamp = current_time
3. Sends to all connected peers
peer.send(channel_update)
4. Peers validate
• Signature correct?
• Timestamp newer than known?
• Channel exists?
5. After validation, forward to other peers
-> Gradually propagates across network
Rate Limiting:
Preventing gossip flood attacks:
• timestamp must be increasing
• Too frequent updates may be ignored
• Nodes can set minimum update interval
• Recommended interval: at least 1 hour
LND Implementation:
• By default rejects too frequent updates
• gossip.channel-update-interval config
Gossip Queries (Sync):
When new node joins network:
query_channel_range:
Request all channels in specified block range
reply_channel_range:
Reply with channel list
query_short_channel_ids:
Request details for specific channels
reply_short_channel_ids_end:
Reply with channel_announcement and channel_update 禁用通道
Channel Disable Flag: channel_flags bit 1 (disable): disable = 0: Channel normally available disable = 1: Channel temporarily disabled Disable Reasons: • Peer offline • Channel liquidity exhausted • Under maintenance • Manual disable Auto-disable Behavior (LND): When peer disconnects: 1. Wait for period (gossip.inactive-channel-ticker) 2. Send channel_update with disable=1 3. Other nodes stop routing to this channel When peer reconnects: 1. Send channel_update with disable=0 2. Channel available for routing again Config: [gossip] inactive-channel-ticker = 20m (default)
私有通道
私有通道不廣播 channel_update。 只有直接參與者知道通道存在。
Gossip 壓縮
可以使用 gossip_timestamp_filter 只接收特定時間後的更新。
陳舊資訊: Gossip 有傳播延遲。路由時可能使用過時的費用資訊, 導致路由失敗。現代節點使用探測來獲取即時資訊。
相關資源
下一步: 了解 Channel Announcements 如何公告新通道。
已複製連結