Correct all fork choice rules for children with no votes.

This commit is contained in:
Age Manning
2019-03-14 15:22:45 +11:00
parent 3112f83786
commit 086e9574d2
6 changed files with 67 additions and 12 deletions

View File

@@ -210,6 +210,7 @@ impl<T: ClientDB + Sized> ForkChoice for SlowLMDGhost<T> {
trace!("Children found: {:?}", children);
let mut head_vote_count = 0;
head_hash = children[0];
for child_hash in children {
let vote_count = self.get_vote_count(&latest_votes, &child_hash)?;
trace!("Vote count for child: {} is: {}", child_hash, vote_count);
@@ -218,6 +219,12 @@ impl<T: ClientDB + Sized> ForkChoice for SlowLMDGhost<T> {
head_hash = *child_hash;
head_vote_count = vote_count;
}
// resolve ties - choose smaller hash
else if vote_count == head_vote_count {
if *child_hash < head_hash {
head_hash = *child_hash;
}
}
}
}
Ok(head_hash)