From fd0aed78e9757f34b040a5fc7705194c75c1388f Mon Sep 17 00:00:00 2001 From: "David A. Harding" Date: Thu, 9 Feb 2023 20:55:02 -1000 Subject: [PATCH] CH01-03: edits for feedback from arufino (thanks!) --- ch01.asciidoc | 24 +++++++++--------------- ch02.asciidoc | 42 ++++++++++++++++++++---------------------- ch03.asciidoc | 44 +++++++++++++++++++++++++++++++++++++++----- 3 files changed, 68 insertions(+), 42 deletions(-) diff --git a/ch01.asciidoc b/ch01.asciidoc index d264232f..ca4e6309 100644 --- a/ch01.asciidoc +++ b/ch01.asciidoc @@ -2,8 +2,6 @@ [[ch01_intro_what_is_bitcoin]] == Introduction -=== What Is Bitcoin? - ((("bitcoin", "defined", id="GSdefine01")))Bitcoin is a collection of concepts and technologies that form the basis of a digital money ecosystem. Units of currency called bitcoin are used to store and transmit value among participants in the Bitcoin network. Bitcoin users communicate with each other using the Bitcoin protocol primarily via the internet, although other transport networks can also be used. The Bitcoin protocol stack, available as open source software, can be run on a wide range of computing devices, including laptops and smartphones, making the technology easily accessible. [TIP] @@ -117,10 +115,7 @@ published by Nakamoto and since revised by many other programmers. The implementation of the Proof-of-Work algorithm (mining) that provides security and resilience for Bitcoin has increased in power exponentially, and now exceeds the combined number of computing operations of the -world's top supercomputers. Bitcoin's total market value has at times -exceeded $1 trillion US dollars, depending on the bitcoin-to-dollar -exchange rate. The largest transaction processed so far by the network -was over a billion US dollars. +world's top supercomputers. Satoshi Nakamoto withdrew from the public in April 2011, leaving the responsibility of developing the code and network to a thriving group of volunteers. The identity of the person or people behind Bitcoin is still unknown. ((("open source licenses")))However, neither Satoshi Nakamoto nor anyone else exerts individual control over the Bitcoin system, which operates based on fully transparent mathematical principles, open source code, and consensus among participants. The invention itself is groundbreaking and has already spawned new science in the fields of distributed computing, economics, and econometrics. @@ -318,8 +313,7 @@ the option to create a new Bitcoin wallet. Because the wallet she has chosen is a non-custodial wallet, Alice (and only Alice) will be in control of her keys. Therefore, she bears responsibility for backing them up, since losing the keys means she loses access to her bitcoins. To -facilitate this, her wallet produces a _recovery code_ (explained more in -<>) that can be used +facilitate this, her wallet produces a _recovery code_ that can be used to restore her wallet. [[recovery_code_intro]] @@ -509,11 +503,6 @@ scanner. This allows Joe to scan the barcode with his smartphone camera so that he doesn't have to type in Alice's Bitcoin address, which is quite long and difficult to type. -[[wallet-send]] -[role="smallereighty"] -.Bitcoin wallet send screen -image::images/send.png["Wallet send screen"] - Joe now has Alice's Bitcoin address set as the recipient. Joe enters the amount as 0.001 bitcoins (BTC), see <>. Some wallets may show the amount in a different denomination: 0.001 BTC is 1 millibitcoin @@ -523,10 +512,15 @@ Some wallets may also suggest Joe enter a label for this transaction; if so, Joe enters "Alice". Weeks or months from now, this will help Joe remember why he sent these 0.001 bitcoins. Some wallets may also prompt Joe about fees. Depending on the wallet and how the transaction is -being sent, the wallet may ask Joe to either enter a transaction feerate or -prompt him with a suggested feerate. The higher the transaction feerate, the +being sent, the wallet may ask Joe to either enter a transaction fee rate or +prompt him with a suggested feerate. The higher the transaction fee rate, the faster the transaction will be confirmed (see <>). +[[wallet-send]] +[role="smallereighty"] +.Bitcoin wallet send screen +image::images/send.png["Wallet send screen"] + Joe then carefully checks to make sure he has entered the correct amount, because he is about to transmit money and mistakes will soon become irreversible. After double-checking the address and amount, he presses diff --git a/ch02.asciidoc b/ch02.asciidoc index 2f6ebd92..c831f318 100644 --- a/ch02.asciidoc +++ b/ch02.asciidoc @@ -1,8 +1,6 @@ [[ch02_bitcoin_overview]] == How Bitcoin Works -=== Transactions, Blocks, Mining, and the Blockchain - ((("bitcoin", "overview of", id="BCover02")))((("central trusted authority")))((("decentralized systems", "bitcoin overview", id="DCSover02")))The Bitcoin system, unlike traditional banking and @@ -16,7 +14,7 @@ is recorded on the blockchain, the distributed ledger of all transactions. Subsequent chapters will delve into the technology behind transactions, the network, and mining. -==== Bitcoin Overview +=== Bitcoin Overview In the overview diagram shown in <>, we see that the Bitcoin system consists of users with wallets containing keys, @@ -85,7 +83,7 @@ also in bitcoin (BTC), at Bitcoin's prevailing exchange rate. ((("payment requests")))((("QR codes", "payment requests")))Bob's e-commerce system will automatically create a QR code containing an -_invoice_ (see <>). +_invoice_ (<>). Unlike a QR code that simply contains a destination Bitcoin address, this invoice is a QR-encoded URI that contains a destination address, @@ -131,11 +129,6 @@ authorize the payment. Within a few seconds (about the same amount of time as a credit card authorization), Bob sees the transaction on the register. -In the following sections, we will examine this transaction in more -detail. We'll see how Alice's wallet constructed it, how it was -propagated across the network, how it was verified, and finally, how Bob -can spend that amount in subsequent transactions. - [NOTE] ==== ((("fractional values")))((("milli-bitcoin")))((("satoshis")))The @@ -160,6 +153,11 @@ https://blockstream.info/tx/674616f1fbc6cc748213648754724eebff0fc04506f2c81efb13 ---- ==== +In the following sections, we will examine this transaction in more +detail. We'll see how Alice's wallet constructed it, how it was +propagated across the network, how it was verified, and finally, how Bob +can spend that amount in subsequent transactions. + === Bitcoin Transactions ((("transactions", "defined")))In simple terms, a transaction tells the @@ -210,7 +208,7 @@ actual transaction, the reference is the 32-byte transaction identifier ":0" indicates the position of the output where Alice received the money; in this case, the first position (position 0). -As shown in the illustration, actual Bitcoin transactions don't +As shown, actual Bitcoin transactions don't explicitly include the value of their input. To determine the value of an input, software needs to use the input's reference to find the previous transaction output being spent. @@ -255,8 +253,8 @@ that's what the protocol itself uses. ==== Making Change ((("change, making")))((("change addresses")))((("addresses", "change -addresses")))In addition one or more outputs that pay the receiver of -bitcoins, many tranactions will also include an output that pays the +addresses")))In addition to one or more outputs that pay the receiver of +bitcoins, many transactions will also include an output that pays the spender of the bitcoins, called a _change_ output. This is because transaction inputs, like currency notes, cannot be divided. If you purchase a $5 US dollar @@ -306,8 +304,8 @@ transaction has one input and two outputs and is shown in .Most common transaction image::images/mbc2_0205.png["Common Transaction"] -Another common form of transaction is a _consolidation transaction* one that spends several inputs -into a single output (see <>). This represents +Another common form of transaction is a _consolidation transaction_ one that spends several inputs +into a single output (<>). This represents the real-world equivalent of exchanging a pile of coins and currency notes for a single larger note. Transactions like these are sometimes generated by wallets and business to clean up lots of smaller amounts. @@ -318,7 +316,7 @@ image::images/mbc2_0206.png["Aggregating Transaction"] Finally, another transaction form that is seen often on the bitcoin ledger is _payment batching_ that pays to multiple outputs -representing multiple recipients (see <>). +representing multiple recipients (<>). This type of transaction is sometimes used by commercial entities to distribute funds, such as when processing payroll payments to multiple employees.((("", startref="Tover02"))) @@ -351,7 +349,7 @@ would contain a copy of the transaction output from Joe's transaction, which was created in exchange for cash (see <>). A bitcoin wallet application that runs on a full node actually contains a copy of every confirmed transaction's unspent outputs, called -*Unspent Transaction Outputs* (UTXOs). +_Unspent Transaction Outputs_ (UTXOs). However, because full nodes use more resources, most user wallets run "lightweight" clients that track only the user's own UTXOs. @@ -587,8 +585,8 @@ suitable Proof-of-Work for new blocks. As more miners started joining the Bitcoin network, the Bitcoin protocol automatically increased the difficulty of finding a new block. Soon, Jing and other miners upgraded to more specialized hardware, such -as high-end dedicated graphical processing units (GPUs) cards such as -those used in gaming desktops. At the time of this writing, +as high-end dedicated graphical processing units (GPUs) +used in gaming desktops. At the time of this writing, the difficulty is so high that it is profitable only to mine with ((("application-specific integrated circuits (ASIC)")))application-specific integrated circuits (ASIC), essentially @@ -658,11 +656,11 @@ alternative version of the transaction where she pays Bob, perhaps with Alice paying miners a share of the money she previously paid Bob. This dishonest behavior will require they expend the effort required to create two new blocks. Instead, miners who behave honestly can create a -single new block and and receive all of the fees from the tranactions +single new block and and receive all of the fees from the transactions they include in it, plus the block reward. Normally, the high cost of dishonestly creating two blocks for a small additional payment is much less profitable than honestly creating a new block, making it unlikely -that a confirmed tranaction will be deliberately changed. For Bob, this +that a confirmed transaction will be deliberately changed. For Bob, this means that he can begin to believe that the payment from Alice can be relied upon. @@ -685,8 +683,8 @@ top of each other, it becomes harder to reverse the transaction, thereby giving Bob more and more confidence that Alice's payment is secure. ((("genesis block")))((("blocks", "genesis block")))((("blockchain -(the)", "genesis block")))In the diagram in <>, we can -see block the block which contains Alice's transaction. Below it are +(the)", "genesis block")))In <>, we can +the block which contains Alice's transaction. Below it are hundreds of thousands of blocks, linked to each other in a chain of blocks (blockchain) all the way back to block #0, known as the _genesis block_. Over time, as the "height" of new blocks increases, so does the diff --git a/ch03.asciidoc b/ch03.asciidoc index 75e01836..645f6ca1 100644 --- a/ch03.asciidoc +++ b/ch03.asciidoc @@ -1,6 +1,30 @@ [[ch03_bitcoin_client]] == Bitcoin Core: The Reference Implementation +People only accept money in exchange for their valuable goods and +services if they believe that they'll be able to spend that money later. +Money that is counterfeit or unexpectedly debased may not be spendable +later, so every person accepting bitcoin has a strong incentive to +verify the integrity of the bitcoins they receive. The Bitcoin system +was designed so that it's possible for software running entirely on your +local computer to perfectly prevent counterfeiting, debasement, and +several other critical problems. Software which provides that function +is called a full verification node because it verifies every confirmed +Bitcoin transaction against every rule in the system. Full verification +nodes, _full nodes_ for short, may also provide tools and data for +understanding how Bitcoin works and what is currently happening in the +network. + +In this chapter, we'll install Bitcoin Core, the implementation which +most full node operators have used since the beginning of the Bitcoin +network. We'll then inspect blocks, transactions, and other data from +your node, data which is authoritative--not because some powerful entity +designated it as such but because your node independently verified it. +Throughout the rest of this book, we'll continue using Bitcoin Core to +create and examine data related to the blockchain and network. + +=== From Bitcoin to Bitcoin Core + ((("open source licenses")))((("Nakamoto, Satoshi")))Bitcoin is an _open source_ project and the source code is available under an open (MIT) license, free to download and use for any purpose. More than just being @@ -15,8 +39,8 @@ contribute to the code—including you! implementation", see="Bitcoin Core")))((("Bitcoin Core", "reference implementation")))When Bitcoin was created by Satoshi Nakamoto, the software was mostly completed before the whitepaper reproduced in -<> was published. Satoshi wanted to make sure it -worked before publishing about it. That first implementation, then simply +<> was published. Satoshi wanted to make sure the +implementation worked before publishing a paper about it. That first implementation, then simply known as "Bitcoin", has been heavily modified and improved. It has evolved into what is known as _Bitcoin Core_, to differentiate it from other implementations. Bitcoin Core is @@ -50,7 +74,7 @@ next chapter, which is less technical. ((("Bitcoin Core", "compiling from source code", id="BCsource03")))((("Bitcoin Core", "compiling from source code", "downloading")))((("code examples, obtaining and using")))Bitcoin Core's -source code can be downloaded as a archive or by cloning the +source code can be downloaded as an archive or by cloning the authoritative source repository from GitHub. ((("Bitcoin Core downloads")))On the https://bitcoincore.org/bin/[Bitcoin Core download page], select the most recent version and download the compressed @@ -484,7 +508,7 @@ block containing that transaction hasn't been pruned. dbcache:: The size of the UTXO cache. The default is 450 MiB. Increase this size on high-end hardware to read and write from your disk less often, or reduce the size on low-end hardware to save memory at the -expense of more using your disk more frequently. +expense of using your disk more frequently. blocksonly:: Minimize your bandwidth usage by only accepting blocks of confirmed transactions from your peers instead of relaying unconfirmed @@ -985,7 +1009,7 @@ If you're implementing a JSON-RPC call in your own program, you can use a generic HTTP library to construct the call, similar to what is shown in the preceding +curl+ example. -However, there are libraries in most every programming language that +However, there are libraries in most popular programming languages that "wrap" the Bitcoin Core API in a way that makes this a lot simpler. We will use the +python-bitcoinlib+ library to simplify API access. Remember, this requires you to have a running Bitcoin Core instance, @@ -1119,3 +1143,13 @@ Many more libraries exist in a variety of other programming languages and more are created all the time.((("", startref="BCalt03")))((("", startref="clients03")))((("", startref="thirdpart03")))((("", startref="toolkit03")))((("", startref="librar03"))) + +If you followed the instructions in this chapter, you now have Bitcoin +Core running and have begun exploring the network and blockchain using +your own full node. From now on you can independently use software you +control, on a computer you control, to verify any bitcoins you receive +follow every rule in the Bitcoin system without having to trust any +outside authority. In the coming chapters, we'll learn more about the +rules of the system and how your node and your wallet use them to secure +your money, protect your privacy, and make spending and receiving +convenient.