mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-19 22:08:30 +00:00
Add fork choice bug fixes.
- Further bug fixes from testing. - Simplify the testing framework. - Add tests for longest chain and GHOST vs bitwise GHOST.
This commit is contained in:
@@ -203,13 +203,22 @@ where
|
||||
}
|
||||
let mut bitmask: BitVec = BitVec::new();
|
||||
// loop through bytes then bits
|
||||
for bit in 0..256 {
|
||||
for bit in 0..=256 {
|
||||
let mut zero_votes = 0;
|
||||
let mut one_votes = 0;
|
||||
let mut single_candidate = None;
|
||||
let mut single_candidate = (None, false);
|
||||
|
||||
trace!("FORKCHOICE: Child vote length: {}", votes.len());
|
||||
for (candidate, votes) in votes.iter() {
|
||||
let candidate_bit: BitVec = BitVec::from_bytes(&candidate);
|
||||
/*
|
||||
trace!(
|
||||
"FORKCHOICE: Child: {} in bits: {:?}",
|
||||
candidate,
|
||||
candidate_bit
|
||||
);
|
||||
trace!("FORKCHOICE: Current bitmask: {:?}", bitmask);
|
||||
*/
|
||||
|
||||
// if the bitmasks don't match
|
||||
if !bitmask.iter().eq(candidate_bit.iter().take(bit)) {
|
||||
@@ -227,15 +236,16 @@ where
|
||||
one_votes += votes;
|
||||
}
|
||||
|
||||
if single_candidate.is_none() {
|
||||
single_candidate = Some(candidate);
|
||||
if single_candidate.0.is_none() {
|
||||
single_candidate.0 = Some(candidate);
|
||||
single_candidate.1 = true;
|
||||
} else {
|
||||
single_candidate = None;
|
||||
single_candidate.1 = false;
|
||||
}
|
||||
}
|
||||
bitmask.push(one_votes > zero_votes);
|
||||
if let Some(candidate) = single_candidate {
|
||||
return Some(*candidate);
|
||||
if single_candidate.1 {
|
||||
return Some(*single_candidate.0.expect("Cannot reach this"));
|
||||
}
|
||||
}
|
||||
// should never reach here
|
||||
|
||||
@@ -192,7 +192,7 @@ impl<T: ClientDB + Sized> ForkChoice for SlowLMDGhost<T> {
|
||||
|
||||
let latest_votes = self.get_latest_votes(&start_state_root, start.slot(), spec)?;
|
||||
|
||||
let mut head_hash = Hash256::zero();
|
||||
let mut head_hash = *justified_block_start;
|
||||
|
||||
loop {
|
||||
debug!("FORKCHOICE: Iteration for block: {}", head_hash);
|
||||
|
||||
Reference in New Issue
Block a user