Skip to content

Commit

Permalink
refactor: Add and use kernel::ImportMempoolOptions
Browse files Browse the repository at this point in the history
This allows optional named arguments with default values.
  • Loading branch information
MarcoFalke committed Apr 20, 2023
1 parent fa4616a commit fa0a6bc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/kernel/mempool_persist.cpp
Expand Up @@ -36,11 +36,11 @@ namespace kernel {

static const uint64_t MEMPOOL_DUMP_VERSION = 1;

bool ImportMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active_chainstate, FopenFn mockable_fopen_function)
bool ImportMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active_chainstate, ImportMempoolOptions&& opts)
{
if (load_path.empty()) return false;

FILE* filestr{mockable_fopen_function(load_path, "rb")};
FILE* filestr{opts.mockable_fopen_function(load_path, "rb")};
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
if (file.IsNull()) {
LogPrintf("Failed to open mempool file from disk. Continuing anyway.\n");
Expand Down
7 changes: 4 additions & 3 deletions src/kernel/mempool_persist.h
Expand Up @@ -17,10 +17,11 @@ bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path,
fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen,
bool skip_file_commit = false);

struct ImportMempoolOptions {
fsbridge::FopenFn mockable_fopen_function{fsbridge::fopen};
};
/** Import the file and attempt to add its contents to the mempool. */
bool ImportMempool(CTxMemPool& pool, const fs::path& load_path,
Chainstate& active_chainstate,
fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
bool ImportMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active_chainstate, ImportMempoolOptions&& opts);

} // namespace kernel

Expand Down
6 changes: 5 additions & 1 deletion src/validation.cpp
Expand Up @@ -71,6 +71,7 @@ using kernel::CCoinsStats;
using kernel::CoinStatsHashType;
using kernel::ComputeUTXOStats;
using kernel::ImportMempool;
using kernel::ImportMempoolOptions;

using fsbridge::FopenFn;
using node::BlockManager;
Expand Down Expand Up @@ -4105,7 +4106,10 @@ void PruneBlockFilesManual(Chainstate& active_chainstate, int nManualPruneHeight
void Chainstate::LoadMempool(const fs::path& load_path, FopenFn mockable_fopen_function)
{
if (!m_mempool) return;
::ImportMempool(*m_mempool, load_path, *this, mockable_fopen_function);
ImportMempool(*m_mempool, load_path, *this,
ImportMempoolOptions{
.mockable_fopen_function = std::move(mockable_fopen_function),
});
m_mempool->SetLoadTried(!ShutdownRequested());
}

Expand Down

0 comments on commit fa0a6bc

Please sign in to comment.