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.

reindex.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2014-2016 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 running bitcoind with -reindex and -reindex-chainstate options.
  6. - Start a single node and generate 3 blocks.
  7. - Stop the node and restart it with -reindex. Verify that the node has reindexed up to block 3.
  8. - Stop the node and restart it with -reindex-chainstate. Verify that the node has reindexed up to block 3.
  9. """
  10. from test_framework.test_framework import BitcoinTestFramework
  11. from test_framework.util import (
  12. start_nodes,
  13. stop_nodes,
  14. assert_equal,
  15. )
  16. import time
  17. class ReindexTest(BitcoinTestFramework):
  18. def __init__(self):
  19. super().__init__()
  20. self.setup_clean_chain = True
  21. self.num_nodes = 1
  22. def setup_network(self):
  23. self.nodes = start_nodes(self.num_nodes, self.options.tmpdir)
  24. def reindex(self, justchainstate=False):
  25. self.nodes[0].generate(3)
  26. blockcount = self.nodes[0].getblockcount()
  27. stop_nodes(self.nodes)
  28. extra_args = [["-reindex-chainstate" if justchainstate else "-reindex", "-checkblockindex=1"]]
  29. self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args)
  30. while self.nodes[0].getblockcount() < blockcount:
  31. time.sleep(0.1)
  32. assert_equal(self.nodes[0].getblockcount(), blockcount)
  33. self.log.info("Success")
  34. def run_test(self):
  35. self.reindex(False)
  36. self.reindex(True)
  37. self.reindex(False)
  38. self.reindex(True)
  39. if __name__ == '__main__':
  40. ReindexTest().main()