Abstract:

The block data of Bitcoin contains the core information on the bitcoin chain, including how bitcoin is traded, block expansion and other issues.

From the birth of Bitcoin to now, a block is born every 10 minutes, visit blockchain.info/ view the latest block information, you can see that the current block size has been set by Satoshi Nakamoto 1MB capacity.

First, blockchain data structure

A complete block structure is mainly composed of the following parts:

A data item byte field instructions
Magic NO 4 The magic number Constant 0 xd9b4bef9
Blocksize 4 Block size The block size after this field in bytes
Blockheader 80 Block head The fields that make up the block header
Transaction counter 1-9 Transaction counter The number of transactions this block contains, including Coinbase transactions
Transactions indefinite trading Transaction information recorded in the block, using the native transaction information format, and the location of the transaction in the data stream must be in the same order as the leaf nodes of the Merkle tree

Ii. Block information analysis

We learn fromwebbtc.comSelect a hash value for 000000000003 ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506 early the block is analyzed.

You can see that the block contains three transaction information. The block information field is parsed below.

1. Block head analysis

The first 80 bytes are the block header.

{
    "hash": "000000000003ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"."ver": 1,
    "prev_block": "000000000002d01c1fccc21636b607dfd930d31d01c3a62104612a1719011250"."mrkl_root": "f3e94742aca4b5ef85488dc37c06c3282295ffec960994b2c0d5ac2a25a95766"."time": 1293623863,
    "bits": 453281356,
    "nonce": 274148111}Copy the code
byte field instructions
4 version Block version number, which indicates the authentication rules that the block complies with
32 Parent block header hash value The hash value of the previous block, calculated using SHA256(SHA256(parent block header))
32 Merkle root The hashes of Merkle roots traded in this block are also calculated using SHA256(SHA256())
4 The time stamp The approximate time generated by this block, a UNIX timestamp accurate to the second, must be strictly greater than the median time of the first 11 blocks, and the full node will reject blocks that exceed its own two-hour timestamp
4 Difficult goals The block of work proves the difficulty target of the algorithm, which has been encoded using a specific algorithm
4 Nonce In order to find a random number that meets the difficulty goal, and to solve the problem of insufficient 32-bit random numbers in the case of soaring computing power, the timestamp and coinbase transaction information can be changed to expand the number of digits of the NONCE

Description:

  • Versions, parent block header hashes, and Merkle roots are encoded in small-endian format, with the low significant bits coming first.
  • The timestamp represents the number of seconds since 00:00:00, January 1, 1970

2.Coinbase transaction information analysis

The first transaction of a block is defined as a Coinbase transaction, which is the bitcoin reward generated by mining. As you can see, the reward for each block mined is currently 12.5 bitcoins, and the next halving will occur in 2020. In addition to the rewards for mining, the miners’ incentives include fees for new bookkeeping, which will be their main source of income in the future if the total number of bitcoins does not increase.

{
    "hash": "8c14f0db3df150123e6f3dbbf30f8b955a8249b62ac1d1ff16284aefa3d06d87"."ver": 1,
    "vin_sz": 1,
    "vout_sz": 1,
    "lock_time": 0."size": 135,
    "in": [{
        "prev_out": {
            "hash": "0000000000000000000000000000000000000000000000000000000000000000"."n": 4294967295}."coinbase": "044c86041b020602"}]."out": [{
        "value": "50.00000000"."scriptPubKey": "041b0e8c2567c12536aa13357b79a073dc4444acb83c4ec7a0e2f99dd7457516c5817242da796924ca4e99947d087fedf9ce467cb9f7c6287078f80 1df276fdf84 OP_CHECKSIG"."next_in": {
            "hash": "f3e6066078e815bb24db0dfbff814f738943bddaaa76f8beba360cfe2882480a"."n": 12}}],"nid": "70ab531a68f973f7d20b8260cb5e7fecba3699c48715b8b44539ff9776d0b88e"
}
Copy the code
byte field describe
4 version The rules of reference for this transaction
1-9 Input counter The number of transaction inputs contained
32 Trading hash No transactions are referenced and all values are 0
4 Transaction output index Fixed 0 XFFFFFFFF
1-9 Coinbase data length Coinbase data length
indefinite Coinbase data In the V2 version of the block, except for the need to start with the block height, other data can be filled in arbitrarily for extra Nonce and mining labels
4 Serial number All values are 1,0 xFFFFFFFF
1-9 Output counter The number of transaction outputs contained
8 The total The value of a bit in terms of satoshi
1-9 Lock script size The length of the subsequent locking script in bytes
indefinite Lock the script A script that defines the conditions required for the payment output
4 Locking time A block number or UNIX timestamp

3. Record transaction information

Let’s take a look at common transaction records.

