

Mastering the Lightning Network (E-book)



Mastering the Lightning Network (E-book) - Najlepsze oferty
Mastering the Lightning Network (E-book) - Opis
The Lightning Network (LN) is a rapidly growing second-layer payment protocol that works on top of Bitcoin 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.This book examines:How the Lightning Network addresses the challenge of blockchain scalingThe Basis of Lightning Technology (BOLT) standards documentsThe five layers of the Lightning Network Protocol SuiteLN basics, including wallets, nodes, and how to operate oneLightning payment channels, onion routing, and gossip protocolFinding paths across payment channels to transport Bitcoin off-chain from sender to recipient Spis treści:Preface
Intended Audience
Conventions Used in This Book
Code Examples
Using Code Examples
References to Companies and Products
Addresses and Transactions in This Book
OReilly Online Learning
How to Contact Us
Contacting Andreas
Contacting René
Contacting Olaoluwa Osuntokun
Acknowledgments by Andreas
Acknowledgments by René
Acknowledgments by Olaoluwa (...) więcej Osuntokun
Contributions
Sources
I. Understanding the Lightning Network
1. Introduction
Lightning Network Basic Concepts
Trust in Decentralized Networks
Fairness Without Central Authority
Trusted Protocols Without Intermediaries
A Fairness Protocol in Action
Security Primitives as Building Blocks
Example of the Fairness Protocol
Motivation for the Lightning Network
Scaling Blockchains
The Lightning Networks Defining Features
Lightning Network Use Cases, Users, and Their Stories
Conclusion
2. Getting Started
Alices First Lightning Wallet
Lightning Nodes
Lightning Explorers
Lightning Wallets
Testnet Bitcoin
Balancing Complexity and Control
Downloading and Installing a Lightning Wallet
Creating a New Wallet
Responsibility with Key Custody
Mnemonic Words
Storing the Mnemonic Safely
Loading Bitcoin onto the Wallet
Acquiring Bitcoin
Receiving Bitcoin
From Bitcoin to Lightning Network
Lightning Network Channels
Opening a Lightning Channel
Buying a Cup of Coffee Using the Lightning Network
Bobs Cafe
A Lightning Invoice
Conclusion
3. How the Lightning Network Works
What Is a Payment Channel?
Payment Channel Basics
Routing Payments Across Channels
Payment Channels
Multisignature Address
Funding Transaction
Example of a poor channel opening procedure
Commitment Transaction
Cheating with Prior State
Announcing the Channel
Closing the Channel
Mutual close (the good way)
Force close (the bad way)
Protocol breach (the ugly way)
Invoices
Payment Hash and Preimage
Additional Metadata
Delivering the Payment
The Peer-to-Peer Gossip Protocol
Pathfinding and Routing
Source-Based Pathfinding
Onion Routing
Payment Forwarding Algorithm
Peer-to-Peer Communication Encryption
Thoughts About Trust
Comparison with Bitcoin
Addresses Versus Invoices, Transactions Versus Payments
Selecting Outputs Versus Finding a Path
Change Outputs on Bitcoin Versus No Change on Lightning
Mining Fees Versus Routing Fees
Varying Fees Depending on Traffic Versus Announced Fees
Public Bitcoin Transactions Versus Private Lightning Payments
Waiting for Confirmations Versus Instant Settlement
Sending Arbitrary Amounts Versus Capacity Restrictions
Incentives for Large Value Payment Versus Small Value Payments
Using the Blockchain as a Ledger Versus as a Court System
Offline Versus Online, Asynchronous Versus Synchronous
Satoshis Versus Millisatoshis
Commonality of Bitcoin and Lightning
Monetary Unit
Irreversibility and Finality of Payments
Trust and Counterparty Risk
Permissionless Operation
Open Source and Open System
Conclusion
4. Lightning Node Software
Lightning Development Environment
Using the Command Line
Downloading the Book Repository
Docker Containers
Bitcoin Core and Regtest
Building the Bitcoin Core Container
Interacting with the bitcoin core container
The c-lightning Lightning Node Project
Building c-lightning as a Docker Container
Setting Up a Docker Network
Running the bitcoind and c-lightning Containers
Installing c-lightning from Source Code
Installing Prerequisite Libraries and Packages
Copying the c-lightning Source Code
Compiling the c-lightning Source Code
The Lightning Network Daemon Node Project
The LND Docker Container
Running the bitcoind and LND Containers
Installing LND from Source Code
Copying the LND Source Code
Compiling the LND Source Code
The Eclair Lightning Node Project
The Eclair Docker Container
Running the bitcoind and Eclair Containers
Installing Eclair from Source Code
Copying the Eclair Source Code
Compiling the Eclair Source Code
Building a Complete Network of Diverse Lightning Nodes
Using docker-compose to Orchestrate Docker Containers
docker-compose Configuration
Starting the Example Lightning Network
Opening Channels and Routing a Payment
Conclusion
5. Operating a Lightning Network Node
Choosing Your Platform
Why Is Reliability Important for Running a Lightning Node?
Types of Hardware Lightning Nodes
Running in the Cloud
Running a Node at Home
What Hardware Is Required to Run a Lightning Node?
Switching Server Configuration in the Cloud
Permanent data storage (drive)
Using an Installer or Helper
RaspiBlitz
Mynode
Umbrel
BTCPay Server
Bitcoin Node or Lightweight Lightning
Operating System Choice
Choose Your Lightning Node Implementation
Installing a Bitcoin or Lightning Node
Background Services
Process Isolation
Node Startup
Node Configuration
Network Configuration
It just works!
Automatic port forwarding using UPnP
Using Tor for incoming connections
Manual port forwarding
Security of Your Node
Operating System Security
Node Access
Node and Channel Backups
Hot Wallet Risk
Sweeping Funds
On-chain sweep
Off-chain sweep
Submarine swap sweep
Submarine swaps with Loop
Lightning Node Uptime and Availability
Tolerate Faults and Automate
Monitoring Node Availability
Watchtowers
Channel Management
Opening Outbound Channels
Autopilot
Getting Inbound Liquidity
Closing Channels
Rebalancing Channels
Routing Fees
Node Management
Ride The Lightning
lndmon
ThunderHub
Conclusion
II. The Lightning Network in Detail
6. Lightning Network Architecture
The Lightning Network Protocol Suite
Lightning in Detail
7. Payment Channels
A Different Way of Using the Bitcoin System
Bitcoin Ownership and Control
Diversity of (Independent) Ownership and Multisig
Joint Ownership Without Independent Control
Preventing Locked and Un-Spendable Bitcoin
Constructing a Payment Channel
Node Private and Public Keys
Node Network Address
Node Identifiers
Connecting Nodes as Direct Peers
Constructing the Channel
Peer Protocol for Channel Management
Channel Establishment Message Flow
The open_channel message
The accept_channel message
The Funding Transaction
Generating a Multisignature Address
Constructing the Funding Transaction
Holding Signed Transactions Without Broadcasting
Refund Before Funding
Constructing the Presigned Refund Transaction
Chaining Transactions Without Broadcasting
Solving Malleability (Segregated Witness)
The funding_created message
The funding_signed message
Broadcasting the Funding Transaction
The funding_locked message
Sending Payments Across the Channel
Splitting the Balance
Competing Commitments
Cheating with Old Commitment Transactions
Revoking Old Commitment Transactions
Asymmetric Commitment Transactions
Delayed (Timelocked) Spending to_self
Revocation Keys
The Commitment Transaction
Advancing the Channel State
The commitment_signed Message
The revoke_and_ack Message
Revoking and Recommitting
Cheating and Penalty in Practice
The Channel Reserve: Ensuring Skin in the Game
Closing the Channel (Cooperative Close)
The Shutdown Message
The closing_signed Message
The Cooperative Close Transaction
Conclusion
8. Routing on a Network of Payment Channels
Routing a Payment
Routing Versus Pathfinding
Creating a Network of Payment Channels
A Physical Example of Routing
Fairness Protocol
Implementing Atomic Trustless Multihop Payments
Revisiting the Tipping Example
On-Chain Versus Off-Chain Settlement of HTLCs
Hash Time-Locked Contracts
HTLCs in Bitcoin Script
Payment Preimage and Hash Verification
Extending HTLCs from Alice to Dina
Back-Propagating the Secret
Signature Binding: Preventing Theft of HTLCs
Hash Optimization
HTLC Cooperative and Timeout Failure
Decrementing Timelocks
Conclusion
9. Channel Operation and Payment Forwarding
Local (Single Channel) Versus Routed (Multiple Channels)
Forwarding Payments and Updating Commitments with HTLCs
HTLC and Commitment Message Flow
Forwarding Payments with HTLCs
Adding an HTLC
The update_add_HTLC Message
HTLC in Commitment Transactions
New Commitment with HTLC Output
Alice Commits
Bob Acknowledges New Commitment and Revokes Old One
Bob Commits
Multiple HTLCs
HTLC Fulfillment
HTLC Propagation
Dina Fulfills the HTLC with Chan
Bob Settles the HTLC with Alice
Removing an HTLC Due to Error or Expiry
Making a Local Payment
Conclusion
10. Onion Routing
A Physical Example Illustrating Onion Routing
Selecting a Path
Building the Layers
Peeling the Layers
Introduction to Onion Routing of HTLCs
Alice Selects the Path
Alice Constructs the Payloads
Final node payload for Dina
Hop payload for Chan
Hop payload for Bob
Finished hop payloads
Key Generation
Alices session key
Key generation details
Shared secret generation
Wrapping the Onion Layers
Fixed-Length Onions
Wrapping the Onion (Outlined)
Wrapping Dinas Hop Payload
Onion routing replay protection and detection
Wrapping Chans Hop Payload
Wrapping Bobs Hop Payload
The Final Onion Packet
Sending the Onion
The update_add_htlc Message
Alice Sends the Onion to Bob
Bob Checks the Onion
Bob Generates Filler
Bob De-Obfuscates His Hop Payload
Bob Extracts the Outer HMAC for the Next Hop
Bob Removes His Payload and Left-Shifts the Onion
Bob Constructs the New Onion Packet
Bob Verifies the HTLC Details
Bob Sends the update_add_htlc to Chan
Chan Forwards the Onion
Dina Receives the Final Payload
Returning Errors
Failure Messages
Stuck payments
Keysend Spontaneous Payments
Custom Onion TLV Records
Sending and Receiving Keysend Payments
Keysend and Custom Records in Lightning Applications
Conclusion
11. Gossip and the Channel Graph
Peer Discovery
P2P Bootstrapping
DNS Bootstrapping
A new peers bootstrapping workflow
SRV Query Options
The Channel Graph
A Directed Graph
Gossip Protocol Messages
The node_announcement Message
The node_announcement message structure
Validating node announcements
The channel_announcement Message
Unannounced (private) channels
Locating a channel on the bitcoin blockchain
The short channel ID
The channel_announcement message structure
Channel announcement validation
The channel_update Message
Ongoing Channel Graph Maintenance
Conclusion
12. Pathfinding and Payment Delivery
Pathfinding in the Lightning Protocol Suite
Where Is the BOLT?
Pathfinding: What Problem Are We Solving?
Selecting the Best Path
Pathfinding in Math and Computer Science
Capacity, Balance, Liquidity
Uncertainty of Balances
Pathfinding Complexity
Keeping It Simple
Pathfinding and Payment Delivery Process
Channel Graph Construction
Uncertainty in the channel graph
Liquidity Uncertainty and Probability
Fees and Other Channel Metrics
Finding Candidate Paths
Payment Delivery (Trial-and-Error Loop)
First Attempt (Path #1)
Learning from failure
Second Attempt (Path #4)
Learning from success
Stale knowledge?
Multipart Payments
Using MPP
Splitting payments
Trial and Error over Multiple Rounds
Conclusion
13. Wire Protocol: Framing and Extensibility
Messaging Layer in the Lightning Protocol Suite
Wire Framing
High-Level Wire Framing
Type Encoding
Type-Length-Value Message Extensions
The Protocol Buffers Message Format
Forward and Backward Compatibility
Type-Length-Value Format
BigSize Integer Encoding
TLV Encoding Constraints
TLV Canonical Encoding
Feature Bits and Protocol Extensibility
Feature Bits as an Upgrade Discoverability Mechanism
TLV for Forward and Backward Compatibility
A Taxonomy of Upgrade Mechanisms
Internal network upgrades
End-to-end upgrades
Channel Construction-Level Updates
Conclusion
14. Lightnings Encrypted Message Transport
Encrypted Transport in the Lightning Protocol Suite
Introduction
The Channel Graph as Decentralized Public Key Infrastructure
Why Not TLS?
The Noise Protocol Framework
Lightning Encrypted Transport in Detail
Noise_XK: Lightning Networks Noise Handshake
Handshake Notation and Protocol Flow
High-Level Overview
Handshake in Three Acts
Handshake session state initialization
Handshake acts
Act One
Act Two
Act Three
Transport message encryption
Encrypting and sending messages
Receiving and decrypting messages
Lightning message key rotation
Conclusion
15. Lightning Payment Requests
Invoices in the Lightning Protocol Suite
Introduction
Lightning Payment Requests Versus Bitcoin Addresses
BOLT #11: Lightning Payment Request Serialization and Interpretation
Payment Request Encoding in Practice
The Human-Readable Prefix
bech32 and the Data Segment
Tagged invoice fields
Conclusion
16. Security and Privacy of the Lightning Network
Why Is Privacy Important?
Definitions of Privacy
Process to Evaluate Privacy
Anonymity Set
Differences Between the Lightning Network and Bitcoin in Terms of Privacy
Attacks on Lightning
Observing Payment Amounts
Linking Senders and Receivers
Revealing Channel Balances (Probing)
Denial of Service
DoS in bitcoin
DoS in Lightning
Known DoS attacks
Commitment Jamming
Channel Liquidity Lockup
Cross-Layer De-Anonymization
On-Chain Bitcoin Entity Clustering
Countermeasures
Off-Chain Lightning Node Clustering
Countermeasures
Cross-Layer Linking: Lightning Nodes and Bitcoin Entities
Lightning Graph
How Does the Lightning Graph Look in Reality?
Lightning graph today
Topology-based attacks
Temporality of the Lightning Network
Centralization in the Lightning Network
Economic Incentives and Graph Structure
Practical Advice for Users to Protect Their Privacy
Unannounced Channels
Routing Considerations
Accepting Channels
Conclusion
References and Further Reading
Privacy and probing attacks
Congestion attacks
Routing considerations
17. Conclusion
Decentralized and Asynchronous Innovation
Bitcoin Protocol and Bitcoin Script Innovation
Lightning Protocol Innovation
TLV Extensibility
Payment Channel Construction
Opt-In End-to-End Features
Lightning Applications (LApps)
Ready, Set, Go!
A. Bitcoin Fundamentals Review
Keys and Digital Signatures
Private and Public Keys
Hashes
Digital Signatures
Signature Types
Bitcoin Transactions
Inputs and Outputs
Transaction Chains
TxID: Transaction Identifiers
Outpoints: Output Identifiers
Bitcoin Script
Running Bitcoin Script
Locking and Unlocking Scripts
Locking to a Public Key (Signature)
Locking to a Hash (Secret)
Multisignature Scripts
Timelock Scripts
Scripts with Multiple Conditions
Using Flow Control in Scripts
B. Docker Basic Installation and Use
Installing Docker
Basic Docker Commands
Building a Container
Running a Container
Executing a Command in a Container
Stopping and Starting a Container
Deleting a Container by Name
Listing Running Containers
Listing Docker Images
Conclusion
C. Wire Protocol Messages
Message Types
Message Structure
Connection Establishment Messages
The init message
Error Communication Messages
The error message
Connection Liveness
The ping message
The pong message
Channel Funding
The open_channel message
The accept_channel message
The funding_created message
The funding_signed message
The funding_locked message
Channel Closing
The shutdown message
The closing_signed message
Channel Operation
The update_add_htlc message
The update_fulfill_hltc message
The update_fail_htlc message
The commitment_signed message
The revoke_and_ack message
The update_fee message
The update_fail_malformed_htlc message
Channel Announcement
The channel_announcement message
The node_announcement message
The channel_update message
The announce_signatures message
Channel Graph Syncing
The query_short_chan_ids message
The reply_short_chan_ids_end message
The query_channel_range message
The reply_channel_range message
The gossip_timestamp_range message
D. Sources and License Notices
Sources
BTCPay Server
Lamassu Industries AG
Glossary
Index mniej
Mastering the Lightning Network (E-book) - Opinie i recenzje
Na liście znajdują się opinie, które zostały zweryfikowane (potwierdzone zakupem) i oznaczone są one zielonym znakiem Zaufanych Opinii. Opinie niezweryfikowane nie posiadają wskazanego oznaczenia.