diff --git a/electrumx/lib/coins.py b/electrumx/lib/coins.py index 9b7cc48..1f7597b 100644 --- a/electrumx/lib/coins.py +++ b/electrumx/lib/coins.py @@ -70,6 +70,7 @@ class Coin(object): DESERIALIZER = lib_tx.Deserializer DAEMON = daemon.Daemon BLOCK_PROCESSOR = BlockProcessor + MEMPOOL_HISTOGRAM_REFRESH_SECS = 500 XPUB_VERBYTES = bytes('????', 'utf-8') XPRV_VERBYTES = bytes('????', 'utf-8') ENCODE_CHECK = Base58.encode_check @@ -423,6 +424,7 @@ class BitcoinCash(BitcoinMixin, Coin): class BitcoinSegwit(BitcoinMixin, Coin): NAME = "BitcoinSegwit" DESERIALIZER = lib_tx.DeserializerSegWit + MEMPOOL_HISTOGRAM_REFRESH_SECS = 120 TX_COUNT = 318337769 TX_COUNT_HEIGHT = 524213 TX_PER_BLOCK = 1400 diff --git a/electrumx/server/mempool.py b/electrumx/server/mempool.py index 5e19a6d..a48a34b 100644 --- a/electrumx/server/mempool.py +++ b/electrumx/server/mempool.py @@ -129,6 +129,8 @@ class MemPool(object): async def _refresh_hashes(self, once): '''Refresh our view of the daemon's mempool.''' + sleep = 5 + histogram_refresh = self.coin.MEMPOOL_HISTOGRAM_REFRESH_SECS // sleep for loop_count in itertools.count(): height = self.daemon.cached_height() hex_hashes = await self.daemon.mempool_hashes() @@ -137,13 +139,12 @@ class MemPool(object): hashes = set(hex_str_to_hash(hh) for hh in hex_hashes) touched = await self._process_mempool(hashes) await self.notifications.on_mempool(touched, height) - # Refresh the cached histogram periodically. Thread it as it - # can be expensive. - if loop_count % 100 == 0: + # Thread mempool histogram refreshes - they can be expensive + if loop_count % histogram_refresh == 0: await self.tasks.run_in_thread(self._update_histogram) if once: return - await asyncio.sleep(5) + await asyncio.sleep(sleep) async def _process_mempool(self, all_hashes): # Re-sync with the new set of hashes