2 # Copyright (c) 2014-2017 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 """Test mempool persistence.
7 By default, bitcoind will dump mempool on shutdown and
8 then reload it on startup. This can be overridden with
9 the -persistmempool=0 command line option.
13 - start node0, node1 and node2. node1 has -persistmempool=0
14 - create 5 transactions on node2 to its own address. Note that these
15 are not sent to node0 or node1 addresses because we don't want
16 them to be saved in the wallet.
17 - check that node0 and node1 have 5 transactions in their mempools
19 - startup node0. Verify that it still has 5 transactions
20 in its mempool. Shutdown node0. This tests that by default the
21 mempool is persistent.
22 - startup node1. Verify that its mempool is empty. Shutdown node1.
23 This tests that with -persistmempool=0, the mempool is not
24 dumped to disk when the node is shut down.
25 - Restart node0 with -persistmempool=0. Verify that its mempool is
26 empty. Shutdown node0. This tests that with -persistmempool=0,
27 the mempool is not loaded from disk on start up.
28 - Restart node0 with -persistmempool. Verify that it has 5
29 transactions in its mempool. This tests that -persistmempool=0
30 does not overwrite a previously valid mempool stored on disk.
35 from test_framework
.test_framework
import BitcoinTestFramework
36 from test_framework
.util
import *
38 class MempoolPersistTest(BitcoinTestFramework
):
42 # We need 3 nodes for this test. Node1 does not have a persistent mempool.
44 self
.setup_clean_chain
= False
45 self
.extra_args
= [[], ["-persistmempool=0"], []]
48 chain_height
= self
.nodes
[0].getblockcount()
49 assert_equal(chain_height
, 200)
51 self
.log
.debug("Mine a single block to get out of IBD")
52 self
.nodes
[0].generate(1)
55 self
.log
.debug("Send 5 transactions from node2 (to its own address)")
57 self
.nodes
[2].sendtoaddress(self
.nodes
[2].getnewaddress(), Decimal("10"))
60 self
.log
.debug("Verify that node0 and node1 have 5 transactions in their mempools")
61 assert_equal(len(self
.nodes
[0].getrawmempool()), 5)
62 assert_equal(len(self
.nodes
[1].getrawmempool()), 5)
64 self
.log
.debug("Stop-start node0 and node1. Verify that node0 has the transactions in its mempool and node1 does not.")
67 self
.nodes
.append(self
.start_node(0, self
.options
.tmpdir
))
68 self
.nodes
.append(self
.start_node(1, self
.options
.tmpdir
))
69 # Give bitcoind a second to reload the mempool
71 wait_until(lambda: len(self
.nodes
[0].getrawmempool()) == 5)
72 assert_equal(len(self
.nodes
[1].getrawmempool()), 0)
74 self
.log
.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.")
77 self
.nodes
.append(self
.start_node(0, self
.options
.tmpdir
, ["-persistmempool=0"]))
78 # Give bitcoind a second to reload the mempool
80 assert_equal(len(self
.nodes
[0].getrawmempool()), 0)
82 self
.log
.debug("Stop-start node0. Verify that it has the transactions in its mempool.")
85 self
.nodes
.append(self
.start_node(0, self
.options
.tmpdir
))
86 wait_until(lambda: len(self
.nodes
[0].getrawmempool()) == 5)
88 if __name__
== '__main__':
89 MempoolPersistTest().main()