From a084ebe1330bcec15715e08b0f65319142927ad1 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Wed, 30 Jun 2021 23:40:39 +0200 Subject: test: introduce `get_weight()` helper for CTransaction --- test/functional/test_framework/messages.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'test/functional/test_framework/messages.py') diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index 504c8c70d4..8d0bd9f69a 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -590,12 +590,15 @@ class CTransaction: return False return True - # Calculate the virtual transaction size using witness and non-witness + # Calculate the transaction weight using witness and non-witness # serialization size (does NOT use sigops). - def get_vsize(self): + def get_weight(self): with_witness_size = len(self.serialize_with_witness()) without_witness_size = len(self.serialize_without_witness()) - return math.ceil(((WITNESS_SCALE_FACTOR - 1) * without_witness_size + with_witness_size) / WITNESS_SCALE_FACTOR) + return (WITNESS_SCALE_FACTOR - 1) * without_witness_size + with_witness_size + + def get_vsize(self): + return math.ceil(self.get_weight() / WITNESS_SCALE_FACTOR) def __repr__(self): return "CTransaction(nVersion=%i vin=%s vout=%s wit=%s nLockTime=%i)" \ -- cgit v1.2.3 From 4af97c74edcda56cd15523bf3a335adea2bad14a Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Thu, 1 Jul 2021 00:10:43 +0200 Subject: test: introduce `get_weight()` helper for CBlock --- test/functional/test_framework/messages.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional/test_framework/messages.py') diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index 8d0bd9f69a..1abe604b28 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -746,6 +746,13 @@ class CBlock(CBlockHeader): self.nNonce += 1 self.rehash() + # Calculate the block weight using witness and non-witness + # serialization size (does NOT use sigops). + def get_weight(self): + with_witness_size = len(self.serialize(with_witness=True)) + without_witness_size = len(self.serialize(with_witness=False)) + return (WITNESS_SCALE_FACTOR - 1) * without_witness_size + with_witness_size + def __repr__(self): return "CBlock(nVersion=%i hashPrevBlock=%064x hashMerkleRoot=%064x nTime=%s nBits=%08x nNonce=%08x vtx=%s)" \ % (self.nVersion, self.hashPrevBlock, self.hashMerkleRoot, -- cgit v1.2.3 From 607076d01bf23c69ac21950c17b01fb4e1130774 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Thu, 1 Jul 2021 01:43:45 +0200 Subject: test: remove confusing `MAX_BLOCK_BASE_SIZE` The constant `MAX_BLOCK_BASE_SIZE` has been removed from the core implementation years ago due to being confusing and superfluous, as it is implied by the block weight limit (see PRs #10618 and #10608). Since there is also no point in still keeping it in the functional test framework, we switch to weight-based accounting on the relevant test code parts and use `MAX_BLOCK_WEIGHT` instead for the block limit checks. --- test/functional/test_framework/messages.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/test_framework/messages.py') diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index 1abe604b28..c0a1a9a8e4 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -32,7 +32,7 @@ from test_framework.siphash import siphash256 from test_framework.util import hex_str_to_bytes, assert_equal MAX_LOCATOR_SZ = 101 -MAX_BLOCK_BASE_SIZE = 1000000 +MAX_BLOCK_WEIGHT = 4000000 MAX_BLOOM_FILTER_SIZE = 36000 MAX_BLOOM_HASH_FUNCS = 50 -- cgit v1.2.3