Skip to content

Commit

Permalink
Merge #12172: Bugfix: RPC: savemempool: Don't save until LoadMempool(…
Browse files Browse the repository at this point in the history
…) is finished

cb1e319 Bugfix: RPC: savemempool: Don't save until LoadMempool() is finished (Jorge Timón)

Pull request description:

  Fixes #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
  • Loading branch information
laanwj committed Mar 29, 2018
2 parents de6bdfd + cb1e319 commit 3b62a91
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/init.cpp
Expand Up @@ -115,7 +115,6 @@ static const char* FEE_ESTIMATES_FILENAME="fee_estimates.dat";
//

std::atomic<bool> fRequestShutdown(false);
std::atomic<bool> fDumpMempoolLater(false);

void StartShutdown()
{
Expand Down Expand Up @@ -205,7 +204,7 @@ void Shutdown()
threadGroup.interrupt_all();
threadGroup.join_all();

if (fDumpMempoolLater && gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
if (g_is_mempool_loaded && gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
DumpMempool();
}

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

/** Sanity checks
Expand Down
6 changes: 5 additions & 1 deletion src/rpc/blockchain.cpp
Expand Up @@ -1607,13 +1607,17 @@ UniValue savemempool(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 0) {
throw std::runtime_error(
"savemempool\n"
"\nDumps the mempool to disk.\n"
"\nDumps the mempool to disk. It will fail until the previous dump is fully loaded.\n"
"\nExamples:\n"
+ HelpExampleCli("savemempool", "")
+ HelpExampleRpc("savemempool", "")
);
}

if (!g_is_mempool_loaded) {
throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet");
}

if (!DumpMempool()) {
throw JSONRPCError(RPC_MISC_ERROR, "Unable to dump mempool to disk");
}
Expand Down
1 change: 1 addition & 0 deletions src/validation.cpp
Expand Up @@ -227,6 +227,7 @@ CAmount maxTxFee = DEFAULT_TRANSACTION_MAXFEE;

CBlockPolicyEstimator feeEstimator;
CTxMemPool mempool(&feeEstimator);
std::atomic_bool g_is_mempool_loaded{false};

/** Constant stuff for coinbase transactions we create: */
CScript COINBASE_FLAGS;
Expand Down
1 change: 1 addition & 0 deletions src/validation.h
Expand Up @@ -158,6 +158,7 @@ extern CScript COINBASE_FLAGS;
extern CCriticalSection cs_main;
extern CBlockPolicyEstimator feeEstimator;
extern CTxMemPool mempool;
extern std::atomic_bool g_is_mempool_loaded;
typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
extern BlockMap& mapBlockIndex;
extern uint64_t nLastBlockTx;
Expand Down

0 comments on commit 3b62a91

Please sign in to comment.