Skip to content

Commit 533eab7

Browse files
committed
bugfix: Streamline setting reindex option
Reverts a bug introduced in b47bd95 "kernel: De-globalize fReindex". The change leads to a GUI user being prompted to re-index on a chainstate loading failure more than once as well as the node actually not reindexing if the user chooses to. Fix this by setting the reindexing option instead of the atomic, which can be safely re-used to indicate that a reindex should be attempted. The bug specifically is caused by the chainman, and thus the blockman and its m_reindexing atomic being destroyed on every iteration of the for loop. The reindex option for ChainstateLoadOptions is currently also set in a confusing way. By using the reindex atomic, it is not obvious in which scenario it is true or false. The atomic is controlled by both the user passing the -reindex option, the user chosing to reindex if something went wrong during chainstate loading when running the gui, and by reading the reindexing flag from the block tree database in LoadBlockIndexDB. In practice this read is done through the chainstate module's CompleteChainstateInitialization's call to LoadBlockIndex. Since this is only done after the reindex option is set already, it does not have an effect on it. Make this clear by using the reindex option from the blockman opts which is only controlled by the user.
1 parent 058af75 commit 533eab7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/init.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
15581558

15591559
node::ChainstateLoadOptions options;
15601560
options.mempool = Assert(node.mempool.get());
1561-
options.reindex = chainman.m_blockman.m_reindexing;
1561+
options.reindex = blockman_opts.reindex;
15621562
options.reindex_chainstate = fReindexChainState;
15631563
options.prune = chainman.m_blockman.IsPruneMode();
15641564
options.check_blocks = args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS);
@@ -1600,13 +1600,13 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
16001600

16011601
if (!fLoaded && !ShutdownRequested(node)) {
16021602
// first suggest a reindex
1603-
if (!options.reindex) {
1603+
if (!blockman_opts.reindex) {
16041604
bool fRet = uiInterface.ThreadSafeQuestion(
16051605
error + Untranslated(".\n\n") + _("Do you want to rebuild the block database now?"),
16061606
error.original + ".\nPlease restart with -reindex or -reindex-chainstate to recover.",
16071607
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
16081608
if (fRet) {
1609-
chainman.m_blockman.m_reindexing = true;
1609+
blockman_opts.reindex = true;
16101610
if (!Assert(node.shutdown)->reset()) {
16111611
LogPrintf("Internal error: failed to reset shutdown signal.\n");
16121612
}

0 commit comments

Comments
 (0)