Channel Rebalancing 通道再平衡
了解閃電網路通道再平衡技術,如何通過循環支付、Submarine Swaps 等方法優化流動性分佈。
什麼是通道再平衡?
通道再平衡是將閃電網路通道中的流動性從一側移動到另一側的過程。 當通道變得「不平衡」(一側餘額過高或過低)時,會影響支付路由能力。 再平衡可以恢復通道的雙向支付能力,提高整體網路效率。
核心問題: 閃電網路通道是單向的容量池。如果你有 1 BTC 的出站容量但沒有入站容量, 你可以發送但無法接收。再平衡讓你調整這個比例。
流動性問題
Channel Capacity Example: Initial State (just opened, single-funded): You <-----------[1 BTC]-----------> Counterparty Your balance: 1 BTC (100% outbound) Their balance: 0 BTC (0% inbound) Problem: You can send 1 BTC, but cannot receive any payment! After sending 0.5 BTC: You <----[0.5 BTC]--+--[0.5 BTC]----> Counterparty Your balance: 0.5 BTC (50% outbound) Their balance: 0.5 BTC (50% inbound) Balanced! Can send/receive 0.5 BTC in both directions After continuous receiving: You <--[0.9 BTC]--+-----[0.1 BTC]----> Counterparty Your balance: 0.9 BTC (90% outbound) Their balance: 0.1 BTC (10% inbound) Problem: Insufficient inbound capacity for large payments!
再平衡方法
1. 循環支付 (Circular Rebalancing)
Circular Payment Principle:
Route through other channels back to yourself, moving liquidity
Your node has multiple channels:
[Router B]
/ \
/ \
needs out / \ has outbound
/ \
[You] [Router C]
\ /
has in \ / needs inbound
\ /
[Router D]
Circular Payment Path:
You -> B -> C -> D -> You
Effect:
- You->B channel: outbound decreases, inbound increases
- B->C channel: unchanged (just routing)
- C->D channel: unchanged (just routing)
- D->You channel: inbound decreases, outbound increases
Cost: Routing fees from each node on the path 2. Submarine Swaps
Submarine Swap Rebalancing:
Get Inbound Capacity (Loop In):
On-chain BTC -----------> Swap Service
|
LN Payment
v
Swap Service -----------> Your Node
Result:
- You spend on-chain BTC
- Get Lightning inbound capacity
- Pay Swap service fee
Get Outbound Capacity (Loop Out):
Your Node ----LN Payment----> Swap Service
|
On-chain BTC
v
Swap Service -----------> Your on-chain address
Result:
- You spend Lightning balance
- Get on-chain BTC + outbound capacity restored
- Pay Swap service fee + on-chain fee
Services: Lightning Loop (LND), Boltz Exchange, etc. 3. 購買入站容量
Inbound Capacity Market:
Service Types:
1. LSP (Lightning Service Provider)
- Opens channels to you
- They provide funds, you get inbound
- Examples: Voltage, Breez LSP
2. Liquidity Marketplaces
- Magma (Amboss)
- Lightning Pool (LND)
- Node operators bid to provide inbound
3. Channel Leasing
- Pay rent for inbound for specific duration
- Counterparty may close channel after lease ends
Lightning Pool Example:
Auction Market:
Buyer (needs inbound) Seller (provides inbound)
- Bid amount - Ask amount
- Capacity needed - Capacity available
- Lease duration - Minimum lease
After Match:
Seller opens channel to buyer, buyer pays lease fee 再平衡策略
被動再平衡
通過路由費用激勵來自然平衡。提高「過剩方向」的費率,降低「稀缺方向」的費率。 讓市場自然將流動性引導到需要的地方。
主動再平衡
定期檢查通道平衡度,當偏離目標比例時執行循環支付或 Swap。 可以自動化,但需要支付費用。
混合策略
結合被動和主動方式。用費率調整作為主要手段,只在極端不平衡時主動再平衡。
自動化工具
LND Rebalancing Tools:
1. bos (Balance of Satoshis)
bos rebalance --amount 100000 \
--out <depleted_channel_id> \
--in <full_channel_id>
2. rebalance-lnd
rebalance.py -t <target_channel> \
-s <source_channel> \
-a 100000
3. Lightning Terminal (Automation)
- Set target balance ratio
- Maximum fee budget
- Auto-execute rebalancing
CLN Rebalancing:
1. c-lightning-rebalance plugin
lightning-cli rebalance -o <out_scid> \
-i <in_scid> \
-a 100000sat
2. circular plugin
lightning-cli circular <amount> \
<outgoing_channel> <incoming_channel>
Fee Calculation:
Cost = Sum(routing fee per hop) + base fees
Rebalance only when: Expected revenue > Cost 再平衡經濟學
Rebalancing Cost-Benefit Analysis:
Scenario:
- Channel capacity: 1 BTC
- Current state: 90% local / 10% remote
- Target state: 50% / 50%
- Amount to move: 0.4 BTC
Circular Payment Cost:
- Average routing fee: 0.1% (1000 ppm)
- Path length: 3-5 hops
- Cost: 0.4 BTC x 0.1% x 4 hops = 0.0016 BTC
- About 1600 sats per 10k sats moved
Submarine Swap Cost:
- Swap service fee: ~0.5%
- On-chain fee: ~2000 sats
- Cost: 0.4 BTC x 0.5% + 2000 = ~22000 sats
- More expensive but more reliable
When Is It Worth It?
Expected routing revenue
Rebalance value = ------------------------- > Rebalance cost
Balance maintenance time
If balanced channels earn extra 500 sats/day,
then 1600 sats rebalance cost pays back in ~3 days. 常見問題
找不到路徑
循環支付需要足夠的流動性路徑。如果網路流動性不足,可能找不到可行路徑。 嘗試分割成多次小額再平衡。
費用過高
有時候循環路徑費用很高。設定最大費用限制,或等待更好的路徑。 非緊急時可以使用被動再平衡。
最佳實踐
1. 選擇好的對等節點
與活躍的路由節點建立通道,自然的支付流量會幫助維持平衡。
2. 動態調整費率
使用費率作為信號,引導流量自然平衡通道,減少主動再平衡需求。
3. 監控並設定閾值
設定平衡閾值(如 20%-80%),只在超出範圍時觸發再平衡。
4. 計算成本效益
追蹤再平衡成本和由此帶來的額外路由收入,確保長期盈利。
實現狀態
Lightning Loop(Submarine Swaps)、Lightning Pool(流動性市場)、 bos 等第三方工具。Lightning Terminal 提供 UI。
通過 rebalance、circular 等插件支持。 也可使用 Boltz Exchange 等第三方 Swap 服務。
相關資源
下一步: 了解 Lightning Address 如何讓閃電支付像發郵件一樣簡單。