Skip to content

Commit b292c41

Browse files
knstPastaPastaPasta
authored andcommitted
partial Merge bitcoin#18628: test: Add various low-level p2p tests
Adds missing changes from p2p_invalid_tx.py but one assert is still disabled fa4c29b test: Add various low-level p2p tests (MarcoFalke) Pull request description: ACKs for top commit: jonatack: ACK fa4c29b Tree-SHA512: 842821b97359d4747c763398f7013415858c18a300cd882887bc812d039b5cbb67b9aa6f68434575dbc3c52f7eb8c43d1b293a59555a7242c0ca615cf44dc0aa
1 parent b43af81 commit b292c41

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

test/functional/p2p_invalid_tx.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def set_test_params(self):
2929
self.num_nodes = 1
3030
self.extra_args = [[
3131
"-acceptnonstdtxn=1",
32+
"-maxorphantxsize=1",
3233
]]
3334
self.setup_clean_chain = True
3435

@@ -103,7 +104,8 @@ def run_test(self):
103104
self.test_orphan_tx_handling(block1.vtx[0].sha256, False)
104105

105106
self.log.info('Test orphan transaction handling, resolve via block')
106-
self.restart_node(0, ["-acceptnonstdtxn=1", '-persistmempool=0'])
107+
self.restart_node(0, ["-acceptnonstdtxn=1", '-persistmempool=0', '-maxorphantxsize=1'])
108+
107109
self.reconnect_p2p(num_connections=2)
108110
self.test_orphan_tx_handling(block2.vtx[0].sha256, True)
109111

@@ -139,6 +141,7 @@ def test_orphan_tx_handling(self, base_tx, resolve_via_block):
139141
tx_orphan_2_invalid = CTransaction()
140142
tx_orphan_2_invalid.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_1.sha256, 2)))
141143
tx_orphan_2_invalid.vout.append(CTxOut(nValue=11 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
144+
tx_orphan_2_invalid.calc_sha256()
142145

143146
self.log.info('Send the orphans ... ')
144147
# Send valid orphan txs from p2ps[0]
@@ -182,6 +185,27 @@ def test_orphan_tx_handling(self, base_tx, resolve_via_block):
182185
wait_until(lambda: 1 == len(node.getpeerinfo()), timeout=12) # p2ps[1] is no longer connected
183186
assert_equal(expected_mempool, set(node.getrawmempool()))
184187

188+
self.log.info('Test orphan pool overflow')
189+
# this test is different with bitcoin due to dashpay/dash#3121
190+
# we have a limit based on size in megabytes, not by amount of txes
191+
# one tx is 91byte; 1Mb / 4451byte = 224; need to send at least 225
192+
orphan_tx_pool = [CTransaction() for _ in range(225)]
193+
for i in range(len(orphan_tx_pool)):
194+
orphan_tx_pool[i].vin.append(CTxIn(outpoint=COutPoint(i, 333)))
195+
for j in range(110):
196+
orphan_tx_pool[i].vout.append(CTxOut(nValue=COIN // 10, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
197+
198+
with node.assert_debug_log(['mapOrphan overflow, removed 1 tx']):
199+
node.p2p.send_txs_and_test(orphan_tx_pool, node, success=False)
200+
201+
rejected_parent = CTransaction()
202+
rejected_parent.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_2_invalid.sha256, 0)))
203+
rejected_parent.vout.append(CTxOut(nValue=11 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
204+
rejected_parent.rehash()
205+
# TODO: somehow it fails on `block` stage without 'not keeping orphan'
206+
#with node.assert_debug_log(['not keeping orphan with rejected parents {}'.format(rejected_parent.hash)]):
207+
node.p2p.send_txs_and_test([rejected_parent], node, success=False)
208+
185209

186210
if __name__ == '__main__':
187211
InvalidTxRequestTest().main()

0 commit comments

Comments
 (0)