11from __future__ import annotations
22
33import asyncio
4+ import copy
45import logging
56import time
67import traceback
@@ -89,6 +90,7 @@ async def tx_request_and_timeout(full_node: FullNode, transaction_id: bytes32, t
8990 receive it or timeout.
9091 """
9192 counter = 0
93+ peers_with_tx = copy .copy (full_node .full_node_store .peers_with_tx .get (transaction_id , {}))
9294 try :
9395 while True :
9496 # Limit to asking a few peers, it's possible that this tx got included on chain already
@@ -98,10 +100,9 @@ async def tx_request_and_timeout(full_node: FullNode, transaction_id: bytes32, t
98100 break
99101 if transaction_id not in full_node .full_node_store .peers_with_tx :
100102 break
101- peers_with_tx : set [bytes32 ] = full_node .full_node_store .peers_with_tx [transaction_id ]
102103 if len (peers_with_tx ) == 0 :
103104 break
104- peer_id = peers_with_tx .pop ()
105+ peer_id , _ = peers_with_tx .popitem ()
105106 assert full_node .server is not None
106107 if peer_id not in full_node .server .all_connections :
107108 continue
@@ -111,7 +112,7 @@ async def tx_request_and_timeout(full_node: FullNode, transaction_id: bytes32, t
111112 await random_peer .send_message (msg )
112113 await asyncio .sleep (5 )
113114 counter += 1
114- if full_node .mempool_manager .seen (transaction_id ):
115+ if full_node .mempool_manager .get_mempool_item (transaction_id ) is not None :
115116 break
116117 except asyncio .CancelledError :
117118 pass
@@ -228,21 +229,22 @@ async def new_transaction(
228229 # If there's current pending request just add this peer to the set of peers that have this tx
229230 if transaction .transaction_id in self .full_node .full_node_store .pending_tx_request :
230231 if transaction .transaction_id in self .full_node .full_node_store .peers_with_tx :
231- current_set = self .full_node .full_node_store .peers_with_tx [transaction .transaction_id ]
232- if peer .peer_node_id in current_set :
232+ current_map = self .full_node .full_node_store .peers_with_tx [transaction .transaction_id ]
233+ if peer .peer_node_id in current_map :
233234 return None
234- current_set . add ( peer .peer_node_id )
235+ current_map [ peer .peer_node_id ] = ( transaction . fees , transaction . cost )
235236 return None
236237 else :
237- new_set = set ()
238- new_set . add ( peer .peer_node_id )
239- self . full_node . full_node_store . peers_with_tx [ transaction . transaction_id ] = new_set
238+ self . full_node . full_node_store . peers_with_tx [ transaction . transaction_id ] = {
239+ peer .peer_node_id : ( transaction . fees , transaction . cost )
240+ }
240241 return None
241242
242243 self .full_node .full_node_store .pending_tx_request [transaction .transaction_id ] = peer .peer_node_id
243- new_set = set ()
244- new_set .add (peer .peer_node_id )
245- self .full_node .full_node_store .peers_with_tx [transaction .transaction_id ] = new_set
244+ self .full_node .full_node_store .peers_with_tx [transaction .transaction_id ] = {
245+ peer .peer_node_id : (transaction .fees , transaction .cost )
246+ }
247+
246248 task_id : bytes32 = bytes32 .secret ()
247249 fetch_task = create_referenced_task (
248250 tx_request_and_timeout (self .full_node , transaction .transaction_id , task_id )
@@ -282,13 +284,15 @@ async def respond_transaction(
282284 spend_name = std_hash (tx_bytes )
283285 if spend_name in self .full_node .full_node_store .pending_tx_request :
284286 self .full_node .full_node_store .pending_tx_request .pop (spend_name )
287+ peers_with_tx = {}
285288 if spend_name in self .full_node .full_node_store .peers_with_tx :
286- self .full_node .full_node_store .peers_with_tx .pop (spend_name )
289+ peers_with_tx = self .full_node .full_node_store .peers_with_tx .pop (spend_name )
287290
288291 # TODO: Use fee in priority calculation, to prioritize high fee TXs
289292 try :
290293 await self .full_node .transaction_queue .put (
291- TransactionQueueEntry (tx .transaction , tx_bytes , spend_name , peer , test ), peer .peer_node_id
294+ TransactionQueueEntry (tx .transaction , tx_bytes , spend_name , peer , test , peers_with_tx ),
295+ peer .peer_node_id ,
292296 )
293297 except TransactionQueueFull :
294298 pass # we can't do anything here, the tx will be dropped. We might do something in the future.
0 commit comments