Skip to content

Commit 3b62a91

Browse files
committed
Merge #12172: Bugfix: RPC: savemempool: Don't save until LoadMempool() is finished
cb1e319 Bugfix: RPC: savemempool: Don't save until LoadMempool() is finished (Jorge Timón) Pull request description: Fixes bitcoin/bitcoin#12142 The tests are a little bit slow, mempool_persist.py goes from about 20 s to about 120 s in my hardware. Perhaps there's a better way to test this. Tree-SHA512: 9e6c24b32a9cf3774e8f0bd81c035b0deb53fba5ac3eb2532d85900579d21cef8a1135b75a4fa0a9d883e3822eb35e7d4b47a0838abf99789039205041962629
2 parents de6bdfd + cb1e319 commit 3b62a91

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

src/init.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ static const char* FEE_ESTIMATES_FILENAME="fee_estimates.dat";
115115
//
116116

117117
std::atomic<bool> fRequestShutdown(false);
118-
std::atomic<bool> fDumpMempoolLater(false);
119118

120119
void StartShutdown()
121120
{
@@ -205,7 +204,7 @@ void Shutdown()
205204
threadGroup.interrupt_all();
206205
threadGroup.join_all();
207206

208-
if (fDumpMempoolLater && gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
207+
if (g_is_mempool_loaded && gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
209208
DumpMempool();
210209
}
211210

@@ -684,8 +683,8 @@ void ThreadImport(std::vector<fs::path> vImportFiles)
684683
} // End scope of CImportingNow
685684
if (gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
686685
LoadMempool();
687-
fDumpMempoolLater = !fRequestShutdown;
688686
}
687+
g_is_mempool_loaded = !fRequestShutdown;
689688
}
690689

691690
/** Sanity checks

src/rpc/blockchain.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,13 +1607,17 @@ UniValue savemempool(const JSONRPCRequest& request)
16071607
if (request.fHelp || request.params.size() != 0) {
16081608
throw std::runtime_error(
16091609
"savemempool\n"
1610-
"\nDumps the mempool to disk.\n"
1610+
"\nDumps the mempool to disk. It will fail until the previous dump is fully loaded.\n"
16111611
"\nExamples:\n"
16121612
+ HelpExampleCli("savemempool", "")
16131613
+ HelpExampleRpc("savemempool", "")
16141614
);
16151615
}
16161616

1617+
if (!g_is_mempool_loaded) {
1618+
throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet");
1619+
}
1620+
16171621
if (!DumpMempool()) {
16181622
throw JSONRPCError(RPC_MISC_ERROR, "Unable to dump mempool to disk");
16191623
}

src/validation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ CAmount maxTxFee = DEFAULT_TRANSACTION_MAXFEE;
227227

228228
CBlockPolicyEstimator feeEstimator;
229229
CTxMemPool mempool(&feeEstimator);
230+
std::atomic_bool g_is_mempool_loaded{false};
230231

231232
/** Constant stuff for coinbase transactions we create: */
232233
CScript COINBASE_FLAGS;

src/validation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ extern CScript COINBASE_FLAGS;
158158
extern CCriticalSection cs_main;
159159
extern CBlockPolicyEstimator feeEstimator;
160160
extern CTxMemPool mempool;
161+
extern std::atomic_bool g_is_mempool_loaded;
161162
typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
162163
extern BlockMap& mapBlockIndex;
163164
extern uint64_t nLastBlockTx;

0 commit comments

Comments
 (0)