Esempio n. 1
0
 async def _refresh_hashes(self, synchronized_event):
     """Refresh our view of the daemon's mempool."""
     while True:
         start = time.perf_counter()
         height = self._daemon.cached_height()
         hex_hashes = await self._daemon.mempool_hashes()
         if height != await self._daemon.height():
             continue
         hashes = {hex_str_to_hash(hh) for hh in hex_hashes}
         async with self.lock:
             new_hashes = hashes.difference(self.notified_mempool_txs)
             touched = await self._process_mempool(hashes)
             self.notified_mempool_txs.update(new_hashes)
             new_touched = {
                 touched_hashx
                 for touched_hashx, txs in self.hashXs.items()
                 if txs.intersection(new_hashes)
             }
         synchronized_event.set()
         synchronized_event.clear()
         await self.on_mempool(touched, new_touched, height)
         duration = time.perf_counter() - start
         self.mempool_process_time_metric.observe(duration)
         try:
             # we wait up to `refresh_secs` but go early if a broadcast happens (which triggers wakeup event)
             await asyncio.wait_for(self.wakeup.wait(),
                                    timeout=self.refresh_secs)
         except asyncio.TimeoutError:
             pass
         finally:
             self.wakeup.clear()
Esempio n. 2
0
 async def _refresh_hashes(self, synchronized_event):
     """Refresh our view of the daemon's mempool."""
     while True:
         height = self.api.cached_height()
         hex_hashes = await self.api.mempool_hashes()
         if height != await self.api.height():
             continue
         hashes = {hex_str_to_hash(hh) for hh in hex_hashes}
         async with self.lock:
             touched = await self._process_mempool(hashes)
         synchronized_event.set()
         synchronized_event.clear()
         await self.api.on_mempool(touched, height)
         try:
             # we wait up to `refresh_secs` but go early if a broadcast happens (which triggers wakeup event)
             await asyncio.wait_for(self.wakeup.wait(), timeout=self.refresh_secs)
         except asyncio.TimeoutError:
             pass
         finally:
             self.wakeup.clear()