СПРАВОЧНЫЙ ЦЕНТР
Basics of Blockchain (1) – Blocks
Опубликовать 2022-01-14
What Is a Block in Blockchain?
A block is essentially a block of data. The data block contains a list of transactions and is used to verify the validity of the transaction information and then generates the next block. The blockchain data structure is sequentially linked by blocks and is based on certain rules. A block is the basic unit of a blockchain network.
Block Structure
Simply put, a block contains a block header and the main body of the block. The block header contains a set of metadata; the main body is a series of transaction lists. To put it simply, a block = a block header + transaction data. Please see the chart below for details:
Block Header
A block head is an 80-byte long string, accounting for a small part of the whole block. The metadata it contains are divided into six parts: the version, previous block hash, Merkle root, timestamp, difficulty Bits, and nonce.
Field | Byte | Note |
The version | 4 bytes | The version of the block, the verification rules abided by the block. |
Previous block hash | 32 bytes | The hash of the last block, obtained using SHA 256 algorithm. |
Merkle root | 32 bytes | The hash of all the hashes of all the transactions in the block |
Timestamp | 4 bytes | The details of the exact time when a block is created in the blockchain. |
Bits | 4 bytes | The difficulty targets that miners work with to add a block to the blockchain using the PoW algorithm. |
Nonce | 4 bytes | A random number meeting the difficulty target of the PoW algorithm. |
1. Version
A block version is the version of a block. It’s used to identify the transaction version and the verification rules referenced by the transactions in the block. As the way we understand the Android 1.0, a block has its own version.
2. Previous block hash
The previous block hash refers to the hash value calculated from the block header data of the previous block, also known as the "hash of its parent block." It enables each newly generated block to be linked behind the previous block sequentially. According to this rule, the current block can be traced all the way back to the genesis block.
3. Merkle Root
Each block in the blockchain contains all of the transactions generated in the block, which are represented as a Merkle Tree. A Merkle Tree is a tree-like data structure used to sum up all the transactions in a block and generate a digital signature for each of the transaction hashes, namely the Merkle Root. The specific calculation method is as follows:
(1) Each Transaction ID (TxID) or Transaction Hash of the transaction data of a block will be put into pairs and hashed again using the SHA 256 algorithm to get a hash.
(2) If the hash is odd, a copy will be made to generate an even number before rehashing.
(3) These processes of (1) and (2) are repeated till only a hash is generated, which is the Merkle Root.
4. Timestamp
A timestamp is a measure of the exact time when a block is created in the blockchain, which will be accurate to second. It ensures that the blocks in the blockchain are arranged in chronological order.
5. Bits
Bits are the compressed form of the mining difficulty target. The difficulty target is a mechanism set up by the Bitcoin blockchain network to adjust the difficulty of mining to ensure that the mining speed is about 10 minutes. The difficulty level is reevaluated after every 2016 blocks (every two weeks).
6. Nonce
A nonce refers to a random number matching the difficulty target of the PoW algorithm, which is also known as the “mining field”. The node needs to hash the block head data continuously until a block header hash that is lower than (or equal to) the defined target is found.
The Main Body of the Block
1. Coinbase transaction
A Coinbase transaction is the first transaction in each block, which is used to reward miners to package the transaction into the block. The rewards are divided into two parts: block reward + the sum of transaction fees other than Coinbase transaction fees.
2. Transaction Structure
There are two kinds of Bitcoin transaction structures, namely, the transaction structure defined in the Bitcoin White Paper and the new Segregated Witness transaction structure. The difference between the two is that the transaction structure defined in the white paper puts the signature data in the transaction script, while the Segregated Witness "separates" the signature data before putting it the transaction time lock.