In the current mining algorithm, a miner will:
1. collect an arbitrary number of unprocessed transactions from thetheir mempool,
Fixed that for you. Using the phrase "the mempool" makes it sound like there is just one mempool that everyone shares. Actually, each full node has its own mempool which may be significatnly different from any other node's mempool.
2. sort the transactions according to their time stamps,
Transactions do not have timestamps. The transactions can be placed in the block in any order at all.
3. hash them in pairs to calculate the Merkle root,
4. hash the Merkle root with the last block hash,
5. hash the result with the nonce,
A Merkle root is calculated from the transaction list.
Next, a block header is built. The block header is 80 bytes long and contains:
- A 4 byte version number
- The 32 byte hash of the previous block in the blockchain
- The 32 byte Merkle Root of the transactions selected for this block
- A 4 byte timestamp
- 4 bytes representing the current difficulty target
- A 4 byte nonce
This 80 byte header is then hashed twice using SHA256 to calculate the hash of this block.
6. compare the size of the result with the target size of the difficulty level.
7. If the hash is too big, increment the nonce and try again.
8. If the hash fits, publish the block and repeat.
Generally correct, however it is possible to try all possible nonce values and still not find a solution. If this happens, then something else in the header must be modified to continue trying. Some possible things the mining pool (or solo miner) can modify are:
- The timestamp.
- The Merkle Root
There are a few ways to modify the Merkle Root. Such as:
- Change the order of transactions in the list
- Modify the coinbase transaction with extraneous information (the transaction that pays the block reward)
- Add or remove transactions from the list
(after which the Merkle Root would be re-calcualted)
But it doesn't end there, now there are multiple blocks on different
branches of the blockchain competing for inclusion into the main trunk.
Typically, there aren't any competing blocks. Typically, one block is solved, and is broadcast. As each solo miner (or mining pool) receives the solved block, they abandon the block they are currently working on and immediately begin a new block.
Occasionally, there may be 2 or three blocks that are all solved so close together in time that different parts of the network hear about different blocks first. In that case each solo miner (or mining pool) chooses the block that they hear about first and build on top of that.
Now what would be the consequences of omitting steps 6 to 8?
1. Eliminate the size requirement of the block hash.
2. Add the simple rule that the block with the smallest hash always wins.
Then anyone can completely destroy a blockchain by simply mining an old block with a lower hash that it was originally included with. Once they do that, all blocks after the block that they re-mined become instantly invalid and all confirmations are lost.
So the new mining algorithm would be:
1. collect an arbitrary number of unprocessed transactions from the mempool,
2. sort the transactions according to their time stamps,
3. hash them in pairs to calculate the Merkle root,
4. hash the Merkle root with the last block hash,
5. hash the result with the nonce as many times as you want,
6. publish the block and repeat.
This would give miners the choice of how much work to do on each block-
whether to mine more on each block or mine less on more blocks.
If miners chose to mine more on each block, the block difficulty increases while the block rate decreases.
If miners chose to mine less on more blocks, the block difficulty decreases while the block rate increases.
This isn't going to work. As a miner, I'd have no way of knowing what height to mine at. I don't know which earlier blocks are at a difficulty where all miners other miners have moved on, and which blocks are still being replaced. Any time a block is replaced, all blocks that came after it are also invalid.
Consequences:
Complete disaster and an unusable system.
The principle of mining is that whoever has the most resources should NOT be able to decide and secure the network.
Fixed that for you.
As long as the largest miner has less hash power than the entire rest of the world combined, Bitcoin's proof-of-work blockchain is decentralized. It is not possible for the "whoever has the most resources" to "decide" or control the network.
If you were to be able to generate a block with little hashpower, it would be pointless for anyone to wait for 6 confirmations.
It is currently possible for an individual with only 1 hash per minute hashpower to "generate a block" (as long as they get lucky and one of their early attempts is lower than the target value. Having more hashpower doesn't guarantee that you'll win the next block, it just increases your odds.
here is the problem, how are you going to stop a miner (or basically any random person with a CPU) to choose the smallest target possible and flood the network will millions of blocks per second.
Correct. An attacker would generate millions of hashes for a block and then sort them from lowest to highest. Then they would publish each of those blocks a few microseconds apart in order. Every other miner/node on the network would have to spend all of their time receiving, verifying, and re-broadcasting all those blocks. The network would be flooded with constant block relaying, and would become unusable.