mirror of
https://github.com/bitcoinbook/bitcoinbook
synced 2024-12-23 23:18:42 +00:00
Edited ch03_bitcoin-core.adoc with Atlas code editor
This commit is contained in:
parent
9d10c02da7
commit
f31ac7d797
@ -15,7 +15,7 @@ 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
|
||||
In this chapter, we'll install Bitcoin Core, the implementation that
|
||||
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
|
||||
@ -32,14 +32,14 @@ open source, Bitcoin is developed by
|
||||
an open community of volunteers. At first, that community consisted of
|
||||
only Satoshi Nakamoto. By 2023, Bitcoin's source code had more than 1,000
|
||||
contributors with about a dozen developers working on the code almost
|
||||
full-time and several dozen more on a part-time basis. Anyone can
|
||||
full time and several dozen more on a part-time basis. Anyone can
|
||||
contribute to the code—including you!
|
||||
|
||||
When Bitcoin was created by Satoshi Nakamoto, the
|
||||
software was mostly completed before publication of the whitepaper reproduced in
|
||||
<<satoshi_whitepaper>>. 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
|
||||
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
|
||||
the _reference implementation_ of the Bitcoin system, meaning that it
|
||||
@ -81,7 +81,7 @@ Bitcoin Core's
|
||||
source code can be downloaded as an archive or by cloning the
|
||||
source repository from GitHub. On the https://bitcoincore.org/bin/[Bitcoin Core download
|
||||
page], select the most recent version and download the compressed
|
||||
archive of the source code. Alternatively, use the git command line to create a
|
||||
archive of the source code. Alternatively, use the Git command line to create a
|
||||
local copy of the source code from the
|
||||
https://github.com/bitcoin/bitcoin[GitHub bitcoin page].
|
||||
|
||||
@ -90,8 +90,8 @@ https://github.com/bitcoin/bitcoin[GitHub bitcoin page].
|
||||
In
|
||||
many of the examples in this chapter we will be using the operating
|
||||
system's command-line interface (also known as a "shell"), accessed via
|
||||
a "terminal" application. The shell will display a prompt; you type a
|
||||
command; and the shell responds with some text and a new prompt for your
|
||||
a "terminal" application. The shell will display a prompt, you type a
|
||||
command, and the shell responds with some text and a new prompt for your
|
||||
next command. The prompt may look different on your system, but in the
|
||||
following examples it is denoted by a +$+ symbol. In the examples, when
|
||||
you see text after a +$+ symbol, don't type the +$+ symbol but type the
|
||||
@ -120,11 +120,11 @@ Resolving deltas: 100% (175649/175649), done.
|
||||
Git is the most widely used
|
||||
distributed version control system, an essential part of any software
|
||||
developer's toolkit. You may need to install the +git+ command, or a
|
||||
graphical user interface for git, on your operating system if you do not
|
||||
graphical user interface for Git, on your operating system if you do not
|
||||
have it already.
|
||||
====
|
||||
|
||||
When the git cloning operation has completed, you will have a complete
|
||||
When the Git cloning operation has completed, you will have a complete
|
||||
local copy of the source code repository in the directory _bitcoin_.
|
||||
Change to this directory using the +cd+ command:
|
||||
|
||||
@ -155,7 +155,7 @@ v0.12.0rc2
|
||||
...
|
||||
----
|
||||
|
||||
The list of tags shows all the released versions of bitcoin. By
|
||||
The list of tags shows all the released versions of Bitcoin. By
|
||||
convention, _release candidates_, which are intended for testing, have
|
||||
the suffix "rc." Stable releases that can be run on production systems
|
||||
have no suffix. From the preceding list, select the highest version
|
||||
@ -189,19 +189,19 @@ in _README.md_ in the _bitcoin_ directory.
|
||||
In this chapter, we will build the Bitcoin Core daemon
|
||||
(server), also known as +bitcoind+ on Linux (a Unix-like system). Review the instructions for
|
||||
compiling the +bitcoind+ command-line client on your platform by reading
|
||||
+doc/build-unix.md+. Alternative instructions can be found in
|
||||
_doc/build-unix.md_. Alternative instructions can be found in
|
||||
the _doc_ directory; for example, _build-windows.md_ for Windows
|
||||
instructions. As of this writing, instructions are available for
|
||||
Android, FreeBSD, NetBSD, OpenBSD, MacOS (OSX), Unix, and Windows.
|
||||
Android, FreeBSD, NetBSD, OpenBSD, macOS (OSX), Unix, and Windows.
|
||||
|
||||
Carefully review the build prerequisites, which are in the first part of
|
||||
the build documentation. These are libraries that must be present on
|
||||
your system before you can begin to compile bitcoin. If these
|
||||
your system before you can begin to compile Bitcoin. If these
|
||||
prerequisites are missing, the build process will fail with an error. If
|
||||
this happens because you missed a prerequisite, you can install it and
|
||||
then resume the build process from where you left off. Assuming the
|
||||
prerequisites are installed, you start the build process by generating a
|
||||
set of build scripts using the _autogen.sh_ script.
|
||||
set of build scripts using the _autogen.sh_ script:
|
||||
|
||||
----
|
||||
$ ./autogen.sh
|
||||
@ -249,7 +249,7 @@ setting, computer lab restrictions may require you to install
|
||||
applications in your home directory (e.g., using +--prefix=$HOME+).
|
||||
|
||||
Here are some useful options that override the default behavior of the
|
||||
configure script:
|
||||
+configure+ script:
|
||||
|
||||
++++
|
||||
<dl>
|
||||
@ -263,7 +263,7 @@ configure script:
|
||||
<dd><p>If you are building a wallet, allow the use of an incompatible version of the Berkeley DB library.</p></dd>
|
||||
|
||||
<dt><code>--with-gui=no</code></dt>
|
||||
<dd><p>Don't build the graphical user interface, which requires the Qt library. This builds server and command-line bitcoin only.</p></dd>
|
||||
<dd><p>Don't build the graphical user interface, which requires the Qt library. This builds server and command-line Bitcoin only.</p></dd>
|
||||
</dl>
|
||||
++++
|
||||
|
||||
@ -363,7 +363,7 @@ of data initially and about 400 MB of Bitcoin transactions per day.
|
||||
These figures are for 2023 and will likely increase over time. If you
|
||||
shut down your node or get disconnected from the internet for several
|
||||
days, your node will need to download the data that it missed. For
|
||||
example, if you close Bitcoin Core for ten days, you will need to
|
||||
example, if you close Bitcoin Core for 10 days, you will need to
|
||||
download approximately 4 GB the next time you start it.
|
||||
|
||||
Depending on whether you choose to index all transactions and keep a
|
||||
@ -429,7 +429,7 @@ configuration file in its data directory on every start. In this section
|
||||
we will examine the various configuration options and set up a
|
||||
configuration file. To locate the configuration file, run +bitcoind
|
||||
-printtoconsole+ in your terminal and look for the first couple of
|
||||
lines.
|
||||
lines:
|
||||
|
||||
----
|
||||
$ bitcoind -printtoconsole
|
||||
@ -625,7 +625,7 @@ $ bitcoin-cli getblockchaininfo
|
||||
}
|
||||
----
|
||||
|
||||
This shows a node with a blockchain height of 0 blocks and 83999
|
||||
This shows a node with a blockchain height of 0 blocks and 83,999
|
||||
headers. The node first fetches the block headers from its peers in
|
||||
order to find the blockchain with the most proof of work and
|
||||
afterward continues to download the full blocks, validating them as it
|
||||
@ -638,7 +638,7 @@ restarts. You will find a number of example startup scripts for various
|
||||
operating systems in Bitcoin Core's source directory under _contrib/init_ and
|
||||
a _README.md_ file showing which system uses which script.
|
||||
|
||||
=== Bitcoin Core Application Programming Interface (API)
|
||||
=== Bitcoin Core API
|
||||
|
||||
Bitcoin Core
|
||||
implements a JSON-RPC interface that can also be accessed using
|
||||
@ -696,7 +696,7 @@ $ bitcoin-cli getblockhash 1000
|
||||
The result is a block hash, which is described in more detail in the
|
||||
following chapters. But for now, this command should return the same
|
||||
result on your system, demonstrating that your Bitcoin Core node is
|
||||
running, is accepting commands, and has information about block 1000 to
|
||||
running, is accepting commands, and has information about block 1,000 to
|
||||
return to you.
|
||||
|
||||
In the next sections we will demonstrate some very useful RPC commands
|
||||
@ -707,7 +707,7 @@ and their expected output.
|
||||
Bitcoin
|
||||
Core provides status reports on different modules through the JSON-RPC
|
||||
interface. The most important commands include +getblockchaininfo+,
|
||||
+getmempoolinfo+, +getnetworkinfo+ and +getwalletinfo+.
|
||||
+getmempoolinfo+, +getnetworkinfo+, and +getwalletinfo+.
|
||||
|
||||
Bitcoin's +getblockchaininfo+ RPC command was introduced earlier. The
|
||||
+getnetworkinfo+ command displays basic information about the status of
|
||||
@ -757,7 +757,7 @@ Bitcoin network and the settings related to this node.
|
||||
It will take some time, perhaps more than a day, for +bitcoind+
|
||||
to catch up to the current blockchain height as it downloads blocks from
|
||||
other Bitcoin nodes and validates every transaction in those
|
||||
blocks--almost a billion transactions as of this writng. You can check
|
||||
blocks--almost a billion transactions as of this writing. You can check
|
||||
its progress using
|
||||
+getblockchaininfo+ to see the number of known blocks. The examples in
|
||||
the rest of this chapter assume you're at least at block 775,072.
|
||||
@ -955,11 +955,11 @@ blocks have been built on top of it, indicating the difficulty of
|
||||
changing any of the transactions in this block. The +height+ tells us
|
||||
how many blocks preceeded this block. We see the block's version, the
|
||||
time it was created (according to its miner), the median time of the 11
|
||||
blocks that preceed this block (a time measurement that's harder for
|
||||
blocks that precede this block (a time measurement that's harder for
|
||||
miners to manipulate), and the size of the block in three different
|
||||
measurements (its legacy stripped size, it's full size, and its size in
|
||||
measurements (its legacy stripped size, its full size, and its size in
|
||||
weight units). We also see some fields used for security and
|
||||
proof-of-work (merkle root, nonce, bits, difficulty, and chainwork);
|
||||
proof of work (merkle root, nonce, bits, difficulty, and chainwork);
|
||||
we'll examine those in detail in <<mining>>.
|
||||
|
||||
==== Using Bitcoin Core's Programmatic Interface
|
||||
@ -990,14 +990,15 @@ This command shows that +curl+ submits an HTTP request to the local host
|
||||
submitting a +jsonrpc+ request for the +getblockchaininfo+ method using
|
||||
+text/plain+ encoding.
|
||||
|
||||
You might notice that curl will ask for credentials to be sent along
|
||||
You might notice that +curl+ will ask for credentials to be sent along
|
||||
with the request. Bitcoin Core will create a random password on each
|
||||
start and place it in the data directory under the name +.cookie+. The
|
||||
+bitcoin-cli+ helper can read this password file given the data
|
||||
directory. Similarly, you can copy the password and pass it to curl (or
|
||||
any higher level Bitcoin Core RPC wrappers), as seen in <<cookie_auth>>.
|
||||
directory. Similarly, you can copy the password and pass it to +curl+ (or
|
||||
any higher-level Bitcoin Core RPC wrappers), as seen in <<cookie_auth>>.
|
||||
|
||||
[[cookie_auth]]
|
||||
.Using cookie-based authentication with Bitcoin Core
|
||||
====
|
||||
----
|
||||
$ cat .bitcoin/.cookie
|
||||
@ -1030,7 +1031,7 @@ call and prints the +block+ parameter from the data returned by Bitcoin
|
||||
Core.
|
||||
|
||||
[[rpc_example]]
|
||||
.Running getblockchaininfo via Bitcoin Core's JSON-RPC API
|
||||
.Running +getblockchaininfo+ via Bitcoin Core's JSON-RPC API
|
||||
====
|
||||
[source,python]
|
||||
----
|
||||
@ -1112,7 +1113,7 @@ spot the difference.
|
||||
|
||||
There
|
||||
are many alternative clients, libraries, toolkits, and even full-node
|
||||
implementations in the bitcoin ecosystem. These are implemented in a
|
||||
implementations in the Bitcoin ecosystem. These are implemented in a
|
||||
variety of programming languages, offering programmers native interfaces
|
||||
in their preferred language.
|
||||
|
||||
@ -1120,7 +1121,7 @@ The following sections list some of the best libraries, clients, and
|
||||
toolkits, organized by programming languages.
|
||||
|
||||
==== C/C++
|
||||
https://github.com/bitcoin/bitcoin[Bitcoin Core] :: The reference implementation of bitcoin
|
||||
https://github.com/bitcoin/bitcoin[Bitcoin Core] :: The reference implementation of Bitcoin
|
||||
|
||||
==== JavaScript
|
||||
https://bcoin.io/[bcoin]:: A modular and scalable full-node implementation with API
|
||||
|
Loading…
Reference in New Issue
Block a user