Skip to content

Commit 3c85563

Browse files
committed
fix: keep databases in memory if running unit tests
1 parent 8763104 commit 3c85563

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

src/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,6 +1996,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
19961996
cache_sizes.coins,
19971997
/*block_tree_db_in_memory=*/false,
19981998
/*coins_db_in_memory=*/false,
1999+
/*dash_dbs_in_memory=*/false,
19992000
/*shutdown_requested=*/ShutdownRequested,
20002001
/*coins_error_cb=*/[]() {
20012002
uiInterface.ThreadSafeMessageBox(

src/node/chainstate.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
6363
int64_t nCoinCacheUsage,
6464
bool block_tree_db_in_memory,
6565
bool coins_db_in_memory,
66+
bool dash_dbs_in_memory,
6667
std::function<bool()> shutdown_requested,
6768
std::function<void()> coins_error_cb)
6869
{
@@ -73,7 +74,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
7374
LOCK(cs_main);
7475

7576
evodb.reset();
76-
evodb = std::make_unique<CEvoDB>(util::DbWrapperParams{.path = data_dir, .memory = false, .wipe = fReset || fReindexChainState});
77+
evodb = std::make_unique<CEvoDB>(util::DbWrapperParams{.path = data_dir, .memory = dash_dbs_in_memory, .wipe = fReset || fReindexChainState});
7778

7879
mnhf_manager.reset();
7980
mnhf_manager = std::make_unique<CMNHFManager>(*evodb);
@@ -89,8 +90,8 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
8990
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, block_tree_db_in_memory, fReset));
9091

9192
DashChainstateSetup(chainman, govman, mn_metaman, mn_sync, sporkman, mn_activeman, chain_helper, cpoolman,
92-
dmnman, evodb, mnhf_manager, llmq_ctx, mempool, data_dir, fReset, fReindexChainState,
93-
consensus_params);
93+
dmnman, evodb, mnhf_manager, llmq_ctx, mempool, data_dir, dash_dbs_in_memory,
94+
/*llmq_dbs_wipe=*/fReset || fReindexChainState, consensus_params);
9495

