parent
d36925d459
commit
f600d3bd87
@ -133,12 +133,3 @@ def increment_byte_string(bs):
|
|||||||
# This can only happen if all characters are 0xff
|
# This can only happen if all characters are 0xff
|
||||||
bs = bytes([1]) + bs
|
bs = bytes([1]) + bs
|
||||||
return bytes(bs)
|
return bytes(bs)
|
||||||
|
|
||||||
async def asyncio_clean_shutdown(loop=None):
|
|
||||||
while True:
|
|
||||||
pending_tasks = [task for task in asyncio.Task.all_tasks(loop)
|
|
||||||
if not task.done()]
|
|
||||||
if len(pending_tasks) <= 1:
|
|
||||||
break
|
|
||||||
await asyncio.sleep(0)
|
|
||||||
await asyncio.sleep(1)
|
|
||||||
|
|||||||
@ -133,9 +133,10 @@ class MemPool(util.LoggedClass):
|
|||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
pending = []
|
pending = []
|
||||||
txs = self.txs
|
txs = self.txs
|
||||||
|
first = True
|
||||||
|
|
||||||
async def process(unprocessed):
|
async def process(unprocessed):
|
||||||
nonlocal pending
|
nonlocal first, pending
|
||||||
|
|
||||||
raw_txs = {}
|
raw_txs = {}
|
||||||
while unprocessed and len(raw_txs) < limit:
|
while unprocessed and len(raw_txs) < limit:
|
||||||
@ -163,9 +164,12 @@ class MemPool(util.LoggedClass):
|
|||||||
hash168s[hash168].add(hex_hash)
|
hash168s[hash168].add(hex_hash)
|
||||||
|
|
||||||
to_do = len(unfetched) + len(unprocessed)
|
to_do = len(unfetched) + len(unprocessed)
|
||||||
if to_do:
|
if to_do and txs:
|
||||||
percent = (len(txs) - to_do) * 100 // len(txs)
|
percent = max(0, len(txs) - to_do) * 100 // len(txs)
|
||||||
self.logger.info('catchup {:d}% complete'.format(percent))
|
self.logger.info('catchup {:d}% complete'.format(percent))
|
||||||
|
elif first:
|
||||||
|
first = False
|
||||||
|
self.logger.info('caught up')
|
||||||
|
|
||||||
return process
|
return process
|
||||||
|
|
||||||
@ -257,7 +261,7 @@ class MemPool(util.LoggedClass):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
hex_hashes = self.hash168s[hash168]
|
hex_hashes = self.hash168s[hash168]
|
||||||
raw_txs = self.daemon.getrawtransactions(hex_hashes)
|
raw_txs = await self.daemon.getrawtransactions(hex_hashes)
|
||||||
result = []
|
result = []
|
||||||
for hex_hash, raw_tx in zip(hex_hashes, raw_txs):
|
for hex_hash, raw_tx in zip(hex_hashes, raw_txs):
|
||||||
item = self.txs.get(hex_hash)
|
item = self.txs.get(hex_hash)
|
||||||
|
|||||||
@ -183,7 +183,7 @@ class ServerManager(util.LoggedClass):
|
|||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
break
|
break
|
||||||
await self.shutdown()
|
await self.shutdown()
|
||||||
await util.asyncio_clean_shutdown()
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
async def start_server(self, kind, *args, **kw_args):
|
async def start_server(self, kind, *args, **kw_args):
|
||||||
protocol_class = LocalRPC if kind == 'RPC' else ElectrumX
|
protocol_class = LocalRPC if kind == 'RPC' else ElectrumX
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user