mirror of
https://github.com/bitcoinbook/bitcoinbook
synced 2025-01-11 00:01:03 +00:00
CH02::mining: replace sudoku example with accurate description
This takes up the same amount of space and is (I think) just as easy to understand, but avoids the indirection of a metaphorical example and some of the confusions it can create, e.g. that mining is a race to complete a puzzle rather than a memoryless lottery. We also remove a later desciption of PoW which is now redundant.
This commit is contained in:
parent
2612342b9e
commit
cb3420c572
@ -542,41 +542,45 @@ and diminishes with time, following a fixed issuance schedule.
|
||||
|
||||
|
||||
Mining achieves a fine balance between cost and reward. Mining uses
|
||||
electricity to solve a mathematical problem. A successful miner will
|
||||
electricity to solve a computational problem. A successful miner will
|
||||
collect a _reward_ in the form of new bitcoin and transaction fees.
|
||||
However, the reward will only be collected if the miner has correctly
|
||||
validated all the transactions, to the satisfaction of the rules of
|
||||
_consensus_. This delicate balance provides security for bitcoin without
|
||||
a central authority.
|
||||
|
||||
A good way to describe mining is like a giant competitive game of sudoku
|
||||
that resets every time someone finds a solution and whose difficulty
|
||||
automatically adjusts so that it takes approximately 10 minutes to find
|
||||
a solution. Imagine a giant sudoku puzzle, several thousand rows and
|
||||
columns in size. If I show you a completed puzzle you can verify it
|
||||
quite quickly. However, if the puzzle has a few squares filled and the
|
||||
rest are empty, it takes a lot of work to solve! The difficulty of the
|
||||
sudoku can be adjusted by changing its size (more or fewer rows and
|
||||
columns), but it can still be verified quite easily even if it is very
|
||||
large. The "puzzle" used in bitcoin is based on a cryptographic hash and
|
||||
exhibits similar characteristics: it is asymmetrically hard to solve but
|
||||
easy to verify, and its difficulty can be adjusted.
|
||||
Mining is designed to be a decentralized lottery. Each miner can create
|
||||
their own lottery ticket by creating a _block template_ that includes
|
||||
the new transactions they want to mine plus some additional data fields.
|
||||
The miner inputs their template into a specially-designed algorithm that
|
||||
scrambles (or "hashes") the data, producing output that looks nothing
|
||||
like the input data. This _hash_ function will always produce the same
|
||||
output for the same input--but nobody can predict what the output will
|
||||
look like for a new input, even if it is only slighly different from a
|
||||
previous input. If the output of hash function matches a template
|
||||
determined by the Bitcoin protocol, the miner wins the lottery and
|
||||
Bitcoin users will accept the block template with its transactions as a
|
||||
valid block. If the output doesn't match the template, the miner makes
|
||||
a small change to their block template and tries again. As of this
|
||||
writing, the number of block templates miners need to try before finding
|
||||
a winning combination is about 168 billion trillions. That's also how
|
||||
many times the hash function needs to be run.
|
||||
|
||||
However, once a winning combination has been found, anyone can verify
|
||||
the block is valid by running the hash function just once. That makes a
|
||||
valid block something that requires an incredible amount of work to
|
||||
create but only a trivial amount of work to verify. The simple
|
||||
verification process is able to probabalistically prove the work was
|
||||
done, so the data necessary to generate that proof--in this case, the
|
||||
block--is called Proof-of-Work (PoW).
|
||||
|
||||
((("mining and consensus", "mining farms and pools")))In
|
||||
<<user-stories>>, we introduced ((("use cases", "mining for
|
||||
bitcoin")))Jing, an entrepreneur in Shanghai. Jing runs a _mining farm_,
|
||||
which is a business that runs thousands of specialized mining computers,
|
||||
competing for the reward. Every 10 minutes or so, Jing's mining
|
||||
computers compete against thousands of similar systems in a global race
|
||||
to find a solution to a block of transactions. ((("Proof-of-Work
|
||||
algorithm")))((("mining and consensus", "Proof-of-Work
|
||||
algorithm")))Finding such a solution, the so-called _Proof-of-Work_
|
||||
(PoW), requires quadrillions of hashing operations per second across the
|
||||
entire Bitcoin network. The algorithm for Proof-of-Work involves
|
||||
repeatedly hashing the header of the block and a random number with the
|
||||
SHA256 cryptographic algorithm until a solution matching a predetermined
|
||||
pattern emerges. The first miner to find such a solution wins the round
|
||||
of competition and publishes that block into the blockchain.
|
||||
competing for the block reward. Jing's mining
|
||||
computers compete against thousands of similar systems in the global
|
||||
lottery to create the next block.
|
||||
|
||||
Jing started mining in 2010 using a very fast desktop computer to find a
|
||||
suitable Proof-of-Work for new blocks. As more miners started joining
|
||||
@ -628,14 +632,14 @@ round.
|
||||
|
||||
((("candidate blocks")))((("blocks", "candidate blocks")))Alice's
|
||||
transaction was picked up by the network and included in the pool of
|
||||
unverified transactions. Once validated by the mining software it was
|
||||
included in a new block, called a _candidate block_, generated by Jing's
|
||||
unverified transactions. Once validated by a full node, it was
|
||||
included in a block template generated by Jing's
|
||||
mining pool. All the miners participating in that mining pool
|
||||
immediately start computing Proof-of-Work for the candidate block.
|
||||
immediately start trying to generate a Proof-of-Work for the block template.
|
||||
Approximately five minutes after the transaction was first transmitted
|
||||
by Alice's wallet, one of Jing's ASIC miners found a solution for the
|
||||
candidate block and announced it to the network. Once other miners
|
||||
validated the winning block they started the race to generate the next
|
||||
block and announced it to the network. After other miners
|
||||
validated the winning block, they started a new lottery to generate the next
|
||||
block.
|
||||
|
||||
Jing's winning block became part of the blockchain as block #277316,
|
||||
|
Loading…
Reference in New Issue
Block a user