{
    "hash": "fff2525b8931402dd09222c50775608f75787bd2b87e56995a7bdd30f79702c4"."ver": 1,
    "vin_sz": 1,
    "vout_sz": 2."lock_time": 0."size": 259,
    "in": [{
        "prev_out": {
            "hash": "87a157f3fd88ac7907c05fc55e271dc4acdc5605d187d646604ca8c0e9382e03"."n": 0}."scriptSig": "3046022100c352d3dd993a981beba4a63ad15c209275ca9470abfcd57da93b58e4eb5dce82022100840792bc1f456062819f15d33ee7055cf7b5ee1 af1ebcc6028d9cdb1c3af774801 04f46db5e9d61a9dc27b8d64ad23e7383a4e6ca164593c2527c038c0857eb67ee8e825dca65046b82c9331586c82e0fd1f633f25f87c161bc6f8a630 121df2b3d3"}]."out": [{
            "value": "5.56000000"."scriptPubKey": "OP_DUP OP_HASH160 c398efa9c392ba6013c5e04ee729755ef7f58b32 OP_EQUALVERIFY OP_CHECKSIG"."address": "1JqDybm2nWTENrHvMyafbSXXtTk5Uv5QAn"."next_in": {
                "hash": "5aa8e36f9423ee5fcf17c1d0d45d6988b8a5773eae8ad25d945bf34352040009"."n": 6}}, {"value": "44.44000000"."scriptPubKey": "OP_DUP OP_HASH160 948c765a6914d43f2a7ac177da2c2f6b52de3d7c OP_EQUALVERIFY OP_CHECKSIG"."address": "1EYTGtG4LnFfiMvjJdsU7GMGCQvsRSjYhx"."next_in": {
                "hash": "220ebc64e21abece964927322cba69180ed853bb187fbc6923bac7d010b9d87a"."n": 0}}],"nid": "fc7704fdd7ec5e69163e51b827fea2133990a26defee2b475408b3c16fd9a968"
}Copy the code

Iii. How to solve the capacity expansion problem

In the early days of bitcoin’s birth, Satoshi Nakamoto set the block size at 1M for the security and stability of the bitcoin system and to prevent the bitcoin system from being attacked. At the time, bitcoin users were small and there were no congestion problems. With the development of bitcoin network, more and more transaction information is stored in a single block. The 1MB block can only hold about 2000 transactions, and when the transaction volume is large, it needs to queue for block write confirmation. The congestion problem of transaction network is becoming more and more serious, so several solutions have been proposed to solve the capacity problem.

1. Expand the block capacity

To solve the problem of too small block, the most direct way is to expand. The median block size doubled in 2015, from 292KB in January to 749KB in December. The problem was simplified to an upgrade to 2MB only after Pieter Wuille Segregated Witness was proposed at the Bitcoin Hong Kong capacity expansion conference in December 2015.

Why not make the blocks bigger, say 30MB? Blocks store transaction information, and if the block size limit is raised to 30MB, the biggest problem is not the CPU capacity bottleneck, but the block propagation and storage. The block size of 30MB May lead to a sharp increase in the lone block rate and empty block rate of the whole network, and the 1.5TB blockchain data produced in a year also exceeds the hard disk capacity of most node machines. Based on this 1.5TB data, blockchain browsers, wallet service providers, etc., may expand by 10 times to 15TB, which is far more than the disk capacity of ordinary machines/databases at present.

In addition to capacity expansion, another solution is to isolate witness and lightning networks.

2. Isolate witness and lightning networks

Segregated Witness (SegWit) is used to solve malleable attacks by stripping the signature data of a transaction from the transaction data.

Bitcoin transactions are mainly made up of two pieces of data. Part of it is transaction data, which records where bitcoin comes from and where it goes. The other part is the witness data, which consists of encrypted data used to prove that the transaction request is authentic.

When Satoshi nakamoto designed bitcoin, he put both parts of information directly into the block, so a block can’t carry more transaction information. If “witness data” is isolated, and the blockchain only records transaction data, a block can host many more transactions.

The Lightning Network solution is to add a “Lightning Network” to the bitcoin Network, transferring small transactions from the original bitcoin chain to the Lightning Network for processing, and then recording the completion of the original chain. This is an off-chain transaction designed to speed up transactions. Ethereum has a similar solution called Raiden Network.

Imagine that the block of bitcoin is a bus, which leaves at a fixed time every ten minutes. When the number of passengers exceeds the capacity of the bus, those who cannot get on have to wait for the next bus. Our goal is to get more people on the bus, which is to carry more transactions.

The Bitcoin blockchain itself can prioritize transactions based on transaction rates, and if you want to quickly complete functions such as transferring money, you can set a high fee. It is similar to the bus letting people who pay more get on first, and those who do not want to pay more have to wait until there are fewer passengers.

The witness of segregation is that we add a truck (SegWit car) behind the bus, and all passengers have to put backpacks and luggage on the truck, because less carry-on items, each person occupies less space, the bus can carry some more people, the load becomes more.

The lightning network can be understood as putting a railway next to a bus route, allowing people who can’t get on a bus to go directly to the train, eliminating the problem of too many people riding on too small a bus.

Isolated Witness and lightning networks are technically feasible, but there are also doubts. Layer 2 networks that rely on isolated witness, such as the Lightning network, cannot be considered as an expansion solution for Bitcoin, because the transactions of the lightning network are not equivalent to the peer-to-peer chain transactions of Bitcoin, and most bitcoin transaction scenarios are not applicable to the lightning network.

Assuming the Lightning network is successfully deployed, there will also be the problem of large payment centers, which defeats the purpose of Bitcoin as a peer-to-peer payment system.

Author:
The more Bing

The original link