From 3b8a584c550fc7788806e04e7a7e76a9dfb07796 Mon Sep 17 00:00:00 2001 From: Grant Wuerker Date: Sun, 21 Jul 2019 22:53:39 +0200 Subject: [PATCH] Expanded fork choice api to provide latest validator message. --- eth2/lmd_ghost/src/lib.rs | 3 +++ eth2/lmd_ghost/src/reduced_tree.rs | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/eth2/lmd_ghost/src/lib.rs b/eth2/lmd_ghost/src/lib.rs index dd413e2eb..f18b5b81f 100644 --- a/eth2/lmd_ghost/src/lib.rs +++ b/eth2/lmd_ghost/src/lib.rs @@ -43,4 +43,7 @@ pub trait LmdGhost: Send + Sync { finalized_block: &BeaconBlock, finalized_block_root: Hash256, ) -> Result<()>; + + /// Returns the latest message for a given validator index. + fn latest_message(&mut self, validator_index: usize) -> Option<(Hash256, Slot)>; } diff --git a/eth2/lmd_ghost/src/reduced_tree.rs b/eth2/lmd_ghost/src/reduced_tree.rs index dace2bda6..f069ae68c 100644 --- a/eth2/lmd_ghost/src/reduced_tree.rs +++ b/eth2/lmd_ghost/src/reduced_tree.rs @@ -87,6 +87,12 @@ where .update_root(new_block.slot, new_root) .map_err(|e| format!("update_finalized_root failed: {:?}", e)) } + + fn latest_message(&mut self, validator_index: usize) -> Option<(Hash256, Slot)> { + self.core + .write() + .latest_message(validator_index) + } } struct ReducedTree { @@ -222,6 +228,13 @@ where Ok(head_node.block_hash) } + pub fn latest_message(&mut self, validator_index: usize) -> Option<(Hash256, Slot)> { + match self.latest_votes.get(validator_index) { + Some(v) => Some((v.hash.clone(), v.slot.clone())), + None => None + } + } + fn find_head_from<'a>(&'a self, start_node: &'a Node) -> Result<&'a Node> { if start_node.does_not_have_children() { Ok(start_node)