aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-05-03 09:23:39 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2017-05-03 11:03:48 +0200
commit2a183de0ecb5401cc3bcf68a42c4f7387ccb460e (patch)
tree7ab3277d01f481072551058bde7c02ff6c4cadde
parentd3dce0eb67e8691745be6cf7e04b920f5e419bd9 (diff)
parenta750d77b950175115fcab528fa0d3a2e0ffab96d (diff)
Merge #9966: Control mempool persistence using a command line parameter
a750d77 Add tests for mempool persistence (John Newbery) 91c91e1 Control mempool persistence using a command line parameter. (John Newbery) Tree-SHA512: 157d01cefd1903b8bfc5cbab42a3cc5e9c1094179bf4b64b3d34c0d4d9b976d593755bfea5c41c631cb758e1de17c6c2058c130d487d20560b7c0bafcddfa520
-rw-r--r--src/init.cpp10
-rw-r--r--src/validation.h3
-rwxr-xr-xtest/functional/mempool_persist.py91
-rwxr-xr-xtest/functional/test_runner.py1
4 files changed, 101 insertions, 4 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 64f571f284..266e1731eb 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -208,8 +208,9 @@ void Shutdown()
StopTorControl();
UnregisterNodeSignals(GetNodeSignals());
- if (fDumpMempoolLater)
+ if (fDumpMempoolLater && GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
DumpMempool();
+ }
if (fFeeEstimatesInitialized)
{
@@ -354,6 +355,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-maxorphantx=<n>", strprintf(_("Keep at most <n> unconnectable transactions in memory (default: %u)"), DEFAULT_MAX_ORPHAN_TRANSACTIONS));
strUsage += HelpMessageOpt("-maxmempool=<n>", strprintf(_("Keep the transaction memory pool below <n> megabytes (default: %u)"), DEFAULT_MAX_MEMPOOL_SIZE));
strUsage += HelpMessageOpt("-mempoolexpiry=<n>", strprintf(_("Do not keep transactions in the mempool longer than <n> hours (default: %u)"), DEFAULT_MEMPOOL_EXPIRY));
+ strUsage += HelpMessageOpt("-persistmempool", strprintf(_("Whether to save the mempool on shutdown and load on restart (default: %u)"), DEFAULT_PERSIST_MEMPOOL));
strUsage += HelpMessageOpt("-blockreconstructionextratxn=<n>", strprintf(_("Extra transactions to keep in memory for compact block reconstructions (default: %u)"), DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN));
strUsage += HelpMessageOpt("-par=<n>", strprintf(_("Set the number of script verification threads (%u to %d, 0 = auto, <0 = leave that many cores free, default: %d)"),
-GetNumCores(), MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS));
@@ -679,8 +681,10 @@ void ThreadImport(std::vector<fs::path> vImportFiles)
StartShutdown();
}
} // End scope of CImportingNow
- LoadMempool();
- fDumpMempoolLater = !fRequestShutdown;
+ if (GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
+ LoadMempool();
+ fDumpMempoolLater = !fRequestShutdown;
+ }
}
/** Sanity checks
diff --git a/src/validation.h b/src/validation.h
index 24ebf238df..c046ba9238 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -131,7 +131,8 @@ static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
static const bool DEFAULT_TXINDEX = false;
static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
-
+/** Default for -persistmempool */
+static const bool DEFAULT_PERSIST_MEMPOOL = true;
/** Default for -mempoolreplacement */
static const bool DEFAULT_ENABLE_REPLACEMENT = true;
/** Default for using fee filter */
diff --git a/test/functional/mempool_persist.py b/test/functional/mempool_persist.py
new file mode 100755
index 0000000000..c22b7ff020
--- /dev/null
+++ b/test/functional/mempool_persist.py
@@ -0,0 +1,91 @@
+#!/usr/bin/env python3
+# Copyright (c) 2014-2017 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+"""Test mempool persistence.
+
+By default, bitcoind will dump mempool on shutdown and
+then reload it on startup. This can be overridden with
+the -persistmempool=false command line option.
+
+Test is as follows:
+
+ - start node0, node1 and node2. node1 has -persistmempool=false
+ - create 5 transactions on node2 to its own address. Note that these
+ are not sent to node0 or node1 addresses because we don't want
+ them to be saved in the wallet.
+ - check that node0 and node1 have 5 transactions in their mempools
+ - shutdown all nodes.
+ - startup node0. Verify that it still has 5 transactions
+ in its mempool. Shutdown node0. This tests that by default the
+ mempool is persistent.
+ - startup node1. Verify that its mempool is empty. Shutdown node1.
+ This tests that with -persistmempool=false, the mempool is not
+ dumped to disk when the node is shut down.
+ - Restart node0 with -persistmempool=false. Verify that its mempool is
+ empty. Shutdown node0. This tests that with -persistmempool=false,
+ the mempool is not loaded from disk on start up.
+ - Restart node0 with -persistmempool=true. Verify that it has 5
+ transactions in its mempool. This tests that -persistmempool=false
+ does not overwrite a previously valid mempool stored on disk.
+
+"""
+
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import *
+
+class MempoolPersistTest(BitcoinTestFramework):
+
+ def __init__(self):
+ super().__init__()
+ self.num_nodes = 3
+ self.setup_clean_chain = False
+
+ def setup_network(self):
+ # We need 3 nodes for this test. Node1 does not have a persistent mempool.
+ self.nodes = []
+ self.nodes.append(start_node(0, self.options.tmpdir))
+ self.nodes.append(start_node(1, self.options.tmpdir, ["-persistmempool=false"]))
+ self.nodes.append(start_node(2, self.options.tmpdir))
+ connect_nodes_bi(self.nodes, 0, 2)
+ connect_nodes_bi(self.nodes, 1, 2)
+ self.is_network_split = False
+
+ def run_test(self):
+ chain_height = self.nodes[0].getblockcount()
+ assert_equal(chain_height, 200)
+
+ self.log.debug("Mine a single block to get out of IBD")
+ self.nodes[0].generate(1)
+
+ self.log.debug("Send 5 transactions from node2 (to its own address)")
+ for i in range(5):
+ self.nodes[2].sendtoaddress(self.nodes[2].getnewaddress(), Decimal("10"))
+ self.sync_all()
+
+ self.log.debug("Verify that node0 and node1 have 5 transactions in their mempools")
+ assert_equal(len(self.nodes[0].getrawmempool()), 5)
+ assert_equal(len(self.nodes[1].getrawmempool()), 5)
+
+ self.log.debug("Stop-start node0 and node1. Verify that node0 has the transactions in its mempool and node1 does not.")
+ stop_nodes(self.nodes)
+ self.nodes = []
+ self.nodes.append(start_node(0, self.options.tmpdir))
+ self.nodes.append(start_node(1, self.options.tmpdir))
+ assert_equal(len(self.nodes[0].getrawmempool()), 5)
+ assert_equal(len(self.nodes[1].getrawmempool()), 0)
+
+ self.log.debug("Stop-start node0 with -persistmempool=false. Verify that it doesn't load its mempool.dat file.")
+ stop_nodes(self.nodes)
+ self.nodes = []
+ self.nodes.append(start_node(0, self.options.tmpdir, ["-persistmempool=false"]))
+ assert_equal(len(self.nodes[0].getrawmempool()), 0)
+
+ self.log.debug("Stop-start node0. Verify that it has the transactions in its mempool.")
+ stop_nodes(self.nodes)
+ self.nodes = []
+ self.nodes.append(start_node(0, self.options.tmpdir))
+ assert_equal(len(self.nodes[0].getrawmempool()), 5)
+
+if __name__ == '__main__':
+ MempoolPersistTest().main()
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index 965fe9ad7f..467e1668d1 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -85,6 +85,7 @@ BASE_SCRIPTS= [
'rest.py',
'mempool_spendcoinbase.py',
'mempool_reorg.py',
+ 'mempool_persist.py',
'httpbasics.py',
'multi_rpc.py',
'proxy_test.py',