From 36ffe24b60d0706e54adc95974c1238368b2a8d6 Mon Sep 17 00:00:00 2001 From: yudetamago Date: Mon, 8 Apr 2019 11:12:40 +0900 Subject: [PATCH] Fix LMD ghost tie-breaking --- cbc_casper_simulator/estimator/lmd_ghost_estimator.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cbc_casper_simulator/estimator/lmd_ghost_estimator.py b/cbc_casper_simulator/estimator/lmd_ghost_estimator.py index 2611fe6..725c4df 100644 --- a/cbc_casper_simulator/estimator/lmd_ghost_estimator.py +++ b/cbc_casper_simulator/estimator/lmd_ghost_estimator.py @@ -12,9 +12,11 @@ def estimate(cls, state: State, justification: Justification) -> Block: store: Store = state.store best_block = store.genesis_block() + while store.has_children_blocks(best_block): + # If "tie" exists, choose the block with the smallest hash. best_block = max(store.children_blocks( - best_block), key=lambda x: scores.get(x, 0)) + best_block), key=lambda block: (scores.get(block, 0), -block.hash)) return Block(best_block.hash) @classmethod