0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

Merge bitcoin/bitcoin#27265: test: check that sigop limit also affects ancestor/descendant size (27171 follow-up)

6d24d1ef2b test: check that sigop limit also affects ancestor/descendant size (Sebastian Falbesoner)

Pull request description:

  This is a follow-up to #27171, adding a check that the sigop-limit vsize logic is also respected for {ancestor,descendant}size calculation (as suggested in https://github.com/bitcoin/bitcoin/pull/27171#pullrequestreview-1331143909). For simplicity, we use a one-parent-one-child cluster here and only check for the case that the sigop-limit equivalent size is larger than the serialized vsize.

ACKs for top commit:
  glozow:
    code review ACK 6d24d1ef2b, thanks for taking!

Tree-SHA512: dc65e455d06cfef1f1d6a53b959f99ec1ca3fe51c98dc1ed5826614b5619773d34aff0171c43a0ede4fd45605b2eb7a9278e027196128bb7ad8586b859f1cf70
This commit is contained in:
fanquake 2023-03-19 12:09:20 +00:00
commit 0973018067
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -12,6 +12,7 @@ from test_framework.messages import (
CTxInWitness,
CTxOut,
WITNESS_SCALE_FACTOR,
tx_from_hex,
)
from test_framework.script import (
CScript,
@ -29,6 +30,7 @@ from test_framework.script_util import (
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
assert_greater_than,
assert_greater_than_or_equal,
)
from test_framework.wallet import MiniWallet
@ -106,6 +108,31 @@ class BytesPerSigOpTest(BitcoinTestFramework):
assert_equal(res['allowed'], True)
assert_equal(res['vsize'], sigop_equivalent_vsize)
# check that the ancestor and descendant size calculations in the mempool
# also use the same max(sigop_equivalent_vsize, serialized_vsize) logic
# (to keep it simple, we only test the case here where the sigop vsize
# is much larger than the serialized vsize, i.e. we create a small child
# tx by getting rid of the large padding output)
tx.vout[0].scriptPubKey = CScript([OP_RETURN, b'test123'])
assert_greater_than(sigop_equivalent_vsize, tx.get_vsize())
self.nodes[0].sendrawtransaction(hexstring=tx.serialize().hex(), maxburnamount='1.0')
# fetch parent tx, which doesn't contain any sigops
parent_txid = tx.vin[0].prevout.hash.to_bytes(32, 'big').hex()
parent_tx = tx_from_hex(self.nodes[0].getrawtransaction(txid=parent_txid))
entry_child = self.nodes[0].getmempoolentry(tx.rehash())
assert_equal(entry_child['descendantcount'], 1)
assert_equal(entry_child['descendantsize'], sigop_equivalent_vsize)
assert_equal(entry_child['ancestorcount'], 2)
assert_equal(entry_child['ancestorsize'], sigop_equivalent_vsize + parent_tx.get_vsize())
entry_parent = self.nodes[0].getmempoolentry(parent_tx.rehash())
assert_equal(entry_parent['ancestorcount'], 1)
assert_equal(entry_parent['ancestorsize'], parent_tx.get_vsize())
assert_equal(entry_parent['descendantcount'], 2)
assert_equal(entry_parent['descendantsize'], parent_tx.get_vsize() + sigop_equivalent_vsize)
def run_test(self):
self.wallet = MiniWallet(self.nodes[0])
@ -120,6 +147,8 @@ class BytesPerSigOpTest(BitcoinTestFramework):
for num_sigops in (69, 101, 142, 183, 222):
self.test_sigops_limit(bytes_per_sigop, num_sigops)
self.generate(self.wallet, 1)
if __name__ == '__main__':
BytesPerSigOpTest().main()