mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
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.
This commit is contained in:
parent
b857ac60d9
commit
06b88ffb8a
6 changed files with 13 additions and 13 deletions
|
@ -1673,7 +1673,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
}
|
}
|
||||||
|
|
||||||
chainman.m_load_block = std::thread(&util::TraceThread, "loadblk", [=, &chainman, &args] {
|
chainman.m_load_block = std::thread(&util::TraceThread, "loadblk", [=, &chainman, &args] {
|
||||||
ThreadImport(chainman, vImportFiles, args);
|
ThreadImport(chainman, vImportFiles, args, ShouldPersistMempool(args) ? MempoolPath(args) : fs::path{});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Wait for genesis block to be processed
|
// Wait for genesis block to be processed
|
||||||
|
|
|
@ -823,7 +823,7 @@ struct CImportingNow {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args)
|
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args, const fs::path& mempool_path)
|
||||||
{
|
{
|
||||||
SetSyscallSandboxPolicy(SyscallSandboxPolicy::INITIALIZATION_LOAD_BLOCKS);
|
SetSyscallSandboxPolicy(SyscallSandboxPolicy::INITIALIZATION_LOAD_BLOCKS);
|
||||||
ScheduleBatchPriority();
|
ScheduleBatchPriority();
|
||||||
|
@ -893,6 +893,6 @@ void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFile
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} // End scope of CImportingNow
|
} // End scope of CImportingNow
|
||||||
chainman.ActiveChainstate().LoadMempool(args);
|
chainman.ActiveChainstate().LoadMempool(mempool_path);
|
||||||
}
|
}
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
|
|
@ -211,7 +211,7 @@ bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatFilePos& pos, c
|
||||||
|
|
||||||
bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex);
|
bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex);
|
||||||
|
|
||||||
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args);
|
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args, const fs::path& mempool_path);
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
|
||||||
#endif // BITCOIN_NODE_BLOCKSTORAGE_H
|
#endif // BITCOIN_NODE_BLOCKSTORAGE_H
|
||||||
|
|
|
@ -43,6 +43,6 @@ FUZZ_TARGET_INIT(validation_load_mempool, initialize_validation_load_mempool)
|
||||||
auto fuzzed_fopen = [&](const fs::path&, const char*) {
|
auto fuzzed_fopen = [&](const fs::path&, const char*) {
|
||||||
return fuzzed_file_provider.open();
|
return fuzzed_file_provider.open();
|
||||||
};
|
};
|
||||||
(void)chainstate.LoadMempool(g_setup->m_args, fuzzed_fopen);
|
(void)chainstate.LoadMempool(MempoolPath(g_setup->m_args), fuzzed_fopen);
|
||||||
(void)DumpMempool(pool, MempoolPath(g_setup->m_args), fuzzed_fopen, true);
|
(void)DumpMempool(pool, MempoolPath(g_setup->m_args), fuzzed_fopen, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3865,12 +3865,10 @@ void PruneBlockFilesManual(CChainState& active_chainstate, int nManualPruneHeigh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CChainState::LoadMempool(const ArgsManager& args, FopenFn mockable_fopen_function)
|
void CChainState::LoadMempool(const fs::path& load_path, FopenFn mockable_fopen_function)
|
||||||
{
|
{
|
||||||
if (!m_mempool) return;
|
if (!m_mempool) return;
|
||||||
if (args.GetBoolArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
|
::LoadMempool(*m_mempool, load_path, *this, mockable_fopen_function);
|
||||||
::LoadMempool(*m_mempool, *this, mockable_fopen_function);
|
|
||||||
}
|
|
||||||
m_mempool->SetLoadTried(!ShutdownRequested());
|
m_mempool->SetLoadTried(!ShutdownRequested());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4644,9 +4642,11 @@ bool CChainState::ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
|
||||||
|
|
||||||
static const uint64_t MEMPOOL_DUMP_VERSION = 1;
|
static const uint64_t MEMPOOL_DUMP_VERSION = 1;
|
||||||
|
|
||||||
bool LoadMempool(CTxMemPool& pool, CChainState& active_chainstate, FopenFn mockable_fopen_function)
|
bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, CChainState& active_chainstate, FopenFn mockable_fopen_function)
|
||||||
{
|
{
|
||||||
FILE* filestr{mockable_fopen_function(gArgs.GetDataDirNet() / "mempool.dat", "rb")};
|
if (load_path.empty()) return false;
|
||||||
|
|
||||||
|
FILE* filestr{mockable_fopen_function(load_path, "rb")};
|
||||||
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
|
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
|
||||||
if (file.IsNull()) {
|
if (file.IsNull()) {
|
||||||
LogPrintf("Failed to open mempool file from disk. Continuing anyway.\n");
|
LogPrintf("Failed to open mempool file from disk. Continuing anyway.\n");
|
||||||
|
|
|
@ -679,7 +679,7 @@ public:
|
||||||
void CheckBlockIndex();
|
void CheckBlockIndex();
|
||||||
|
|
||||||
/** Load the persisted mempool from disk */
|
/** Load the persisted mempool from disk */
|
||||||
void LoadMempool(const ArgsManager& args, fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
|
void LoadMempool(const fs::path& load_path, fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
|
||||||
|
|
||||||
/** Update the chain tip based on database information, i.e. CoinsTip()'s best block. */
|
/** Update the chain tip based on database information, i.e. CoinsTip()'s best block. */
|
||||||
bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
@ -1018,7 +1018,7 @@ bool DeploymentEnabled(const ChainstateManager& chainman, DEP dep)
|
||||||
bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path, fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen, bool skip_file_commit = false);
|
bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path, fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen, bool skip_file_commit = false);
|
||||||
|
|
||||||
/** Load the mempool from disk. */
|
/** Load the mempool from disk. */
|
||||||
bool LoadMempool(CTxMemPool& pool, CChainState& active_chainstate, fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
|
bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, CChainState& active_chainstate, fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the expected assumeutxo value for a given height, if one exists.
|
* Return the expected assumeutxo value for a given height, if one exists.
|
||||||
|
|
Loading…
Add table
Reference in a new issue