- snip -
So, am I correct in thinking that these "complex mathematical equations" that miners solve with their machines are actually the resolution of all the transactions going through the (closed) system? Which would make sense actually....the more people using it, the more Bitcoin being moved, the more complex the ledger gets so the harder it becomes to resolve, or tally up....
- snip -
No.
(See bottom of post for tl;dr
First, each miner (or mining pool) gathers up a group of unconfirmed transactions and places them in order. The solo miner (or mining pool) gets to choose which transactions (if any) they want to confirm. It doesn't matter if they put together 1000 transactions or 0 transactions, the result is still a valid block as long as they choose valid transactions and put them in a valid order. Each set of ordered transactions is called a "block" of transactions. So there are potentially millions of different unconfirmed blocks being worked on simultaneously. The miners and mining pools have a financial incentive to include transactions in their block if the transaction pays a transaction fee, because the miner (or pool) gets to keep the transaction fees of all the transactions they include in their block if they successfully "solve" the block (we'll get into "solving" a block in a bit). To receive these transaction fees, one special transaction is allowed to be included in the block. This special transaction has no input values, and the sum of the output values is allowed to be less than or equal to the current block subsidy (25 BTC right now) plus the sum of all transaction fees of all transactions in the block.
Next, each miner (or mining pool) creates an 80 byte header for their block of transactions. This is called a "block header". They use a hashing process to generate a unique number (called a merkle root) for their block of transactions, and they include this merkle root in the header. You can't change any information in the block of transactions at all without it resulting in a different merkle root. Therefore, it can be easily verified that a list of transactions that is transmitted with a block header is the EXACT correct list of transactions in the EXACT correct order for that block header. The miner (or pool) must also include a hash of the most recently solved block in their block header. This "links" the block they are working on to the previous block and provides an indication of the order of the blocks, creating a chain like structure (called "the blockchain"). Some additional useful information is included in the block header (such as a timestamp, a version number, and the current difficulty target). The block header also has a 4 byte field called a "nonce". We'll get into the purpose of the "nonce" next.
Now the solo miner calculates a SHA256 hash of the block header. This results in a 256 bit (32 byte) value between 0 and 1.1579X10
77. They then calculate a SHA256 hash of that value, which results in a different 256 bit (32 byte) value between 0 and 1.1579X10
77. If the block was created by a mining pool, then they will create many different blocks and send the block headers off to all the pool participants. The pool participants will perform the two SHA256 hashes themselves and check for themselves to see if their resulting hash value is low enough.
If that second value is less than the current target difficulty, then the block is "solved", and the miner can broadcast their block to all their peers. Every peer that received a copy of the "solved" block verifies that everything is correct (valid transactions, in a valid order, with a valid merkle rook, block header has a valid previous block hash, block header hashes to a value lower than the current target difficulty, special transaction outputs don't exceed sum of block subsidy and transaction fees, etc). If the solved block passes all validity tests, then the peers broadcast the block to all of their connected peers. Those peers also verify that everything is correct, before broadcasting it to all their connected peers, and so on until the entire network has received the solved block and verified for themselves that the block is valid.
If that second value is NOT less than the current target difficulty, then the "nonce" serves it's purpose. The solo miner (or pool participant) increments the nonce from 0 to 1 (which is a change to the block header) and then performs the two SHA256 hashes on the new block header. They check to see if the new resulting value is lower than the difficulty target. If it is not, then they increment the nonce, and try again. They continue this until all 4294967296 possible nonce values have been tried. If after trying all possible nonce values the miner (or pool participant) has not found a SHA256 value that is lower than the target difficulty, then the solo miner (or mining pool) changes information in their list of transactions and computes the resulting new merkle root (which is a change to the block header). Then they start over with a nonce of 0 and try again. This process is repeated by all mining equipment until someone is lucky enough to find a SHA256 hash value that is lower than the target difficulty. Then they broadcast their "solved" block (see previous paragraph).
The "difficulty" is a number somewhere between 0 and 1.1579X10
77. The protocol automatically adjusts the difficulty every 2016 blocks. If the current block height is a multiple of 2016 and the difference in timestamps between the current block and the block 2106 blocks ago is less than 20160 minutes, then blocks have been being solved too fast, and the difficulty target is reduced to a lower value to make less likely to find a SHA256 hash that is less than the target difficulty. If the difference in timestamps is greater than 20160 minutes, then the blocks are being solved too slow, and the difficulty target is increased to a higher value to make it more likely to find a SHA256 hash that is less than the target difficulty.
Since EVERY node on the entire network validates EVERYTHING about the blocks it receives before it accepts or re-broadcasts the block, it is impossible for anyone to send a block that has invalid transactions, or that pays themselves a block reward that is too high, or broadcast a block that doesn't result in a double-SHA256 hash that is lower than the current target difficulty.
tl;dr:
That's it. That's basically the mining process. There are a few technical details that I've left out or simplified a bit (for example, I didn't explain how to calculate a SHA256 hash, you can look that up on wikipedia if you're interested), the point is that
the description of "complex mathematical equations" is a very misleading way of explaining what is happening. It's actually a very simple and very fast SHA256 calculation. It just that the target value is low enough that the SHA256 has to be calculated on MANY different block headers until someone stumbles upon a resulting value that is lower than the target. As of the current difficulty cycle, it requires on average about 213,294,220,000,000,000,000 double-SHA256 hash attempts before someone is lucky enough to stumble upon a hash value that is low enough.