Guard reduced tree from errors
This commit is contained in:
parent
ed6c39e25a
commit
6bb3a65189
@ -311,6 +311,7 @@ where
|
||||
/// become redundant and removed from the reduced tree.
|
||||
fn remove_latest_message(&mut self, validator_index: usize) -> Result<()> {
|
||||
if let Some(vote) = *self.latest_votes.get(validator_index) {
|
||||
if self.nodes.contains_key(&vote.hash) {
|
||||
self.get_mut_node(vote.hash)?.remove_voter(validator_index);
|
||||
let node = self.get_node(vote.hash)?.clone();
|
||||
|
||||
@ -357,6 +358,7 @@ where
|
||||
|
||||
self.latest_votes.insert(validator_index, Some(vote));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -370,7 +372,8 @@ where
|
||||
/// - it does not have any votes.
|
||||
fn maybe_delete_node(&mut self, hash: Hash256) -> Result<()> {
|
||||
let should_delete = {
|
||||
let node = self.get_node(hash)?.clone();
|
||||
if let Ok(node) = self.get_node(hash) {
|
||||
let node = node.clone();
|
||||
|
||||
if let Some(parent_hash) = node.parent_hash {
|
||||
if (node.children.len() == 1) && !node.has_votes() {
|
||||
@ -391,6 +394,10 @@ where
|
||||
// A node without a parent is the genesis node and should not be deleted.
|
||||
false
|
||||
}
|
||||
} else {
|
||||
// No need to delete a node that does not exist.
|
||||
false
|
||||
}
|
||||
};
|
||||
|
||||
if should_delete {
|
||||
|
Loading…
Reference in New Issue
Block a user