Bitcoin Blocks
This lecture talks about what bitcoin blocks are actually composed of in respect to the innards and what the code version may look like. If you’re wondering, it is transactions but it’s not that simple. The transaction are stored in an efficient fashion. They can be visualized pretty easily from a variety of sources.
Questions answered in this Post:
- Why does bitcoin bundle transactions?
- What are the two major data structures that the bitcoin block chain is composed with? Describe them.
- Where can you observe block contents?
- What is a coin base transaction
Why bundle transactions together?
- single unit of work for miners
- limit length of hash-chain of blocks which equals faster verification of history
- too much overhead would be created if you did it per transaction
- allow the hashed chain for blocks to be shorter because you only need one block for multiple transactions
Bitcoin blockchain has two data structures: hash chain of blocks and a merkle tree.
First, the bitcoin block structure contains a hash chain of blocks. A hash chain is that list of blocks where each block also contains a reference to the block previous to it.
A block contains three items:
- block header
- hash pointer to transaction data
- hash pointer to the previous block in the sequence
At this point, even though you don’t know what the hash of the transaction data completely refers to, this structure should sound just like a linked list. When I say hash of some transaction data, I’m referring to that second data structure called a merkle tree. The merkle tree contains all the transactions included within the block. Merkle tree as you might guess looks like a tree specifically a binary tree. The tree contains all the transactions hashed in the leaves. Each node above that contains the hash of the two children that gets concatenated together. The root of the tree, the final node that combines the left and right children is the root hash. This is called the “merkle root”. The merkle root gets stamped on the block header.
I think of the Merkle tree as an efficient transaction storage tree that utilizes hash functions and allows one to verify if a transaction is within the block (tree) in just log(n) where n is the number of transactions in the block. Also, once the tree is computed, it’s easy to tell whether the data has been tampered with.
Right so now that we know what the structure looks like, what do you see if you looked at the written blocks. As I mentioned earlier, a block contains three components: block header, hash pointer to transaction data, and a hash pointer to the previous block in the sequence.
Sample block header
"hash": "000001aad2",
"ver"": 2.
"prev_block": 00001a3",
"time": 139.
"bits": 411900,
"nonce": 459841,
"mrkl_root": "89776..."
all the transaction data
"mrkl_root": "89776...",
"n_tx":354,
"size" 181520,
"tx": [
]
"mrkl_tree":[]
}
If you go to blockchain.info, you can easily see records of these blocks. There are quite a few places to view bitcoin blocks. I’ve listed a few more below.
This CryptoCoinNews article site teaches you to code a quick Python script to write your own block parser. It’s sparse without any UI but it’ll get the job done. Definitely give kudos to tenthirtyone.
Here’s the link to block that I’m going to explain further
You can see that this is block numbered 456842. As mentioned previous the header contains the hash. Also, it contains the previous block hash linked as well as the Merkle Root hash.
That’s just the beginning looking at this block since block chain pulls out all the components. The number of transactions is 202 transactions where the nonce was 3378386187. Remember the nonce was that small target value that the miner found which enabled them to write the next block.
When I looked at these there were a few values that were interesting specifically block reward and the first transaction listed.
What is a block reward?
A block reward is how much a miner gets getting the privilege to publish the next block. This value is $14,737.28. How was that value calculated? Currently the number of bitcoin a miner earns for publishing a block is 12 BTC. I looked at Bitcoin block half which shows the current block reward and the next time the change is going to occur.
Why does this transaction have the message “No Inputs(Newly Generated Coins”?
Ok, that sounds like a dumb question. It clearly indicates that this is a newly generated coin, which not surprising is called a coinbase transaction.
Unique characteristics of the coinbase transaction
- has a single input and single output
- input doesn’t redeem a previous output and thus contains a null hash pointer
- value is fixed and halves every 210,000 blocks
- special arbitrary parameter where one can put anything