Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_tx_download.py
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | class TxDownloadTest(BitcoinTestFramework): | ||||
def test_tx_requests(self): | def test_tx_requests(self): | ||||
self.log.info( | self.log.info( | ||||
"Test that we request transactions from all our peers, eventually") | "Test that we request transactions from all our peers, eventually") | ||||
txid = 0xdeadbeef | txid = 0xdeadbeef | ||||
self.log.info("Announce the txid from each incoming peer to node 0") | self.log.info("Announce the txid from each incoming peer to node 0") | ||||
msg = msg_inv([CInv(t=1, h=txid)]) | msg = msg_inv([CInv(t=MSG_TX, h=txid)]) | ||||
for p in self.nodes[0].p2ps: | for p in self.nodes[0].p2ps: | ||||
p.send_and_ping(msg) | p.send_and_ping(msg) | ||||
outstanding_peer_index = [i for i in range(len(self.nodes[0].p2ps))] | outstanding_peer_index = [i for i in range(len(self.nodes[0].p2ps))] | ||||
def getdata_found(peer_index): | def getdata_found(peer_index): | ||||
p = self.nodes[0].p2ps[peer_index] | p = self.nodes[0].p2ps[peer_index] | ||||
with mininode_lock: | with mininode_lock: | ||||
Show All 27 Lines | def test_inv_block(self): | ||||
hexstring=tx, | hexstring=tx, | ||||
privkeys=[self.nodes[0].get_deterministic_priv_key().key], | privkeys=[self.nodes[0].get_deterministic_priv_key().key], | ||||
)['hex'] | )['hex'] | ||||
ctx = FromHex(CTransaction(), tx) | ctx = FromHex(CTransaction(), tx) | ||||
txid = int(ctx.rehash(), 16) | txid = int(ctx.rehash(), 16) | ||||
self.log.info( | self.log.info( | ||||
"Announce the transaction to all nodes from all {} incoming peers, but never send it".format(NUM_INBOUND)) | "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)]) | msg = msg_inv([CInv(t=MSG_TX, h=txid)]) | ||||
for p in self.peers: | for p in self.peers: | ||||
p.send_and_ping(msg) | p.send_and_ping(msg) | ||||
self.log.info("Put the tx in node 0's mempool") | self.log.info("Put the tx in node 0's mempool") | ||||
self.nodes[0].sendrawtransaction(tx) | self.nodes[0].sendrawtransaction(tx) | ||||
# Since node 1 is connected outbound to an honest peer (node 0), it | # Since node 1 is connected outbound to an honest peer (node 0), it | ||||
# should get the tx within a timeout. (Assuming that node 0 | # should get the tx within a timeout. (Assuming that node 0 | ||||
Show All 15 Lines | def test_in_flight_max(self): | ||||
MAX_GETDATA_IN_FLIGHT, TX_EXPIRY_INTERVAL / 60)) | MAX_GETDATA_IN_FLIGHT, TX_EXPIRY_INTERVAL / 60)) | ||||
txids = [i for i in range(MAX_GETDATA_IN_FLIGHT + 2)] | txids = [i for i in range(MAX_GETDATA_IN_FLIGHT + 2)] | ||||
p = self.nodes[0].p2ps[0] | p = self.nodes[0].p2ps[0] | ||||
with mininode_lock: | with mininode_lock: | ||||
p.tx_getdata_count = 0 | p.tx_getdata_count = 0 | ||||
p.send_message(msg_inv([CInv(t=1, h=i) for i in txids])) | p.send_message(msg_inv([CInv(t=MSG_TX, h=i) for i in txids])) | ||||
wait_until(lambda: p.tx_getdata_count >= | wait_until(lambda: p.tx_getdata_count >= | ||||
MAX_GETDATA_IN_FLIGHT, lock=mininode_lock) | MAX_GETDATA_IN_FLIGHT, lock=mininode_lock) | ||||
with mininode_lock: | with mininode_lock: | ||||
assert_equal(p.tx_getdata_count, MAX_GETDATA_IN_FLIGHT) | assert_equal(p.tx_getdata_count, MAX_GETDATA_IN_FLIGHT) | ||||
self.log.info( | self.log.info( | ||||
"Now check that if we send a NOTFOUND for a transaction, we'll get one more request") | "Now check that if we send a NOTFOUND for a transaction, we'll get one more request") | ||||
p.send_message(msg_notfound(vec=[CInv(t=1, h=txids[0])])) | p.send_message(msg_notfound(vec=[CInv(t=MSG_TX, h=txids[0])])) | ||||
wait_until( | wait_until( | ||||
lambda: p.tx_getdata_count >= MAX_GETDATA_IN_FLIGHT + 1, | lambda: p.tx_getdata_count >= MAX_GETDATA_IN_FLIGHT + 1, | ||||
timeout=10, | timeout=10, | ||||
lock=mininode_lock) | lock=mininode_lock) | ||||
with mininode_lock: | with mininode_lock: | ||||
assert_equal(p.tx_getdata_count, MAX_GETDATA_IN_FLIGHT + 1) | assert_equal(p.tx_getdata_count, MAX_GETDATA_IN_FLIGHT + 1) | ||||
WAIT_TIME = TX_EXPIRY_INTERVAL // 2 + TX_EXPIRY_INTERVAL | WAIT_TIME = TX_EXPIRY_INTERVAL // 2 + TX_EXPIRY_INTERVAL | ||||
self.log.info( | self.log.info( | ||||
"if we wait about {} minutes, we should eventually get more requests".format( | "if we wait about {} minutes, we should eventually get more requests".format( | ||||
WAIT_TIME / 60)) | WAIT_TIME / 60)) | ||||
self.nodes[0].setmocktime(int(time.time() + WAIT_TIME)) | self.nodes[0].setmocktime(int(time.time() + WAIT_TIME)) | ||||
wait_until(lambda: p.tx_getdata_count == MAX_GETDATA_IN_FLIGHT + 2) | wait_until(lambda: p.tx_getdata_count == MAX_GETDATA_IN_FLIGHT + 2) | ||||
self.nodes[0].setmocktime(0) | self.nodes[0].setmocktime(0) | ||||
def test_spurious_notfound(self): | def test_spurious_notfound(self): | ||||
self.log.info('Check that spurious notfound is ignored') | self.log.info('Check that spurious notfound is ignored') | ||||
self.nodes[0].p2ps[0].send_message(msg_notfound(vec=[CInv(1, 1)])) | self.nodes[0].p2ps[0].send_message(msg_notfound(vec=[CInv(MSG_TX, 1)])) | ||||
def run_test(self): | def run_test(self): | ||||
# Setup the p2p connections | # Setup the p2p connections | ||||
self.peers = [] | self.peers = [] | ||||
for node in self.nodes: | for node in self.nodes: | ||||
for i in range(NUM_INBOUND): | for i in range(NUM_INBOUND): | ||||
self.peers.append(node.add_p2p_connection(TestP2PConn())) | self.peers.append(node.add_p2p_connection(TestP2PConn())) | ||||
Show All 16 Lines |