mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 01:05:47 +00:00
Add progress
This commit is contained in:
@@ -125,6 +125,7 @@ impl ProtoArray {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// back-prop best-child/target updates
|
||||||
for i in (start..d.len()).rev() {
|
for i in (start..d.len()).rev() {
|
||||||
if let Some(best_child) = self.get_best_child(i)? {
|
if let Some(best_child) = self.get_best_child(i)? {
|
||||||
// TODO: array access safety
|
// TODO: array access safety
|
||||||
@@ -144,7 +145,6 @@ impl ProtoArray {
|
|||||||
if self.weights[i] > self.weights[best_child_of_parent] {
|
if self.weights[i] > self.weights[best_child_of_parent] {
|
||||||
self.best_child[parent] = Some(i)
|
self.best_child[parent] = Some(i)
|
||||||
}
|
}
|
||||||
// Do thing
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: what is this?
|
// TODO: what is this?
|
||||||
@@ -225,23 +225,44 @@ impl ProtoArray {
|
|||||||
// TODO: safe array access.
|
// TODO: safe array access.
|
||||||
self.best_descendant[i].saturating_sub(start);
|
self.best_descendant[i].saturating_sub(start);
|
||||||
|
|
||||||
if let Some(parent) = self.parents[i] {
|
self.parents[i] = if let Some(parent) = self.parents[i] {
|
||||||
if parent < start {
|
if parent < start {
|
||||||
parent = None
|
None
|
||||||
} else {
|
} else {
|
||||||
// TODO: what happens if this becomes negative?? Safety issue.
|
Some(parent.saturating_sub(start))
|
||||||
parent -= start
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
self.indices
|
*self
|
||||||
.get_mut(n.block_root)
|
.indices
|
||||||
.ok_or_else(|| Error::NodeUnknown(n.block_root))? -= start
|
.get_mut(&node.block_root)
|
||||||
|
.ok_or_else(|| Error::NodeUnknown(node.block_root))? -= start
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn head_fn(&self) -> Result<Hash256, Error> {
|
||||||
|
let mut i = *self
|
||||||
|
.indices
|
||||||
|
.get(&self.dag.finalized)
|
||||||
|
.ok_or_else(|| Error::FinalizedNodeUnknown(self.dag.finalized))?;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
// TODO: safe array access.
|
||||||
|
if let Some(best_child) = self.best_child[i] {
|
||||||
|
i = best_child;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: safe array access.
|
||||||
|
Ok(self.nodes[i].block_root)
|
||||||
|
}
|
||||||
|
|
||||||
fn check_consistency(&self) -> Result<(), Error> {
|
fn check_consistency(&self) -> Result<(), Error> {
|
||||||
let num_nodes = self.nodes.len();
|
let num_nodes = self.nodes.len();
|
||||||
if self.best_child.len() != num_nodes {
|
if self.best_child.len() != num_nodes {
|
||||||
|
|||||||
Reference in New Issue
Block a user