Address majority of Michael's comments

This commit is contained in:
Paul Hauner
2020-01-29 13:18:20 +11:00
parent 023ce333a1
commit e1c32e1489
4 changed files with 10 additions and 11 deletions

View File

@@ -65,7 +65,7 @@ impl<T: BeaconChainTypes> ForkChoice<T> {
Self { Self {
backend, backend,
genesis_block_root, genesis_block_root,
checkpoint_manager: RwLock::new(CheckpointManager::new(genesis_checkpoint.clone())), checkpoint_manager: RwLock::new(CheckpointManager::new(genesis_checkpoint)),
_phantom: PhantomData, _phantom: PhantomData,
} }
} }

View File

@@ -248,10 +248,9 @@ impl CheckpointManager {
finalized: state.finalized_checkpoint.clone(), finalized: state.finalized_checkpoint.clone(),
}; };
// From the given state, read the block root at first slot of // Using the given `state`, determine its ancestor at the slot of our current justified
// `self.justified_checkpoint.epoch`. If that root matches, then // epoch. Later, this will be compared to the root of the current justified checkpoint
// `new_justified_checkpoint` is a descendant of `self.justified_checkpoint` and we may // to determine if this state is descendant of our current justified state.
// proceed (see next `if` statement).
let new_checkpoint_ancestor = Self::get_block_root_at_slot( let new_checkpoint_ancestor = Self::get_block_root_at_slot(
state, state,
chain, chain,

View File

@@ -34,12 +34,12 @@ impl ProtoArray {
/// the best-child of each parent. /// the best-child of each parent.
/// ///
/// The structure of the `self.nodes` array ensures that the child of each node is always /// The structure of the `self.nodes` array ensures that the child of each node is always
/// touched before it's parent. /// touched before its parent.
/// ///
/// For each node, the following is done: /// For each node, the following is done:
/// ///
/// - Update the nodes weight with the corresponding delta. /// - Update the node's weight with the corresponding delta.
/// - Back-propgrate each nodes delta to its parents delta. /// - Back-propagate each node's delta to its parents delta.
/// - Compare the current node with the parents best-child, updating it if the current node /// - Compare the current node with the parents best-child, updating it if the current node
/// should become the best child. /// should become the best child.
/// - If required, update the parents best-descendant with the current node or its best-descendant. /// - If required, update the parents best-descendant with the current node or its best-descendant.
@@ -63,7 +63,7 @@ impl ProtoArray {
// Iterate backwards through all indices in `self.nodes`. // Iterate backwards through all indices in `self.nodes`.
for node_index in (0..self.nodes.len()).rev() { for node_index in (0..self.nodes.len()).rev() {
let node = &mut self let node = self
.nodes .nodes
.get_mut(node_index) .get_mut(node_index)
.ok_or_else(|| Error::InvalidNodeIndex(node_index))?; .ok_or_else(|| Error::InvalidNodeIndex(node_index))?;
@@ -108,7 +108,7 @@ impl ProtoArray {
.get_mut(parent_index) .get_mut(parent_index)
.ok_or_else(|| Error::InvalidParentDelta(parent_index))?; .ok_or_else(|| Error::InvalidParentDelta(parent_index))?;
// Back-propogate the nodes delta to its parent. // Back-propagate the nodes delta to its parent.
*parent_delta += node_delta; *parent_delta += node_delta;
self.maybe_update_best_child_and_descendant(parent_index, node_index)?; self.maybe_update_best_child_and_descendant(parent_index, node_index)?;

View File

@@ -261,7 +261,7 @@ fn compute_deltas(
// of our tree (i.e., pre-finalization) and therefore not interesting. // of our tree (i.e., pre-finalization) and therefore not interesting.
if let Some(current_delta_index) = indices.get(&vote.current_root).copied() { if let Some(current_delta_index) = indices.get(&vote.current_root).copied() {
let delta = deltas let delta = deltas
.get_mut(current_delta_index) .get(current_delta_index)
.ok_or_else(|| Error::InvalidNodeDelta(current_delta_index))? .ok_or_else(|| Error::InvalidNodeDelta(current_delta_index))?
.checked_sub(old_balance as i64) .checked_sub(old_balance as i64)
.ok_or_else(|| Error::DeltaOverflow(current_delta_index))?; .ok_or_else(|| Error::DeltaOverflow(current_delta_index))?;