Introduction to Payment Channels
Payment channels represent one of the most significant scaling solutions for blockchain networks. They allow two parties to conduct an unlimited number of transactions off-chain while only settling the final state on-chain, dramatically increasing throughput and reducing fees.
Why Payment Channels Matter
On-chain transactions face fundamental limitations:
| Metric | On-Chain (Bitcoin) | Payment Channel (Lightning) |
|---|---|---|
| Throughput | ~7 TPS | Millions of TPS |
| Confirmation Time | 10+ minutes | Milliseconds |
| Fee per Transaction | 50+ | Fractions of a cent |
| Micropayment Viability | No | Yes |
| Privacy | Public on ledger | Off-chain, private |
Core Concepts
A payment channel is a bilateral relationship between two parties who agree on a balance allocation that can be updated off-chain. The channel is opened with an on-chain funding transaction and closed with a settlement transaction.
Channel Lifecycle
The lifecycle of a payment channel follows a well-defined sequence of states:
Step 1: Channel Opening
When Alice wants to open a channel with Bob, she creates a funding transaction that locks a specific amount of bitcoin into a 2-of-2 multisig address:
Funding Transaction:
Input: Alice's UTXO (1.0 BTC)
Output: 2-of-2(Alice, Bob) = 1.0 BTC
Both parties exchange commitment transactions that represent their current balance. These are pre-signed but not broadcast until channel closure.
Step 2: Off-Chain Transactions
Once the channel is open, Alice and Bob can exchange payments instantly:
Initial State: Alice: 0.5 BTC | Bob: 0.5 BTC
Alice pays Bob 0.1 BTC:
New State: Alice: 0.4 BTC | Bob: 0.6 BTC
Bob pays Alice 0.05 BTC:
New State: Alice: 0.45 BTC | Bob: 0.55 BTC
Each state update is represented by a pair of commitment transactions signed by both parties. Only the latest state is valid, enforced by revocation keys.
Step 3: Channel Closure
Cooperative Close: Both parties agree on the final state and broadcast the closing transaction.
Force Close (Unilateral): If one party becomes unresponsive, the other can broadcast the latest commitment transaction after a timelock expires.
HTLC Mechanism
The Hashed Time-Locked Contract is the cryptographic primitive that enables multi-hop routing. An HTLC has two conditions for spending:
Where:
- is the SHA-256 hash of preimage
- is the HTLC expiry (CLTV timelock)
- is the revocation timelock
HTLC Flow Diagram
Lightning Network Architecture
The Lightning Network builds on payment channels to create a routed network of channels:
Node Discovery and Graph
Lightning nodes discover peers through:
- DNS Seeders β Bootstrap nodes providing initial peer lists
- Node Announcements β Broadcast signed node information
- Channel Announcements β Broadcast channel existence and capacity
- Route Hints β Embedded in invoices for private channels
Routing Algorithms
The Lightning Network uses source-based routing with pathfinding algorithms:
Path Finding Algorithm:
1. Build graph from channel announcements
2. Dijkstra's algorithm with fee-weighted edges
3. Consider: base_fee, fee_rate, CLTV_delta, capacity
4. Select path with lowest total cost
5. Generate HTLC chain along path
The cost function for routing is:
Channel Capacity and Liquidity
Channel capacity determines the maximum payment that can be routed through a channel:
| Channel Capacity | Max Payment | Use Case | Annual Fees (est.) |
|---|---|---|---|
| 0.01 BTC (~0.50β$2 | |||
| 0.1 BTC (~5β$20 | |||
| 1.0 BTC (~50β$200 | |||
| 10.0 BTC (~500β$2,000 |
Fee Structure
Lightning routing fees consist of two components:
Where:
base_feeis in millisatoshis (msat)fee_rateis in parts per million (ppm)amountis in satoshis
Channel State Machine
Each channel maintains a series of commitment transactions representing valid states:
Security Considerations
Revocation and Punishment
When a new state is agreed upon, the old state's revocation key is revealed. If a party broadcasts an old (revoked) state, the other party can claim all funds using the revocation key:
Watchtowers
Watchtowers are third-party services that monitor the blockchain for fraudulent channel closures:
| Watchtower Feature | Description |
|---|---|
| State Monitoring | Watches for old commitment transactions |
| Penalty Transaction | Automatically broadcasts justice transaction |
| Privacy | Only needs encrypted state data |
| Compensation | Typically takes a percentage of penalty |
Real-World Examples
Strike (Global Payments)
Strike uses the Lightning Network to enable instant USD payments globally. Users can send dollars that are converted to BTC on Lightning, routed, and converted back to USD at the destination β all in seconds.
Wallet of Satoshi
A custodial Lightning wallet with over 100,000 users, demonstrating consumer adoption of Lightning for everyday payments from coffee to online purchases.
Bitfinex Integration
Bitfinex integrated Lightning Network for deposits and withdrawals, allowing traders to move funds on/off the exchange instantly with near-zero fees.
Trade-Offs
| Advantage | Disadvantage |
|---|---|
| Near-instant settlements | Requires online presence (both parties) |
| Minimal fees | Capital locked in channels |
| Unlimited throughput | Routing failures possible |
| Micropayments enabled | Liquidity management complexity |
| Privacy (off-chain) | Watchtower dependency for security |
Interview Questions
-
How does the Lightning Network prevent a party from broadcasting an old commitment transaction to steal funds?
The revocation mechanism uses per-commitment secrets derived from a seed. When a new state is created, the old state's revocation key is revealed. If an old state is broadcast, the other party can use the revocation key to claim all funds via a punishment transaction. This creates a strong economic incentive against cheating.
-
Explain how HTLCs enable multi-hop atomic payments across the Lightning Network.
HTLCs use a hash lock (H(r)) and time lock (CLTV). The sender creates an HTLC with the recipient's hash. Intermediate nodes forward HTLCs with decreasing timelocks. When the recipient reveals the preimage r, each hop claims the payment in reverse order. If any hop fails, the timelock ensures the sender can reclaim funds. This guarantees atomicity β either all hops succeed or none do.
-
What are the trade-offs between using a Lightning Network channel versus an on-chain transaction for a $10 payment?
Lightning offers near-instant confirmation (<1 second) versus 10+ minutes on-chain, fees of fractions of a cent versus 50, and better privacy since transactions are off-chain. However, it requires both parties to be online, the recipient must have a channel with sufficient incoming capacity, and there's a small risk of routing failure. For frequent payments, Lightning is vastly superior; for one-time large payments, on-chain may be preferred.
Quiz Questions
-
What is the primary purpose of the CLTV (CheckLockTimeVerify) timelock in an HTLC?
- a) To set the maximum channel capacity
- b) To ensure the HTLC expires if not claimed within a specified time
- c) To calculate routing fees
- d) To encrypt off-chain transactions
-
How many transactions are needed to open a bidirectional payment channel?
- a) 1
- b) 2
- c) 3
- d) 4
-
In the Lightning Network, what happens if a node broadcasts a revoked commitment transaction?
- a) The transaction is rejected by the network
- b) The other party can claim all funds using the revocation key
- c) The channel automatically closes cooperatively
- d) The transaction is confirmed after a 2-week delay