From 5bf96a10c5c6d37c86f0454d9fa52927774494eb Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Fri, 25 Oct 2019 20:28:14 +0100 Subject: [PATCH] Adds method to compute distance from given block to chain tip --- pisa/block_processor.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pisa/block_processor.py b/pisa/block_processor.py index 26f16c1..5e63ce5 100644 --- a/pisa/block_processor.py +++ b/pisa/block_processor.py @@ -45,6 +45,21 @@ class BlockProcessor: return block_count + def get_distance_to_tip(self, target_block_hash): + distance = None + + chain_tip = self.get_best_block_hash() + chain_tip_height = self.get_block(chain_tip).get("height") + + target_block = self.get_block(target_block_hash).get("height") + + if target_block is not None: + target_block_height = target_block.get("height") + + distance = chain_tip_height - target_block_height + + return distance + # FIXME: The following two functions does not seem to belong here. They come from the Watcher, and need to be # separated since they will be reused by the TimeTraveller. # DISCUSS: 36-who-should-check-appointment-trigger