π€ The Scaling Problem
Bitcoin's base layer processes ~7 transactions per second. To become global money, we need millions of transactions per second. But increasing the block size would centralize the network by making it expensive to run a full node.
Key Insight: What if most transactions didn't need to be on the blockchain? What if two parties could transact thousands of times with only two on-chain transactions: one to open a channel, one to close it?
That's exactly what Lightning payment channels enable.
What is a Payment Channel?
A payment channel is a bidirectional payment relationship between two parties (Alice and Bob) that allows them to send bitcoin back and forth instantly, with near-zero fees, without broadcasting transactions to the blockchain.
The Core Concept
Think of it like a bar tab:
- You open a tab (put money down) β Opening transaction (on-chain)
- You order drinks throughout the night β Off-chain payments
- At the end, you settle the final balance β Closing transaction (on-chain)
But unlike a bar tab where you trust the bartender, Lightning channels are trustlessβ either party can close the channel at any time and get their correct balance, enforced by Bitcoin's consensus rules.
Channel Lifecycle
1. Channel Opening
Alice wants to open a channel with Bob. She creates a funding transaction that locks Bitcoin in a 2-of-2 multisig address controlled by both Alice and Bob.
βββββββββββββββββββββββββββββββββββββββ
β Funding Transaction (on-chain) β
βββββββββββββββββββββββββββββββββββββββ€
β β
β Alice locks: 0.5 BTC β
β Bob locks: 0.3 BTC β
β βββββββββββββββββββββ β
β Total: 0.8 BTC β
β β
β β 2-of-2 Multisig Address β
β (requires both signatures) β
βββββββββββββββββββββββββββββββββββββββ
Important: Before broadcasting the funding transaction, Alice and Bob create the first commitment transaction that allows them to get their money back. This prevents one party from stealing funds.
2. Channel Updates (Off-Chain Payments)
Once the channel is open, Alice and Bob can update the balance distribution as many times as they want without touching the blockchain. Each update creates a new commitment transaction that spends from the funding transaction.
State 0 (Opening):
Alice: 0.5 BTC | Bob: 0.3 BTC
Alice pays Bob 0.1 BTC β State 1:
Alice: 0.4 BTC | Bob: 0.4 BTC
Bob pays Alice 0.2 BTC β State 2:
Alice: 0.6 BTC | Bob: 0.2 BTC
Alice pays Bob 0.05 BTC β State 3:
Alice: 0.55 BTC | Bob: 0.25 BTC
Each state is represented by a pair of commitment transactions (one for Alice, one for Bob). Only the latest state should be broadcastableβold states must be revoked.
3. Channel Closing
Either party can close the channel at any time:
- Cooperative Close: Both parties agree on the final balance and sign a closing transaction. Fast and cheap.
- Unilateral Close: One party broadcasts their latest commitment transaction. Requires a time delay for security.
- Breach Close: If someone tries to broadcast an old state, the other party can claim all funds as a penalty.
Commitment Transactions: The Security Mechanism
The brilliant part of Lightning is the revocation mechanism that makes old channel states unbroadcastable (or extremely costly to broadcast).
How Commitment Transactions Work
Each time Alice and Bob update the channel balance, they create two commitment transactions:
- Alice's commitment tx: Spends the funding output, gives Bob his balance immediately, but delays Alice's balance
- Bob's commitment tx: Spends the funding output, gives Alice her balance immediately, but delays Bob's balance
Why the delay? The delay (typically 144 blocks / ~1 day) gives the other party time to detect if you're broadcasting an old state and punish you.
Revocation Keys
When moving to a new state, both parties exchange revocation keys for the previous state. This key allows the other party to spend your delayed output if you cheat by broadcasting an old commitment transaction.
Alice broadcasts old State 1 (cheating):
ββββββββββββββββββββββββββββββββββ
β State 1: Alice 0.4, Bob 0.4 β
ββββββββββββββββββββββββββββββββββ
β
Bob detects this (watchtower or running node)
β
Bob uses revocation key to claim ALL 0.8 BTC
β
π Bob gets 0.8 BTC, Alice gets 0 (penalty)
This penalty mechanism is what makes Lightning trustlessβtrying to cheat results in losing all your funds.
Lightning Lab: Build a Payment Channel
Experience opening a channel, making payments, and understanding commitment transactions interactively.
π© Alice
π¨ Bob
π© Alice
π¨ Bob
Current Commitment Transaction #0
Balance History
πΌ Watchtower Concept
A watchtower is a service that monitors the blockchain for old commitment transactions while you're offline. If it detects cheating, it broadcasts the penalty transaction on your behalf, ensuring your funds are protected even when you're not watching.
Technical Deep Dive
Commitment Transaction Structure
A commitment transaction has two outputs:
Commitment Transaction (Alice's version):
ββ Output 0: Bob's balance
β ββ scriptPubKey: Bob can spend immediately
β
ββ Output 1: Alice's balance
ββ scriptPubKey: Two spending paths:
ββ Path 1: Alice can spend after timelock (144 blocks)
ββ Path 2: Bob can spend immediately using revocation key
RSMC (Revocable Sequence Maturity Contract)
The script that enables revocable commitments uses OP_CHECKSEQUENCEVERIFY:
OP_IF
# Revocation path
<revocation_pubkey>
OP_ELSE
# Delayed path
<to_self_delay>
OP_CHECKSEQUENCEVERIFY
OP_DROP
<local_delayed_pubkey>
OP_ENDIF
OP_CHECKSIG
This allows either the revocation key to spend immediately (if cheating is detected) or the owner to spend after a delay.
Think About It
Question: Why does each party need their own commitment transaction? Why can't they share one?
Answer: Because each party needs to be penalized for broadcasting old states. In Alice's commitment tx, her output is delayed (so Bob can penalize her). In Bob's commitment tx, his output is delayed (so Alice can penalize him). If they shared one commitment tx, only one party could be penalized!
Key Takeaways
- Payment channels enable instant, low-fee Bitcoin payments off-chain
- Channels require only 2 on-chain transactions: open and close
- Each channel state has two commitment transactions (one for each party)
- Commitment transactions use time delays and revocation keys to prevent cheating
- Broadcasting an old state results in losing all your funds (penalty transaction)
- Channels are trustlessβno need to trust your counterparty
- Watchtowers can monitor for fraud attempts while you're offline