From 8a10979db09b854af41e2e6f1dc99fc498ed7707 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Fri, 8 Nov 2019 14:23:06 +0000 Subject: [PATCH] Refactors Responder and BlockProcessor Brings check_confirmations back to the Responder --- pisa/block_processor.py | 22 ---------------------- pisa/responder.py | 24 +++++++++++++++++++++--- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/pisa/block_processor.py b/pisa/block_processor.py index e3a2bc6..c44ead1 100644 --- a/pisa/block_processor.py +++ b/pisa/block_processor.py @@ -80,25 +80,3 @@ class BlockProcessor: distance = chain_tip_height - target_block_height return distance - - # DISCUSS: This method comes from the Responder and seems like it could go back there. - @staticmethod - # NOTCOVERED - def check_confirmations(txs, unconfirmed_txs, tx_job_map, missed_confirmations): - - for tx in txs: - if tx in tx_job_map and tx in unconfirmed_txs: - unconfirmed_txs.remove(tx) - - logger.info("Confirmation received for transaction", tx=tx) - - elif tx in unconfirmed_txs: - if tx in missed_confirmations: - missed_confirmations[tx] += 1 - - else: - missed_confirmations[tx] = 1 - - logger.info("Transaction missed a confirmation", tx=tx, missed_confirmations=missed_confirmations[tx]) - - return unconfirmed_txs, missed_confirmations diff --git a/pisa/responder.py b/pisa/responder.py index 4452a48..ecd516b 100644 --- a/pisa/responder.py +++ b/pisa/responder.py @@ -153,9 +153,7 @@ class Responder: # ToDo: #9-add-data-persistence if prev_block_hash == block.get("previousblockhash"): - self.unconfirmed_txs, self.missed_confirmations = BlockProcessor.check_confirmations( - txs, self.unconfirmed_txs, self.tx_job_map, self.missed_confirmations - ) + self.check_confirmations(txs) txs_to_rebroadcast = self.get_txs_to_rebroadcast(txs) completed_jobs = self.get_completed_jobs(height) @@ -186,6 +184,26 @@ class Responder: logger.info("No more pending jobs, going back to sleep") + # NOTCOVERED + def check_confirmations(self, txs): + + for tx in txs: + if tx in self.tx_job_map and tx in self.unconfirmed_txs: + self.unconfirmed_txs.remove(tx) + + logger.info("Confirmation received for transaction", tx=tx) + + elif tx in self.unconfirmed_txs: + if tx in self.missed_confirmations: + self.missed_confirmations[tx] += 1 + + else: + self.missed_confirmations[tx] = 1 + + logger.info( + "Transaction missed a confirmation", tx=tx, missed_confirmations=self.missed_confirmations[tx] + ) + def get_txs_to_rebroadcast(self, txs): txs_to_rebroadcast = []