Adds method to compute distance from given block to chain tip

This commit is contained in:
Sergi Delgado Segura
2019-10-25 20:28:14 +01:00
parent 162de92026
commit 5bf96a10c5

View File

@@ -45,6 +45,21 @@ class BlockProcessor:
return block_count 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 # 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. # separated since they will be reused by the TimeTraveller.
# DISCUSS: 36-who-should-check-appointment-trigger # DISCUSS: 36-who-should-check-appointment-trigger