Bitcoin Forum
April 26, 2024, 04:19:01 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Block size limit in source code  (Read 671 times)
x3m (OP)
Newbie
*
Offline Offline

Activity: 23
Merit: 10


View Profile
September 21, 2017, 04:07:27 PM
 #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.
1714105141
Hero Member
*
Offline Offline

Posts: 1714105141

View Profile Personal Message (Offline)

Ignore
1714105141
Reply with quote  #2

1714105141
Report to moderator
1714105141
Hero Member
*
Offline Offline

Posts: 1714105141

View Profile Personal Message (Offline)

Ignore
1714105141
Reply with quote  #2

1714105141
Report to moderator
1714105141
Hero Member
*
Offline Offline

Posts: 1714105141

View Profile Personal Message (Offline)

Ignore
1714105141
Reply with quote  #2

1714105141
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714105141
Hero Member
*
Offline Offline

Posts: 1714105141

View Profile Personal Message (Offline)

Ignore
1714105141
Reply with quote  #2

1714105141
Report to moderator
1714105141
Hero Member
*
Offline Offline

Posts: 1714105141

View Profile Personal Message (Offline)

Ignore
1714105141
Reply with quote  #2

1714105141
Report to moderator
1714105141
Hero Member
*
Offline Offline

Posts: 1714105141

View Profile Personal Message (Offline)

Ignore
1714105141
Reply with quote  #2

1714105141
Report to moderator
Carlton Banks
Legendary
*
Offline Offline

Activity: 3430
Merit: 3071



View Profile
September 21, 2017, 05:23:09 PM
Merited by ABCbits (2)
 #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)

Vires in numeris
BitUsher
Legendary
*
Offline Offline

Activity: 994
Merit: 1034


View Profile
September 21, 2017, 05:51:32 PM
Merited by ABCbits (3)
 #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.
x3m (OP)
Newbie
*
Offline Offline

Activity: 23
Merit: 10


View Profile
September 21, 2017, 06:05:45 PM
 #4

Thanks a lot BitUsher and Carlton Banks.
Carlton Banks
Legendary
*
Offline Offline

Activity: 3430
Merit: 3071



View Profile
September 21, 2017, 07:17:42 PM
Merited by ABCbits (1)
 #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.

Vires in numeris
DannyHamilton
Legendary
*
Offline Offline

Activity: 3374
Merit: 4606



View Profile
September 21, 2017, 08:47:35 PM
Merited by pooya87 (4), ABCbits (3)
 #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.
x3m (OP)
Newbie
*
Offline Offline

Activity: 23
Merit: 10


View Profile
September 22, 2017, 11:39:50 AM
 #7

Wow, thanks DannyHamilton ... legendary explanation!
Replies like this help a lot to understand the logic in the code.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!