From 9da97cc4c3db252ca43ca51bed6cc2b614e765f8 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 24 May 2023 17:33:14 +0200 Subject: [PATCH] fix: check if payload is transition payload (#2816) --- crates/consensus/beacon/src/engine/mod.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/consensus/beacon/src/engine/mod.rs b/crates/consensus/beacon/src/engine/mod.rs index 2c3c5003f9..075648ad38 100644 --- a/crates/consensus/beacon/src/engine/mod.rs +++ b/crates/consensus/beacon/src/engine/mod.rs @@ -290,9 +290,20 @@ where // 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() { + // parent is in side-chain: validated but not canonical yet Some(parent_hash) } else { - self.blockchain.find_canonical_ancestor(parent_hash) + let parent_hash = self.blockchain.find_canonical_ancestor(parent_hash)?; + let parent_header = self.blockchain.header(&parent_hash).ok().flatten()?; + + // we need to check if the parent block is the last POW block, if so then the payload is + // the first POS. The engine API spec mandates a zero hash to be returned: + if parent_header.difficulty != U256::ZERO { + return Some(H256::zero()) + } + + // parent is canonical POS block + Some(parent_hash) } }