Skip to content

Commit f3b06b1

Browse files
committed
mempool: Disconnected peer orphans removal test
1 parent 8e29fd4 commit f3b06b1

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2023 RBB S.r.l
3+
4+
# SPDX-License-Identifier: MIT
5+
# Licensed under the MIT License;
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""Mempool orphan from disconnected peer
18+
19+
Check that:
20+
* A peer sees an orphan transaction
21+
* When the originator disconnects, the orphan is removed
22+
"""
23+
24+
from test_framework.test_framework import BitcoinTestFramework
25+
from test_framework.mintlayer import (make_tx, reward_input, tx_input)
26+
import scalecodec
27+
28+
class MempoolOrphanFromDIsconnectedPeerTest(BitcoinTestFramework):
29+
30+
def set_test_params(self):
31+
self.setup_clean_chain = True
32+
self.num_nodes = 2
33+
self.extra_args = [[], []]
34+
35+
def setup_network(self):
36+
self.setup_nodes()
37+
self.sync_all(self.nodes[0:1])
38+
self.connect_nodes(0, 1)
39+
40+
def run_test(self):
41+
node0 = self.nodes[0]
42+
node1 = self.nodes[1]
43+
44+
# Get genesis ID
45+
genesis_id = node0.chainstate_best_block_id()
46+
47+
(tx1, tx1_id) = make_tx([ reward_input(genesis_id) ], [ 1_000_000 ] )
48+
(tx2, tx2_id) = make_tx([ tx_input(tx1_id) ], [ 900_000 ] )
49+
50+
# Submit two transactions that build on top of each other but only propagate the second one
51+
node0.mempool_submit_transaction(tx1)
52+
node0.p2p_submit_transaction(tx2)
53+
54+
# Check the node gets the orphan transaction
55+
self.wait_until(lambda: node1.mempool_contains_orphan_tx(tx2_id), timeout = 5)
56+
57+
# Now disconnect the nodes and check the orphan is gone
58+
self.disconnect_nodes(0, 1)
59+
self.wait_until(lambda: not node1.mempool_contains_orphan_tx(tx2_id), timeout = 5)
60+
61+
# Some final sanity checks
62+
assert node0.mempool_contains_tx(tx1_id)
63+
assert node0.mempool_contains_tx(tx2_id)
64+
assert not node1.mempool_contains_tx(tx1_id)
65+
assert not node1.mempool_contains_tx(tx2_id)
66+
assert not node1.mempool_contains_orphan_tx(tx1_id)
67+
assert not node1.mempool_contains_orphan_tx(tx2_id)
68+
69+
70+
if __name__ == '__main__':
71+
MempoolOrphanFromDIsconnectedPeerTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class UnicodeOnWindowsError(ValueError):
114114
'mempool_basic_reorg.py',
115115
'mempool_eviction.py',
116116
'mempool_ibd.py',
117+
'mempool_orphan_peer_disconnected.py',
117118
'mempool_submit_orphan.py',
118119
'mempool_submit_tx.py',
119120
'mempool_timelocked_tx.py',

0 commit comments

Comments
 (0)