MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / wait_for_new_peer

Method wait_for_new_peer

test/functional/test_framework/test_node.py:647–661  ·  view source on GitHub ↗

Wait until the node is connected to at least one new peer. We detect this by watching for an increased highest peer id, using the `getpeerinfo` RPC call. Note that the simpler approach of only accounting for the number of peers suffers from race conditions, as discon

(self, timeout=5)

Source from the content-addressed store, hash-verified

645
646 @contextlib.contextmanager
647 def wait_for_new_peer(self, timeout=5):
648 """
649 Wait until the node is connected to at least one new peer. We detect this
650 by watching for an increased highest peer id, using the `getpeerinfo` RPC call.
651 Note that the simpler approach of only accounting for the number of peers
652 suffers from race conditions, as disconnects from unrelated previous peers
653 could happen anytime in-between.
654 """
655 def get_highest_peer_id():
656 peer_info = self.getpeerinfo()
657 return peer_info[-1]["id"] if peer_info else -1
658
659 initial_peer_id = get_highest_peer_id()
660 yield
661 self.wait_until(lambda: get_highest_peer_id() > initial_peer_id, timeout=timeout)
662
663 def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, match=ErrorMatch.FULL_TEXT, *args, **kwargs):
664 """Attempt to start the node and expect it to raise an error.

Callers 3

test_getpeerinfoMethod · 0.80
test_earlykeyresponseMethod · 0.80
run_testMethod · 0.80

Calls 1

wait_untilMethod · 0.95

Tested by

no test coverage detected