Table of Contents
Andreas M. Antonopoulos
Mastering the Lightning Network
Image
Mastering the Lightning Network
A Second Layer Blockchain Protocol for Instant Bitcoin Payments
by Andreas M. Antonopoulos, Olaoluwa Osuntokun, and Ren Pickhardt
Copyright 2022 aantonop Books LLC, Ren Pickhardt, and uuddlrlrbasLLC. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc., 1005 GravensteinHighway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or salespromotional use. Online editions are also available for most titles(http://oreilly.com). For more information, contact ourcorporate/institutional sales department: 800-998-9938 orcorporate@oreilly.com.
- Acquisitions Editor: Michelle Smith
- Development Editor: Michele Cronin
- Production Editor: Kristen Brown
- Copyeditor: Tom Sullivan
- Proofreader: Sonia Saruba
- Indexer: WordCo Indexing Services, Inc.
- Interior Designer: David Futato
- Cover Designer: Karen Montgomery
- Illustrator: Kate Dullea
- December 2021: First Edition
Revision History for the First Edition
- 2021-11-22: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781492054863 for releasedetails.
The OReilly logo is a registered trademark of OReilly Media, Inc.Mastering the Lightning Network, the cover image, and related tradedress are trademarks of OReilly Media, Inc.
The views expressed in this work are those of the authors, and do notrepresent the publishers views. While the publisher and the authorshave used good faith efforts to ensure that the information andinstructions contained in this work are accurate, the publisher and theauthors disclaim all responsibility for errors or omissions, includingwithout limitation responsibility for damages resulting from the use ofor reliance on this work. Use of the information and instructionscontained in this work is at your own risk. If any code samples or othertechnology this work contains or describes is subject to open sourcelicenses or the intellectual property rights of others, it is yourresponsibility to ensure that your use thereof complies with suchlicenses and/or rights. This book is not intended as legal or financialadvice; use the appropriate advice. Please consult a qualifiedprofessional if you require legal/financial advice.
Mastering the Lightning Network is offered under the Creative CommonsAttribution-Noncommercial-No Derivative Works 4.0 International License(CC BY-NC-ND 4.0).
ISBN-13: 978-1492054863
ISBN-10: 1492054860
About the Authors
Andreas M. Antonopoulos is a best-selling author, speaker, educator,and highly sought after expert in Bitcoin and open blockchaintechnologies. He is known for making complex subjects easy to understandand highlighting both the positive and negative impacts thesetechnologies can have on our global societies.
Andreas has written two more best-selling technical books forprogrammers with OReilly Media, Mastering Bitcoin and MasteringEthereum. He has also published The Internet of Money series ofbooks, which focus on the social, political, and economic importance andimplications of these technologies. Andreas produces free educationalcontent on his YouTube channel weekly and teaches virtual workshops onhis website. Learn more at aantonop.com.
Olaoluwa Osuntokun is the cofounder and CTO of Lightning Labs, andalso the lead developer of lnd, one of the main implementations ofLightning. He received his BS and MS in Computer Science from UCSB andwas a member of the Forbes 30 Under 30 class of 2019. During hisgraduate studies he focused on the field of applied cryptography,specifically encrypted search. He has been an active Bitcoin developerfor over five years, and is an author of several Bitcoin ImprovementProposals (BIP-157 and 158). These days, his primary focus lies inbuilding, designing, and evolving private, scalable off-chain blockchainprotocols, such as Lightning.
Ren Pickhardt is a trained mathematician and data science consultantwho uses his statistical knowledge to do research with NTNU aboutpathfinding, privacy, reliability of payments, and service-levelagreements of the Lightning Network. Ren maintains a technical anddeveloper-oriented YouTubechannel about the Lightning Network and has answered roughly half ofthe questions about the Lightning Network on the Bitcoin Stack Exchange,making him the go-to point for almost all new developers who want tojoin the space. Ren has held numerous workshops about the LightningNetwork in public and private, including teaching students of the 2019Chaincode Labs residency together with other core Lightning developers.
Preface
The Lightning Network (LN) is a second layer peer-to-peer network that allows us to make Bitcoin payments "off-chain," meaning without committing them as transactions to the Bitcoin blockchain.
The Lightning Network gives us Bitcoin payments that are secure, cheap, fast, and much more private, even for very small payments.
Building on the idea of payment channels, first proposed by Bitcoins inventor Satoshi Nakamoto, the Lightning Network is a routed network of payment channels where payments "hop" across a path of payment channels from the sender to the recipient.
The initial idea of the Lightning Network was proposed in 2015 in the groundbreaking paper "The Bitcoin Lightning Network: Scalable Off-Chain Instant Payments," by Joseph Poon and Thaddeus Dryja. By 2017, there was a "test" Lightning Network running on the internet, as different groups built compatible implementations and coordinated to set some interoperability standards. In 2018, the Lightning Network went "live" and payments started flowing.
In 2019, Andreas M. Antonopoulos, Olaoluwa Osuntokun, and Ren Pickhardt agreed to collaborate to write this book. It appears we have been successful!
How to Use This Book
Intended Audience
This book is mostly intended for technical readers with an understanding of the fundamentals of Bitcoin and other open blockchains.
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold
Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values determined by context.
This element signifies a tip or suggestion.
This element signifies a general note.
This element indicates a warning or caution.
Code Examples
The examples are illustrated in Go, C++, Python, and using the command line of a Unix-like operating system. All code snippets are available in the GitHub repository under the code subdirectory. Fork the book code, try the code examples, or submit corrections via GitHub.