aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2017-09-06 13:48:00 -0700
committerMarcoFalke <falke.marco@gmail.com>2017-09-06 13:49:25 -0700
commitbc561b4b7d6a3f71649d37d5eb9047c29efa2b13 (patch)
treeb95d6bc057fbab7a220844f1fc25d5224efcaf40 /src
parent961901f77e55aa07d5048000d57bcd218ae74b08 (diff)
parent1aa97ee088ea03dd208be054c5ad9198c1f13329 (diff)
Merge #11099: [RPC][mempool]: Add savemempool RPC
1aa97ee08 Add savemempool RPC (Lawrence Nahum) 467cbbcbf Add return value to DumpMempool (Lawrence Nahum) Pull request description: Adds a simple parameterless rpc command to dump the mempool. Rationale: Sometimes there can be a crash for whatever reason (bug, power loss, etc) causing the mempool.dat file to not be saved. This change allows to script/cron the rpc call to have more regular saves to the file as well as cli/ad-hoc. This should solve issue https://github.com/bitcoin/bitcoin/issues/11086 Tree-SHA512: e856ae9777425a4521279c9b58e69285d8e374790bebefd3284cf91931eac0e456f86224f427a087a01bf70440bf6e439fa02c8a34940eb1046ae473e98b6aaa
Diffstat (limited to 'src')
-rw-r--r--src/rpc/blockchain.cpp20
-rw-r--r--src/validation.cpp6
-rw-r--r--src/validation.h2
3 files changed, 25 insertions, 3 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index 9fae9a7cd9..d131635067 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -1534,6 +1534,25 @@ UniValue getchaintxstats(const JSONRPCRequest& request)
return ret;
}
+UniValue savemempool(const JSONRPCRequest& request)
+{
+ if (request.fHelp || request.params.size() != 0) {
+ throw std::runtime_error(
+ "savemempool\n"
+ "\nDumps the mempool to disk.\n"
+ "\nExamples:\n"
+ + HelpExampleCli("savemempool", "")
+ + HelpExampleRpc("savemempool", "")
+ );
+ }
+
+ if (!DumpMempool()) {
+ throw JSONRPCError(RPC_MISC_ERROR, "Unable to dump mempool to disk");
+ }
+
+ return NullUniValue;
+}
+
static const CRPCCommand commands[] =
{ // category name actor (function) argNames
// --------------------- ------------------------ ----------------------- ----------
@@ -1554,6 +1573,7 @@ static const CRPCCommand commands[] =
{ "blockchain", "gettxout", &gettxout, {"txid","n","include_mempool"} },
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, {} },
{ "blockchain", "pruneblockchain", &pruneblockchain, {"height"} },
+ { "blockchain", "savemempool", &savemempool, {} },
{ "blockchain", "verifychain", &verifychain, {"checklevel","nblocks"} },
{ "blockchain", "preciousblock", &preciousblock, {"blockhash"} },
diff --git a/src/validation.cpp b/src/validation.cpp
index 0edc9bc32a..d1ef11759c 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -4331,7 +4331,7 @@ bool LoadMempool(void)
return true;
}
-void DumpMempool(void)
+bool DumpMempool(void)
{
int64_t start = GetTimeMicros();
@@ -4351,7 +4351,7 @@ void DumpMempool(void)
try {
FILE* filestr = fsbridge::fopen(GetDataDir() / "mempool.dat.new", "wb");
if (!filestr) {
- return;
+ return false;
}
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
@@ -4375,7 +4375,9 @@ void DumpMempool(void)
LogPrintf("Dumped mempool: %gs to copy, %gs to dump\n", (mid-start)*MICRO, (last-mid)*MICRO);
} catch (const std::exception& e) {
LogPrintf("Failed to dump mempool: %s. Continuing anyway.\n", e.what());
+ return false;
}
+ return true;
}
//! Guess how far we are in the verification process at the given block index
diff --git a/src/validation.h b/src/validation.h
index 214d29173c..23d4b35585 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -478,7 +478,7 @@ static const unsigned int REJECT_HIGHFEE = 0x100;
CBlockFileInfo* GetBlockFileInfo(size_t n);
/** Dump the mempool to disk. */
-void DumpMempool();
+bool DumpMempool();
/** Load the mempool from disk. */
bool LoadMempool();