From 65b7702efec6735d39f5e4a5cf8092629f4f80ea Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 18 May 2023 05:03:51 -0400 Subject: [PATCH] fix: return latestValidHash from sidechains (#2725) --- crates/consensus/beacon/src/engine/mod.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/consensus/beacon/src/engine/mod.rs b/crates/consensus/beacon/src/engine/mod.rs index d82668d97d..ec39970212 100644 --- a/crates/consensus/beacon/src/engine/mod.rs +++ b/crates/consensus/beacon/src/engine/mod.rs @@ -276,11 +276,13 @@ where return Some(H256::zero()) } - // TODO(mattsse): This could be invoked on new payload which does not make tree canonical, - // which would make this inaccurate, e.g. if an invalid payload is received in this - // scenario: FUC (unknown head) -> valid payload -> invalid payload - - self.blockchain.find_canonical_ancestor(parent_hash) + // If this is sent from new payload then the parent hash could be in a side chain, and is + // not necessarily canonical + if self.blockchain.header_by_hash(parent_hash).is_some() { + Some(parent_hash) + } else { + self.blockchain.find_canonical_ancestor(parent_hash) + } } /// Loads the header for the given `block_number` from the database.