Bitcoin mining it’s a descentralized computational process that serves 2 purposes: to confirm transactions in a trustful manner when enough computational power (effort) is devoted to the block, and to find new Bitcoins in each block.
What is a block?
A block is where the transaction data of the Bitcoin network is recorded. Each block contains a record of some or all recent transactions and a reference to the block that came before. It also contains an answer to a difficult-to-solve mathematical puzzle which is unique to each block. This new blocks cannot be submitted to the network (Blockchain) without the correct answer, the miners compete to be the next to find the answer that “solves” the current block.
There is a reward of brand new Bitcoins for solving each block, every block contains a record of Bitcoin addresses entitled to receive the reward. This record is known as a generation transaction or coinbase transaction and it is always the first transaction appearing in every block. Miners also get incentive to include transactions in their blocks because of the attached transtaction fees.
The number of Bitcoins generated per block started at 50 and is halved to half every 210,000 blocks which would be every 4 years.
The network adjusts the difficulty of the mathematical problem automatically, such that it targets a goal of solving an average of 6 blocks per hour. Every 2016 blocks (solved in about two weeks), the Bitcoin network compare the actual number of blocks created with the goal and modify the target by the percentage that it varied. The network comes to a consensus and automatically increases or decreases the difficulty of generating blocks.
What is a block header in Bitcoin?
The main way of identifying a block in the blockchain is via its block header hash.
The block header hash is calculated by running the block header through the SHA256 algorithm twice.
A block header hash is not sent through the network but instead is calculated by each node as part of the verification process of each block.
The block header data is shown in the table below.
The Bitcoin version number is used to keep track of upgrades and changes in the protocol. The previous block header hash is the linkage into the previous block and secures the chain.
The timestamp is the number of seconds since the first of January 1970 and the difficulty target of the block is the number of zeroes that must be found when hashing the block header in order to meet the required level of proof of work to maintain the block time at 10 minutes.
The nonce is the value that is altered by the miners to try different permutations to archieve the difficulty level required – the nonce has been appended by the extra nonce function which sits in the coinbase transaction – or the first transaction of the Merkle root signifying who to pay the block reward to – an extra counter to add permutations to as the nonce number can be used well within a second by mining equipment.
What is Proof-of-Work?
It’s a method to ensure that the information (this would be the new block) was difficult enough to be made (costly, time-consuming). For more information click here.
How does a Bitcoin node verify a transaction?
A node will look at a transaction as it arrives and then run a series of checks to verify it.
Each node builds its own transaction pool, which are mostly the same.
The conditions can change and evolve over time and a present list can be checked through the AcceptToMemoryPool, CheckTransaction and Checkinputs functions in the Bitcoin client.
1. Transactions syntax and data structure are correct.
2. Input and outputs have values.
3. Transaction is less than the block size of 1 MB.
4. Values must be more than 0 and less than 21 million.
5. None of the inputs have a hash that is equal to 0.
6. Locktime is less than the maximum allowed number.
7. Transaction size is greater than or equal to 100 bytes.
8. Number of signatures is less than the signatute limit.
9. Unlocking script can only push numbers onto the stack.
10. Locking script must match isstandard format.
11. A matching transaction must exist.
12. If a transaction is missing move the transaction to the orphan transaction pool.
13. If the transaction is a coinbase transaction then it must have a maturity of 100 confirmations.
14. For each input the output must exist and not have been spent.
15. Check that each input value is in the required range.
16. Reject if the input value is less than the output value.
17. Reject if the transaction value is to low to get into an empty block.
18. Unlocking scripts for each input must be verified against the output locking scripts.