From 6e02c8ca388449a6b2bf453aea8050258456ad8b Mon Sep 17 00:00:00 2001 From: 4tochka Date: Mon, 6 May 2019 12:19:05 +0400 Subject: [PATCH] connector --- pybtc/connector.py | 29 +++++++++++++---------------- setup.py | 2 +- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/pybtc/connector.py b/pybtc/connector.py index 85a5e99..b8bbef1 100644 --- a/pybtc/connector.py +++ b/pybtc/connector.py @@ -15,7 +15,7 @@ import asyncio import time import io from collections import OrderedDict -import pylru +from lru import LRU class Connector: def __init__(self, node_rpc_url, node_zerromq_url, logger, @@ -78,7 +78,6 @@ class Connector: self.non_cached_blocks = 0 self.total_received_tx_time = 0 self.start_time = time.time() - self.tmp = pylru.lrucache(1000000) # cache and system self.block_preload_cache_limit = block_preload_cache_limit @@ -357,7 +356,7 @@ class Connector: return self.active_block = asyncio.Future() - # self.log.debug("Block %s %s" % (block["height"], block["hash"])) + self.log.debug("Block %s %s" % (block["height"], block["hash"])) self.cache_loading = True if self.last_block_height < self.app_block_height_on_start else False @@ -464,7 +463,6 @@ class Connector: self.await_tx = set(tx_bin_list) self.await_tx_future = {i: asyncio.Future() for i in tx_bin_list} self.block_txs_request = asyncio.Future() - tx_count = len(block["rawTx"]) for i in block["rawTx"]: self.loop.create_task(self._new_transaction(block["rawTx"][i], block["time"], @@ -491,14 +489,13 @@ class Connector: await self.rpc.close() self.rpc = aiojsonrpc.rpc(self.rpc_url, self.loop, timeout=self.rpc_timeout) raise RuntimeError("block transaction request timeout") - tx_count = len(block["tx"]) + tx_count = len(block["tx"]) self.total_received_tx += tx_count self.total_received_tx_time += time.time() - q rate = round(self.total_received_tx/self.total_received_tx_time) self.log.debug("Transactions received: %s [%s] received tx rate tx/s ->> %s <<" % (tx_count, time.time() - q, rate)) async def verify_block_position(self, block): - return if "previousblockhash" not in block : return if self.block_headers_cache.len() == 0: @@ -748,10 +745,10 @@ class Connector: class UTXO(): def __init__(self, db_pool, loop, log, cache_size): - self.cached = pylru.lrucache(cache_size) + self.cached = LRU(cache_size) self.missed = set() - self.destroyed = pylru.lrucache(200000) - self.deleted = pylru.lrucache(200000) + self.destroyed = LRU(200000) + self.deleted = LRU(200000) self.log = log self.loaded = OrderedDict() self.maturity = 100 @@ -959,8 +956,8 @@ def decode_block_tx(block): b["strippedSize"] = 80 b["version"] = unpack("L", b["version"]).hex() - b["previousBlockHash"] = s.read(32) - b["merkleRoot"] = s.read(32) + b["previousBlockHash"] = rh2s(s.read(32)) + b["merkleRoot"] = rh2s(s.read(32)) b["time"] = unpack("