6
6
7
7
By default, bitcoind will dump mempool on shutdown and
8
8
then reload it on startup. This can be overridden with
9
- the -persistmempool=false command line option.
9
+ the -persistmempool=0 command line option.
10
10
11
11
Test is as follows:
12
12
13
- - start node0, node1 and node2. node1 has -persistmempool=false
13
+ - start node0, node1 and node2. node1 has -persistmempool=0
14
14
- create 5 transactions on node2 to its own address. Note that these
15
15
are not sent to node0 or node1 addresses because we don't want
16
16
them to be saved in the wallet.
20
20
in its mempool. Shutdown node0. This tests that by default the
21
21
mempool is persistent.
22
22
- startup node1. Verify that its mempool is empty. Shutdown node1.
23
- This tests that with -persistmempool=false , the mempool is not
23
+ This tests that with -persistmempool=0 , the mempool is not
24
24
dumped to disk when the node is shut down.
25
- - Restart node0 with -persistmempool=false . Verify that its mempool is
26
- empty. Shutdown node0. This tests that with -persistmempool=false ,
25
+ - Restart node0 with -persistmempool=0 . Verify that its mempool is
26
+ empty. Shutdown node0. This tests that with -persistmempool=0 ,
27
27
the mempool is not loaded from disk on start up.
28
- - Restart node0 with -persistmempool=true . Verify that it has 5
29
- transactions in its mempool. This tests that -persistmempool=false
28
+ - Restart node0 with -persistmempool. Verify that it has 5
29
+ transactions in its mempool. This tests that -persistmempool=0
30
30
does not overwrite a previously valid mempool stored on disk.
31
31
32
32
"""
33
+ import time
33
34
35
+ from test_framework .mininode import wait_until
34
36
from test_framework .test_framework import BitcoinTestFramework
35
37
from test_framework .util import *
36
38
37
39
class MempoolPersistTest (BitcoinTestFramework ):
38
40
39
41
def __init__ (self ):
40
42
super ().__init__ ()
43
+ # We need 3 nodes for this test. Node1 does not have a persistent mempool.
41
44
self .num_nodes = 3
42
45
self .setup_clean_chain = False
43
-
44
- def setup_network (self ):
45
- # We need 3 nodes for this test. Node1 does not have a persistent mempool.
46
- self .nodes = []
47
- self .nodes .append (start_node (0 , self .options .tmpdir ))
48
- self .nodes .append (start_node (1 , self .options .tmpdir , ["-persistmempool=false" ]))
49
- self .nodes .append (start_node (2 , self .options .tmpdir ))
50
- connect_nodes_bi (self .nodes , 0 , 2 )
51
- connect_nodes_bi (self .nodes , 1 , 2 )
52
- self .is_network_split = False
46
+ self .extra_args = [[], ["-persistmempool=0" ], []]
53
47
54
48
def run_test (self ):
55
49
chain_height = self .nodes [0 ].getblockcount ()
56
50
assert_equal (chain_height , 200 )
57
51
58
52
self .log .debug ("Mine a single block to get out of IBD" )
59
53
self .nodes [0 ].generate (1 )
54
+ self .sync_all ()
60
55
61
56
self .log .debug ("Send 5 transactions from node2 (to its own address)" )
62
57
for i in range (5 ):
@@ -72,20 +67,24 @@ def run_test(self):
72
67
self .nodes = []
73
68
self .nodes .append (start_node (0 , self .options .tmpdir ))
74
69
self .nodes .append (start_node (1 , self .options .tmpdir ))
75
- assert_equal (len (self .nodes [0 ].getrawmempool ()), 5 )
70
+ # Give bitcoind a second to reload the mempool
71
+ time .sleep (1 )
72
+ assert wait_until (lambda : len (self .nodes [0 ].getrawmempool ()) == 5 )
76
73
assert_equal (len (self .nodes [1 ].getrawmempool ()), 0 )
77
74
78
- self .log .debug ("Stop-start node0 with -persistmempool=false . Verify that it doesn't load its mempool.dat file." )
75
+ self .log .debug ("Stop-start node0 with -persistmempool=0 . Verify that it doesn't load its mempool.dat file." )
79
76
stop_nodes (self .nodes )
80
77
self .nodes = []
81
- self .nodes .append (start_node (0 , self .options .tmpdir , ["-persistmempool=false" ]))
78
+ self .nodes .append (start_node (0 , self .options .tmpdir , ["-persistmempool=0" ]))
79
+ # Give bitcoind a second to reload the mempool
80
+ time .sleep (1 )
82
81
assert_equal (len (self .nodes [0 ].getrawmempool ()), 0 )
83
82
84
83
self .log .debug ("Stop-start node0. Verify that it has the transactions in its mempool." )
85
84
stop_nodes (self .nodes )
86
85
self .nodes = []
87
86
self .nodes .append (start_node (0 , self .options .tmpdir ))
88
- assert_equal ( len (self .nodes [0 ].getrawmempool ()), 5 )
87
+ assert wait_until ( lambda : len (self .nodes [0 ].getrawmempool ()) == 5 )
89
88
90
89
if __name__ == '__main__' :
91
90
MempoolPersistTest ().main ()
0 commit comments