diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2023-05-17 00:55:09 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2023-07-10 10:47:17 -0300 |
commit | 430e7027a18870a296abb0bbd9332cbe40d8fdc0 (patch) | |
tree | f3eb0ea165cce9123f47bed6ff3130cbb9bb97e6 /src/index/base.h | |
parent | 225e213110602b4fd1d345167f5f92d26557f6c1 (diff) | |
download | bitcoin-430e7027a18870a296abb0bbd9332cbe40d8fdc0.tar.xz |
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.
Diffstat (limited to 'src/index/base.h')
-rw-r--r-- | src/index/base.h | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/index/base.h b/src/index/base.h index 8affee90f8..8b986fe8c4 100644 --- a/src/index/base.h +++ b/src/index/base.h @@ -54,6 +54,8 @@ protected: }; private: + /// Whether the index has been initialized or not. + std::atomic<bool> m_init{false}; /// Whether the index is in sync with the main chain. The flag is flipped /// from false to true once, after which point this starts processing /// ValidationInterface notifications to stay in sync. @@ -69,9 +71,6 @@ 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 @@ -142,9 +141,12 @@ public: void Interrupt(); - /// Start initializes the sync state and registers the instance as a - /// ValidationInterface so that it stays in sync with blockchain updates. - [[nodiscard]] bool Start(); + /// Initializes the sync state and registers the instance to the + /// validation interface so that it stays in sync with blockchain updates. + [[nodiscard]] bool Init(); + + /// Starts the initial sync process. + [[nodiscard]] bool StartBackgroundSync(); /// Stops the instance from staying in sync with blockchain updates. void Stop(); |