Skip to content

Commit

Permalink
scripted-diff: rename 'loadblk' thread name to 'initload'
Browse files Browse the repository at this point in the history
The thread does not only load blocks, it loads the mempool and,
in a future commit, will start the indexes as well.

Also, renamed the 'ThreadImport' function to 'ImportBlocks'
And the 'm_load_block' class member to 'm_thread_load'.

-BEGIN VERIFY SCRIPT-

sed -i "s/ThreadImport/ImportBlocks/g" $(git grep -l ThreadImport -- ':!/doc/')
sed -i "s/loadblk/initload/g" $(git grep -l loadblk -- ':!/doc/release-notes/')
sed -i "s/m_load_block/m_thread_load/g" $(git grep -l m_load_block)

-END VERIFY SCRIPT-
  • Loading branch information
furszy committed Jul 7, 2023
1 parent ed4462c commit 0457510
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion doc/developer-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ Threads
: Started from `main()` in `bitcoind.cpp`. Responsible for starting up and
shutting down the application.

- [ThreadImport (`b-loadblk`)](https://doxygen.bitcoincore.org/namespacenode.html#ab4305679079866f0f420f7dbf278381d)
- [ThreadImport (`b-initload`)](https://doxygen.bitcoincore.org/namespacenode.html#ab4305679079866f0f420f7dbf278381d)
: Loads blocks from `blk*.dat` files or `-loadblock=<file>` on startup.

- [CCheckQueue::Loop (`b-scriptch.x`)](https://doxygen.bitcoincore.org/class_c_check_queue.html#a6e7fa51d3a25e7cb65446d4b50e6a987)
Expand Down
2 changes: 1 addition & 1 deletion src/bitcoin-chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ int main(int argc, char* argv[])
// Without this precise shutdown sequence, there will be a lot of nullptr
// dereferencing and UB.
scheduler.stop();
if (chainman.m_load_block.joinable()) chainman.m_load_block.join();
if (chainman.m_thread_load.joinable()) chainman.m_thread_load.join();
StopScriptCheckWorkerThreads();

GetMainSignals().FlushBackgroundCallbacks();
Expand Down
12 changes: 6 additions & 6 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ using node::LoadChainstate;
using node::MempoolPath;
using node::NodeContext;
using node::ShouldPersistMempool;
using node::ThreadImport;
using node::ImportBlocks;
using node::VerifyLoadedChainstate;

static constexpr bool DEFAULT_PROXYRANDOMIZE{true};
Expand Down Expand Up @@ -268,7 +268,7 @@ void Shutdown(NodeContext& node)
// After everything has been shut down, but before things get flushed, stop the
// CScheduler/checkqueue, scheduler and load block thread.
if (node.scheduler) node.scheduler->stop();
if (node.chainman && node.chainman->m_load_block.joinable()) node.chainman->m_load_block.join();
if (node.chainman && node.chainman->m_thread_load.joinable()) node.chainman->m_thread_load.join();
StopScriptCheckWorkerThreads();

// After the threads that potentially access these pointers have been stopped,
Expand Down Expand Up @@ -1545,7 +1545,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)

// ********************************************************* Step 8: start indexers

// If reindex-chainstate was specified, delay syncing indexes until ThreadImport has reindexed the chain
// If reindex-chainstate was specified, delay syncing indexes until ImportBlocks has reindexed the chain
if (!fReindexChainState) g_indexes_ready_to_sync = true;
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
auto result{WITH_LOCK(cs_main, return CheckLegacyTxindex(*Assert(chainman.m_blockman.m_block_tree_db)))};
Expand Down Expand Up @@ -1656,9 +1656,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
vImportFiles.push_back(fs::PathFromString(strFile));
}

chainman.m_load_block = std::thread(&util::TraceThread, "loadblk", [=, &chainman, &args] {
chainman.m_thread_load = std::thread(&util::TraceThread, "initload", [=, &chainman, &args] {
// Import blocks
ThreadImport(chainman, vImportFiles);
ImportBlocks(chainman, vImportFiles);
// Load mempool from disk
chainman.ActiveChainstate().LoadMempool(ShouldPersistMempool(args) ? MempoolPath(args) : fs::path{});
});
Expand All @@ -1667,7 +1667,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
{
WAIT_LOCK(g_genesis_wait_mutex, lock);
// We previously could hang here if StartShutdown() is called prior to
// ThreadImport getting started, so instead we just wait on a timer to
// ImportBlocks getting started, so instead we just wait on a timer to
// check ShutdownRequested() regularly.
while (!fHaveGenesis && !ShutdownRequested()) {
g_genesis_wait_cv.wait_for(lock, std::chrono::milliseconds(500));
Expand Down
2 changes: 1 addition & 1 deletion src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ class ImportingNow
}
};

void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles)
void ImportBlocks(ChainstateManager& chainman, std::vector<fs::path> vImportFiles)
{
ScheduleBatchPriority();

Expand Down
2 changes: 1 addition & 1 deletion src/node/blockstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class BlockManager
void CleanupBlockRevFiles() const;
};

void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles);
void ImportBlocks(ChainstateManager& chainman, std::vector<fs::path> vImportFiles);
} // namespace node

#endif // BITCOIN_NODE_BLOCKSTORAGE_H
2 changes: 1 addition & 1 deletion src/node/chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static ChainstateLoadResult CompleteChainstateInitialization(
// At this point blocktree args are consistent with what's on disk.
// If we're not mid-reindex (based on disk + args), add a genesis block on disk
// (otherwise we use the one already on disk).
// This is called again in ThreadImport after the reindex completes.
// This is called again in ImportBlocks after the reindex completes.
if (!fReindex && !chainman.ActiveChainstate().LoadGenesisBlock()) {
return {ChainstateLoadStatus::FAILURE, _("Error initializing block database")};
}
Expand Down
2 changes: 1 addition & 1 deletion src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ class ChainstateManager

const util::SignalInterrupt& m_interrupt;
const Options m_options;
std::thread m_load_block;
std::thread m_thread_load;
//! A single BlockManager instance is shared across each constructed
//! chainstate to avoid duplicating block metadata.
node::BlockManager m_blockman;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def check_clean_start():
b'init message: Starting network threads',
b'net thread start',
b'addcon thread start',
b'loadblk thread start',
b'initload thread start',
b'txindex thread start',
b'block filter index thread start',
b'coinstatsindex thread start',
Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def wait_for_rpc_connection(self):
# Wait for the node to finish reindex, block import, and
# loading the mempool. Usually importing happens fast or
# even "immediate" when the node is started. However, there
# is no guarantee and sometimes ThreadImport might finish
# is no guarantee and sometimes ImportBlocks might finish
# later. This is going to cause intermittent test failures,
# because generally the tests assume the node is fully
# ready after being started.
Expand Down

0 comments on commit 0457510

Please sign in to comment.