From f5a1deee31d7e6616e97db01a2d777741939b014 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 2 Mar 2022 16:24:03 +1100 Subject: [PATCH] Fix proto-array bug --- consensus/proto_array/src/proto_array.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/consensus/proto_array/src/proto_array.rs b/consensus/proto_array/src/proto_array.rs index b0e8991a785..847235e0619 100644 --- a/consensus/proto_array/src/proto_array.rs +++ b/consensus/proto_array/src/proto_array.rs @@ -395,6 +395,12 @@ impl ProtoArray { // Collect all *ancestors* which were declared invalid since they reside between the // `head_block_root` and the `latest_valid_ancestor_root`. loop { + // If there is no latest valid block then exit this loop early and don't invalidate any + // blocks. + if !latest_valid_ancestor_is_descendant { + break; + } + let node = self .nodes .get_mut(index) @@ -404,17 +410,7 @@ impl ProtoArray { ExecutionStatus::Valid(hash) | ExecutionStatus::Invalid(hash) | ExecutionStatus::Unknown(hash) => { - // If we're no longer processing the `head_block_root` and the last valid - // ancestor is unknown, exit this loop and proceed to invalidate and - // descendants of `head_block_root`/`latest_valid_ancestor_root`. - // - // In effect, this means that if an unknown hash (junk or pre-finalization) is - // supplied, don't validate any ancestors. The alternative is to invalidate - // *all* ancestors, which would likely involve shutting down the client due to - // an invalid justified checkpoint. - if !latest_valid_ancestor_is_descendant && node.root != head_block_root { - break; - } else if Some(hash) == latest_valid_ancestor_hash { + if Some(hash) == latest_valid_ancestor_hash { // If the `best_child` or `best_descendant` of the latest valid hash was // invalidated, set those fields to `None`. //