diff options
author | Ryan Ofsky <ryan@ofsky.org> | 2022-01-17 18:36:40 -0500 |
---|---|---|
committer | Ryan Ofsky <ryan@ofsky.org> | 2022-07-18 13:39:55 -0500 |
commit | bef4e405f3de2718dfee279a9abff4daf016da26 (patch) | |
tree | 52a53b50ad0da1ae8dcf59dc1a0ef174df1381e8 /src/index/base.h | |
parent | addb4f2af183a25ce4a6b6485b5b49575a2ba31b (diff) |
indexes, refactor: Remove CBlockIndex* uses in index Init methods
Replace overriden index Init() methods that use the best block
CBlockIndex* pointer with pure CustomInit() callbacks that are passed
the block hash and height.
This gets rid of more CBlockIndex* pointer uses so indexes can work
outside the bitcoin-node process. It also simplifies the initialization
call sequence so index implementations are not responsible for
initializing the base class.
There is a slight change in behavior here since now the best block
pointer is loaded and checked before the custom index init functions are
called instead of while they are called.
Diffstat (limited to 'src/index/base.h')
-rw-r--r-- | src/index/base.h | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/index/base.h b/src/index/base.h index 3586376459..82317c1ec2 100644 --- a/src/index/base.h +++ b/src/index/base.h @@ -63,6 +63,9 @@ private: std::thread m_thread_sync; CThreadInterrupt m_interrupt; + /// Read best block locator and check that data needed to sync has not been pruned. + bool Init(); + /// Sync the index with the block index starting from the current best block. /// Intended to be run in its own thread, m_thread_sync, and can be /// interrupted with m_interrupt. Once the index gets in sync, the m_synced @@ -90,10 +93,8 @@ protected: void ChainStateFlushed(const CBlockLocator& locator) override; - const CBlockIndex* CurrentIndex() { return m_best_block_index.load(); }; - /// Initialize internal state from the database and block index. - [[nodiscard]] virtual bool Init(); + [[nodiscard]] virtual bool CustomInit(const std::optional<interfaces::BlockKey>& block) { return true; } /// Write update index entries for a newly connected block. virtual bool WriteBlock(const CBlock& block, const CBlockIndex* pindex) { return true; } |