Skip to content

Commit 0973018

Browse files
committed
Merge bitcoin/bitcoin#27265: test: check that sigop limit also affects ancestor/descendant size (27171 follow-up)
6d24d1e 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 bitcoin/bitcoin#27171 (review)). 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 6d24d1e, thanks for taking! Tree-SHA512: dc65e455d06cfef1f1d6a53b959f99ec1ca3fe51c98dc1ed5826614b5619773d34aff0171c43a0ede4fd45605b2eb7a9278e027196128bb7ad8586b859f1cf70
2 parents 053b2d3 + 6d24d1e commit 0973018

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/functional/mempool_sigoplimit.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
CTxInWitness,
1313
CTxOut,
1414
WITNESS_SCALE_FACTOR,
15+
tx_from_hex,
1516
)
1617
from test_framework.script import (
1718
CScript,
@@ -29,6 +30,7 @@
2930
from test_framework.test_framework import BitcoinTestFramework
3031
from test_framework.util import (
3132
assert_equal,
33+
assert_greater_than,
3234
assert_greater_than_or_equal,
3335
)
3436
from test_framework.wallet import MiniWallet
@@ -106,6 +108,31 @@ def test_sigops_limit(self, bytes_per_sigop, num_sigops):
106108
assert_equal(res['allowed'], True)
107109
assert_equal(res['vsize'], sigop_equivalent_vsize)
108110

111+
# check that the ancestor and descendant size calculations in the mempool
112+
# also use the same max(sigop_equivalent_vsize, serialized_vsize) logic
113+
# (to keep it simple, we only test the case here where the sigop vsize
114+
# is much larger than the serialized vsize, i.e. we create a small child
115+
# tx by getting rid of the large padding output)
116+
tx.vout[0].scriptPubKey = CScript([OP_RETURN, b'test123'])
117+
assert_greater_than(sigop_equivalent_vsize, tx.get_vsize())
118+
self.nodes[0].sendrawtransaction(hexstring=tx.serialize().hex(), maxburnamount='1.0')
119+
120+
# fetch parent tx, which doesn't contain any sigops
121+
parent_txid = tx.vin[0].prevout.hash.to_bytes(32, 'big').hex()
122+
parent_tx = tx_from_hex(self.nodes[0].getrawtransaction(txid=parent_txid))
123+
124+
entry_child = self.nodes[0].getmempoolentry(tx.rehash())
125+
assert_equal(entry_child['descendantcount'], 1)
126+
assert_equal(entry_child['descendantsize'], sigop_equivalent_vsize)
127+
assert_equal(entry_child['ancestorcount'], 2)
128+
assert_equal(entry_child['ancestorsize'], sigop_equivalent_vsize + parent_tx.get_vsize())
129+
130+
entry_parent = self.nodes[0].getmempoolentry(parent_tx.rehash())
131+
assert_equal(entry_parent['ancestorcount'], 1)
132+
assert_equal(entry_parent['ancestorsize'], parent_tx.get_vsize())
133+
assert_equal(entry_parent['descendantcount'], 2)
134+
assert_equal(entry_parent['descendantsize'], parent_tx.get_vsize() + sigop_equivalent_vsize)
135+
109136
def run_test(self):
110137
self.wallet = MiniWallet(self.nodes[0])
111138

@@ -120,6 +147,8 @@ def run_test(self):
120147
for num_sigops in (69, 101, 142, 183, 222):
121148
self.test_sigops_limit(bytes_per_sigop, num_sigops)
122149

150+
self.generate(self.wallet, 1)
151+
123152

124153
if __name__ == '__main__':
125154
BytesPerSigOpTest().main()

0 commit comments

Comments
 (0)