From 0d4b58978ccd5423f8026a8436215c14279abff4 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sat, 10 Aug 2019 17:19:27 +1000 Subject: [PATCH] Make fork choice write lock in to read lock --- eth2/lmd_ghost/src/reduced_tree.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/eth2/lmd_ghost/src/reduced_tree.rs b/eth2/lmd_ghost/src/reduced_tree.rs index 9668620b79..822c388f6a 100644 --- a/eth2/lmd_ghost/src/reduced_tree.rs +++ b/eth2/lmd_ghost/src/reduced_tree.rs @@ -111,7 +111,7 @@ where } fn latest_message(&self, validator_index: usize) -> Option<(Hash256, Slot)> { - self.core.write().latest_message(validator_index) + self.core.read().latest_message(validator_index) } } @@ -258,10 +258,10 @@ 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, + pub fn latest_message(&self, validator_index: usize) -> Option<(Hash256, Slot)> { + match self.latest_votes.get_ref(validator_index) { + Some(Some(v)) => Some((v.hash.clone(), v.slot.clone())), + _ => None, } } @@ -776,6 +776,14 @@ where &self.0[i] } + pub fn get_ref(&self, i: usize) -> Option<&T> { + if i < self.0.len() { + Some(&self.0[i]) + } else { + None + } + } + pub fn insert(&mut self, i: usize, element: T) { self.ensure(i); self.0[i] = element;