index: Avoid async shutdown on init error

This commit is contained in:
MarcoFalke
2021-04-28 14:01:37 +02:00
parent 2e30e328a7
commit faad68fcd4
7 changed files with 23 additions and 17 deletions

View File

@@ -98,9 +98,7 @@ bool BaseIndex::Init()
}
}
if (prune_violation) {
// throw error and graceful shutdown if we can't build the index
FatalError("%s: %s best block of the index goes beyond pruned data. Please disable the index or reindex (which will download the whole blockchain again)", __func__, GetName());
return false;
return InitError(strprintf(Untranslated("%s best block of the index goes beyond pruned data. Please disable the index or reindex (which will download the whole blockchain again)"), GetName()));
}
}
return true;
@@ -339,17 +337,17 @@ void BaseIndex::Interrupt()
m_interrupt();
}
void BaseIndex::Start()
bool BaseIndex::Start()
{
// Need to register this ValidationInterface before running Init(), so that
// callbacks are not missed if Init sets m_synced to true.
RegisterValidationInterface(this);
if (!Init()) {
FatalError("%s: %s failed to initialize", __func__, GetName());
return;
return false;
}
m_thread_sync = std::thread(&util::TraceThread, GetName(), [this] { ThreadSync(); });
return true;
}
void BaseIndex::Stop()

View File

@@ -84,7 +84,7 @@ protected:
const CBlockIndex* CurrentIndex() { return m_best_block_index.load(); };
/// Initialize internal state from the database and block index.
virtual bool Init();
[[nodiscard]] virtual bool Init();
/// Write update index entries for a newly connected block.
virtual bool WriteBlock(const CBlock& block, const CBlockIndex* pindex) { return true; }
@@ -117,7 +117,7 @@ public:
/// Start initializes the sync state and registers the instance as a
/// ValidationInterface so that it stays in sync with blockchain updates.
void Start();
[[nodiscard]] bool Start();
/// Stops the instance from staying in sync with blockchain updates.
void Stop();