aboutsummaryrefslogtreecommitdiff
path: root/src/index
diff options
context:
space:
mode:
authorMartin Zumsande <mzumsande@gmail.com>2022-05-23 21:07:29 +0200
committerMartin Zumsande <mzumsande@gmail.com>2023-05-17 11:14:28 -0400
commit97844d9268b87b5d09b1091bfd0326ed18ce5b91 (patch)
treea5f5056ea6825feb4b22e3533cd43025b29c4932 /src/index
parent60bec3c82d09ec208bf0028ad32499e251ad205e (diff)
downloadbitcoin-97844d9268b87b5d09b1091bfd0326ed18ce5b91.tar.xz
index: Enable reindex-chainstate with active indexes
This is achieved by letting the index sync thread wait until reindex-chainstate is finished. This also disables the pruning check when reindexing the chainstate (which is incompatible with prune mode) because there would be no chain at this point in init.
Diffstat (limited to 'src/index')
-rw-r--r--src/index/base.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/index/base.cpp b/src/index/base.cpp
index 67c7156c55..7444579395 100644
--- a/src/index/base.cpp
+++ b/src/index/base.cpp
@@ -23,6 +23,8 @@
#include <string>
#include <utility>
+using node::g_indexes_ready_to_sync;
+
constexpr uint8_t DB_BEST_BLOCK{'B'};
constexpr auto SYNC_LOG_INTERVAL{30s};
@@ -105,7 +107,9 @@ bool BaseIndex::Init()
// datadir and an index enabled. If this is the case, indexation will happen solely
// via `BlockConnected` signals until, possibly, the next restart.
m_synced = m_best_block_index.load() == active_chain.Tip();
- if (!m_synced) {
+
+ // Skip pruning check if indexes are not ready to sync (because reindex-chainstate has wiped the chain).
+ if (!m_synced && g_indexes_ready_to_sync) {
bool prune_violation = false;
if (!m_best_block_index) {
// index is not built yet
@@ -161,6 +165,12 @@ static const CBlockIndex* NextSyncBlock(const CBlockIndex* pindex_prev, CChain&
void BaseIndex::ThreadSync()
{
SetSyscallSandboxPolicy(SyscallSandboxPolicy::TX_INDEX);
+ // Wait for a possible reindex-chainstate to finish until continuing
+ // with the index sync
+ while (!g_indexes_ready_to_sync) {
+ if (!m_interrupt.sleep_for(std::chrono::milliseconds(500))) return;
+ }
+
const CBlockIndex* pindex = m_best_block_index.load();
if (!m_synced) {
std::chrono::steady_clock::time_point last_log_time{0s};