1640 | @@ -1643,17 +1641,17 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
1641 | // ********************************************************* Step 8: start indexers
1642 |
1643 | if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
1644 | - g_txindex = std::make_unique<TxIndex>(interfaces::MakeChain(node), cache_sizes.tx_index, false, fReindex);
1645 | + g_txindex = std::make_unique<TxIndex>(interfaces::MakeChain(node), cache_sizes.tx_index, false, chainman.m_blockman.m_reindexing);
In commit "kernel: De-globalize fReindex" (9b2c9c2fce32fe858d1361e863c72108a384a5c8)
It seems like there is a prexisting bug here, and the f_wipe argument passed here should be blockman_opts.reindex instead of chainman.m_blockman.m_reindexing or fReindex. Otherwise if the node is restarted before reindexing completes the TxIndex will be wiped a second time?
Same for BlockFilterIndex and CoinStatsIndex below
Good catch! To be clear from my comments before, it is not that big of an issue if the indexes are wiped again. AFAICT the operations executed while the reindexing atomic is true do not issue any validation signals, so they don't have an effect on the indexes. However recreating them is redundant and I don't think it is particularly useful. I think it would also be good to make the behavior between the coins and the other indexes consistent, so I'll take your suggestion here.
AFAICT the operations executed while the reindexing atomic is true do not issue any validation signals, so they don't have an effect on the indexes.
I need to test this, but this would be surprising to me. I think the idea behind having a separate StartIndexBackgroundSync function that runs after index initialization is that indexes should be able to receive signals during reindexing when -reindex is used so they do not need to completely resync when indexing is finished.
Will check on this, but I think I might recommend just keeping behavior unchanged in this PR so it is a more straightforward refactoring. Or this behavior is worth changing, it seems like it could be moved to a separate commit.
I need to test this, but this would be surprising to me.
Indeed, my impression was wrong. When we restart after a previous reindex without passing in -reindex, the first step is activating the chain again.
Ok, I think I get the different mechanics involved here now and think if initially wiping an index is going to change, it should be done in a separate pull request. Will revert this change.