Skip to content

Commit 06b88ff

Browse files
committed
LoadMempool: Pass in load_path, stop using gArgs
Also: 1. Have CChainState::LoadMempool and ::ThreadImport take in paths and pass it through untouched to LoadMempool. 2. Make LoadMempool exit early if the load_path is empty. 3. Adjust the call to ::ThreadImport in ::AppInitMain to correctly pass in an empty path if mempool persistence is disabled.
1 parent b857ac6 commit 06b88ff

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

src/init.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
16731673
}
16741674

16751675
chainman.m_load_block = std::thread(&util::TraceThread, "loadblk", [=, &chainman, &args] {
1676-
ThreadImport(chainman, vImportFiles, args);
1676+
ThreadImport(chainman, vImportFiles, args, ShouldPersistMempool(args) ? MempoolPath(args) : fs::path{});
16771677
});
16781678

16791679
// Wait for genesis block to be processed

src/node/blockstorage.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ struct CImportingNow {
823823
}
824824
};
825825

826-
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args)
826+
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args, const fs::path& mempool_path)
827827
{
828828
SetSyscallSandboxPolicy(SyscallSandboxPolicy::INITIALIZATION_LOAD_BLOCKS);
829829
ScheduleBatchPriority();
@@ -893,6 +893,6 @@ void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFile
893893
return;
894894
}
895895
} // End scope of CImportingNow
896-
chainman.ActiveChainstate().LoadMempool(args);
896+
chainman.ActiveChainstate().LoadMempool(mempool_path);
897897
}
898898
} // namespace node

src/node/blockstorage.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatFilePos& pos, c
211211

212212
bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex);
213213

214-
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args);
214+
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args, const fs::path& mempool_path);
215215
} // namespace node
216216

217217
#endif // BITCOIN_NODE_BLOCKSTORAGE_H

src/test/fuzz/validation_load_mempool.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ FUZZ_TARGET_INIT(validation_load_mempool, initialize_validation_load_mempool)
4343
auto fuzzed_fopen = [&](const fs::path&, const char*) {
4444
return fuzzed_file_provider.open();
4545
};
46-
(void)chainstate.LoadMempool(g_setup->m_args, fuzzed_fopen);
46+
(void)chainstate.LoadMempool(MempoolPath(g_setup->m_args), fuzzed_fopen);
4747
(void)DumpMempool(pool, MempoolPath(g_setup->m_args), fuzzed_fopen, true);
4848
}

src/validation.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -3865,12 +3865,10 @@ void PruneBlockFilesManual(CChainState& active_chainstate, int nManualPruneHeigh
38653865
}
38663866
}
38673867

3868-
void CChainState::LoadMempool(const ArgsManager& args, FopenFn mockable_fopen_function)
3868+
void CChainState::LoadMempool(const fs::path& load_path, FopenFn mockable_fopen_function)
38693869
{
38703870
if (!m_mempool) return;
3871-
if (args.GetBoolArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
3872-
::LoadMempool(*m_mempool, *this, mockable_fopen_function);
3873-
}
3871+
::LoadMempool(*m_mempool, load_path, *this, mockable_fopen_function);
38743872
m_mempool->SetLoadTried(!ShutdownRequested());
38753873
}
38763874

@@ -4644,9 +4642,11 @@ bool CChainState::ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
46444642

46454643
static const uint64_t MEMPOOL_DUMP_VERSION = 1;
46464644

4647-
bool LoadMempool(CTxMemPool& pool, CChainState& active_chainstate, FopenFn mockable_fopen_function)
4645+
bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, CChainState& active_chainstate, FopenFn mockable_fopen_function)
46484646
{
4649-
FILE* filestr{mockable_fopen_function(gArgs.GetDataDirNet() / "mempool.dat", "rb")};
4647+
if (load_path.empty()) return false;
4648+
4649+
FILE* filestr{mockable_fopen_function(load_path, "rb")};
46504650
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
46514651
if (file.IsNull()) {
46524652
LogPrintf("Failed to open mempool file from disk. Continuing anyway.\n");

src/validation.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ class CChainState
679679
void CheckBlockIndex();
680680

681681
/** Load the persisted mempool from disk */
682-
void LoadMempool(const ArgsManager& args, fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
682+
void LoadMempool(const fs::path& load_path, fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
683683

684684
/** Update the chain tip based on database information, i.e. CoinsTip()'s best block. */
685685
bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
@@ -1018,7 +1018,7 @@ bool DeploymentEnabled(const ChainstateManager& chainman, DEP dep)
10181018
bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path, fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen, bool skip_file_commit = false);
10191019

10201020
/** Load the mempool from disk. */
1021-
bool LoadMempool(CTxMemPool& pool, CChainState& active_chainstate, fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
1021+
bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, CChainState& active_chainstate, fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
10221022

10231023
/**
10241024
* Return the expected assumeutxo value for a given height, if one exists.

0 commit comments

Comments
 (0)