A block header is perhaps the most important part of the information that gets recorded in a blockchain ledger.
Although every chain has different information in the header of their blocks, there are a few pieces of information that are nearly always present.
- Chain Version
- Timestamp
- Previous Block Hash
- Merkle Root Hash
- Current Target Difficulty
- Nonce
What is listed above, is actually the exact header used by Bitcoin blockchain and it is 80 bytes if data.
The chain version is used to identify various information such as what wallet address format to use, what fields are valid in a block, and the likes. If anything changes in the future a new version can be used to distinguish between the old and the new.
The timestamp is the current time when the block was mined. Obviously timestamps are important for countless reasons. I don't need to explain that.
The previous block hash is used to tie the last block that was mined to the current block that was mined. This is why it is a block chain because each block is chained to the last by adding that blocks hash,
The merkle root hash is a little difficult to explain. Every hash of every transaction in a block, is paired with the next transaction. If an odd number of transactions exist the last hash is paired with itself. These pairs are then rehashed. Then the process start of pairing the hashes again. This is done until only a single hash remains. This is called the merkle root hash. Its purpose is to ensure that no one can remove a transaction, re-order a transaction, or add a transaction to an already validated block (for example a malicious mining node).
The current target difficulty tells us how difficult it was for the miner to mine the current block in question - meaning the block will always have a hash value that is less than the current difficulty level.
The nonce is just a random number that increases each time a miner attempts to find a valid block until one is found. Its a piece of ever changing data. The larger the nonce the longer it took to mining node to find the block.
At Contractless, we changed this entirely. We did not record a version, instead preferring to buiold this into the source and RPC but not the chain itself.
That recduced our header from 80 bytes to 76 bytes.
We also used a torrent based system for syncing that provides a layer of security that doesn't exist in other chains. It can perform tyhe same function that the merkle hash performs in verifying the order of transactions, that no new transactions are added, and that no transactions are removed. This means countractless did not need a merkle root hash at all.
Our 76 bytes are now down to 44 bytes.
We also changed the Currency Target Difficulty to Next Target Difficulty.
With our Difficulty Formula the current block calculates the next block difficulty. In doing this, every block is tied to the previous block through its hash and is tied to the next block through its difficulty.
The next block difficulty is recalculated every single time a block gets mined. Its calculation is based on the previous blocks time stamp, the current block timestamp, the difference in between those times, and its evaluation based on our target block time of between 10 and 20 seconds.
So our block header only contains 4 pieces of data making it the worlds smallest block header.
The only thing I want to mention at this point is when talking about the previous block hash, we only use the hashing function on the header itself. We do not add a hash of the entire block as each transaction is already hashed and signed. So we tie each header hash to the previous header hash.
In a future post I will explain more about the actual mining process and how this change in the header drastically affects other aspects of the blockchain but for now this explains the data in the block header as well as how we calculate the difficulty (the code is nicely commented so anyone can understand it even if they don't code).