Skip to content

Commit cb1e319

Browse files
committed
Bugfix: RPC: savemempool: Don't save until LoadMempool() is finished
1 parent 624bee9 commit cb1e319

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
@@ -116,7 +116,6 @@ static const char* FEE_ESTIMATES_FILENAME="fee_estimates.dat";
116116
//
117117

118118
std::atomic<bool> fRequestShutdown(false);
119-
std::atomic<bool> fDumpMempoolLater(false);
120119

121120
void StartShutdown()
122121
{
@@ -208,7 +207,7 @@ void Shutdown()
208207
threadGroup.interrupt_all();
209208
threadGroup.join_all();
210209

211-
if (fDumpMempoolLater && gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
210+
if (g_is_mempool_loaded && gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
212211
DumpMempool();
213212
}
214213

@@ -692,8 +691,8 @@ void ThreadImport(std::vector<fs::path> vImportFiles)
692691
} // End scope of CImportingNow
693692
if (gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
694693
LoadMempool();
695-
fDumpMempoolLater = !fRequestShutdown;
696694
}
695+
g_is_mempool_loaded = !fRequestShutdown;
697696
}
698697

699698
/** 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)