p2p_block_sync.py raw

   1  #!/usr/bin/env python3
   2  # Copyright (c) 2022-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 block download
   6  
   7  Ensure that even in IBD, we'll eventually sync chain from inbound peers
   8  (whether we have only inbound peers or both inbound and outbound peers).
   9  """
  10  
  11  from test_framework.test_framework import BitcoinTestFramework
  12  
  13  class BlockSyncTest(BitcoinTestFramework):
  14  
  15      def set_test_params(self):
  16          self.setup_clean_chain = True
  17          self.num_nodes = 3
  18  
  19      def setup_network(self):
  20          self.setup_nodes()
  21          # Construct a network:
  22          # node0 -> node1 -> node2
  23          # So node1 has both an inbound and outbound peer.
  24          # In our test, we will mine a block on node0, and ensure that it makes
  25          # to both node1 and node2.
  26          self.connect_nodes(0, 1)
  27          self.connect_nodes(1, 2)
  28  
  29      def run_test(self):
  30          self.log.info("Setup network: node0->node1->node2")
  31          self.log.info("Mining one block on node0 and verify all nodes sync")
  32          self.generate(self.nodes[0], 1)
  33          self.log.info("Success!")
  34  
  35  
  36  if __name__ == '__main__':
  37      BlockSyncTest(__file__).main()
  38