Add tests for importing blocks on invalid parents (#3123)

## Issue Addressed

NA

## Proposed Changes

- Adds more checks to prevent importing blocks atop parent with invalid execution payloads.
- Adds a test for these conditions.

## Additional Info

NA
This commit is contained in:
Paul Hauner
2022-04-05 20:58:16 +00:00
parent bac7c3fa54
commit 42cdaf5840
4 changed files with 111 additions and 16 deletions

View File

@@ -315,6 +315,21 @@ impl ProtoArray {
execution_status: block.execution_status,
};
// If the parent has an invalid execution status, return an error before adding the block to
// `self`.
if let Some(parent_index) = node.parent {
let parent = self
.nodes
.get(parent_index)
.ok_or(Error::InvalidNodeIndex(parent_index))?;
if parent.execution_status.is_invalid() {
return Err(Error::ParentExecutionStatusIsInvalid {
block_root: block.root,
parent_root: parent.root,
});
}
}
self.indices.insert(node.root, node_index);
self.nodes.push(node.clone());