"Can you explain the mining process in detail?"
"When are hashes calculated? How are the transactions selected from the mempool?"
"Does the client software automatically confirm the correct blocks?"
All right, Leonard, let me try [to explain].
[Imagine] you are running a mining node connected to an ASIC, a hardware hashing machine.
Usually, that is a USB-connected device.
Of course, more advanced ASICs are directly connected [via an] Ethernet [port], but let's keep it simple for now.
You have a computer running a Bitcoin Core full node. It is connected to the peer-to-peer network.
It is receiving transactions and blocks as they [are broadcast by other nodes in the network].
[Your node] has this mining ASIC connected over USB. It can send [the ASIC] a candidate block and say,
"Go hash this [block header] and find a nonce that makes it valid."
"Calculate the proof-of-work for me."
The mining node on the miner's computer will be receiving transactions and blocks.
It will wait until it receives a [new] valid block, which means that somebody else won the competition.
Somebody else managed to mine a [valid] block. As soon as it has received a [new] valid block...
There is some nuance there, but let's say it just received Block #10.
[The mining node] knows that someone won the competition to construct Block #10.
The race to construct Block #11 [has started].
[The mining node must first] validate that block.
If you build on a block that is invalid, you will be wasting time, energy, and hash power.
The first thing a miner must do is validate the [last] block, [before] they construct a new candidate block.
The mining software will construct a candidate block. First, it will construct an empty block (no transactions).
The block header [of this candidate block] will [contain] the hash of the previous block.
So, Block #10 which [was just mined]? A hash of that block will go in your new candidate block.
That is the "parent." Great. Now put a timestamp in there.
Now we have the basis of a candidate block.
It doesn't have any transactions in it [yet]. Next, I will add one transaction [to the block].
That is called the coinbase transaction, where you pay yourself 12.5 bitcoin as a reward [for the proof-of-work].
You [essentially] write myself a check for 12.5 bitcoin, payable to your own Bitcoin address.
[Alternatively, you could be in a mining pool, but] let's keep this very simple. You are doing this solo.
So, you put one coinbase transaction in the block and calculate the Merkle root, a hash of that transaction;
You will put that in the block header. Now it is a valid block. That is all you need, one coinbase transaction.
You have a valid block header and a valid Merkle root, which we will talk about in a subsequent section.
You have a timestamp and a hash of the previous block, so that is a valid block header.
At this point, you can send [the candidate block] to your mining equipment so it can get a head start.
Over USB, your [mining node] sends [the candidate block] to your mining hardware and says,
"Find me an nonce that works for this difficulty [target]." The mining hardware will start hashing and hashing,
trying as many nonces per second as it possibly can.
This [candidate block] only contains the coinbase transaction, so you are not earning any fees [yet],
but you can add transactions to earn fees.
[Your mining node] will then look into the mempool and start picking transactions.
Every [miner] can use a different strategy for taking transactions from the mempool.
But obviously, if I am smart about it, I would want to maximize my income.
[Blocks] have a limited amount of space, so you would probably pick the transactions...
that pay the most fee [for the least amount of space], meaning the highest level of satoshis per byte.
Bytes are [how you measure the space being] used up in the block, and if I can get the maximum fee per byte,
then I will earn the maximum fee possible for this one-megabyte block [of transactions].
There are some interesting calculations to be made with the SegWit discount, etc. but let's ignore that for [now].
Let's say you have a software program that just sorts transactions in the mempool by their size and fee,
[ranked by] the highest satoshi per byte.
Well, that will be the first transaction in your block, [as you] start stuffing transactions into the block...
until the block is full, and that is it.
Now you send the new header, with a different Merkle root [due to] more transactions than just the coinbase,
to your mining hardware, which will start hashing to find the proof-of-work.
At some point, let's say your mining hardware finds a nonce that produces valid proof-of-work.
It sends that result to your node, which broadcasts it to the [rest of the] network, and everyone sees the block.
[They verify that] Block #11 has indeed been found and it is valid.
[You] made sure all transactions [included in the block] are valid, [because you] wouldn't want to waste time.
[Everyone makes] sure that every transaction was properly validated and wasn't double-spending,
with the right amount of inputs and outputs, the correct scripts, etc.
[Your] block is valid. As soon as everybody else sees it, they will start working on Block #12.
Block #11 is now part of history. One hundred blocks later, you can spend the 12.5 bitcoin from the coinbase.
That is basically a summary of how [Bitcoin] mining works, from the perspective of a miner.
One little subtle detail there: as soon as I had a valid block, [even] with just a coinbase transaction,
I didn't put transactions in it [right away].
I sent that empty block with just the coinbase [transaction] to the mining hardware [to work on].
While the node was picking and validating transactions from the mempool, [the ASIC]...
was already mining an empty block.
There is a reason for that. It might take [the ASIC a few seconds longer] to validate the transactions...
I want to put into the block, to validate that the previous block and its transactions were also correct.
During that time, there is no reason for the mining hardware to just sit there doing nothing.
Those four or five seconds could be enough time for it to [get lucky] and find a valid nonce for proof-of-work.
[Miners] want the mining hardware working all the time, which is why you will sometimes see empty blocks.
They pop up every now and then. You will see a block that only has a coinbase transaction.
Usually it comes very shortly after a block was found.
You will see two [close in succession], where the second one will be empty.
That happens because the hash power was not idle while the node was finding and validating transactions...
to put into the candidate block, and that's fine.
In fact, it is great. That extra hashing power adds security to the Bitcoin network.
It increases the cumulative difficulty of the chain. It doesn't [generally] take away from the capacity...
of the network because another block might be found in the next few seconds [anyway].
There is no problem with that, it is a normal part of the network.
"If my node finds a block, is the verification automatic, or does a [real] person need to do manual work...
to enable it to go through?"
No. This is entirely automated. There is no manual process whatsoever [beyond racking the hardware].
The software mines, validates, verifies, and propagates. There is no human involved at all.
It would be impossible to have a human involved due to the [processing] speeds we're talking about.
A delay of milliseconds can cost hundreds of thousands of dollars per day. Absolutely not.
No people are involved in this, [except to rack the hardware and maintain the facilities].
As a person, you choose what software to run, and by extension choose what consensus rules to follow.
You choose what policies the mining program will follow. Once you have made those choices,
you run [the software] and that is it.
"Some say that a few miners control 70% of the hash power. Is this centralization?"
Yes, that would be centralization on one axis of the [Bitcoin] system.
Though it is not really clear that a few miners control 70% of the hash power.
I think that is probably an over-estimation. It is possible some miners control more than 50%...
of the hash power, and this is a problem.
It is a form of centralization, but I think it is a temporary phenomenon [that stems from]...
the very rapid performance increases from CPU to GPU to FPGA to 40-nanometer ASICS,
and all the way down to 12-nanometer ASICS, which we saw [develop] over the past nine years.
That rapid increase in performance [meant that] miners who controlled [the fabrication]...
of silicon chips gained an enormous advantage.
But that enormous increase in performance is over.
You cannot keep going down from 12-nanometer [at the same pace]; that is now the cutting-edge technology...
available in fabrication, which means a more level playing field has arrived.
We are likely to see less centralization of mining over time because other forces,
such as operational risks with geographic concentration, political risks, electricity availability risk, natural disaster,
and all these other risks, work against centralization.
If you have a hundred thousand miners in a warehouse, pulling ten megawatts of electricity in one region,
you have many economy-of-scale advantages, but one lightning strike, one political maneuver,
one additional tax, one fire or flood in your warehouse, one electrical interruption, and you [can] lose everything.
There are disadvantages to having everything concentrated in one place.
The question is, will the forces of decentralization versus the forces of centralization balance out?
That is a very difficult question to answer.
Just because Bitcoin [may be] centralized in one area, doesn't mean it is not decentralized in other areas.
Decentralization is not a 'yes' / 'no' question. You can't really ask, "Is this decentralized or not?"
You should think of it as a multi-dimensional scale.
It could be somewhat centralized in some aspects of the system.
The question is, is this system more decentralized on more aspects than any other comparable system?
I would say Bitcoin is the most decentralized, at-scale payment system that exists in the world,
in several different aspects.
I think that Bitcoin is likely to [become] more decentralized over time. We will see [what happens].