跳至主要內容
高級

Funding Transaction 注資交易

深入了解閃電網路通道的注資交易結構,如何建立 2-of-2 多簽輸出並確保通道安全。

10 分鐘

什麼是注資交易?

注資交易(Funding Transaction)是開設閃電網路通道的鏈上交易。 它創建一個 2-of-2 多簽輸出,將資金鎖定在通道中。 這筆交易確認後,通道就可以開始使用。注資交易的 TXID 和輸出索引組成通道的唯一標識。

通道基礎: 注資交易是通道的「錨點」。所有後續的承諾交易都花費這個輸出, 但在協商關閉或強制關閉之前不會廣播。

交易結構

Funding Transaction Structure

┌──────────────────────────────────────────────────────────┐
│ Funding Transaction                                      │
├──────────────────────────────────────────────────────────┤
│ Inputs:                                                  │
│   - Initiator's UTXO(s)                                  │
│   - [Dual-Fund: Acceptor's UTXO(s)]                      │
│                                                          │
│ Outputs:                                                 │
│   [0] Funding Output (channel funds)                     │
│       P2WSH: 2-of-2 multisig                             │
│       Amount: total channel capacity                     │
│   [1+] Change outputs (if any)                           │
└──────────────────────────────────────────────────────────┘

Funding Output Script (2-of-2 multisig P2WSH):

OP_2
<pubkey_A> (lexicographically smaller pubkey)
<pubkey_B> (lexicographically larger pubkey)
OP_2
OP_CHECKMULTISIG

Pubkeys used:
• funding_pubkey (exchanged in open_channel)
• Lexicographic order ensures determinism

開通道流程

Single-Funded Channel Opening

Alice (initiator)                  Bob (acceptor)
  |                                    |
  |---- open_channel ----------------->|
  |     funding_pubkey: A_fund         |
  |     funding_satoshis: 1000000      |
  |                                    |
  |<--- accept_channel ----------------|
  |     funding_pubkey: B_fund         |
  |                                    |
  | [Alice builds funding tx]          |
  | [Alice builds initial commit tx]   |
  |                                    |
  |---- funding_created -------------->|
  |     funding_txid                   |
  |     funding_output_index           |
  |     signature (for Bob's commit)   |
  |                                    |
  |<--- funding_signed ----------------|
  |     signature (for Alice's commit) |
  |                                    |
  | [Alice broadcasts funding tx]      |
  |                                    |
  | [Waiting for confirmations...]     |
  |                                    |
  |<--- channel_ready -----------------|
  |---- channel_ready ---------------->|
  |                                    |
  | [Channel usable]                   |

Critical Sequence:
1. First exchange commitment tx signatures
2. Ensure both parties can exit
3. Then broadcast funding tx
-> Prevents funds from being locked forever

安全考慮

承諾交易先行

必須先獲得對方的承諾交易簽名,才能廣播注資交易。 否則資金可能被永久鎖定在無法花費的多簽中。

TXID 穩定性

必須使用 SegWit 輸入,確保 TXID 不會被第三方篡改(malleability)。 承諾交易引用的 TXID 必須穩定。

確認要求

標準通道需要等待注資交易確認(通常 3-6 個區塊)。 零確認通道可以跳過等待但需要信任對方。

金額驗證

接受方必須驗證注資交易的輸出金額與協商一致。 錯誤的金額會導致後續計算錯誤。

Dual-Funded 注資

Dual-Funded Transaction (Interactive TX Construction)

Alice                                 Bob
  |                                    |
  |---- open_channel2 ---------------->|
  |<--- accept_channel2 ---------------|
  |                                    |
  | [Interactive tx construction]      |
  |                                    |
  |---- tx_add_input ----------------->| Alice adds input
  |<--- tx_add_input ------------------| Bob adds input
  |---- tx_add_output ---------------->| Add channel output
  |<--- tx_add_output -----------------| Bob change
  |---- tx_add_output ---------------->| Alice change
  |                                    |
  |---- tx_complete ------------------>|
  |<--- tx_complete -------------------|
  |                                    |
  | [Exchange commitment tx sigs]      |
  |<--- commitment_signed ------------>|
  |                                    |
  | [Exchange funding tx sigs]         |
  |<--- tx_signatures ---------------->|
  |                                    |
  | [Broadcast funding tx]             |

Dual-Funding Benefits:
• Both parties can contribute funds
• Bidirectional capacity from start
• Supports liquidity purchases

Taproot 通道

Taproot Channel Funding Output

Traditional P2WSH:
• Script visible: obviously 2-of-2 multisig
• Size: ~71 bytes witness
• Privacy: identifiable as Lightning channel

Taproot (P2TR):
Uses MuSig2 aggregated pubkey

Internal pubkey:
  P = MuSig2(funding_pubkey_A, funding_pubkey_B)

Cooperative close: key path spend
  -> Looks like regular single-sig transaction

Force close: script path spend
  -> Reveals script, but only when necessary

Benefits:
• Full privacy on cooperative close
• Smaller transaction size
• Lower fees

SCID 派生

Deriving Short Channel ID from Funding TX

SCID Structure (8 bytes):
┌────────────────┬────────────────┬────────────────┐
│ Block Height   │ TX Index       │ Output Index   │
│ (24 bits)      │ (24 bits)      │ (16 bits)      │
└────────────────┴────────────────┴────────────────┘

Derivation Example:
1. Funding tx confirmed in block 700000
2. Transaction position in block: 1234th
3. Channel output is output index 0
-> SCID = 700000x1234x0

Uses:
• Uniquely identify channel
• Reference channel during routing
• Used in gossip announcements
• Can be replaced by SCID alias (privacy)

查看注資交易

Viewing Channel Funding Transaction

LND:
# List channels
lncli listchannels | jq '.channels[0].channel_point'
# Output format: <txid>:<output_index>

# View pending channels
lncli pendingchannels

CLN:
# List channels
lightning-cli listpeerchannels | jq '.[0].funding_txid'

# View in block explorer
# Visit mempool.space/tx/<txid>

Identifying Lightning Funding Transactions:
• P2WSH output
• Standard multisig script
• Usually large, round amounts
• Or uses Taproot (newer channels)

隱私提示: 傳統注資交易在鏈上可被識別。使用 Taproot 通道和協商關閉可以 大幅提升隱私,使通道看起來像普通交易。

相關資源

下一步: 了解 通道公告 如何向網路廣播通道資訊。

已複製連結
已複製到剪貼簿