0%

Launched in early 2018, the Lightning Network (LN) is rapidly growing in users and capacity. This second-layer payment protocol works on top of Bitcoin and other cryptocurrencies to provide near-instantaneous transactions between two parties. With this practical guide, authors Andreas M. Antonopoulos, Olaoluwa Osuntokun, and Rene Pickhardt explain how this advancement will enable the next level of scale for Bitcoin, increasing speed and privacy while reducing fees.

Ideal for developers, systems architects, investors, and entrepreneurs looking to gain a better understanding of LN, this book demonstrates why experts consider LN a critical solution to Bitcoin's scalability problem. You'll learn how LN has the potential to support far more transactions than today's financial networks, ushering in an era of global micro-transactions at sub-second resolution.

In several parts, this book examines:

  • The challenges of scaling blockchain technology and why the Lightning Network was invented
  • LN basics including wallets, nodes, and lightning payments
  • Lightning payment channels and how they work
  • Routing payments by constructing paths of payment channels from sender to recipient, including onion routing, and atomic multi-path payments
  • Lightning developments such as eltoo, Schnorr signatures, HODL invoices, JIT routing, channel splicing, and channel factories
  • Building applications on Lightning (Lapps)

Table of Contents

  1. 1. Introduction
    1. Lightning Network Basic Concepts
    2. Trust in decentralized networks
    3. Fairness without central authority
    4. Trusted protocols without intermediaries
    5. A fairness protocol in action
    6. Security primitives as building blocks
    7. Example of the fairness protocol
    8. Motivation for the Lightning Network
    9. Scaling Blockchains
    10. The Lightning Network’s defining features
    11. Lightning Network Use Cases, Users, and Their Stories
    12. Chapter Summary
  2. 2. Getting Started
    1. Alice’s First Lightning Wallet
    2. Lightning Nodes
    3. Lightning Explorer
    4. Lightning Wallets
    5. Testnet Bitcoin
    6. Balancing complexity and control
    7. Downloading and Installing a Lightning Wallet
    8. Creating a New Wallet
    9. Responsibility with Key Custody
    10. Mnemonic Words
    11. Storing the Mnemonic Safely
    12. Loading Bitcoin Into the Wallet
    13. Acquiring Bitcoin
    14. Receiving Bitcoin
    15. From Bitcoin to Lightning Network
    16. Lightning Network Channels
    17. Opening a Lightning Channel
    18. Buying a Cup of Coffee using LN
    19. Bob’s Cafe
    20. A Lightning Invoice
    21. Conclusion
  3. 3. How the Lightning Network works
    1. What is a payment channel?
    2. Payment channel basics
    3. Routing payments across channels
    4. Payment channels
    5. Multisignature address
    6. Funding transaction
    7. Commitment Transaction
    8. Cheating with prior state
    9. Announcing the channel
    10. Closing the channel
    11. Invoices
    12. Payment hash and preimage
    13. Additional metadata
    14. Delivering the payment
    15. The peer-to-peer gossip protocol
    16. Pathfinding and routing
    17. Source-based pathfinding
    18. Onion routing
    19. Payment forwarding algorithm
    20. Peer-to-peer communication encryption
    21. Thoughts about trust
    22. Comparison with Bitcoin
    23. Addresses vs. invoices, transactions vs. payments
    24. Selecting outputs vs. finding a path
    25. Change outputs on Bitcoin vs. no change on Lightning
    26. Mining fees vs. routing fees
    27. Varying fees depending on traffic vs. announced fees
    28. Public Bitcoin transactions vs. private Lightning payments
    29. Waiting for confirmations vs. instant settlement
    30. Sending arbitrary amounts vs. capacity restrictions
    31. Incentives for large value payment vs. small value payments
    32. Using the Blockchain as a ledger vs. as a court system
    33. Offline vs. online, asynchronous vs. synchronous
    34. Satoshis vs. milli-satoshis
    35. Commonality of Bitcoin and Lightning
    36. Monetary unit
    37. Irreversibility and finality of payments
    38. Trust and counterparty risk
    39. Permissionless operation
    40. Open source and open system
    41. Conclusion
  4. 4. Lightning node software
    1. Lightning development environment
    2. Using the command-line
    3. Downloading the book repository
    4. Docker containers
    5. Installing Docker
    6. Basic Docker commands
    7. Bitcoin Core and regtest
    8. The c-lightning Lightning node project
    9. Building c-lightning as a Docker container
    10. Setting up a Docker network
    11. Running the bitcoind and c-lightning containers
    12. Installing c-lightning from source code
    13. Installing prerequisite libraries and packages
    14. Copying the c-lightning source code
    15. Compiling the c-lightning source code
    16. The Lightning Network Daemon (LND) node project
    17. Building LND as a Docker container
    18. Running the bitcoind and LND containers
    19. Installing LND from source code
    20. Copying the LND source code
    21. Compiling the LND source code
    22. The Eclair Lightning node project
    23. Building Eclair as a Docker container
    24. Running the bitcoind and Eclair containers
    25. Installing Eclair from source code
    26. Copying the Eclair source code
    27. Compiling the Eclair source code
    28. Building a complete network of diverse Lightning nodes
    29. Using docker-compose to orchestrate Docker containers
    30. Docker-compose configuration
    31. Starting the example Lightning network
    32. Opening channels and routing a payment
    33. Conclusion
  5. 5. Operating a Lightning Network Node
    1. Choosing your platform
    2. Why is reliability important for running a Lightning node?
    3. Types of hardware Lightning nodes
    4. Running in the “cloud”
    5. Running a node at home
    6. What hardware is required to run a Lightning node?
    7. Switching server configuration in the cloud
    8. Using an installer or helper
    9. RaspiBlitz
    10. MyNode
    11. Umbrel
    12. BTCPay Server
    13. Bitcoin node or lightweight Lightning
    14. Operating system choice
    15. Choose your Lightning node implementation
    16. Installing a Bitcoin or Lightning node
    17. Background services
    18. Process isolation
    19. Node startup
    20. Node configuration
    21. Network configuration
    22. Security of your node
    23. Operating system security
    24. Node access
    25. Node and channel backups
    26. Static Channel Backups (SCB)
    27. Hot wallet risk
    28. Sweeping funds
    29. Lightning node uptime and availability
    30. Tolerate faults and automate
    31. Monitoring node availability
    32. Watchtowers
    33. Channel management
    34. Opening outbound channels
    35. Getting inbound liquidity
    36. Closing channels
    37. Re-balancing channels
    38. Routing fees
    39. Node management
    40. Ride The Lightning (RTL)
    41. LNDMon
    42. Thunderhub
    43. Conclusion
  6. 6. Lightning Network Architecture
    1. The Lightning Network Protocol Suite
  7. 7. Payment Channels
    1. A different way of using the Bitcoin system
    2. Bitcoin ownership and control
    3. Diversity of (independent) ownership and multisig
    4. Joint ownership without independent control
    5. Preventing “locked” and un-spendable Bitcoin
    6. Constructing a payment channel
    7. Node private and public keys
    8. Node network address
    9. Node identifiers
    10. Connecting nodes as direct peers
    11. Constructing the channel
    12. Peer Protocol for Channel Management
    13. Channel establishment message flow
    14. The funding transaction
    15. Generating a multisignature address
    16. Constructing the funding transaction
    17. Holding signed transactions without broadcasting
    18. Refund before funding
    19. Constructing the pre-signed refund transaction
    20. Chaining transactions without broadcasting
    21. Solving malleability (Segregated Witness)
    22. Broadcasting the funding transaction
    23. Sending payments across the channel
    24. Splitting the balance
    25. Competing commitments
    26. Cheating with old commitment transactions
    27. Revoking old commitment transactions
    28. Asymmetric commitment transactions
    29. Delayed (timelocked) spending to_self
    30. Revocation keys
    31. The commitment transaction
    32. Advancing the channel state
    33. The commitment_signed message
    34. The revoke_and_ack message
    35. Revoking and re-committing
    36. Cheating and penalty in practice
    37. The channel reserve: ensuring skin in the game
    38. Closing the channel (cooperative close)
    39. The shutdown message
    40. The closing_signed message
    41. The cooperative close transaction
    42. Conclusion
  8. 8. Routing on a Network of Payment Channels
    1. Routing a payment
    2. Routing vs. Path Finding
    3. Creating a network of payment channels
    4. A physical example of “routing”
    5. Fairness Protocol
    6. Implementing Atomic Trustless Multihop Payments
    7. Revisiting our example
    8. On-chain vs Off-chain settlement of HTLCs
    9. Hash Time Locked Contracts (HTLCs)
    10. HTLCs in Bitcoin Script
    11. Payment pre-image and hash verification
    12. Extending HTLCs from Alice to Dina
    13. Back-propagating the secret
    14. Signature binding - preventing theft of HTLCs
    15. Hash Optimization
    16. HTLC cooperative and timeout failure
    17. Decrementing time-locks
    18. Conclusion
  9. 9. Channel Operation and Payment Forwarding
    1. Local (single channel) vs Routed (multiple channels)
    2. Forwarding payments and updating commitments with HTLCs
    3. HTLC and commitment message flow
    4. Forwarding payments with HTLCs
    5. Adding an HTLC
    6. The update_add_htlc message
    7. HTLC in commitment transaction
    8. New commitment with HTLC output
    9. Alice commits
    10. Bob acknowledges new commitment and revokes old one
    11. Bob commits
    12. Multiple HTLCs
    13. HTLC fulfillment
    14. HTLC propagation
    15. Dina fulfills the HTLC with Chan
    16. Bob settles the HTLC with Alice
    17. Removing an HTLC due to error or expiry
    18. Making a local payment
    19. Conclusion
  10. A. Bitcoin Fundamentals Review
    1. Keys and digital signatures
    2. Private and public keys
    3. Hashes
    4. Digital signatures
    5. Signature Types
    6. Bitcoin transactions
    7. Inputs and outputs
    8. Transaction chains
    9. TxID: Transaction identifiers
    10. Outpoints: output identifiers
    11. Bitcoin Script
    12. Running Bitcoin Script
    13. Locking and Unlocking Scripts
    14. Locking to a public key (signature)
    15. Locking to a hash (secret)
    16. Multisignature scripts
    17. Timelock scripts
    18. Scripts with multiple conditions
    19. Using Flow Control in Scripts
  11. Glossary
18.221.129.19