5 ms·
Mining a block is just brute-forcing until you find a SHA hash that is small enough. Or until someone else mines a block, in which case you have to start again
by jcbrand 4y ago
Mining a block is just brute-forcing until you find a SHA hash that is small enough.
Or until someone else mines a block, in which case you have to start again from scratch.
It's not some sort of race to find a block, and as soon as someone finds a block everyone has to start again.
If miner A and miner B are both mining, and miner A mines a block, then miner B has to start from scratch with a new block because in all likelihood miner B was including transactions in his un-mined block that are now already mined by miner A.
So yes, as soon as someone finds a block, everyone has to start again and that's why mining is in fact a race to find a block.
If I give you £100 every time you find a random number that satisfies some property, the amount of £100s you get is independent of how many other people are making money with the same scheme.
This is not how Bitcoin mining works. The "random number that satisfies some property" is dependent on the transactions included in your block, and if other miners include those transactions that are mined in blocks before yours, then you have to start from scratch.
- jstanley 4y agoNo, I still think you don't get it. You seem to think that mining a block is something that takes a long time, and that work is wasted if someone else managed to mine a block first. Mining a block takes an incredibly short amount of time, but pays off with incredibly low probability. You have to do lots of attempts to find a block. You don't spend 10 minutes trying to compute one hash, and then throw up your hands in disappointment if it wasn't low enough. > Or until someone else mines a block, in which case you have to start again from scratch. You always start again from scratch after every single hash. Billions of times per second. You're no more likely to find a block on your millionth hash than on your first. The work doesn't add up. Each hash you try is either low enough or it's not, and either way you try again. > The "random number that satisfies some property" is dependent on the transactions included in your block, and if other miners include those transactions that are mined in blocks before yours, then you have to start from scratch. That's correct, but you only wasted a small amount of time during the overlap between the other miner finding a new block and you hearing about it.
- jcbrand 4y agoThe random number that you're trying to find by means of (yes, repeatedly) hashing, is dependent on the transactions in your block (which are hashed together in a Merkle tree). Not only that, but the number you're trying to hash is also dependent on the previous block (hence it being called a blockchain). So as soon as another miner mines a block, the block you're mining immediately becomes invalid. For two reasons, the block height of your block is now too low (it has the wrong parent) and it (most likely) includes already mined transactions. So even if you happened to still mine your current block, it will be rejected by the nodes in the network for having the wrong block height and for including already mined transactions. So, you have to assemble a new block, which uses the latest mined block as parent and you have to include new transactions from the mempool. There's a cost to doing this, it takes time away from the actual hashing, which is what I meant with "starting from scratch". For the reasons outlined above, you're not mining blocks independently from everyone else.