diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h --- a/src/node/blockstorage.h +++ b/src/node/blockstorage.h @@ -48,7 +48,6 @@ static constexpr size_t BLOCK_SERIALIZATION_HEADER_SIZE = CMessageHeader::MESSAGE_START_SIZE + sizeof(unsigned int); -extern std::atomic_bool fImporting; extern std::atomic_bool fReindex; // Because validation code takes pointers to the map's CBlockIndex objects, if @@ -142,6 +141,8 @@ explicit BlockManager(Options opts) : m_prune_mode{opts.prune_target > 0}, m_opts{std::move(opts)} {}; + std::atomic m_importing{false}; + BlockMap m_block_index GUARDED_BY(cs_main); std::vector GetAllBlockIndices() @@ -201,7 +202,7 @@ return m_opts.prune_target; } - [[nodiscard]] bool LoadingBlocks() const { return fImporting || fReindex; } + [[nodiscard]] bool LoadingBlocks() const { return m_importing || fReindex; } /** * Calculate the amount of disk space the block & undo files currently use diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -24,7 +24,6 @@ #include namespace node { -std::atomic_bool fImporting(false); std::atomic_bool fReindex(false); static FILE *OpenUndoFile(const FlatFilePos &pos, bool fReadOnly = false); @@ -855,15 +854,17 @@ return blockPos; } -struct CImportingNow { - CImportingNow() { - assert(fImporting == false); - fImporting = true; - } +class ImportingNow { + std::atomic &m_importing; - ~CImportingNow() { - assert(fImporting == true); - fImporting = false; +public: + ImportingNow(std::atomic &importing) : m_importing{importing} { + assert(m_importing == false); + m_importing = true; + } + ~ImportingNow() { + assert(m_importing == true); + m_importing = false; } }; @@ -873,7 +874,7 @@ ScheduleBatchPriority(); { - CImportingNow imp; + ImportingNow imp{chainman.m_blockman.m_importing}; // -reindex if (fReindex) { @@ -978,7 +979,7 @@ StartShutdown(); return; } - } // End scope of CImportingNow + } // End scope of ImportingNow chainman.ActiveChainstate().LoadMempool(mempool_path); } } // namespace node diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -270,7 +270,7 @@ return chainman().ActiveChainstate().IsInitialBlockDownload(); } bool isLoadingBlocks() override { - return node::fReindex || node::fImporting; + return chainman().m_blockman.LoadingBlocks(); } void setNetworkActive(bool active) override { if (m_context->connman) {