Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/mininode.py
Show First 20 Lines • Show All 748 Lines • ▼ Show 20 Lines | |||||
class P2PTxInvStore(P2PInterface): | class P2PTxInvStore(P2PInterface): | ||||
"""A P2PInterface which stores a count of how many times each txid has been announced.""" | """A P2PInterface which stores a count of how many times each txid has been announced.""" | ||||
def __init__(self): | def __init__(self): | ||||
super().__init__() | super().__init__() | ||||
self.tx_invs_received = defaultdict(int) | self.tx_invs_received = defaultdict(int) | ||||
def on_inv(self, message): | def on_inv(self, message): | ||||
# Send getdata in response. | |||||
super().on_inv(message) | |||||
# Store how many times invs have been received for each tx. | # Store how many times invs have been received for each tx. | ||||
for i in message.inv: | for i in message.inv: | ||||
if i.type == MSG_TX: | if i.type == MSG_TX: | ||||
# save txid | # save txid | ||||
self.tx_invs_received[i.hash] += 1 | self.tx_invs_received[i.hash] += 1 | ||||
def get_invs(self): | def get_invs(self): | ||||
with mininode_lock: | with mininode_lock: | ||||
return list(self.tx_invs_received.keys()) | return list(self.tx_invs_received.keys()) | ||||
def wait_for_broadcast(self, txns, timeout=60): | |||||
"""Waits for the txns (list of txids) to complete initial broadcast. | |||||
The mempool should mark unbroadcast=False for these transactions. | |||||
""" | |||||
# Wait until invs have been received (and getdatas sent) for each txid. | |||||
self.wait_until(lambda: set(self.get_invs()) == set( | |||||
[int(tx, 16) for tx in txns]), timeout) | |||||
# Flush messages and wait for the getdatas to be processed | |||||
self.sync_with_ping() |