Expanded fork choice api to provide latest validator message.

This commit is contained in:
Grant Wuerker 2019-07-21 22:53:39 +02:00
parent bef7ca6bfb
commit 3b8a584c55
No known key found for this signature in database
GPG Key ID: F7EA56FDDA6C464F
2 changed files with 16 additions and 0 deletions

View File

@ -43,4 +43,7 @@ pub trait LmdGhost<S: Store, E: EthSpec>: 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)>;
}

View File

@ -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<T, E> {
@ -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)