From 6d16e3989218eb6c27891a71d85f1eec5cedbff9 Mon Sep 17 00:00:00 2001
From: Diederik Loerakker <proto@protolambda.com>
Date: Thu, 29 Apr 2021 16:42:21 +0200
Subject: [PATCH] catalyst: check if block exists in assemble-block call with
 unknown parent-hash (#22770)

---
 eth/catalyst/api.go | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/eth/catalyst/api.go b/eth/catalyst/api.go
index d6ea691d02ff..d7e2af1c1a5d 100644
--- a/eth/catalyst/api.go
+++ b/eth/catalyst/api.go
@@ -109,6 +109,11 @@ func (api *consensusAPI) AssembleBlock(params assembleBlockParams) (*executableD
 
 	bc := api.eth.BlockChain()
 	parent := bc.GetBlockByHash(params.ParentHash)
+	if parent == nil {
+		log.Warn("Cannot assemble block with parent hash to unknown block", "parentHash", params.ParentHash)
+		return nil, fmt.Errorf("cannot assemble block with unknown parent %s", params.ParentHash)
+	}
+
 	pool := api.eth.TxPool()
 
 	if parent.Time() >= params.Timestamp {