You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mempool_persist.py 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python3
  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.
  6. By default, bitcoind will dump mempool on shutdown and
  7. then reload it on startup. This can be overridden with
  8. the -persistmempool=0 command line option.
  9. Test is as follows:
  10. - start node0, node1 and node2. node1 has -persistmempool=0
  11. - create 5 transactions on node2 to its own address. Note that these
  12. are not sent to node0 or node1 addresses because we don't want
  13. them to be saved in the wallet.
  14. - check that node0 and node1 have 5 transactions in their mempools
  15. - shutdown all nodes.
  16. - startup node0. Verify that it still has 5 transactions
  17. in its mempool. Shutdown node0. This tests that by default the
  18. mempool is persistent.
  19. - startup node1. Verify that its mempool is empty. Shutdown node1.
  20. This tests that with -persistmempool=0, the mempool is not
  21. dumped to disk when the node is shut down.
  22. - Restart node0 with -persistmempool=0. Verify that its mempool is
  23. empty. Shutdown node0. This tests that with -persistmempool=0,
  24. the mempool is not loaded from disk on start up.
  25. - Restart node0 with -persistmempool. Verify that it has 5
  26. transactions in its mempool. This tests that -persistmempool=0
  27. does not overwrite a previously valid mempool stored on disk.
  28. """
  29. import time
  30. from test_framework.test_framework import BitcoinTestFramework
  31. from test_framework.util import *
  32. class MempoolPersistTest(BitcoinTestFramework):
  33. def set_test_params(self):
  34. self.num_nodes = 3
  35. self.extra_args = [[], ["-persistmempool=0"], []]
  36. def run_test(self):
  37. chain_height = self.nodes[0].getblockcount()
  38. assert_equal(chain_height, 200)
  39. self.log.debug("Mine a single block to get out of IBD")
  40. self.nodes[0].generate(1)
  41. self.sync_all()
  42. self.log.debug("Send 5 transactions from node2 (to its own address)")
  43. for i in range(5):
  44. self.nodes[2].sendtoaddress(self.nodes[2].getnewaddress(), Decimal("10"))
  45. self.sync_all()
  46. self.log.debug("Verify that node0 and node1 have 5 transactions in their mempools")
  47. assert_equal(len(self.nodes[0].getrawmempool()), 5)
  48. assert_equal(len(self.nodes[1].getrawmempool()), 5)
  49. self.log.debug("Stop-start node0 and node1. Verify that node0 has the transactions in its mempool and node1 does not.")
  50. self.stop_nodes()
  51. self.start_node(0)
  52. self.start_node(1)
  53. # Give bitcoind a second to reload the mempool
  54. time.sleep(1)
  55. wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5)
  56. assert_equal(len(self.nodes[1].getrawmempool()), 0)
  57. self.log.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.")
  58. self.stop_nodes()
  59. self.start_node(0, extra_args=["-persistmempool=0"])
  60. # Give bitcoind a second to reload the mempool
  61. time.sleep(1)
  62. assert_equal(len(self.nodes[0].getrawmempool()), 0)
  63. self.log.debug("Stop-start node0. Verify that it has the transactions in its mempool.")
  64. self.stop_nodes()
  65. self.start_node(0)
  66. wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5)
  67. if __name__ == '__main__':
  68. MempoolPersistTest().main()