connector

This commit is contained in:
4tochka 2019-05-09 23:14:27 +04:00
parent 0effe6fa0f
commit 5b3bc9e5f5
3 changed files with 19 additions and 13 deletions

View File

@ -12,6 +12,8 @@ import traceback
from pybtc.connector.utils import decode_block_tx from pybtc.connector.utils import decode_block_tx
import pickle import pickle
from lru import LRU from lru import LRU
class BlockLoader: class BlockLoader:
def __init__(self, parent, workers=8): def __init__(self, parent, workers=8):
self.worker_limit = workers self.worker_limit = workers
@ -52,7 +54,7 @@ class BlockLoader:
except Exception as err: except Exception as err:
self.log.error(str(traceback.format_exc())) self.log.error(str(traceback.format_exc()))
self.log.error("watchdog error %s " % err) self.log.error("watchdog error %s " % err)
await asyncio.sleep(60) await asyncio.sleep(10)
async def loading(self): async def loading(self):
@ -159,10 +161,10 @@ class BlockLoader:
continue continue
if msg_type == b'result': if msg_type == b'result':
self.worker_busy[index] = False
blocks = pickle.loads(msg) blocks = pickle.loads(msg)
for i in blocks: for i in blocks:
self.parent.block_preload.set(i, blocks[i]) self.parent.block_preload.set(i, blocks[i])
self.worker_busy[index] = False
# def disconnect(self,ip): # def disconnect(self,ip):

View File

@ -441,8 +441,6 @@ class Connector:
self.log.error(str(traceback.format_exc())) self.log.error(str(traceback.format_exc()))
self.log.error("block error %s" % str(err)) self.log.error("block error %s" % str(err))
finally: finally:
self.active_block.set_result(True)
# self.log.debug("%s block [%s tx/ %s size] processing time %s cache [%s/%s]" % # self.log.debug("%s block [%s tx/ %s size] processing time %s cache [%s/%s]" %
# (block["height"], # (block["height"],
# len(block["tx"]), # len(block["tx"]),
@ -454,6 +452,7 @@ class Connector:
self.get_next_block_mutex = True self.get_next_block_mutex = True
self.loop.create_task(self.get_next_block()) self.loop.create_task(self.get_next_block())
self.blocks_processing_time += time.time() - tq self.blocks_processing_time += time.time() - tq
self.active_block.set_result(True)
async def fetch_block_transactions(self, block, tx_bin_list): async def fetch_block_transactions(self, block, tx_bin_list):
q = time.time() q = time.time()

View File

@ -43,18 +43,23 @@ class UTXO():
del self.cached[outpoint] del self.cached[outpoint]
def destroy_utxo(self, block_height): def destroy_utxo(self, block_height):
block_height -= self.maturity
while self.destroyed: while self.destroyed:
outpoint = self.destroyed.pop() r = self.destroyed.pop()
try: if r[1] > block_height:
del self.cached[outpoint] self.destroyed.appendleft(r)
self.destroyed_utxo += 1 break
except: else:
try: try:
del self.loaded[outpoint] del self.cached[r[0]]
self.destroyed_utxo += 1 self.destroyed_utxo += 1
except: except:
self.destroyed_utxo += 1 try:
pass del self.loaded[r[0]]
self.destroyed_utxo += 1
except:
self.destroyed_utxo += 1
pass
return return
@ -148,7 +153,7 @@ class UTXO():
self._requests += 1 self._requests += 1
try: try:
i = self.cached[key] i = self.cached[key]
self.destroyed.append(key) self.destroyed.append((key, block_height))
# try: # try:
# self.destroyed[block_height].add(key) # self.destroyed[block_height].add(key)
# except: # except: