Author

Topic: Block size limit in source code (Read 698 times)

x3m
newbie
Activity: 23
Merit: 10
September 22, 2017, 06:39:50 AM
#7
Wow, thanks DannyHamilton ... legendary explanation!
Replies like this help a lot to understand the logic in the code.
legendary
Activity: 3472
Merit: 4801
September 21, 2017, 03:47:35 PM
#6
Note that there is also a:
Code:
static const int WITNESS_SCALE_FACTOR = 4;
https://github.com/bitcoin/bitcoin/blob/505955052e60e0681865f3064e005ca0d3aa90bf/src/consensus/consensus.h#L21



And when validating the size of a received block, the following code is used:
Code:
bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW, bool fCheckMerkleRoot)
{
// These are checks that are independent of context.

. . .

// Size limits
    if (block.vtx.empty() || block.vtx.size() * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT)
return state.DoS(100, false, REJECT_INVALID, "bad-blk-length", false, "size limits failed");
https://github.com/bitcoin/bitcoin/blob/f088a1bb392eaecd912ff9bca6967a8f4765c2b7/src/validation.cpp#L2814


So, if
block.vtx.size() is greater than 1000000
then
block.vtx.size() * WITNESS_SCALE_FACTOR will be greater than 4000000

which is the value of MAX_BLOCK_WEIGHT

As such, any block such that block.vtx.size() is larger than 1 megabyte will be rejected as invalid.
legendary
Activity: 3430
Merit: 3080
September 21, 2017, 02:17:42 PM
#5
This allows Blocks up to 4MB theoretically , but more realistic max blocksizes will be an occasionally rare 3.7MB (assuming near 100% segwit txs)

https://testnet.smartbit.com.au/block/00000000000016a805a7c5d27c3cc0ecb6d51372e15919dfb49d24bd56ae0a8b

90% and up segwit tx usage will result in 1.9-2.1MB average blocksizes based upon the type of tx mix we see today.

I think it may be sensible to point out that "we see today" is an important condition of your statement. In future, Lightning, CT and MAST transactions could push that average higher.
x3m
newbie
Activity: 23
Merit: 10
September 21, 2017, 01:05:45 PM
#4
Thanks a lot BitUsher and Carlton Banks.
legendary
Activity: 994
Merit: 1035
September 21, 2017, 12:51:32 PM
#3
Can anyone please tell me where the heck is the maximum block size (1M) defined and where it is used in the code to check? Thanks.

Limit is no longer 1MB , and no longer defined by size but weight of 4 million units-

https://github.com/bitcoin/bitcoin/blob/master/src/consensus/consensus.h

Quote from: Bitcoin Github
/** The maximum allowed size for a serialized block, in bytes (only for buffer size limits) */
static const unsigned int MAX_BLOCK_SERIALIZED_SIZE = 4000000;
/** The maximum allowed weight for a block, see BIP 141 (network rule) */
static const unsigned int MAX_BLOCK_WEIGHT = 4000000;
/** The maximum allowed number of signature check operations in a block (network rule) */
static const int64_t MAX_BLOCK_SIGOPS_COST = 80000;
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
static const int COINBASE_MATURITY = 100;

This allows Blocks up to 4MB theoretically , but more realistic max blocksizes will be an occasionally rare 3.7MB (assuming near 100% segwit txs)

https://testnet.smartbit.com.au/block/00000000000016a805a7c5d27c3cc0ecb6d51372e15919dfb49d24bd56ae0a8b

90% and up segwit tx usage will result in 1.9-2.1MB average blocksizes based upon the type of tx mix we see today.
legendary
Activity: 3430
Merit: 3080
September 21, 2017, 12:23:09 PM
#2
Can anyone please tell me where the heck is the maximum block size (1M) defined and where it is used in the code to check? Thanks.

It's a variable called MAX_BLOCK_WEIGHT, and it's in a file in the consensus sub-directory called consensus.h (and it's 4M, not 1M)
x3m
newbie
Activity: 23
Merit: 10
September 21, 2017, 11:07:27 AM
#1
Can anyone please tell me where the heck is the maximum block size (1M) defined and where it is used in the code to check? Thanks.
Jump to: