Block structure
Field |
Description |
Size |
Magic no |
value always 0xD9B4BEF9 |
4 bytes |
Blocksize |
number of bytes following up to end of block |
4 bytes |
Blockheader |
consists of 6 items |
80 bytes |
Transaction counter |
positive integer VI = VarInt
|
1 - 9 bytes |
transactions |
the (non empty) list of transactions |
-many transactions |
BLOCKHEADER :
Version |
Block version number |
You upgrade the software and it specifies a new version |
4 |
hashPrevBlock |
256-bit hash of the previous block header |
A new block comes in |
32 |
hashMerkleRoot |
256-bit hash based on all of the transactions in the block |
A transaction is accepted |
32 |
Time |
Current block timestamp as seconds since 1970-01-01T00:00 UTC |
Every few seconds |
4 |
Bits |
Current target in compact format |
The difficulty is adjusted |
4 |
Nonce |
32-bit number (starts at 0) |
A hash is tried (increments) |
4 |
Description
Each block contains, among other things, the current time, a record of some or all recent transactions, and a reference to the block that came immediately before it. It also contains an answer to a difficult-to-solve mathematical puzzle - the answer to which is unique to each block. New blocks cannot be submitted to the network without the correct answer - the process of “mining” is essentially the process of competing to be the next to find the answer that “solves” the current block. The mathematical problem in each block is extremely difficult to solve, but once a valid solution is found, it is very easy for the rest of the network to confirm that the solution is correct. There are multiple valid solutions for any given block - only one of the solutions needs to be found for the block to be solved.
Because there is a reward of brand new bitcoins for solving each block, every block also contains a record of which Bitcoin addresses or scripts are entitled to receive the reward. This record is known as a generation transaction, or a coinbase transaction, and is always the first transaction appearing in every block. The number of Bitcoins generated per block starts at 50 and is halved every 210,000 blocks (about four years).
Bitcoin transactions are broadcast to the network by the sender, and all peers trying to solve blocks collect the transaction records and add them to the block they are working to solve. Miners get incentive to include transactions in their blocks because of attached transaction fees.
The difficulty of the mathematical problem is automatically adjusted by the network, such that it targets a goal of solving an average of 6 blocks per hour. Every 2016 blocks (solved in about two weeks), all Bitcoin clients compare the actual number created with this 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.
Because each block contains a reference to the prior block, the collection of all blocks in existence can be said to form a chain. However, it’s possible for the chain to have temporary splits - for example, if two miners arrive at two different valid solutions for the same block at the same time, unbeknownst to one another. The peer-to-peer network is designed to resolve these splits within a short period of time, so that only one branch of the chain survives.
The client accepts the ‘longest’ chain of blocks as valid. The ‘length’ of the entire block chain refers to the chain with the most combined difficulty, not the one with the most blocks. This prevents someone from forking the chain and creating a large number of low-difficulty blocks, and having it accepted by the network as ‘longest’.
https://en.bitcoin.it/wiki/Block