mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-22 14:24:44 +00:00
Correct all fork choice rules for children with no votes.
This commit is contained in:
@@ -380,11 +380,23 @@ impl<T: ClientDB + Sized> ForkChoice for OptimizedLMDGhost<T> {
|
||||
*child_votes.entry(child).or_insert_with(|| 0) += vote;
|
||||
}
|
||||
}
|
||||
// given the votes on the children, find the best child
|
||||
current_head = self
|
||||
.choose_best_child(&child_votes)
|
||||
.ok_or(ForkChoiceError::CannotFindBestChild)?;
|
||||
trace!("Best child found: {}", current_head);
|
||||
// check if we have votes of children, if not select the smallest hash child
|
||||
if child_votes.is_empty() {
|
||||
current_head = *children
|
||||
.iter()
|
||||
.min_by(|child1, child2| child1.cmp(child2))
|
||||
.expect("Must be children here");
|
||||
trace!(
|
||||
"Children have no votes - smallest hash chosen: {}",
|
||||
current_head
|
||||
);
|
||||
} else {
|
||||
// given the votes on the children, find the best child
|
||||
current_head = self
|
||||
.choose_best_child(&child_votes)
|
||||
.ok_or(ForkChoiceError::CannotFindBestChild)?;
|
||||
trace!("Best child found: {}", current_head);
|
||||
}
|
||||
}
|
||||
|
||||
// didn't find head yet, proceed to next iteration
|
||||
|
||||
Reference in New Issue
Block a user