0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-10 10:52:31 -05:00

test: Combine sync_send_with_ping and sync_with_ping

This commit is contained in:
MarcoFalke 2023-09-05 12:11:54 +02:00
parent 260445bee8
commit fae0b21e6c
No known key found for this signature in database
8 changed files with 12 additions and 16 deletions

View file

@ -133,7 +133,7 @@ class AddrTest(BitcoinTestFramework):
self.mocktime += 10 * 60 self.mocktime += 10 * 60
self.nodes[0].setmocktime(self.mocktime) self.nodes[0].setmocktime(self.mocktime)
for peer in receivers: for peer in receivers:
peer.sync_send_with_ping() peer.sync_with_ping()
def oversized_addr_test(self): def oversized_addr_test(self):
self.log.info('Send an addr message that is too large') self.log.info('Send an addr message that is too large')

View file

@ -48,7 +48,7 @@ class P2PAddrFetch(BitcoinTestFramework):
self.assert_getpeerinfo(peer_ids=[peer_id]) self.assert_getpeerinfo(peer_ids=[peer_id])
self.log.info("Check that we send getaddr but don't try to sync headers with the addr-fetch peer") self.log.info("Check that we send getaddr but don't try to sync headers with the addr-fetch peer")
peer.sync_send_with_ping() peer.sync_with_ping()
with p2p_lock: with p2p_lock:
assert peer.message_count['getaddr'] == 1 assert peer.message_count['getaddr'] == 1
assert peer.message_count['getheaders'] == 0 assert peer.message_count['getheaders'] == 0

View file

@ -101,7 +101,7 @@ class P2PBlocksOnly(BitcoinTestFramework):
# Bump time forward to ensure m_next_inv_send_time timer pops # Bump time forward to ensure m_next_inv_send_time timer pops
self.nodes[0].setmocktime(int(time.time()) + 60) self.nodes[0].setmocktime(int(time.time()) + 60)
conn.sync_send_with_ping() conn.sync_with_ping()
assert int(txid, 16) not in conn.get_invs() assert int(txid, 16) not in conn.get_invs()
def check_p2p_inv_violation(self, peer): def check_p2p_inv_violation(self, peer):

View file

@ -94,11 +94,11 @@ class P2PCompactBlocksBlocksOnly(BitcoinTestFramework):
block1 = self.build_block_on_tip() block1 = self.build_block_on_tip()
p2p_conn_blocksonly.send_message(msg_headers(headers=[CBlockHeader(block1)])) p2p_conn_blocksonly.send_message(msg_headers(headers=[CBlockHeader(block1)]))
p2p_conn_blocksonly.sync_send_with_ping() p2p_conn_blocksonly.sync_with_ping()
assert_equal(p2p_conn_blocksonly.last_message['getdata'].inv, [CInv(MSG_BLOCK | MSG_WITNESS_FLAG, block1.sha256)]) assert_equal(p2p_conn_blocksonly.last_message['getdata'].inv, [CInv(MSG_BLOCK | MSG_WITNESS_FLAG, block1.sha256)])
p2p_conn_high_bw.send_message(msg_headers(headers=[CBlockHeader(block1)])) p2p_conn_high_bw.send_message(msg_headers(headers=[CBlockHeader(block1)]))
p2p_conn_high_bw.sync_send_with_ping() p2p_conn_high_bw.sync_with_ping()
assert_equal(p2p_conn_high_bw.last_message['getdata'].inv, [CInv(MSG_CMPCT_BLOCK, block1.sha256)]) assert_equal(p2p_conn_high_bw.last_message['getdata'].inv, [CInv(MSG_CMPCT_BLOCK, block1.sha256)])
self.log.info("Test that getdata(CMPCT) is still sent on BIP152 low bandwidth connections" self.log.info("Test that getdata(CMPCT) is still sent on BIP152 low bandwidth connections"

View file

@ -177,7 +177,7 @@ class FilterTest(BitcoinTestFramework):
filter_peer.merkleblock_received = False filter_peer.merkleblock_received = False
filter_peer.tx_received = False filter_peer.tx_received = False
self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=7 * COIN) self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=7 * COIN)
filter_peer.sync_send_with_ping() filter_peer.sync_with_ping()
assert not filter_peer.merkleblock_received assert not filter_peer.merkleblock_received
assert not filter_peer.tx_received assert not filter_peer.tx_received

View file

@ -151,7 +151,7 @@ class P2PIBDStallingTest(BitcoinTestFramework):
def all_sync_send_with_ping(self, peers): def all_sync_send_with_ping(self, peers):
for p in peers: for p in peers:
if p.is_connected: if p.is_connected:
p.sync_send_with_ping() p.sync_with_ping()
def is_block_requested(self, peers, hash): def is_block_requested(self, peers, hash):
for p in peers: for p in peers:

View file

@ -53,7 +53,7 @@ class P2PIBDTxRelayTest(BitcoinTestFramework):
peer_inver.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=txid)])) peer_inver.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=txid)]))
# The node should not send a getdata, but if it did, it would first delay 2 seconds # The node should not send a getdata, but if it did, it would first delay 2 seconds
self.nodes[0].setmocktime(int(time.time() + NONPREF_PEER_TX_DELAY)) self.nodes[0].setmocktime(int(time.time() + NONPREF_PEER_TX_DELAY))
peer_inver.sync_send_with_ping() peer_inver.sync_with_ping()
with p2p_lock: with p2p_lock:
assert txid not in peer_inver.getdata_requests assert txid not in peer_inver.getdata_requests
self.nodes[0].disconnect_p2ps() self.nodes[0].disconnect_p2ps()

View file

@ -558,16 +558,12 @@ class P2PInterface(P2PConnection):
self.send_message(message) self.send_message(message)
self.sync_with_ping(timeout=timeout) self.sync_with_ping(timeout=timeout)
def sync_send_with_ping(self, timeout=60): def sync_with_ping(self, timeout=60):
"""Ensure SendMessages is called on this connection""" """Ensure ProcessMessages and SendMessages is called on this connection"""
# Calling sync_with_ping twice requires that the node calls # Sending two pings back-to-back, requires that the node calls
# `ProcessMessage` twice, and thus ensures `SendMessages` must have # `ProcessMessage` twice, and thus ensures `SendMessages` must have
# been called at least once # been called at least once
self.sync_with_ping() self.send_message(msg_ping(nonce=0))
self.sync_with_ping()
def sync_with_ping(self, timeout=60):
"""Ensure ProcessMessages is called on this connection"""
self.send_message(msg_ping(nonce=self.ping_counter)) self.send_message(msg_ping(nonce=self.ping_counter))
def test_function(): def test_function():