MCPcopy Create free account
hub / github.com/ElementsProject/elements / P2PTxInvStore

Class P2PTxInvStore

test/functional/test_framework/p2p.py:767–792  ·  view source on GitHub ↗

A P2PInterface which stores a count of how many times each txid has been announced.

Source from the content-addressed store, hash-verified

765 assert tx.hash not in raw_mempool, "{} tx found in mempool".format(tx.hash)
766
767class P2PTxInvStore(P2PInterface):
768 """A P2PInterface which stores a count of how many times each txid has been announced."""
769 def __init__(self):
770 super().__init__()
771 self.tx_invs_received = defaultdict(int)
772
773 def on_inv(self, message):
774 super().on_inv(message) # Send getdata in response.
775 # Store how many times invs have been received for each tx.
776 for i in message.inv:
777 if (i.type == MSG_TX) or (i.type == MSG_WTX):
778 # save txid
779 self.tx_invs_received[i.hash] += 1
780
781 def get_invs(self):
782 with p2p_lock:
783 return list(self.tx_invs_received.keys())
784
785 def wait_for_broadcast(self, txns, timeout=60):
786 """Waits for the txns (list of txids) to complete initial broadcast.
787 The mempool should mark unbroadcast=False for these transactions.
788 """
789 # Wait until invs have been received (and getdatas sent) for each txid.
790 self.wait_until(lambda: set(self.tx_invs_received.keys()) == set([int(tx, 16) for tx in txns]), timeout=timeout)
791 # Flush messages and wait for the getdatas to be processed
792 self.sync_with_ping()

Callers 6

run_testMethod · 0.90
run_testMethod · 0.90
run_testMethod · 0.90
test_broadcastMethod · 0.90

Calls

no outgoing calls

Tested by 2

test_broadcastMethod · 0.72