πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
NEWSLIVESearch All Content
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

Payment Channels & Lightning Network

Blockchain Payment Systems🟒 Free Lesson

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:

MetricOn-Chain (Bitcoin)Payment Channel (Lightning)
Throughput~7 TPSMillions of TPS
Confirmation Time10+ minutesMilliseconds
Fee per Transaction50+Fractions of a cent
Micropayment ViabilityNoYes
PrivacyPublic on ledgerOff-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:

Payment Channel Lifecycle1. Open ChannelFunding Tx On-Chain2. Commitment TxExchange Signatures3. Update StateOff-Chain Payments4. Cooperatively CloseFinal State On-Chain5. Force CloseUnilateral ExitAliceNode: alice_nodeBobNode: bob_nodeUnlimited Off-Chain TransactionsHashed Time-Locked Contract (HTLC)H(r) = hash of preimage rRevealed only when claiming paymentTimelock: CLTV DeltaTime-bound expiry for each hopAtomic Multi-hopAll-or-nothing payment routing

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:

Architecture Diagram
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:

Architecture Diagram
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

Multi-Hop HTLC Routing (A → B → C → D)AliceSourceBobHop 1CarolHop 2DaveDestinationHTLCHTLCHTLCPreimage rPreimage rPreimage rHTLC Parameters at Each HopAlice→Bob:Amount: 1.0 BTC, CLTV: 540Bob→Carol:Amount: 0.99 BTC, CLTV: 480Carol→Dave:Amount: 0.98 BTC, CLTV: 420Each hop reduces CLTV by delta (typically 40-60 blocks) and deducts routing fee

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:

  1. DNS Seeders β€” Bootstrap nodes providing initial peer lists
  2. Node Announcements β€” Broadcast signed node information
  3. Channel Announcements β€” Broadcast channel existence and capacity
  4. Route Hints β€” Embedded in invoices for private channels

Routing Algorithms

The Lightning Network uses source-based routing with pathfinding algorithms:

Architecture Diagram
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 CapacityMax PaymentUse CaseAnnual 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_fee is in millisatoshis (msat)
  • fee_rate is in parts per million (ppm)
  • amount is in satoshis

Channel State Machine

Each channel maintains a series of commitment transactions representing valid states:

Channel State TransitionsChannel OpenState: 1.0 / 0.0State 2State: 0.7 / 0.3State 3State: 0.4 / 0.6Channel CloseSettled On-ChainPay 0.3Pay 0.3CloseRevocation MechanismPer-Commitment SecretSHA256(seed, index)Revocation Keyrevocation_pubkey = per_commitment_secret Γ— G

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 FeatureDescription
State MonitoringWatches for old commitment transactions
Penalty TransactionAutomatically broadcasts justice transaction
PrivacyOnly needs encrypted state data
CompensationTypically 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

AdvantageDisadvantage
Near-instant settlementsRequires online presence (both parties)
Minimal feesCapital locked in channels
Unlimited throughputRouting failures possible
Micropayments enabledLiquidity management complexity
Privacy (off-chain)Watchtower dependency for security

Interview Questions

  1. 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.

  2. 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.

  3. 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

  1. 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
  2. How many transactions are needed to open a bidirectional payment channel?

    • a) 1
    • b) 2
    • c) 3
    • d) 4
  3. 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
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-09-22

β€”
β˜†β˜†β˜†β˜†β˜†
0 ratings

Rate & Feedback

Need Expert Blockchain Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement