Skip to content

Commit 0f1cf9b

Browse files
committed
refactor: index, make synchronous Sync() mechanism accessible
1 parent 11d859d commit 0f1cf9b

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/index/base.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static const CBlockIndex* NextSyncBlock(const CBlockIndex* pindex_prev, CChain&
142142
return chain.Next(chain.FindFork(pindex_prev));
143143
}
144144

145-
void BaseIndex::ThreadSync()
145+
void BaseIndex::Sync()
146146
{
147147
const CBlockIndex* pindex = m_best_block_index.load();
148148
if (!m_synced) {
@@ -392,7 +392,7 @@ bool BaseIndex::StartBackgroundSync()
392392
{
393393
if (!m_init) throw std::logic_error("Error: Cannot start a non-initialized index");
394394

395-
m_thread_sync = std::thread(&util::TraceThread, GetName(), [this] { ThreadSync(); });
395+
m_thread_sync = std::thread(&util::TraceThread, GetName(), [this] { Sync(); });
396396
return true;
397397
}
398398

src/index/base.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,6 @@ class BaseIndex : public CValidationInterface
7878
std::thread m_thread_sync;
7979
CThreadInterrupt m_interrupt;
8080

81-
/// Sync the index with the block index starting from the current best block.
82-
/// Intended to be run in its own thread, m_thread_sync, and can be
83-
/// interrupted with m_interrupt. Once the index gets in sync, the m_synced
84-
/// flag is set and the BlockConnected ValidationInterface callback takes
85-
/// over and the sync thread exits.
86-
void ThreadSync();
87-
8881
/// Write the current index state (eg. chain block locator and subclass-specific items) to disk.
8982
///
9083
/// Recommendations for error handling:
@@ -152,9 +145,16 @@ class BaseIndex : public CValidationInterface
152145
/// validation interface so that it stays in sync with blockchain updates.
153146
[[nodiscard]] bool Init();
154147

155-
/// Starts the initial sync process.
148+
/// Starts the initial sync process on a background thread.
156149
[[nodiscard]] bool StartBackgroundSync();
157150

151+
/// Sync the index with the block index starting from the current best block.
152+
/// Intended to be run in its own thread, m_thread_sync, and can be
153+
/// interrupted with m_interrupt. Once the index gets in sync, the m_synced
154+
/// flag is set and the BlockConnected ValidationInterface callback takes
155+
/// over and the sync thread exits.
156+
void Sync();
157+
158158
/// Stops the instance from staying in sync with blockchain updates.
159159
void Stop();
160160

0 commit comments

Comments
 (0)