Skip to content

Commit d3d7547

Browse files
committed
Add -reindex-chainstate that does not rebuild block index
1 parent fb8fad1 commit d3d7547

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

qa/rpc-tests/reindex.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

66
#
7-
# Test -reindex with CheckBlockIndex
7+
# Test -reindex and -reindex-chainstate with CheckBlockIndex
88
#
99
from test_framework.test_framework import BitcoinTestFramework
1010
from test_framework.util import *
@@ -20,13 +20,20 @@ def setup_network(self):
2020
self.is_network_split = False
2121
self.nodes.append(start_node(0, self.options.tmpdir))
2222

23-
def run_test(self):
23+
def reindex(self, justchainstate=False):
2424
self.nodes[0].generate(3)
25+
blockcount = self.nodes[0].getblockcount()
2526
stop_node(self.nodes[0], 0)
2627
wait_bitcoinds()
27-
self.nodes[0]=start_node(0, self.options.tmpdir, ["-debug", "-reindex", "-checkblockindex=1"])
28-
assert_equal(self.nodes[0].getblockcount(), 3)
28+
self.nodes[0]=start_node(0, self.options.tmpdir, ["-debug", "-reindex-chainstate" if justchainstate else "-reindex", "-checkblockindex=1"])
29+
assert_equal(self.nodes[0].getblockcount(), blockcount)
2930
print("Success")
3031

32+
def run_test(self):
33+
self.reindex(False)
34+
self.reindex(True)
35+
self.reindex(False)
36+
self.reindex(True)
37+
3138
if __name__ == '__main__':
3239
ReindexTest().main()

src/init.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ std::string HelpMessage(HelpMessageMode mode)
327327
strUsage += HelpMessageOpt("-prune=<n>", strprintf(_("Reduce storage requirements by pruning (deleting) old blocks. This mode is incompatible with -txindex and -rescan. "
328328
"Warning: Reverting this setting requires re-downloading the entire blockchain. "
329329
"(default: 0 = disable pruning blocks, >%u = target size in MiB to use for block files)"), MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024));
330-
strUsage += HelpMessageOpt("-reindex", _("Rebuild block chain index from current blk000??.dat files on startup"));
330+
strUsage += HelpMessageOpt("-reindex-chainstate", _("Rebuild chain state from the currently indexed blocks"));
331+
strUsage += HelpMessageOpt("-reindex", _("Rebuild chain state and block index from the blk*.dat files on disk"));
331332
#ifndef WIN32
332333
strUsage += HelpMessageOpt("-sysperms", _("Create new files with system default permissions, instead of umask 077 (only effective with disabled wallet functionality)"));
333334
#endif
@@ -1164,6 +1165,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
11641165
// ********************************************************* Step 7: load block chain
11651166

11661167
fReindex = GetBoolArg("-reindex", false);
1168+
bool fReindexChainState = GetBoolArg("-reindex-chainstate", false);
11671169

11681170
// Upgrading to 0.8; hard-link the old blknnnn.dat files into /blocks/
11691171
boost::filesystem::path blocksDir = GetDataDir() / "blocks";
@@ -1225,7 +1227,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
12251227
delete pblocktree;
12261228

12271229
pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReindex);
1228-
pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex);
1230+
pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex || fReindexChainState);
12291231
pcoinscatcher = new CCoinsViewErrorCatcher(pcoinsdbview);
12301232
pcoinsTip = new CCoinsViewCache(pcoinscatcher);
12311233

@@ -1254,7 +1256,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
12541256

12551257
// Check for changed -txindex state
12561258
if (fTxIndex != GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
1257-
strLoadError = _("You need to rebuild the database using -reindex to change -txindex");
1259+
strLoadError = _("You need to rebuild the database using -reindex-chainstate to change -txindex");
12581260
break;
12591261
}
12601262

0 commit comments

Comments
 (0)