Skip to content

Commit

Permalink
mempool: Disconnected peer orphans removal test
Browse files Browse the repository at this point in the history
  • Loading branch information
iljakuklic committed Aug 10, 2023
1 parent 8e29fd4 commit f3b06b1
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
71 changes: 71 additions & 0 deletions test/functional/mempool_orphan_peer_disconnected.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
# Copyright (c) 2023 RBB S.r.l
# opensource@mintlayer.org
# SPDX-License-Identifier: MIT
# Licensed under the MIT License;
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Mempool orphan from disconnected peer
Check that:
* A peer sees an orphan transaction
* When the originator disconnects, the orphan is removed
"""

from test_framework.test_framework import BitcoinTestFramework
from test_framework.mintlayer import (make_tx, reward_input, tx_input)
import scalecodec

class MempoolOrphanFromDIsconnectedPeerTest(BitcoinTestFramework):

def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 2
self.extra_args = [[], []]

def setup_network(self):
self.setup_nodes()
self.sync_all(self.nodes[0:1])
self.connect_nodes(0, 1)

def run_test(self):
node0 = self.nodes[0]
node1 = self.nodes[1]

# Get genesis ID
genesis_id = node0.chainstate_best_block_id()

(tx1, tx1_id) = make_tx([ reward_input(genesis_id) ], [ 1_000_000 ] )
(tx2, tx2_id) = make_tx([ tx_input(tx1_id) ], [ 900_000 ] )

# Submit two transactions that build on top of each other but only propagate the second one
node0.mempool_submit_transaction(tx1)
node0.p2p_submit_transaction(tx2)

# Check the node gets the orphan transaction
self.wait_until(lambda: node1.mempool_contains_orphan_tx(tx2_id), timeout = 5)

# Now disconnect the nodes and check the orphan is gone
self.disconnect_nodes(0, 1)
self.wait_until(lambda: not node1.mempool_contains_orphan_tx(tx2_id), timeout = 5)

# Some final sanity checks
assert node0.mempool_contains_tx(tx1_id)
assert node0.mempool_contains_tx(tx2_id)
assert not node1.mempool_contains_tx(tx1_id)
assert not node1.mempool_contains_tx(tx2_id)
assert not node1.mempool_contains_orphan_tx(tx1_id)
assert not node1.mempool_contains_orphan_tx(tx2_id)


if __name__ == '__main__':
MempoolOrphanFromDIsconnectedPeerTest().main()
1 change: 1 addition & 0 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class UnicodeOnWindowsError(ValueError):
'mempool_basic_reorg.py',
'mempool_eviction.py',
'mempool_ibd.py',
'mempool_orphan_peer_disconnected.py',
'mempool_submit_orphan.py',
'mempool_submit_tx.py',
'mempool_timelocked_tx.py',
Expand Down

0 comments on commit f3b06b1

Please sign in to comment.