Skip to content

Commit 41a1b5f

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#23046: test: Add txindex migration test
fadc4c7 test: Add txindex migration test (MarcoFalke) Pull request description: Test for #22626 ACKs for top commit: theStack: Tested ACK fadc4c7 🌁 Tree-SHA512: fc7133ef52826bf0d4fa2ac72c3f1bed4a185ff7492396552ff2cbf6531b053238039211a710cbb949379c56875cd7715f1ed49a514dd3b3f1b46554e3d4bef5
2 parents 8251316 + fadc4c7 commit 41a1b5f

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2021 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test that legacy txindex will be disabled on upgrade.
6+
7+
Previous releases are required by this test, see test/README.md.
8+
"""
9+
10+
import os
11+
import shutil
12+
13+
from test_framework.test_framework import BitcoinTestFramework
14+
from test_framework.wallet import MiniWallet
15+
16+
17+
class MempoolCompatibilityTest(BitcoinTestFramework):
18+
def set_test_params(self):
19+
self.num_nodes = 3
20+
self.extra_args = [
21+
["-reindex", "-txindex"],
22+
[],
23+
[],
24+
]
25+
26+
def skip_test_if_missing_module(self):
27+
self.skip_if_no_previous_releases()
28+
29+
def setup_network(self):
30+
self.add_nodes(
31+
self.num_nodes,
32+
self.extra_args,
33+
versions=[
34+
160300, # Last release with legacy txindex
35+
None, # For MiniWallet, without migration code
36+
200100, # Any release with migration code (0.17.x - 22.x)
37+
],
38+
)
39+
self.start_nodes()
40+
self.connect_nodes(0, 1)
41+
self.connect_nodes(1, 2)
42+
43+
def run_test(self):
44+
mini_wallet = MiniWallet(self.nodes[1])
45+
mini_wallet.rescan_utxos()
46+
spend_utxo = mini_wallet.get_utxo()
47+
mini_wallet.send_self_transfer(from_node=self.nodes[1], utxo_to_spend=spend_utxo)
48+
self.generate(self.nodes[1], 1)
49+
50+
self.log.info("Check legacy txindex")
51+
self.nodes[0].getrawtransaction(txid=spend_utxo["txid"]) # Requires -txindex
52+
53+
self.stop_nodes()
54+
legacy_chain_dir = os.path.join(self.nodes[0].datadir, self.chain)
55+
56+
self.log.info("Migrate legacy txindex")
57+
migrate_chain_dir = os.path.join(self.nodes[2].datadir, self.chain)
58+
shutil.rmtree(migrate_chain_dir)
59+
shutil.copytree(legacy_chain_dir, migrate_chain_dir)
60+
with self.nodes[2].assert_debug_log([
61+
"Upgrading txindex database...",
62+
"txindex is enabled at height 200",
63+
]):
64+
self.start_node(2, extra_args=["-txindex"])
65+
self.nodes[2].getrawtransaction(txid=spend_utxo["txid"]) # Requires -txindex
66+
67+
self.log.info("Drop legacy txindex")
68+
drop_index_chain_dir = os.path.join(self.nodes[1].datadir, self.chain)
69+
shutil.rmtree(drop_index_chain_dir)
70+
shutil.copytree(legacy_chain_dir, drop_index_chain_dir)
71+
self.nodes[1].assert_start_raises_init_error(
72+
extra_args=["-txindex"],
73+
expected_msg="Error: The block index db contains a legacy 'txindex'. To clear the occupied disk space, run a full -reindex, otherwise ignore this error. This error message will not be displayed again.",
74+
)
75+
# Build txindex from scratch and check there is no error this time
76+
self.start_node(1, extra_args=["-txindex"])
77+
self.nodes[2].getrawtransaction(txid=spend_utxo["txid"]) # Requires -txindex
78+
79+
self.stop_nodes()
80+
81+
self.log.info("Check migrated txindex can not be read by legacy node")
82+
err_msg = f": You need to rebuild the database using -reindex to change -txindex.{os.linesep}Please restart with -reindex or -reindex-chainstate to recover."
83+
shutil.rmtree(legacy_chain_dir)
84+
shutil.copytree(migrate_chain_dir, legacy_chain_dir)
85+
self.nodes[0].assert_start_raises_init_error(extra_args=["-txindex"], expected_msg=err_msg)
86+
shutil.rmtree(legacy_chain_dir)
87+
shutil.copytree(drop_index_chain_dir, legacy_chain_dir)
88+
self.nodes[0].assert_start_raises_init_error(extra_args=["-txindex"], expected_msg=err_msg)
89+
90+
91+
if __name__ == "__main__":
92+
MempoolCompatibilityTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@
296296
'rpc_deriveaddresses.py --usecli',
297297
'p2p_ping.py',
298298
'rpc_scantxoutset.py',
299+
'feature_txindex_compatibility.py',
299300
'feature_logging.py',
300301
'feature_anchors.py',
301302
'feature_coinstatsindex.py',

0 commit comments

Comments
 (0)