connector

This commit is contained in:
4tochka 2019-06-02 13:19:51 +04:00
parent 6da23ff7f3
commit acd1fb0277

View File

@ -373,13 +373,9 @@ class Connector:
if not self.active_block.done(): return if not self.active_block.done(): return
try: try:
self.active_block = asyncio.Future() self.active_block = asyncio.Future()
self.cache_loading = True if self.last_block_height < self.app_block_height_on_start else False self.cache_loading = True if self.last_block_height < self.app_block_height_on_start else False
if not self.deep_synchronization: if not self.deep_synchronization:
if not self.block_batch_handler: if not self.block_batch_handler:
tx_bin_list = [block["rawTx"][i]["txId"] for i in block["rawTx"]] tx_bin_list = [block["rawTx"][i]["txId"] for i in block["rawTx"]]
@ -434,56 +430,53 @@ class Connector:
self.log.warning("Blocks %s; tx rate: %s;" % (block["height"], tx_rate)) self.log.warning("Blocks %s; tx rate: %s;" % (block["height"], tx_rate))
if self.utxo_data: if self.utxo_data:
loading = "Loading ... " if self.cache_loading else "" loading = "Loading ... " if self.cache_loading else ""
self.log.debug(loading + "UTXO %s; hit rate: %s;" % (self.utxo.len(),
round(self.utxo.hit_rate(), 4)))
self.log.debug("Blocks downloaded %s; decoded %s" % (round(self.blocks_download_time, 4),
round(self.blocks_decode_time, 4)))
if self.deep_synchronization: if self.deep_synchronization:
self.log.debug("Blocks: not cached %s; " self.log.debug("-Blocks--------------------------------------------------------------------")
"cache count %s; " self.log.debug("Blocks downloaded %s s; decoded %s s" % (int(self.blocks_download_time),
int(self.blocks_decode_time)))
self.log.debug("Blocks not cached %s; "
"blocks cached %s; "
"cache size %s M;" % (self.non_cached_blocks, "cache size %s M;" % (self.non_cached_blocks,
self.block_preload.len(), self.block_preload.len(),
round(self.block_preload._store_size / 1024 / 1024, 2))) round(self.block_preload._store_size / 1024 / 1024, 2)))
if self.block_preload._store: self.log.debug("Cache first block %s; "
self.log.debug( "cache last block %s;" % (next(iter(self.block_preload._store)),
"cache first block %s; " next(reversed(self.block_preload._store))))
"cache last block %s;" % ( self.log.debug("Preload coins cache -> %s:%s [%s] "
next(iter(self.block_preload._store)), "preload cache efficiency %s ;" % (self.preload_cached,
next(reversed(self.block_preload._store)))) self.preload_cached_annihilated,
self.preload_cached_total,
round(self.preload_cached_total
/ self.destroyed_coins, 4)))
self.log.debug("utxo checkpoint block %s; " self.log.debug("-UTXO---------------------------------------------------------------------")
"saved utxo %s; " if loading: self.log.debug(loading)
"deleted utxo %s; "
"loaded utxo %s; "% (self.utxo.last_saved_block, self.log.debug("Cache count %s; hit rate: %s;" % (self.utxo.len(),
self.utxo.saved_utxo, round(self.utxo.hit_rate(), 4)))
self.utxo.deleted_utxo, self.log.debug("Checkpoint block %s; saved to db %s; "
self.utxo.loaded_utxo "deleted from db %s; "
)) "loaded utxo from db %s; "% (self.utxo.last_saved_block,
self.log.debug("Preload coins cache -> %s:%s [%s] " self.utxo.saved_utxo,
"preload cache effectivity %s ;" % (self.preload_cached, self.utxo.deleted_utxo,
self.preload_cached_annihilated, self.utxo.loaded_utxo))
self.preload_cached_total, self.log.debug("-Coins--------------------------------------------------------------------")
round(self.preload_cached_total
/ self.destroyed_coins, 4)))
self.log.debug("Coins %s; destroyed %s; " self.log.debug("Coins %s; destroyed %s; "
"unspent %s; op_return %s;" % (self.coins, "unspent %s; op_return %s;" % (self.coins,
self.destroyed_coins, self.destroyed_coins,
self.coins - self.destroyed_coins, self.coins - self.destroyed_coins,
self.op_return)) self.op_return))
self.log.debug("Coins destroyed in cache %s; " self.log.debug("Coins destroyed in cache %s; "
"cache effectivity %s;" % (self.destroyed_coins - self.utxo.deleted_utxo - self.preload_cached_annihilated, "cache efficiency %s [%s];" % (self.utxo._hit,
round((self.destroyed_coins - self.utxo.deleted_utxo - self.preload_cached_annihilated) round( self.utxo._hit / self.destroyed_coins, 4),
/ self.destroyed_coins, 4))) round((self.utxo._hit + self.preload_cached_annihilated)
/ self.destroyed_coins, 4)))
self.log.debug("total tx fetch time %s;" % self.total_received_tx_time)
self.log.debug("total blocks processing time %s;" % self.blocks_processing_time)
t = int(time.time() - self.start_time) t = int(time.time() - self.start_time)
h = t // 3600 h, m, s = t // 3600, (t % 3600 ) // 60, (t % 3600) % 60
m = (t % 3600 ) // 60
s = (t % 3600) % 60
self.log.info("Total time %s:%s:%s;" % (h,m,s)) self.log.info("Total time %s:%s:%s;" % (h,m,s))
# after block added handler # after block added handler
if self.after_block_handler and not self.cache_loading: if self.after_block_handler and not self.cache_loading:
try: try:
@ -501,13 +494,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.log.debug("%s block [%s tx/ %s size] processing time %s cache [%s/%s]" %
# (block["height"],
# len(block["tx"]),
# block["size"] / 1000000,
# tm(bt),
# len(self.block_hashes._store),
# len(self.block_preload._store)))
if self.node_last_block > self.last_block_height: if self.node_last_block > self.last_block_height:
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())
@ -561,7 +547,6 @@ class Connector:
for i in tx["vOut"]: for i in tx["vOut"]:
if "_s_" in tx["vOut"][i]: if "_s_" in tx["vOut"][i]:
self.preload_cached_annihilated += 1
self.coins += 1 self.coins += 1
else: else:
out = tx["vOut"][i] out = tx["vOut"][i]
@ -592,17 +577,14 @@ class Connector:
try: try:
tx["vIn"][i]["coin"] = inp["_a_"] tx["vIn"][i]["coin"] = inp["_a_"]
c += 1 c += 1
self.preload_cached_total += 1 self.preload_cached_annihilated += 1
except: except:
try: try:
tx["vIn"][i]["coin"] = inp["_c_"] tx["vIn"][i]["coin"] = inp["_c_"]
c += 1 c += 1
self.preload_cached_total += 1 self.preload_cached_total += 1
self.preload_cached += 1 self.preload_cached += 1
try: self.utxo.get(outpoint)
self.utxo.get(outpoint)
except:
self.utxo.deleted.add(outpoint)
except: except:
r = self.utxo.get(outpoint) r = self.utxo.get(outpoint)
if r: if r: