- Blockchain By Example
- Bellaj Badr Richard Horrocks Xun (Brian) Wu
- 457字
- 2021-06-10 18:53:45
Block size
Welcome to the most controversial issue in Bitcoin!
Block size is simply the size, in bytes, of the serialized block. Initially, Bitcoin's block had a maximum size set to 1 MB. This limit was introduced initially by Satoshi to protect the network against DOS attacks, until it was recently raised after the introduction of Segwit. Segwit, or Segregated Witness, is a technique enabling the production of blocks with a size of up to 4 MB by putting their signatures (which use roughly 60 percent of the transaction space) in an extra space, enabling block capacity to be scaled while maintaining backward compatibility. Segwit introduced the concept of weight instead of size, enabling old nodes (which recognize only 1 MB blocks) to see only placeholders, while nodes upgraded to Segwit are still able to see the entire block and validate the signatures (4 MB).
The calculation of the weight is a bit more complicated than the simple block size = 1 MB. The miners now need to build blocks, which do not violate the conditions determined by the CheckBlock() function defined in validation.cpp:
The GetSerializeSize function just computes the size in bytes of a serialized block for the network-ignoring witnesses. Therefore we can deduce that the weight is proportional to size by a factor of WITNESS_SCALE_FACTOR as follows: maximum size = Weight/ WITNESS_SCALE_FACTOR.
Any block, such that block.vtx.size() is larger than 1 MB, will be rejected as invalid.
You might find this weight concept a useless fancy hack, but it isn't as it solves the dilemma of scaling Bitcoin without breaking the Bitcoin network consensus (backward compatibility). As we are starting a new network, we can directly increase block size or keep the Segwit solution with a higher block weight. In this guide, we'll opt for the second approach.
Prior to Bitcoin 0.15, the limit was defined in the src\consensus\consensus.h as follows:
static const unsigned int MAX_BLOCK_BASE_SIZE = 1000000;
This set the maximum limit of a Bitcoin block to 1 MB, excluding witness data.
Since Segwit activation, the weight parameters have been defined in consensus.h:
To double the weight, we have to double the values of these four parameters. This theoretically allows us to mine blocks of up to 8 MB, but a more realistic maximum block size will be an occasionally rare 7.7 MB (assuming near 100% Segwit transactions). By processing big blocks, we have to make a trade-off between scalability and the growth in the blockchain's size. As the blockchain is an unalterable database, reaching a big size implies higher centralization as few storage points will be able to store data.
Congratulations! You just replicated the schism of the Bitcoin community, which was proposal BIP141 (Segwit). But what are BIPs?