feature_abortnode.py raw

   1  #!/usr/bin/env python3
   2  # Copyright (c) 2019-present 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 bitcoind aborts if can't disconnect a block.
   6  
   7  - Start a single node and generate 3 blocks.
   8  - Delete the undo data.
   9  - Mine a fork that requires disconnecting the tip.
  10  - Verify that bitcoind AbortNode's.
  11  """
  12  from test_framework.test_framework import BitcoinTestFramework
  13  
  14  
  15  class AbortNodeTest(BitcoinTestFramework):
  16      def set_test_params(self):
  17          self.setup_clean_chain = True
  18          self.num_nodes = 2
  19  
  20      def setup_network(self):
  21          self.setup_nodes()
  22          # We'll connect the nodes later
  23  
  24      def run_test(self):
  25          self.generate(self.nodes[0], 3, sync_fun=self.no_op)
  26  
  27          # Deleting the undo file will result in reorg failure
  28          (self.nodes[0].blocks_path / "rev00000.dat").unlink()
  29  
  30          # Connecting to a node with a more work chain will trigger a reorg
  31          # attempt.
  32          self.generate(self.nodes[1], 3, sync_fun=self.no_op)
  33          with self.nodes[0].assert_debug_log(["Failed to disconnect block"]):
  34              self.connect_nodes(0, 1)
  35              self.generate(self.nodes[1], 1, sync_fun=self.no_op)
  36  
  37              # Check that node0 aborted
  38              self.log.info("Waiting for crash")
  39              self.nodes[0].wait_until_stopped(timeout=5, expect_error=True, expected_stderr="Error: A fatal internal error occurred, see debug.log for details: Failed to disconnect block.")
  40          self.log.info("Node crashed - now verifying restart fails")
  41          self.nodes[0].assert_start_raises_init_error()
  42  
  43  
  44  if __name__ == '__main__':
  45      AbortNodeTest(__file__).main()
  46