1
0
mirror of https://github.com/bitcoinbook/bitcoinbook synced 2024-11-22 16:18:11 +00:00

CH01-03: edits for feedback from arufino (thanks!)

This commit is contained in:
David A. Harding 2023-02-09 20:55:02 -10:00
parent 23340d43bf
commit fd0aed78e9
3 changed files with 68 additions and 42 deletions

View File

@ -2,8 +2,6 @@
[[ch01_intro_what_is_bitcoin]] [[ch01_intro_what_is_bitcoin]]
== Introduction == 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. ((("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] [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 implementation of the Proof-of-Work algorithm (mining) that provides
security and resilience for Bitcoin has increased in power security and resilience for Bitcoin has increased in power
exponentially, and now exceeds the combined number of computing operations of the exponentially, and now exceeds the combined number of computing operations of the
world's top supercomputers. Bitcoin's total market value has at times world's top supercomputers.
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.
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. 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 chosen is a non-custodial wallet, Alice (and only Alice) will be in
control of her keys. Therefore, she bears responsibility for backing control of her keys. Therefore, she bears responsibility for backing
them up, since losing the keys means she loses access to her bitcoins. To 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 facilitate this, her wallet produces a _recovery code_ that can be used
<<recovery_code_intro>>) that can be used
to restore her wallet. to restore her wallet.
[[recovery_code_intro]] [[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 so that he doesn't have to type in Alice's Bitcoin address, which is
quite long and difficult to type. 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 Joe now has Alice's Bitcoin address set as the recipient. Joe enters the
amount as 0.001 bitcoins (BTC), see <<wallet-send>>. Some wallets may amount as 0.001 bitcoins (BTC), see <<wallet-send>>. Some wallets may
show the amount in a different denomination: 0.001 BTC is 1 millibitcoin show the amount in a different denomination: 0.001 BTC is 1 millibitcoin
@ -527,6 +516,11 @@ being sent, the wallet may ask Joe to either enter a transaction feerate or
prompt him with a suggested feerate. The higher the transaction fee rate, the prompt him with a suggested feerate. The higher the transaction fee rate, the
faster the transaction will be confirmed (see <<confirmations>>). faster the transaction will be confirmed (see <<confirmations>>).
[[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 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 amount, because he is about to transmit money and mistakes will soon become
irreversible. After double-checking the address and amount, he presses irreversible. After double-checking the address and amount, he presses

View File

@ -1,8 +1,6 @@
[[ch02_bitcoin_overview]] [[ch02_bitcoin_overview]]
== How Bitcoin Works == How Bitcoin Works
=== Transactions, Blocks, Mining, and the Blockchain
((("bitcoin", "overview of", id="BCover02")))((("central trusted ((("bitcoin", "overview of", id="BCover02")))((("central trusted
authority")))((("decentralized systems", "bitcoin overview", authority")))((("decentralized systems", "bitcoin overview",
id="DCSover02")))The Bitcoin system, unlike traditional banking and 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. Subsequent chapters will delve into the technology behind
transactions, the network, and mining. transactions, the network, and mining.
==== Bitcoin Overview === Bitcoin Overview
In the overview diagram shown in <<bitcoin-overview>>, we see that the In the overview diagram shown in <<bitcoin-overview>>, we see that the
Bitcoin system consists of users with wallets containing keys, 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 ((("payment requests")))((("QR codes", "payment requests")))Bob's
e-commerce system will automatically create a QR code containing an e-commerce system will automatically create a QR code containing an
_invoice_ (see <<invoice-QR>>). _invoice_ (<<invoice-QR>>).
Unlike a QR code that simply contains a destination Bitcoin address, this Unlike a QR code that simply contains a destination Bitcoin address, this
invoice is a QR-encoded URI that contains a destination address, 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 time as a credit card authorization), Bob sees the transaction on the
register. 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] [NOTE]
==== ====
((("fractional values")))((("milli-bitcoin")))((("satoshis")))The ((("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 === Bitcoin Transactions
((("transactions", "defined")))In simple terms, a transaction tells the ((("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 ":0" indicates the position of the output where Alice received the
money; in this case, the first position (position 0). 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 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 an input, software needs to use the input's reference to find the
previous transaction output being spent. previous transaction output being spent.
@ -255,8 +253,8 @@ that's what the protocol itself uses.
==== Making Change ==== Making Change
((("change, making")))((("change addresses")))((("addresses", "change ((("change, making")))((("change addresses")))((("addresses", "change
addresses")))In addition one or more outputs that pay the receiver of addresses")))In addition to one or more outputs that pay the receiver of
bitcoins, many tranactions will also include an output that pays the bitcoins, many transactions will also include an output that pays the
spender of the bitcoins, called a _change_ output. spender of the bitcoins, called a _change_ output.
This is because transaction inputs, This is because transaction inputs,
like currency notes, cannot be divided. If you purchase a $5 US dollar 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 .Most common transaction
image::images/mbc2_0205.png["Common Transaction"] image::images/mbc2_0205.png["Common Transaction"]
Another common form of transaction is a _consolidation transaction* one that spends several inputs Another common form of transaction is a _consolidation transaction_ one that spends several inputs
into a single output (see <<transaction-consolidating>>). This represents into a single output (<<transaction-consolidating>>). This represents
the real-world equivalent of exchanging a pile of coins and currency the real-world equivalent of exchanging a pile of coins and currency
notes for a single larger note. Transactions like these are sometimes notes for a single larger note. Transactions like these are sometimes
generated by wallets and business to clean up lots of smaller amounts. 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 Finally, another transaction form that is seen often on the bitcoin
ledger is _payment batching_ that pays to multiple outputs ledger is _payment batching_ that pays to multiple outputs
representing multiple recipients (see <<transaction-distributing>>). representing multiple recipients (<<transaction-distributing>>).
This type of transaction is sometimes used by commercial entities to This type of transaction is sometimes used by commercial entities to
distribute funds, such as when processing payroll payments to multiple distribute funds, such as when processing payroll payments to multiple
employees.((("", startref="Tover02"))) 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 <<getting_first_bitcoin>>). which was created in exchange for cash (see <<getting_first_bitcoin>>).
A bitcoin wallet application that runs on a full node actually A bitcoin wallet application that runs on a full node actually
contains a copy of every confirmed transaction's unspent outputs, called 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 However, because full nodes use more resources, most
user wallets run "lightweight" clients that track only the user's own user wallets run "lightweight" clients that track only the user's own
UTXOs. 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 the Bitcoin network, the Bitcoin protocol automatically increased the
difficulty of finding a new block. difficulty of finding a new block.
Soon, Jing and other miners upgraded to more specialized hardware, such Soon, Jing and other miners upgraded to more specialized hardware, such
as high-end dedicated graphical processing units (GPUs) cards such as as high-end dedicated graphical processing units (GPUs)
those used in gaming desktops. At the time of this writing, used in gaming desktops. At the time of this writing,
the difficulty is so high that it is profitable only to mine with the difficulty is so high that it is profitable only to mine with
((("application-specific integrated circuits ((("application-specific integrated circuits
(ASIC)")))application-specific integrated circuits (ASIC), essentially (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 Alice paying miners a share of the money she previously paid Bob. This
dishonest behavior will require they expend the effort required to dishonest behavior will require they expend the effort required to
create two new blocks. Instead, miners who behave honestly can create a 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 they include in it, plus the block reward. Normally, the high cost of
dishonestly creating two blocks for a small additional payment is much dishonestly creating two blocks for a small additional payment is much
less profitable than honestly creating a new block, making it unlikely 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 means that he can begin to believe that the payment from Alice can be
relied upon. 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. giving Bob more and more confidence that Alice's payment is secure.
((("genesis block")))((("blocks", "genesis block")))((("blockchain ((("genesis block")))((("blocks", "genesis block")))((("blockchain
(the)", "genesis block")))In the diagram in <<block-alice1>>, we can (the)", "genesis block")))In <<block-alice1>>, we can
see block the block which contains Alice's transaction. Below it are the block which contains Alice's transaction. Below it are
hundreds of thousands of blocks, linked to each other in a chain of 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 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 block_. Over time, as the "height" of new blocks increases, so does the

View File

@ -1,6 +1,30 @@
[[ch03_bitcoin_client]] [[ch03_bitcoin_client]]
== Bitcoin Core: The Reference Implementation == 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 ((("open source licenses")))((("Nakamoto, Satoshi")))Bitcoin is an _open
source_ project and the source code is available under an open (MIT) 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 license, free to download and use for any purpose. More than just being
@ -15,8 +39,8 @@ contribute to the code&#x2014;including you!
implementation", see="Bitcoin Core")))((("Bitcoin Core", "reference implementation", see="Bitcoin Core")))((("Bitcoin Core", "reference
implementation")))When Bitcoin was created by Satoshi Nakamoto, the implementation")))When Bitcoin was created by Satoshi Nakamoto, the
software was mostly completed before the whitepaper reproduced in software was mostly completed before the whitepaper reproduced in
<<satoshi_whitepaper>> was published. Satoshi wanted to make sure it <<satoshi_whitepaper>> was published. Satoshi wanted to make sure the
worked before publishing about it. That first implementation, then simply implementation worked before publishing a paper about it. That first implementation, then simply
known as "Bitcoin", has been heavily modified and known as "Bitcoin", has been heavily modified and
improved. It has evolved into what is known as _Bitcoin Core_, to improved. It has evolved into what is known as _Bitcoin Core_, to
differentiate it from other implementations. Bitcoin Core is differentiate it from other implementations. Bitcoin Core is
@ -50,7 +74,7 @@ next chapter, which is less technical.
((("Bitcoin Core", "compiling from source code", ((("Bitcoin Core", "compiling from source code",
id="BCsource03")))((("Bitcoin Core", "compiling from source code", id="BCsource03")))((("Bitcoin Core", "compiling from source code",
"downloading")))((("code examples, obtaining and using")))Bitcoin Core's "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 authoritative source repository from GitHub. ((("Bitcoin Core
downloads")))On the https://bitcoincore.org/bin/[Bitcoin Core download downloads")))On the https://bitcoincore.org/bin/[Bitcoin Core download
page], select the most recent version and download the compressed 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 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 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 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 blocksonly:: Minimize your bandwidth usage by only accepting blocks of
confirmed transactions from your peers instead of relaying unconfirmed 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 a generic HTTP library to construct the call, similar to what is shown
in the preceding +curl+ example. 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 "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. will use the +python-bitcoinlib+ library to simplify API access.
Remember, this requires you to have a running Bitcoin Core instance, 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")))((("", and more are created all the time.((("", startref="BCalt03")))((("",
startref="clients03")))((("", startref="thirdpart03")))((("", startref="clients03")))((("", startref="thirdpart03")))((("",
startref="toolkit03")))((("", startref="librar03"))) 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.