Fix bug in reduced tree fork choice
This commit is contained in:
parent
0b2ad4d0a1
commit
7a4c3e26ac
@ -284,16 +284,11 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_finalize() {
|
fn can_finalize() {
|
||||||
let num_blocks_produced = MinimalEthSpec::slots_per_epoch() * 1 + 2;
|
let num_blocks_produced = MinimalEthSpec::slots_per_epoch() * 5;
|
||||||
|
|
||||||
let harness = get_harness(VALIDATOR_COUNT);
|
let harness = get_harness(VALIDATOR_COUNT);
|
||||||
|
|
||||||
harness.extend_chain(BuildStrategy::OnCanonicalHead, num_blocks_produced as usize);
|
harness.extend_chain(BuildStrategy::OnCanonicalHead, num_blocks_produced as usize);
|
||||||
/*
|
|
||||||
for _ in 0..num_blocks_produced {
|
|
||||||
harness.extend_chain(BuildStrategy::OnCanonicalHead);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
let state = &harness.chain.head().beacon_state;
|
let state = &harness.chain.head().beacon_state;
|
||||||
|
|
||||||
@ -316,7 +311,5 @@ mod test {
|
|||||||
state.current_epoch() - 2,
|
state.current_epoch() - 2,
|
||||||
"the head should be finalized two behind the current epoch"
|
"the head should be finalized two behind the current epoch"
|
||||||
);
|
);
|
||||||
|
|
||||||
panic!();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/// An implementation of "reduced tree" LMD GHOST fork choice.
|
//! An implementation of "reduced tree" LMD GHOST fork choice.
|
||||||
///
|
//!
|
||||||
/// This algorithm was concieved at IC3 Cornell, 2019.
|
//! This algorithm was concieved at IC3 Cornell, 2019.
|
||||||
///
|
//!
|
||||||
/// This implementation is incomplete and has known bugs.
|
//! This implementation is incomplete and has known bugs. Do not use in production.
|
||||||
use super::{LmdGhost, Result as SuperResult};
|
use super::{LmdGhost, Result as SuperResult};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@ -406,6 +406,8 @@ where
|
|||||||
let mut added_new_ancestor = false;
|
let mut added_new_ancestor = false;
|
||||||
|
|
||||||
if !prev_in_tree.children.is_empty() {
|
if !prev_in_tree.children.is_empty() {
|
||||||
|
let mut added = false;
|
||||||
|
|
||||||
for &child_hash in &prev_in_tree.children {
|
for &child_hash in &prev_in_tree.children {
|
||||||
if self
|
if self
|
||||||
.iter_ancestors(child_hash)?
|
.iter_ancestors(child_hash)?
|
||||||
@ -417,14 +419,16 @@ where
|
|||||||
node.children.push(child_hash);
|
node.children.push(child_hash);
|
||||||
prev_in_tree.replace_child(child_hash, node.block_hash)?;
|
prev_in_tree.replace_child(child_hash, node.block_hash)?;
|
||||||
|
|
||||||
added_new_ancestor = true;
|
added = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !added {
|
||||||
for &child_hash in &prev_in_tree.children {
|
for &child_hash in &prev_in_tree.children {
|
||||||
let ancestor_hash = self.find_least_common_ancestor(node.block_hash, child_hash)?;
|
let ancestor_hash =
|
||||||
|
self.find_least_common_ancestor(node.block_hash, child_hash)?;
|
||||||
|
|
||||||
if ancestor_hash != prev_in_tree.block_hash {
|
if ancestor_hash != prev_in_tree.block_hash {
|
||||||
let child = self.get_mut_node(child_hash)?;
|
let child = self.get_mut_node(child_hash)?;
|
||||||
@ -448,6 +452,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !added_new_ancestor {
|
if !added_new_ancestor {
|
||||||
node.parent_hash = Some(prev_in_tree.block_hash);
|
node.parent_hash = Some(prev_in_tree.block_hash);
|
||||||
|
Loading…
Reference in New Issue
Block a user