|
28 | 28 | - Restart node0 with -persistmempool. Verify that it has 5
|
29 | 29 | transactions in its mempool. This tests that -persistmempool=0
|
30 | 30 | does not overwrite a previously valid mempool stored on disk.
|
| 31 | + - Remove node0 mempool.dat and verify savemempool RPC recreates it |
| 32 | + and verify that node1 can load it and has 5 transaction in its |
| 33 | + mempool. |
| 34 | + - Verify that savemempool throws when the RPC is called if |
| 35 | + node1 can't write to disk. |
31 | 36 |
|
32 | 37 | """
|
| 38 | +import os |
33 | 39 | import time
|
34 | 40 |
|
35 | 41 | from test_framework.test_framework import BitcoinTestFramework
|
@@ -78,5 +84,27 @@ def run_test(self):
|
78 | 84 | self.start_node(0)
|
79 | 85 | wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5)
|
80 | 86 |
|
| 87 | + mempooldat0 = os.path.join(self.options.tmpdir, 'node0', 'regtest', 'mempool.dat') |
| 88 | + mempooldat1 = os.path.join(self.options.tmpdir, 'node1', 'regtest', 'mempool.dat') |
| 89 | + self.log.debug("Remove the mempool.dat file. Verify that savemempool to disk via RPC re-creates it") |
| 90 | + os.remove(mempooldat0) |
| 91 | + self.nodes[0].savemempool() |
| 92 | + assert os.path.isfile(mempooldat0) |
| 93 | + |
| 94 | + self.log.debug("Stop nodes, make node1 use mempool.dat from node0. Verify it has 5 transactions") |
| 95 | + os.rename(mempooldat0, mempooldat1) |
| 96 | + self.stop_nodes() |
| 97 | + self.start_node(1, extra_args=[]) |
| 98 | + wait_until(lambda: len(self.nodes[1].getrawmempool()) == 5) |
| 99 | + |
| 100 | + self.log.debug("Prevent bitcoind from writing mempool.dat to disk. Verify that `savemempool` fails") |
| 101 | + # to test the exception we are setting bad permissions on a tmp file called mempool.dat.new |
| 102 | + # which is an implementation detail that could change and break this test |
| 103 | + mempooldotnew1 = mempooldat1 + '.new' |
| 104 | + with os.fdopen(os.open(mempooldotnew1, os.O_CREAT, 0o000), 'w'): |
| 105 | + pass |
| 106 | + assert_raises_jsonrpc(-1, "Unable to dump mempool to disk", self.nodes[1].savemempool) |
| 107 | + os.remove(mempooldotnew1) |
| 108 | + |
81 | 109 | if __name__ == '__main__':
|
82 | 110 | MempoolPersistTest().main()
|
0 commit comments