Bitcoin Forum
May 01, 2024, 12:00:19 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Assuming block.vtx.size() return tx count why is it used for block size check?  (Read 75 times)
Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
February 20, 2021, 09:07:07 AM
Merited by Welsh (3), Heisenberg_Hunter (1)
 #1

I'm trying to figure out what validations are being performed on block size and so far found this line:
https://github.com/bitcoin/bitcoin/blob/828bb776d29cbdfad3937ba100c428e3244c652f/src/validation.cpp#L3348
Code:
if (block.vtx.empty() || 
    block.vtx.size() * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT ||
    ::GetSerializeSize(block, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT)

Google tells me that in c++ the size() method in std::vector (which is block.vtx type) returns item count which makes me wonder why is transaction count being multiplied by 4 and compared with max block weight?

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
1714564819
Hero Member
*
Offline Offline

Posts: 1714564819

View Profile Personal Message (Offline)

Ignore
1714564819
Reply with quote  #2

1714564819
Report to moderator
1714564819
Hero Member
*
Offline Offline

Posts: 1714564819

View Profile Personal Message (Offline)

Ignore
1714564819
Reply with quote  #2

1714564819
Report to moderator
Each block is stacked on top of the previous one. Adding another block to the top makes all lower blocks more difficult to remove: there is more "weight" above each block. A transaction in a block 6 blocks deep (6 confirmations) will be very difficult to remove.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714564819
Hero Member
*
Offline Offline

Posts: 1714564819

View Profile Personal Message (Offline)

Ignore
1714564819
Reply with quote  #2

1714564819
Report to moderator
NotATether
Legendary
*
Offline Offline

Activity: 1582
Merit: 6718


bitcoincleanup.com / bitmixlist.org


View Profile WWW
February 20, 2021, 11:37:20 AM
Last edit: February 20, 2021, 11:47:27 AM by NotATether
 #2

It is not measuring the size in bytes, it is measuring it in weight units. To convert from bytes to WUs you multiply  by 4. That is why WITNESS_SCALE_FACTOR is set to 4. MAX_BLOCK_WEIGHT is set to 4000000 weight units which corresponds to 1vMB blocks size.

Anyway, it looks like the second condition is just a strawman check to guard against having more transactions than what is physically possible in a block (hypothetically assuming each transaction has a 1vbyte size) and that the actual block size check is made in the third condition with GetSerializeSize().

@Coding Enthusiast I edited my answer.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
February 20, 2021, 11:40:04 AM
 #3

That doesn't answer my question.

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
j2002ba2
Full Member
***
Offline Offline

Activity: 204
Merit: 437


View Profile
February 20, 2021, 11:42:18 AM
 #4

You'd have to ask Satoshi about this. Code snippet from v0.1.0 (or 0.1.3):

Code:
bool CBlock::CheckBlock() const
{
    // These are checks that are independent of context
    // that can be verified before saving an orphan block.

    // Size limits
    if (vtx.empty() || vtx.size() > MAX_SIZE || ::GetSerializeSize(*this, SER_DISK) > MAX_SIZE)
        return error("CheckBlock() : size limits failed");

vjudeu
Hero Member
*****
Offline Offline

Activity: 670
Merit: 1549



View Profile
February 20, 2021, 01:16:44 PM
Merited by Welsh (3), Coding Enthusiast (2)
 #5

This is just pure guessing, but I will share my thoughts with you:

This check is needed because minimal physically possible transaction size is one byte and because merkle tree has no size limit, without this check it would be possible to attack just by creating enormously large merkle tree. So, maybe it is redundant and maybe this case will never happen, but it is here just to make sure that if for example block size limit is 1 MB, then it should be impossible to make a block with more than one million transactions. And because merkle root is a binary tree, it is possible to check that the whole tree depth is not higher than 20.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
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!