mocacinno
Legendary
Offline
Activity: 3556
Merit: 5187
https://merel.mobi => buy facemasks with BTC/LTC
|
|
September 26, 2018, 01:13:02 PM Last edit: September 26, 2018, 01:28:13 PM by mocacinno |
|
OK, time to set the record straight (again).
As usual, it seems like a thread about mining has been derailed, and the amount of misinformation is starting to grow. I'm not going to point fingers here, i'm just going to try to give a newbie-friendly explanation about mining, omitting a lot of technicality's that would make it hard for somebody to understand what's going on.
Bitcoin is built on top of the blockchain technology. A blockchain is basically a chain of "blocks". You can see each block as a datafile. This datafile contains a number of transactions. In bitcoin, the size of the datafile is limited. A block also has a header. This header is built like this: version - previous block header hash - merkle root hash - time - nbits - nonce
Some of these fields in the block header aren't interesting for my story... But the following fields are:
previous block header hash => because the header of a new valid block contains the hash of the header of a the previous block, the blocks actually make a "chain" (the blockchain). You can't just remove a block from the blockchain, because the next block actually uses the hash of this removed block in it's own header... So throwing away a block would make the next blocks invalid.
merkle root hash => i won't go into detail about merkle trees, but basically if you change any transaction in a block, the hash of the merkle root will change, so there is no way to meddle with transactions in a block without changing the block header
nonce => an increment... Important for mining.
Now, what is mining? A miner runs a normal node, this node builds an utxo set of all unspent outputs that can be spent in new transactions. It also fills it's mempool with all new transactions that are being broadcasted. When a miner receives a new block, he immediately checks this block for errors, and if everything is ok, he removes all spent unspent outputs from it's utxo set, adds all new unspent outputs to his utxo set and removes all transactions in the valid block from his mempool. He now puts together transactions from his mempool to form a new block, and creates a new block header... Then, his ASIC starts to increment the nonce, leaving the rest of the block header static. For each nonce increment, the ASIC takes the sha256 hash of the sha256 hash of the new block header. IF the miner finds a nonce for which the sha256d hash is UNDER the current target, he found a valid block, and he can broadcast this block to all other nodes. At this point, all miners will re-start the process of utxo and mempool manipulations, building a new block, incrementing nonce,...
A miner can add a coinbase reward of 12,5 BTC (halving every 210.000 blocks). He can also add the sum of the fees of the transactions he has added to the block he's trying to solve. So the more fee per byte of transaction data (limited blocksize, remember), the more interesting it is to add a certain transaction.
The target is changed when the difficulty is changed. Every 2016 blocks, the algorithm calculates how much the average time between 2 valid blocks was. If the time between two blocks was bigger than 10 minutes, the difficulty gets adjusted downwards (and the target goes upwards making it easyer to find a valid block) and vice versa. This mechanism makes sure the average time between 2 blocks is ~10 minutes. At the moment, the difficulty is soooooo high (and the target is soooooo low), the odds of you finding a valid block by yourself is allmost nonexistent (especially if you don't own hardware that was built for the sole purpose of bitcoin mining => this hardware is called an ASIC). People have joined together in pools. A pool is a way for many (sometimes thousands) of small miners trying to solve a block together. If a member of the pool solves a block, the coinbase reward gets distributed fairly amongst all members of the pool.
If you have other questions, try the forum's search function.... If you can't find your answer: don't hesistate to ask.
|