Changed log format to JSON; fixed missing return value in get_potential_matches

This commit is contained in:
Salvatore Ingala
2019-10-08 16:32:09 +07:00
parent 1b229cb441
commit ed0cb4f632
11 changed files with 87 additions and 85 deletions

View File

@@ -3,9 +3,9 @@ from threading import Thread
from hashlib import sha256
from binascii import unhexlify
from pisa import logging, M
from pisa.cleaner import Cleaner
from pisa.carrier import Carrier
from pisa import logging
from pisa.tools import check_tx_in_chain
from pisa.block_processor import BlockProcessor
from pisa.utils.zmq_subscriber import ZMQHandler
@@ -45,7 +45,7 @@ class Responder:
def add_response(self, uuid, dispute_txid, justice_txid, justice_rawtx, appointment_end, retry=False):
if self.asleep:
logging.info("[Responder] waking up!")
logging.info(M("[Responder] waking up!"))
carrier = Carrier()
receipt = carrier.send_transaction(justice_rawtx, justice_txid)
@@ -80,8 +80,7 @@ class Responder:
if confirmations == 0:
self.unconfirmed_txs.append(justice_txid)
logging.info('[Responder] new job added (dispute txid = {}, justice txid = {}, appointment end = {})'
.format(dispute_txid, justice_txid, appointment_end))
logging.info(M("[Responder] new job added.", dispute_txid=dispute_txid, justice_txid=justice_txid, appointment_end=appointment_end))
if self.asleep:
self.asleep = False
@@ -109,9 +108,7 @@ class Responder:
txs = block.get('tx')
height = block.get('height')
logging.info("[Responder] new block received {}".format(block_hash))
logging.info("[Responder] prev. block hash {}".format(block.get('previousblockhash')))
logging.info("[Responder] list of transactions: {}".format(txs))
logging.info(M("[Responder] new block received", block_hash=block_hash, prev_block_hash=block.get('previousblockhash'), txs=txs))
# ToDo: #9-add-data-persistence
# change prev_block_hash condition
@@ -125,8 +122,8 @@ class Responder:
self.rebroadcast(txs_to_rebroadcast)
else:
logging.warning("[Responder] reorg found! local prev. block id = {}, remote prev. block id = {}"
.format(prev_block_hash, block.get('previousblockhash')))
logging.warning(M("[Responder] reorg found!",
local_prev_block_hash=prev_block_hash, remote_prev_block_hash=block.get('previousblockhash')))
self.handle_reorgs()
@@ -136,7 +133,7 @@ class Responder:
self.asleep = True
self.zmq_subscriber.terminate = True
logging.info("[Responder] no more pending jobs, going back to sleep")
logging.info(M("[Responder] no more pending jobs, going back to sleep"))
def get_txs_to_rebroadcast(self, txs):
txs_to_rebroadcast = []
@@ -172,8 +169,8 @@ class Responder:
self.add_response(uuid, self.jobs[uuid].dispute_txid, self.jobs[uuid].justice_txid,
self.jobs[uuid].justice_rawtx, self.jobs[uuid].appointment_end, retry=True)
logging.warning("[Responder] tx {} has missed {} confirmations. Rebroadcasting"
.format(self.jobs[uuid].justice_txid, CONFIRMATIONS_BEFORE_RETRY))
logging.warning(M("[Responder] Transaction has missed many confirmations. Rebroadcasting.",
justice_txid=self.jobs[uuid].justice_txid, confirmations_missed=CONFIRMATIONS_BEFORE_RETRY))
# FIXME: Legacy code, must be checked and updated/fixed
def handle_reorgs(self):
@@ -189,8 +186,8 @@ class Responder:
# If both transactions are there, we only need to update the justice tx confirmation count
if justice_in_chain:
logging.info("[Responder] updating confirmation count for {}: prev. {}, current {}".format(
job.justice_txid, job.confirmations, justice_confirmations))
logging.info(M("[Responder] updating confirmation count for transaction.",
justice_txid=job.justice_txid, prev_count=job.confirmations, curr_count=justice_confirmations))
job.confirmations = justice_confirmations
@@ -203,7 +200,7 @@ class Responder:
else:
# ToDo: #24-properly-handle-reorgs
# FIXME: if the dispute is not on chain (either in mempool or not there al all), we need to call the
# FIXME: if the dispute is not on chain (either in mempool or not there at all), we need to call the
# reorg manager
logging.warning("[Responder] dispute and justice transaction missing. Calling the reorg manager")
logging.error("[Responder] reorg manager not yet implemented")
logging.warning(M("[Responder] dispute and justice transaction missing. Calling the reorg manager"))
logging.error(M("[Responder] reorg manager not yet implemented"))