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)