From 9614b4667c11e766605655a2390ba68dcd50da94 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Mon, 5 Jun 2023 20:13:54 -0400 Subject: [PATCH] fix: mark downloaded block as invalid if insertion fails (#3003) --- crates/consensus/beacon/src/engine/mod.rs | 4 ++++ crates/interfaces/src/blockchain_tree/error.rs | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/crates/consensus/beacon/src/engine/mod.rs b/crates/consensus/beacon/src/engine/mod.rs index a394d91af03a..7d6333e2169a 100644 --- a/crates/consensus/beacon/src/engine/mod.rs +++ b/crates/consensus/beacon/src/engine/mod.rs @@ -1009,6 +1009,10 @@ where } Err(err) => { debug!(target: "consensus::engine", ?err, "Failed to insert downloaded block"); + if !matches!(err.kind(), InsertBlockErrorKind::Internal(_)) { + // non-internal error kinds occurr if the payload is invalid + self.invalid_headers.insert(err.into_block().header); + } } } } diff --git a/crates/interfaces/src/blockchain_tree/error.rs b/crates/interfaces/src/blockchain_tree/error.rs index 2f48b91dfc0f..36012996b676 100644 --- a/crates/interfaces/src/blockchain_tree/error.rs +++ b/crates/interfaces/src/blockchain_tree/error.rs @@ -65,6 +65,12 @@ impl InsertBlockError { Self::new(block, InsertBlockErrorKind::Execution(error)) } + /// Consumes the error and returns the block that resulted in the error + #[inline] + pub fn into_block(self) -> SealedBlock { + self.inner.block + } + /// Returns the error kind #[inline] pub fn kind(&self) -> &InsertBlockErrorKind {