Repository navigation
Expand file tree
/
Copy pathmempool_compatibility.py
More file actions
executable file
·76 lines (59 loc) · 3.16 KB
/
Copy pathmempool_compatibility.py
File metadata and controls
executable file
·76 lines (59 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
# Copyright (c) 2017-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test that mempool.dat is both backward and forward compatible between versions
NOTE: The test is designed to prevent cases when compatibility is broken accidentally.
In case we need to break mempool compatibility we can continue to use the test by just bumping the version number.
Previous releases are required by this test, see test/README.md.
"""
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
from test_framework.wallet import MiniWallet
class MempoolCompatibilityTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.setup_clean_chain = True
self.extra_args = [["-persistmempoolv1=1"], []]
def skip_test_if_missing_module(self):
self.skip_if_no_previous_releases()
def setup_network(self):
self.add_nodes(self.num_nodes, extra_args=self.extra_args, versions=[
310000, # Any release with -persistmempoolv1
None,
])
self.start_nodes()
def run_test(self):
self.log.info("Test that mempool.dat is compatible between versions")
old_node, new_node = self.nodes
new_wallet = MiniWallet(new_node)
self.connect_nodes(0, 1)
self.generate(new_wallet, 1)
self.generate(new_node, COINBASE_MATURITY)
self.log.info("Add a transaction to mempool on old node and shutdown")
old_tx_hash = new_wallet.send_self_transfer(from_node=old_node)["txid"]
assert old_tx_hash in old_node.getrawmempool()
self.stop_nodes()
self.log.info("Move mempool.dat from old to new node")
old_node_mempool = old_node.chain_path / "mempool.dat"
new_node_mempool = new_node.chain_path / "mempool.dat"
old_node_mempool.replace(new_node_mempool)
self.log.info("Start new node and verify mempool contains the tx")
# The old node wrote the legacy v1 format (-persistmempoolv1), so this covers reading it
self.start_node(1)
assert old_tx_hash in new_node.getrawmempool()
self.log.info("Add unbroadcasted tx to mempool on new node and shutdown")
unbroadcasted_tx_hash = new_wallet.send_self_transfer(from_node=new_node)['txid']
assert unbroadcasted_tx_hash in new_node.getrawmempool()
assert_equal(new_node.getmempoolentry(unbroadcasted_tx_hash)["unbroadcast"], True)
self.stop_node(1)
self.log.info("Move mempool.dat from new to old node")
new_node_mempool.rename(old_node_mempool)
self.log.info("Start old node again and verify mempool contains the txs and the unbroadcast set")
self.start_node(0)
assert old_tx_hash in old_node.getrawmempool()
assert unbroadcasted_tx_hash in old_node.getrawmempool()
assert_equal(old_node.getmempoolentry(unbroadcasted_tx_hash)["unbroadcast"], True)
if __name__ == "__main__":
MempoolCompatibilityTest(__file__).main()