9596
if (fReset) {
9697
pblocktree->WriteReindexing(true);
@@ -230,8 +231,8 @@ void DashChainstateSetup(ChainstateManager& chainman,
230231
std::unique_ptr<LLMQContext>& llmq_ctx,
231232
CTxMemPool* mempool,
232233
const fs::path& data_dir,
233-
bool fReset,
234-
bool fReindexChainState,
234+
bool llmq_dbs_in_memory,
235+
bool llmq_dbs_wipe,
235236
const Consensus::Params& consensus_params)
236237
{
237238
// Same logic as pblocktree
@@ -248,7 +249,7 @@ void DashChainstateSetup(ChainstateManager& chainman,
248249
llmq_ctx.reset();
249250
llmq_ctx = std::make_unique<LLMQContext>(chainman, *dmnman, *evodb, mn_metaman, *mnhf_manager, sporkman,
250251
*mempool, mn_activeman.get(), mn_sync,
251-
util::DbWrapperParams{.path = data_dir, .memory = false, .wipe = fReset || fReindexChainState});
252+
util::DbWrapperParams{.path = data_dir, .memory = llmq_dbs_in_memory, .wipe = llmq_dbs_wipe});
252253
mempool->ConnectManagers(dmnman.get(), llmq_ctx->isman.get());
253254
// Enable CMNHFManager::{Process, Undo}Block
254255
mnhf_manager->ConnectManagers(&chainman, llmq_ctx->qman.get());

src/node/chainstate.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
108108
int64_t nCoinCacheUsage,
109109
bool block_tree_db_in_memory,
110110
bool coins_db_in_memory,
111+
bool dash_dbs_in_memory,
111112
std::function<bool()> shutdown_requested = nullptr,
112113
std::function<void()> coins_error_cb = nullptr);
113114

@@ -126,8 +127,8 @@ void DashChainstateSetup(ChainstateManager& chainman,
126127
std::unique_ptr<LLMQContext>& llmq_ctx,
127128
CTxMemPool* mempool,
128129
const fs::path& data_dir,
129-
bool fReset,
130-
bool fReindexChainState,
130+
bool llmq_dbs_in_memory,
131+
bool llmq_dbs_wipe,
131132
const Consensus::Params& consensus_params);
132133

133134
void DashChainstateSetupClose(std::unique_ptr<CChainstateHelper>& chain_helper,

src/test/util/setup_common.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ std::ostream& operator<<(std::ostream& os, const uint256& num)
125125

126126
void DashChainstateSetup(ChainstateManager& chainman,
127127
NodeContext& node,
128-
bool fReset,
129-
bool fReindexChainState,
128+
bool llmq_dbs_in_memory,
129+
bool llmq_dbs_wipe,
130130
const Consensus::Params& consensus_params)
131131
{
132132
DashChainstateSetup(chainman, *Assert(node.govman.get()), *Assert(node.mn_metaman.get()), *Assert(node.mn_sync.get()),
133133
*Assert(node.sporkman.get()), node.mn_activeman, node.chain_helper, node.cpoolman, node.dmnman,
134134
node.evodb, node.mnhf_manager, node.llmq_ctx, Assert(node.mempool.get()), node.args->GetDataDirNet(),
135-
fReset, fReindexChainState, consensus_params);
135+
llmq_dbs_in_memory, llmq_dbs_wipe, consensus_params);
136136
}
137137

138138
void DashChainstateSetupClose(NodeContext& node)
@@ -331,7 +331,8 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
331331
m_cache_sizes.coins_db,
332332
m_cache_sizes.coins,
333333
/*block_tree_db_in_memory=*/true,
334-
/*coins_db_in_memory=*/true);
334+
/*coins_db_in_memory=*/true,
335+
/*dash_dbs_in_memory=*/true);
335336
assert(!maybe_load_error.has_value());
336337

337338
auto maybe_verify_error = VerifyLoadedChainstate(

src/test/util/setup_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ static constexpr CAmount CENT{1000000};
8787
/** Initialize Dash-specific components during chainstate initialization (NodeContext-friendly aliases) */
8888
void DashChainstateSetup(ChainstateManager& chainman,
8989
node::NodeContext& node,
90-
bool fReset,
91-
bool fReindexChainState,
90+
bool llmq_dbs_in_memory,
91+
bool llmq_dbs_wipe,
9292
const Consensus::Params& consensus_params);
9393
void DashChainstateSetupClose(node::NodeContext& node);
9494

src/test/validation_chainstatemanager_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
5151
/*cache_size_bytes=*/1 << 23, /*in_memory=*/true, /*should_wipe=*/false);
5252
WITH_LOCK(::cs_main, c1.InitCoinsCache(1 << 23));
5353

54-
DashChainstateSetup(manager, m_node, /*fReset=*/false, /*fReindexChainState=*/false, consensus_params);
54+
DashChainstateSetup(manager, m_node, /*llmq_dbs_in_memory=*/true, /*llmq_dbs_wipe=*/false, consensus_params);
5555

5656
BOOST_CHECK(!manager.IsSnapshotActive());
5757
BOOST_CHECK(WITH_LOCK(::cs_main, return !manager.IsSnapshotValidated()));
@@ -84,7 +84,7 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
8484
);
8585
chainstates.push_back(&c2);
8686

87-
DashChainstateSetup(manager, m_node, /*fReset=*/false, /*fReindexChainState=*/false, consensus_params);
87+
DashChainstateSetup(manager, m_node, /*llmq_dbs_in_memory=*/true, /*llmq_dbs_wipe=*/false, consensus_params);
8888

8989
BOOST_CHECK_EQUAL(manager.SnapshotBlockhash().value(), snapshot_blockhash);
9090

0 commit comments

Comments
 (0)