diff --git a/ch01.asciidoc b/ch01.asciidoc index 38d44c2..34c1145 100644 --- a/ch01.asciidoc +++ b/ch01.asciidoc @@ -2,6 +2,10 @@ [[ch01_intro_what_is_the_lightning_network]] == Introduction +In this chapter we introduce the Lightning Network (LN), and introduce some of the key concepts without going into too much detail. We also present a number of users and their stories, who we will follow throughout the book to help us explore the Lightning Network in practical terms. Finally, we introduce our first user 'Alice' as she selects an LN wallet and prepares to make her first LN transaction, to buy a cup of coffee from Bob's Cafe. + +The first and second chapters of this book should be approachable by any reader, regardless of technical experience. Some basic knowledge about Bitcoin is assumed but can be readily acquired by reading the first two chapters of _Mastering Bitcoin_ which are available for free, online. + === What is the Lightning Network? The Lightning Network (LN) is a "second layer" protocol on top of Bitcoin and other blockchains that enables fast, secure, private, trustless, and permissionless payments. @@ -14,12 +18,42 @@ The LN uses onion routing, similar to the protocol used by The Onion Router (TOR === Motivation for the Lightning Network +The Lightning Network was first proposed in February 2015 by Joseph Poon and Thaddeus Dryja as a possible solution to the Bitcoin Scalability Problem. +As Bitcoin grows, and the demand for transactions grows, block sizes will increase until eventually hitting the block size limit, leaving excess transactions to wait in a queue. +Simply increasing block sizes has the undesirable effect of centralizing the network. +Blockchains are gossip protocols, and each node is required to know and validate every single transaction that occurs on the network. +As such, the greater the block sizes, the greater the processing and storage requirements for each individual node. +The greater the requirements, the fewer the nodes that will ultimately be run. -// TODO +In the Lightning Network whitepaper, Poon and Dryja estimate that in order for Bitcoin to reach the 47,000 transactions per second processed at peak by Visa, it would require 8GB blocks. +This would make running a node completely untenable for anyone but large scale enterprises and industrial grade operations. +The result would be a network in which only a few users can actually validate the state of the ledger, which ultimately breaks the trust model of Bitcoin. + +The Lightning Network proposes a new network, a "second layer", where users can transact with each other peer-to-peer, without publishing every transaction to the Bitcoin blockchain. +Users may transact on the Lightning Network as many times with as many users as they want, making use of the Bitcoin blockchain only in order to load Bitcoin onto the network initially and to "settle", that is: remove Bitcoin from the Lightning Network. +The result is that many more Bitcoin transactions can take place "off-chain", with only the initial loading and final settlement transactions needing to be validated and stored by Bitcoin nodes. +Aside from reducing the burden on nodes, these transactions will be cheaper for users as they do not need to pay blockchain fees, and more private for users as they are not published to all participants of the network. + +While the Lightning Network was initially conceived for Bitcoin, it is able to be implemented on any blockchain that meets its technical requirements. === Lightning Network Basic Concepts -// TODO Introduce and briefly explain the basic concepts of the LN +* Blockchain: a single distributed ledger agreed upon by a network of participating nodes. The Lightning Network does not use a blockchain to transact, but requires transactions recorded in a blockchain in order for Bitcoin to enter and leave the network. +* Channel: a channel is a financial relationship between two nodes on the Lightning Network. Two users can open a channel with each other using a Bitcoin transaction, and transact with each other by moving Bitcoin from one side of the channel to the other. +* Capacity: channels require Bitcoin to be pre-loaded into them before they can be used. This becomes the maximum amount of Bitcoin that can be transacted using this channel i.e. it's capacity. +** In-Bound Capacity: the maximum amount of Bitcoin that can be received using a channel. Your in-bound capacity is increased when a user opens a channel with you, or you make a payment to another user. +** Out-Bound Capacity: the maximum amount of Bitcoin that can be sent using a channel. Your out-bound capacity is increased when you open a channel with another user, or you receive a payment from another user. +* Invoice: a request for payment from another user that can take the form of a text string or a QR code. Lightning Invoices can be specified with a description and an amount the invoicer is requesting. +* Node: a node is a participant on the Lightning Network. Nodes can open and close channels with each other, route payments from other nodes, and manage their own wallets. Typically a Lightning Network node user will also run a Bitcoin Node to keep track of the status of on-chain payments +* On-Chain/Off-Chain: a payment is considered "on-chain" if it is included in the Bitcoin (or other underlying) blockchain where it is publicly visible to all nodes. Payments that are not visible in the underlying blockchain are "off-chain" +* Route: when making a payment from one user to another, the payment will move along many intermediary nodes before reaching the receiver. This path from the sender to the receiver forms a route on the network. +** Routing fees: each intermediary node will request a fee for transmitting the payment. The sum of these are the routing fees paid by the sender +* Transaction: a payment from one user to another. Lightning Network transactions are Bitcoin transactions not yet recorded on the Bitcoin blockchain. +** Funding Transaction: a transaction that locks Bitcoin into a smart contract to open a channel. +** Settlement Transaction: a transaction that closes a channel, and allocates the locked Bitcoin to the channel owners according to the final balance of the channel. +** Penalty Transaction: if one user tries to "cheat" by claiming a prior state of the channel, the other user can publish a penalty transaction to the Bitcoin blockchain, which allocates all Bitcoin in that channel to them. +* Wallet: an application that manages private keys in order to send and receive Bitcoins. Lightning Wallets have additional features over and above Bitcoin Wallets in that they can open and close channels, and send and receive lightning payments. + [[user-stories]] === Lightning Network Use Cases, Users, and Their Stories @@ -92,10 +126,10 @@ Finally, those seeking simplicity and convenience, even at the expense of contro Here are the three broad categories of lightning wallets and the relative degree of control they offer to the user: |=== -| Wallet Type | LN Participation | Keys/Funds Custody | Technical Skill Needed | -| Full Node & Wallet | Full Node | User Control | High | -| Non-Custodial Wallet | Rely on 3rd-party node | User Control | Medium | -| Custodial Wallet | 3rd-party node | 3rd-party custody | Low | +| Wallet Type | LN Node | Keystore/Custody | Technical Skill | +| Full Node & Wallet | Full Node | Non-Custodial | High | +| Non-Custodial Wallet | 3rd-party node | Non-Custodial | Medium | +| Custodial Wallet | 3rd-party node | Custodial | Low | |=== @@ -103,11 +137,19 @@ Lightning wallets can be installed on a variety of devices, including laptops, s Here are some current examples of LN node and wallet applications for different types of devices: +// TODO: Add a lot more examples, confirm the details for correctness |=== -| Application | Device | LN Node | Bitcoin Node | Wallet Type | -| lnd | Server | Full Node | Bitcoin Core/btcd | Full Control | -| c-lightning | Server | Full Node | Bitcoin Core | Full Control | -| eclair | Server | Full Node | Bitcoin Core/Electrum | Full Control | -| Zap Desktop | Desktop | Full Node | Bitcoin Core/btcd | Full Control | -| Eclair Mobile | Mobile | Lightweight | Electrum | Full Control | +| Application | Device | LN Node | Bitcoin Node | Keystore | +| lnd | Server | Full Node | Bitcoin Core/btcd | User Control | +| c-lightning | Server | Full Node | Bitcoin Core | User Control | +| Eclair Server | Server | Full Node | Bitcoin Core/Electrum | User Control | +| Zap Desktop | Desktop | Full Node | Bitcoin Core/btcd | User Control | +| Eclair Mobile | Mobile | Lightweight | Electrum | User Control | +| Blue Wallet | Mobile | None | None | Custodial | |=== + +=== Alice's First LN Wallet + +Alice is a long time Bitcoin user. We first met Alice in Chapter 1 of _"Mastering Bitcoin"_ footnote:["Mastering Bitcoin 2nd Edition, Chapter 1" Andreas M. Antonopoulos (https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch01.asciidoc).], when she bought a cup of coffee from Bob's cafe, using a bitcoin transaction. Now, Alice is eager to learn about and experiment with the Lightning Network. First, she has to select an LN wallet that meets her needs. + +Alice does not want to entrust custody of her bitcoin to third parties. She has learned enough about cryptocurrency to know how to use a wallet. She also wants a mobile wallet so that she can use it for small payments on-the-go, so she chooses the _Eclair_ wallet, a popular non-custodial mobile LN wallet.