diff --git a/test/functional/feature_maxuploadtarget.py b/test/functional/feature_maxuploadtarget.py --- a/test/functional/feature_maxuploadtarget.py +++ b/test/functional/feature_maxuploadtarget.py @@ -99,8 +99,7 @@ # 144MB will be reserved for relaying new blocks, so expect this to # succeed for ~70 tries. for i in range(success_count): - p2p_conns[0].send_message(getdata_request) - p2p_conns[0].sync_with_ping() + p2p_conns[0].send_and_ping(getdata_request) assert_equal(p2p_conns[0].block_receive_map[big_old_block], i + 1) assert_equal(len(self.nodes[0].getpeerinfo()), 3) @@ -118,8 +117,7 @@ # We'll try 200 times getdata_request.inv = [CInv(2, big_new_block)] for i in range(200): - p2p_conns[1].send_message(getdata_request) - p2p_conns[1].sync_with_ping() + p2p_conns[1].send_and_ping(getdata_request) assert_equal(p2p_conns[1].block_receive_map[big_new_block], i + 1) self.log.info("Peer 1 able to repeatedly download new block") @@ -139,8 +137,7 @@ # and p2p_conns[2] should be able to retrieve the old block. self.nodes[0].setmocktime(int(time.time())) p2p_conns[2].sync_with_ping() - p2p_conns[2].send_message(getdata_request) - p2p_conns[2].sync_with_ping() + p2p_conns[2].send_and_ping(getdata_request) assert_equal(p2p_conns[2].block_receive_map[big_old_block], 1) self.log.info("Peer 2 able to download old block") @@ -159,8 +156,7 @@ # retrieve 20 blocks which should be enough to break the 1MB limit getdata_request.inv = [CInv(2, big_new_block)] for i in range(20): - self.nodes[0].p2p.send_message(getdata_request) - self.nodes[0].p2p.sync_with_ping() + self.nodes[0].p2p.send_and_ping(getdata_request) assert_equal( self.nodes[0].p2p.block_receive_map[big_new_block], i + 1) diff --git a/test/functional/p2p_filter.py b/test/functional/p2p_filter.py --- a/test/functional/p2p_filter.py +++ b/test/functional/p2p_filter.py @@ -65,8 +65,7 @@ def run_test(self): self.log.info('Add filtered P2P connection to the node') filter_node = self.nodes[0].add_p2p_connection(FilterNode()) - filter_node.send_message(filter_node.watch_filter_init) - filter_node.sync_with_ping() + filter_node.send_and_ping(filter_node.watch_filter_init) filter_address = self.nodes[0].decodescript( filter_node.watch_script_pubkey)['addresses'][0] @@ -106,8 +105,8 @@ self.log.info( 'Check that after deleting filter all txs get relayed again') - filter_node.send_message(msg_filterclear()) - filter_node.sync_with_ping() + filter_node.send_and_ping(msg_filterclear()) + for _ in range(5): txid = self.nodes[0].sendtoaddress( self.nodes[0].getnewaddress(), 7) diff --git a/test/functional/p2p_leak_tx.py b/test/functional/p2p_leak_tx.py --- a/test/functional/p2p_leak_tx.py +++ b/test/functional/p2p_leak_tx.py @@ -41,8 +41,7 @@ want_tx = msg_getdata() want_tx.inv.append(CInv(t=1, h=int(txid, 16))) inbound_peer.last_message.pop('notfound', None) - inbound_peer.send_message(want_tx) - inbound_peer.sync_with_ping() + inbound_peer.send_and_ping(want_tx) if inbound_peer.last_message.get('notfound'): self.log.debug( diff --git a/test/functional/p2p_sendheaders.py b/test/functional/p2p_sendheaders.py --- a/test/functional/p2p_sendheaders.py +++ b/test/functional/p2p_sendheaders.py @@ -324,8 +324,8 @@ new_block.solve() test_node.send_header_for_blocks([new_block]) test_node.wait_for_getdata([new_block.sha256]) - test_node.send_message(msg_block(new_block)) - test_node.sync_with_ping() # make sure this block is processed + # make sure this block is processed + test_node.send_and_ping(msg_block(new_block)) wait_until(lambda: inv_node.block_announced, timeout=60, lock=mininode_lock) inv_node.clear_block_announcements() diff --git a/test/functional/p2p_tx_download.py b/test/functional/p2p_tx_download.py --- a/test/functional/p2p_tx_download.py +++ b/test/functional/p2p_tx_download.py @@ -67,8 +67,7 @@ self.log.info("Announce the txid from each incoming peer to node 0") msg = msg_inv([CInv(t=1, h=txid)]) for p in self.nodes[0].p2ps: - p.send_message(msg) - p.sync_with_ping() + p.send_and_ping(msg) outstanding_peer_index = [i for i in range(len(self.nodes[0].p2ps))] @@ -112,8 +111,7 @@ "Announce the transaction to all nodes from all {} incoming peers, but never send it".format(NUM_INBOUND)) msg = msg_inv([CInv(t=1, h=txid)]) for p in self.peers: - p.send_message(msg) - p.sync_with_ping() + p.send_and_ping(msg) self.log.info("Put the tx in node 0's mempool") self.nodes[0].sendrawtransaction(tx) diff --git a/test/functional/p2p_unrequested_blocks.py b/test/functional/p2p_unrequested_blocks.py --- a/test/functional/p2p_unrequested_blocks.py +++ b/test/functional/p2p_unrequested_blocks.py @@ -114,11 +114,8 @@ tips[i], create_coinbase(2), block_time)) blocks_h2[i].solve() block_time += 1 - test_node.send_message(msg_block(blocks_h2[0])) - min_work_node.send_message(msg_block(blocks_h2[1])) - - for x in [test_node, min_work_node]: - x.sync_with_ping() + test_node.send_and_ping(msg_block(blocks_h2[0])) + min_work_node.send_and_ping(msg_block(blocks_h2[1])) assert_equal(self.nodes[0].getblockcount(), 2) assert_equal(self.nodes[1].getblockcount(), 1) @@ -130,9 +127,8 @@ int("0x" + self.nodes[0].getblockhash(0), 0), create_coinbase(1), block_time) block_time += 1 block_h1f.solve() - test_node.send_message(msg_block(block_h1f)) + test_node.send_and_ping(msg_block(block_h1f)) - test_node.sync_with_ping() tip_entry_found = False for x in self.nodes[0].getchaintips(): if x['hash'] == block_h1f.hash: @@ -147,9 +143,8 @@ block_h1f.sha256, create_coinbase(2), block_time) block_time += 1 block_h2f.solve() - test_node.send_message(msg_block(block_h2f)) + test_node.send_and_ping(msg_block(block_h2f)) - test_node.sync_with_ping() # Since the earlier block was not processed by node, the new block # can't be fully validated. tip_entry_found = False @@ -167,9 +162,8 @@ block_h3 = create_block( block_h2f.sha256, create_coinbase(3), block_h2f.nTime + 1) block_h3.solve() - test_node.send_message(msg_block(block_h3)) + test_node.send_and_ping(msg_block(block_h3)) - test_node.sync_with_ping() # Since the earlier block was not processed by node, the new block # can't be fully validated. tip_entry_found = False @@ -198,8 +192,7 @@ # Now send the block at height 5 and check that it wasn't accepted # (missing header) - test_node.send_message(msg_block(all_blocks[1])) - test_node.sync_with_ping() + test_node.send_and_ping(msg_block(all_blocks[1])) assert_raises_rpc_error(-5, "Block not found", self.nodes[0].getblock, all_blocks[1].hash) assert_raises_rpc_error(-5, "Block not found", @@ -210,8 +203,7 @@ headers_message = msg_headers() headers_message.headers.append(CBlockHeader(all_blocks[0])) test_node.send_message(headers_message) - test_node.send_message(msg_block(all_blocks[1])) - test_node.sync_with_ping() + test_node.send_and_ping(msg_block(all_blocks[1])) self.nodes[0].getblock(all_blocks[1].hash) # Now send the blocks in all_blocks @@ -237,9 +229,7 @@ test_node = self.nodes[0].add_p2p_connection(P2PInterface()) - test_node.send_message(msg_block(block_h1f)) - - test_node.sync_with_ping() + test_node.send_and_ping(msg_block(block_h1f)) assert_equal(self.nodes[0].getblockcount(), 2) self.log.info( "Unrequested block that would complete more-work chain was ignored") @@ -261,9 +251,7 @@ self.log.info("Inv at tip triggered getdata for unprocessed block") # 7. Send the missing block for the third time (now it is requested) - test_node.send_message(msg_block(block_h1f)) - - test_node.sync_with_ping() + test_node.send_and_ping(msg_block(block_h1f)) assert_equal(self.nodes[0].getblockcount(), 290) self.nodes[0].getblock(all_blocks[286].hash) assert_equal(self.nodes[0].getbestblockhash(), all_blocks[286].hash) @@ -298,9 +286,8 @@ headers_message.headers.append(CBlockHeader(block_290f)) headers_message.headers.append(CBlockHeader(block_291)) headers_message.headers.append(CBlockHeader(block_292)) - test_node.send_message(headers_message) + test_node.send_and_ping(headers_message) - test_node.sync_with_ping() tip_entry_found = False for x in self.nodes[0].getchaintips(): if x['hash'] == block_292.hash: @@ -311,9 +298,8 @@ self.nodes[0].getblock, block_292.hash) test_node.send_message(msg_block(block_289f)) - test_node.send_message(msg_block(block_290f)) + test_node.send_and_ping(msg_block(block_290f)) - test_node.sync_with_ping() self.nodes[0].getblock(block_289f.hash) self.nodes[0].getblock(block_290f.hash) diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -353,8 +353,7 @@ def solve_and_send_block(prevhash, height, time): b = create_block(prevhash, create_coinbase(height), time) b.solve() - node.p2p.send_message(msg_block(b)) - node.p2p.sync_with_ping() + node.p2p.send_and_ping(msg_block(b)) return b b21f = solve_and_send_block(int(b20hash, 16), 21, b20['time'] + 1)