Skip to content

Commit fa20d73

Browse files
author
MarcoFalke
committed
refactor: Add and use kernel::ImportMempoolOptions
This allows optional named arguments with default values.
1 parent fa88669 commit fa20d73

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
16771677
}
16781678
// Load mempool from disk
16791679
if (auto* pool{chainman.ActiveChainstate().GetMempool()}) {
1680-
LoadMempool(*pool, ShouldPersistMempool(args) ? MempoolPath(args) : fs::path{}, chainman.ActiveChainstate());
1680+
LoadMempool(*pool, ShouldPersistMempool(args) ? MempoolPath(args) : fs::path{}, chainman.ActiveChainstate(), {});
16811681
pool->SetLoadTried(!chainman.m_interrupt);
16821682
}
16831683
});

src/kernel/mempool_persist.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ namespace kernel {
3636

3737
static const uint64_t MEMPOOL_DUMP_VERSION = 1;
3838

39-
bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active_chainstate, FopenFn mockable_fopen_function)
39+
bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active_chainstate, ImportMempoolOptions&& opts)
4040
{
4141
if (load_path.empty()) return false;
4242

43-
FILE* filestr{mockable_fopen_function(load_path, "rb")};
43+
FILE* filestr{opts.mockable_fopen_function(load_path, "rb")};
4444
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
4545
if (file.IsNull()) {
4646
LogPrintf("Failed to open mempool file from disk. Continuing anyway.\n");

src/kernel/mempool_persist.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ bool DumpMempool(const CTxMemPool& pool, const fs::path& dump_path,
1717
fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen,
1818
bool skip_file_commit = false);
1919

20+
struct ImportMempoolOptions {
21+
fsbridge::FopenFn mockable_fopen_function{fsbridge::fopen};
22+
};
2023
/** Import the file and attempt to add its contents to the mempool. */
2124
bool LoadMempool(CTxMemPool& pool, const fs::path& load_path,
2225
Chainstate& active_chainstate,
23-
fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
26+
ImportMempoolOptions&& opts);
2427

2528
} // namespace kernel
2629

src/test/fuzz/validation_load_mempool.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ FUZZ_TARGET(validation_load_mempool, .init = initialize_validation_load_mempool)
4848
auto fuzzed_fopen = [&](const fs::path&, const char*) {
4949
return fuzzed_file_provider.open();
5050
};
51-
(void)LoadMempool(pool, MempoolPath(g_setup->m_args), chainstate, fuzzed_fopen);
51+
(void)LoadMempool(pool, MempoolPath(g_setup->m_args), chainstate,
52+
{
53+
.mockable_fopen_function = fuzzed_fopen,
54+
});
5255
pool.SetLoadTried(true);
5356
(void)DumpMempool(pool, MempoolPath(g_setup->m_args), fuzzed_fopen, true);
5457
}

0 commit comments

Comments
 (0)