connector
This commit is contained in:
parent
0effe6fa0f
commit
5b3bc9e5f5
@ -12,6 +12,8 @@ import traceback
|
||||
from pybtc.connector.utils import decode_block_tx
|
||||
import pickle
|
||||
from lru import LRU
|
||||
|
||||
|
||||
class BlockLoader:
|
||||
def __init__(self, parent, workers=8):
|
||||
self.worker_limit = workers
|
||||
@ -52,7 +54,7 @@ class BlockLoader:
|
||||
except Exception as err:
|
||||
self.log.error(str(traceback.format_exc()))
|
||||
self.log.error("watchdog error %s " % err)
|
||||
await asyncio.sleep(60)
|
||||
await asyncio.sleep(10)
|
||||
|
||||
|
||||
async def loading(self):
|
||||
@ -159,10 +161,10 @@ class BlockLoader:
|
||||
continue
|
||||
|
||||
if msg_type == b'result':
|
||||
self.worker_busy[index] = False
|
||||
blocks = pickle.loads(msg)
|
||||
for i in blocks:
|
||||
self.parent.block_preload.set(i, blocks[i])
|
||||
self.worker_busy[index] = False
|
||||
|
||||
|
||||
# def disconnect(self,ip):
|
||||
|
||||
@ -441,8 +441,6 @@ class Connector:
|
||||
self.log.error(str(traceback.format_exc()))
|
||||
self.log.error("block error %s" % str(err))
|
||||
finally:
|
||||
|
||||
self.active_block.set_result(True)
|
||||
# self.log.debug("%s block [%s tx/ %s size] processing time %s cache [%s/%s]" %
|
||||
# (block["height"],
|
||||
# len(block["tx"]),
|
||||
@ -454,6 +452,7 @@ class Connector:
|
||||
self.get_next_block_mutex = True
|
||||
self.loop.create_task(self.get_next_block())
|
||||
self.blocks_processing_time += time.time() - tq
|
||||
self.active_block.set_result(True)
|
||||
|
||||
async def fetch_block_transactions(self, block, tx_bin_list):
|
||||
q = time.time()
|
||||
|
||||
@ -43,18 +43,23 @@ class UTXO():
|
||||
del self.cached[outpoint]
|
||||
|
||||
def destroy_utxo(self, block_height):
|
||||
block_height -= self.maturity
|
||||
while self.destroyed:
|
||||
outpoint = self.destroyed.pop()
|
||||
try:
|
||||
del self.cached[outpoint]
|
||||
self.destroyed_utxo += 1
|
||||
except:
|
||||
r = self.destroyed.pop()
|
||||
if r[1] > block_height:
|
||||
self.destroyed.appendleft(r)
|
||||
break
|
||||
else:
|
||||
try:
|
||||
del self.loaded[outpoint]
|
||||
del self.cached[r[0]]
|
||||
self.destroyed_utxo += 1
|
||||
except:
|
||||
self.destroyed_utxo += 1
|
||||
pass
|
||||
try:
|
||||
del self.loaded[r[0]]
|
||||
self.destroyed_utxo += 1
|
||||
except:
|
||||
self.destroyed_utxo += 1
|
||||
pass
|
||||
|
||||
return
|
||||
|
||||
@ -148,7 +153,7 @@ class UTXO():
|
||||
self._requests += 1
|
||||
try:
|
||||
i = self.cached[key]
|
||||
self.destroyed.append(key)
|
||||
self.destroyed.append((key, block_height))
|
||||
# try:
|
||||
# self.destroyed[block_height].add(key)
|
||||
# except:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user