mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-02 11:55:42 +02:00
refactor: index, decouple 'Init' from 'Start'
So indexes can be initialized without spawning the sync thread. This makes asynchronous indexes startup possible in the following commits.
This commit is contained in:
@@ -81,6 +81,13 @@ BaseIndex::~BaseIndex()
|
||||
|
||||
bool BaseIndex::Init()
|
||||
{
|
||||
// m_chainstate member gives indexing code access to node internals. It is
|
||||
// removed in followup https://github.com/bitcoin/bitcoin/pull/24230
|
||||
m_chainstate = &m_chain->context()->chainman->ActiveChainstate();
|
||||
// Register to validation interface before setting the 'm_synced' flag, so that
|
||||
// callbacks are not missed once m_synced is true.
|
||||
RegisterValidationInterface(this);
|
||||
|
||||
CBlockLocator locator;
|
||||
if (!GetDB().ReadBestBlock(locator)) {
|
||||
locator.SetNull();
|
||||
@@ -147,6 +154,7 @@ 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 = synced;
|
||||
m_init = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -401,15 +409,9 @@ void BaseIndex::Interrupt()
|
||||
m_interrupt();
|
||||
}
|
||||
|
||||
bool BaseIndex::Start()
|
||||
bool BaseIndex::StartBackgroundSync()
|
||||
{
|
||||
// m_chainstate member gives indexing code access to node internals. It is
|
||||
// removed in followup https://github.com/bitcoin/bitcoin/pull/24230
|
||||
m_chainstate = &m_chain->context()->chainman->ActiveChainstate();
|
||||
// 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()) return false;
|
||||
if (!m_init) throw std::logic_error("Error: Cannot start a non-initialized index");
|
||||
|
||||
m_thread_sync = std::thread(&util::TraceThread, GetName(), [this] { ThreadSync(); });
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user