mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-30 18:51:15 +02:00
Merge bitcoin/bitcoin#22378: test: remove confusing MAX_BLOCK_BASE_SIZE
607076d01b
test: remove confusing `MAX_BLOCK_BASE_SIZE` (Sebastian Falbesoner)4af97c74ed
test: introduce `get_weight()` helper for CBlock (Sebastian Falbesoner)a084ebe133
test: introduce `get_weight()` helper for CTransaction (Sebastian Falbesoner) Pull request description: This is a very late follow-up PR to #10618, which removed the constant `MAX_BLOCK_BASE_SIZE` from the core implementation about four years ago (see also #10608 in why it was considered confusing and superfluous). Since there is also no point in still keeping it in the functional test framework, the PR switches to weight-based accounting on the relevant test code parts and use `MAX_BLOCK_WEIGHT` instead for the block limit checks. To prepare that, the first two commits introduce `get_weight()` helpers for the classes CTransaction and CBlock, respectively. ACKs for top commit: MarcoFalke: review ACK607076d01b
🚴 Tree-SHA512: d59aa0b6b3dfd0a849b8063e66de275d252f705f99e25cd3bf6daec028b47d946777ee5b42a060f5283cb18e917ac073119c2c0e11bbc21211f69ef0a6ed335a
This commit is contained in:
@ -33,7 +33,7 @@ from test_framework.siphash import siphash256
|
||||
from test_framework.util import 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
|
||||
|
||||
@ -608,12 +608,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)" \
|
||||
@ -761,6 +764,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,
|
||||
|
Reference in New Issue
Block a user