indexes, refactor: Pass Chain interface instead of CChainState class to indexes

Passing abstract Chain interface will let indexes run in separate
processes.

This commit does not change behavior in any way.
This commit is contained in:
Ryan Ofsky
2022-01-13 07:57:54 -05:00
parent a0b5b4ae5a
commit 33b4d48cfc
15 changed files with 58 additions and 33 deletions

View File

@@ -4,7 +4,9 @@
#include <chainparams.h>
#include <index/base.h>
#include <interfaces/chain.h>
#include <node/blockstorage.h>
#include <node/context.h>
#include <node/interface_ui.h>
#include <shutdown.h>
#include <tinyformat.h>
@@ -49,6 +51,9 @@ void BaseIndex::DB::WriteBestBlock(CDBBatch& batch, const CBlockLocator& locator
batch.Write(DB_BEST_BLOCK, locator);
}
BaseIndex::BaseIndex(std::unique_ptr<interfaces::Chain> chain)
: m_chain{std::move(chain)} {}
BaseIndex::~BaseIndex()
{
Interrupt();
@@ -346,9 +351,11 @@ void BaseIndex::Interrupt()
m_interrupt();
}
bool BaseIndex::Start(CChainState& active_chainstate)
bool BaseIndex::Start()
{
m_chainstate = &active_chainstate;
// 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);