Skip to content

Commit fac7181

Browse files
author
merge-script
committed
Merge bitcoin/bitcoin#22582: test: a test to check descendant limits
fa7db1c [test] checks descendants limtis for second generation Package descendants (ritickgoenka) Pull request description: This PR adds a new functional test to test the new descendant limits for packages that were proposed in #21800. ``` +----------------------+ | | | M1 | | ^ ^ | | M2 ^ | | . ^ | | . ^ | | . ^ | | . ^ | | M24 ^ | | ^ | | P1 | | ^ | | P2 | | | +----------------------+ ``` This test is for checking a transaction to fail its descendant count limits because of a combination of mempool descendants, package direct descendants, and package indirect descendants. In this test, P1 has M1 as a mempool ancestor, P2 has no in-mempool ancestors, but when combined P2 has M1 as an ancestor and M1 exceeds descendant_limits (23 in-mempool descendants + 2 in-package descendants, a total of 26 including itself) ACKs for top commit: ryanofsky: Code review ACK fa7db1c. Only were suggested changes since last review: simplifying test and dropping P3 transaction as John suggested, and adding assert_equal I suggested glozow: ACK fa7db1c jnewbery: ACK fa7db1c Tree-SHA512: d1eb993550ac8ce31cbe42e17c6522a213ede66970d5d9391f31a116477ab5889fefa6ff2df6ceadd63a28c1be1ad893b0e8e449247e9ade2ca61dc636508d68
2 parents b05d3e7 + fa7db1c commit fac7181

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

test/functional/mempool_package_limits.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
bulk_transaction,
2727
create_child_with_parents,
2828
make_chain,
29+
DEFAULT_FEE,
2930
)
3031

3132
class MempoolPackageLimitsTest(BitcoinTestFramework):
@@ -50,6 +51,7 @@ def run_test(self):
5051

5152
self.test_chain_limits()
5253
self.test_desc_count_limits()
54+
self.test_desc_count_limits_2()
5355
self.test_anc_count_limits()
5456
self.test_anc_count_limits_2()
5557
self.test_anc_count_limits_bushy()
@@ -177,6 +179,74 @@ def test_desc_count_limits(self):
177179
self.generate(node, 1)
178180
assert all([res["allowed"] for res in node.testmempoolaccept(rawtxs=package_hex)])
179181

182+
def test_desc_count_limits_2(self):
183+
"""Create a Package with 24 transaction in mempool and 2 transaction in package:
184+
M1
185+
^ ^
186+
M2 ^
187+
. ^
188+
. ^
189+
. ^
190+
M24 ^
191+
^
192+
P1
193+
^
194+
P2
195+
P1 has M1 as a mempool ancestor, P2 has no in-mempool ancestors, but when
196+
combined P2 has M1 as an ancestor and M1 exceeds descendant_limits(23 in-mempool
197+
descendants + 2 in-package descendants, a total of 26 including itself).
198+
"""
199+
200+
node = self.nodes[0]
201+
package_hex = []
202+
# M1
203+
first_coin_a = self.coins.pop()
204+
parent_value = (first_coin_a["amount"] - DEFAULT_FEE) / 2 # Deduct reasonable fee and make 2 outputs
205+
inputs = [{"txid": first_coin_a["txid"], "vout": 0}]
206+
outputs = [{self.address : parent_value}, {ADDRESS_BCRT1_P2WSH_OP_TRUE : parent_value}]
207+
rawtx = node.createrawtransaction(inputs, outputs)
208+
209+
parent_signed = node.signrawtransactionwithkey(hexstring=rawtx, privkeys=self.privkeys)
210+
assert parent_signed["complete"]
211+
parent_tx = tx_from_hex(parent_signed["hex"])
212+
parent_txid = parent_tx.rehash()
213+
node.sendrawtransaction(parent_signed["hex"])
214+
215+
# Chain M2...M24
216+
spk = parent_tx.vout[0].scriptPubKey.hex()
217+
value = parent_value
218+
txid = parent_txid
219+
for i in range(23): # M2...M24
220+
(tx, txhex, value, spk) = make_chain(node, self.address, self.privkeys, txid, value, 0, spk)
221+
txid = tx.rehash()
222+
node.sendrawtransaction(txhex)
223+
224+
# P1
225+
value_p1 = (parent_value - DEFAULT_FEE)
226+
rawtx_p1 = node.createrawtransaction([{"txid": parent_txid, "vout": 1}], [{self.address : value_p1}])
227+
tx_child_p1 = tx_from_hex(rawtx_p1)
228+
tx_child_p1.wit.vtxinwit = [CTxInWitness()]
229+
tx_child_p1.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
230+
tx_child_p1_hex = tx_child_p1.serialize().hex()
231+
txid_child_p1 = tx_child_p1.rehash()
232+
package_hex.append(tx_child_p1_hex)
233+
tx_child_p1_spk = tx_child_p1.vout[0].scriptPubKey.hex()
234+
235+
# P2
236+
(_, tx_child_p2_hex, _, _) = make_chain(node, self.address, self.privkeys, txid_child_p1, value_p1, 0, tx_child_p1_spk)
237+
package_hex.append(tx_child_p2_hex)
238+
239+
assert_equal(24, node.getmempoolinfo()["size"])
240+
assert_equal(2, len(package_hex))
241+
testres = node.testmempoolaccept(rawtxs=package_hex)
242+
assert_equal(len(testres), len(package_hex))
243+
for txres in testres:
244+
assert_equal(txres["package-error"], "package-mempool-limits")
245+
246+
# Clear mempool and check that the package passes now
247+
node.generate(1)
248+
assert all([res["allowed"] for res in node.testmempoolaccept(rawtxs=package_hex)])
249+
180250
def test_anc_count_limits(self):
181251
"""Create a 'V' shaped chain with 24 transactions in the mempool and 3 in the package:
182252
M1a M1b

0 commit comments

Comments
 (0)