Lightning Network — Complete Technical Guide

Payment channels, HTLCs, multi-hop routing, BOLTs, MPP, onion routing, liquidity management

Nexus

20. Mai 2026May 20, 2026 · 6 Min. Lesezeit6 min read

Lightning Network

A layer-2 payment protocol on top of Bitcoin. Near-instant, low-cost micropayments.

Core Concept#

Instead of every payment going on-chain (slow, expensive), counterparties open a payment channel (on-chain), then transact off-chain unlimited times, only settling on-chain when closing.

BITCOIN LAYER 1          │  LIGHTNING LAYER 2
                         │
┌──────────────┐         │   ┌──────┐
│  Funding TX  │─────────│──▶│Channel│  ← 2-of-2 multisig UTXO
│  0.1 BTC     │         │   │  0.1  │
└──────────────┘         │   └──┬─┬─┘
                         │      │ │
                         │   ┌──┘ └──┐
                         │   ▼       ▼
                         │  Alice   Bob
                         │  0.05    0.05
                         │
  (on-chain, visible)    │  (off-chain, private, instant)

Payment Channels#

Opening#

  1. Funding TX: Alice sends BTC to a 2-of-2 multisig address — this is the channel
  2. Commitment TX (unbroadcast): Pre-signed refund held by both parties
  3. Channel now open — Alice and Bob can transact instantly

Updating State#

Each payment creates and exchanges a new commitment transaction:

Closing#

Hash Time-Locked Contracts (HTLCs)#

The core contract that enables multi-hop routing.

Alice ──HTLC──▶ Bob ──HTLC──▶ Carol ──HTLC──▶ Dave
(2 BTC)        (1.5 BTC)      (1 BTC)        (0.5 BTC)

Each hop uses the SAME payment_hash H(R)
Carol generates preimage R, reveals to claim her HTLC
R propagates backward: Dave → Carol → Bob → Alice
All HTLCs settle atomically.

HTLC Parameters#

Parameter Description
payment_hash = H(R) Hash of the secret preimage R
amount Value to transfer
cltv_expiry Block height timeout
payment_preimage = R Revealed by receiver to claim

CLTV Delta#

Each hop reduces the timeout. Typical delta: 40 blocks (~7 hours).

Sender:  cltv_expiry = 700,140
Hop 1:   cltv_expiry = 700,100  (delta = 40)
Hop 2:   cltv_expiry = 700,060  (delta = 40)
Receiver: cltv_expiry = 700,020 (delta = 40)

This ensures each hop has time to claim after the next hop reveals R.

Routing#

Network Graph#

G = (V, E)
V: Lightning nodes (pubkeys)
E: Payment channels (with capacity, fees, reliability)

Fee Model#

Total fee = base_fee + (amount × fee_rate / 1,000,000)

Example: base=1000 msat, rate=100
  1,000 sat:   fee = 1000 + (1,000,000 × 100 / 1M) = 1,100 msat ≈ 1 sat
  100,000 sat: fee = 1000 + (100,000,000 × 100 / 1M) = 11,000 msat = 11 sat

Pathfinding#

  1. Build graph from gossip data
  2. Filter edges with insufficient capacity
  3. Run modified Dijkstra (weight = fees)
  4. Try paths sequentially (trial-and-error for liquidity)

Onion Routing (Sphinx)#

Sender knows:  full path
Hop 1 knows:   [sender, self, hop 2]
Hop 2 knows:   [hop 1, self, hop 3]
Hop 3 knows:   [hop 2, self, receiver]
Receiver knows: [hop 3, self]

Invoices (BOLT #11)#

lnbc10u1p3unwf...  // bech32-encoded invoice

Decoded:
  amount:       100 sats
  description:  "coffee"
  payment_hash: a1b2c3...
  payee:        02a1b2c3...
  expiry:       3600 seconds
  route_hints:  [private channel paths]

Key fields:

BOLT Specifications#

BOLT Title Description
#1 Base Protocol Message framing, encryption
#2 Peer Protocol Channel lifecycle
#3 Transactions On-chain format
#4 Onion Routing Payment packet construction
#5 On-Chain Handling Force close, HTLC resolution
#7 P2P Node Discovery Gossip protocol
#8 Transport Noise_XK encrypted comms
#9 Feature Bits Capability negotiation
#11 Invoice Protocol BOLT 11 invoice format
#12 Offers Reusable payment endpoints

Multi-Path Payments (MPP)#

Large payments split across multiple routes:

1 BTC payment:
  Route A: 0.3 BTC  (Alice → B → C → D → Dave)
  Route B: 0.7 BTC  (Alice → E → F → Dave)

Same payment_hash, different paths.
Dave waits for all shards before revealing preimage.

Enables payments larger than any single channel.

Liquidity#

Concept Definition
Local balance Amount YOU can send
Remote balance Amount YOU can receive
Inbound liquidity Someone else's BTC on your side
Outbound liquidity Your BTC on your side

Management Techniques#

  1. Circular rebalancing: Route payment to yourself through different path
  2. Submarine swap: Swap on-chain BTC for off-chain LN capacity
  3. Loop out → Loop in: Push BTC out then back in
  4. Liquidity ads: Market for channel leases (Lightning Pool)
  5. JIT routing: Just-in-Time channel rebalancing

Network Statistics (2024)#

Metric Value
Public nodes ~15,000–20,000
Public channels ~60,000–80,000
Total capacity ~5,000+ BTC
Avg fee < 1 sat

Future#

PTLCs (Point Time-Locked Contracts)#

eltoo / LN-Symmetry#

Channel Factories#

Taproot & MuSig2#

Key Takeaways#

#bitcoin#documentation#nostr

Written by

Comments

No comments yet. Start the conversation.

Contents

11 sections

  1. Core Concept
  2. Payment Channels
  3. Hash Time-Locked Contracts (HTLCs)
  4. Routing
  5. Invoices (BOLT #11)
  6. BOLT Specifications
  7. Multi-Path Payments (MPP)
  8. Liquidity
  9. Network Statistics (2024)
  10. Future
  11. Key Takeaways