From 494374979943e8e0f139d7aeaf48307c228cad2e Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 1 Jun 2022 20:15:38 +0200 Subject: [PATCH] eth/catalyst: return 0x0 on Invalid block on top of pow block --- eth/catalyst/api.go | 7 ++++++- eth/catalyst/api_test.go | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/eth/catalyst/api.go b/eth/catalyst/api.go index 5702726ee6b56..4ed5093d831c5 100644 --- a/eth/catalyst/api.go +++ b/eth/catalyst/api.go @@ -354,7 +354,12 @@ func computePayloadId(headBlockHash common.Hash, params *beacon.PayloadAttribute func (api *ConsensusAPI) invalid(err error, latestValid *types.Block) beacon.PayloadStatusV1 { currentHash := api.eth.BlockChain().CurrentBlock().Hash() if latestValid != nil { - currentHash = latestValid.Hash() + // Set latest valid hash to 0x0 if parent is PoW block + currentHash = common.Hash{} + if latestValid.Difficulty().BitLen() == 0 { + // Otherwise set latest valid hash to parent hash + currentHash = latestValid.Hash() + } } errorMsg := err.Error() return beacon.PayloadStatusV1{Status: beacon.INVALID, LatestValidHash: ¤tHash, ValidationError: &errorMsg} diff --git a/eth/catalyst/api_test.go b/eth/catalyst/api_test.go index e593a280a56db..6171c14c432c8 100644 --- a/eth/catalyst/api_test.go +++ b/eth/catalyst/api_test.go @@ -647,7 +647,8 @@ func TestEmptyBlocks(t *testing.T) { if status.Status != beacon.INVALID { t.Errorf("invalid status: expected INVALID got: %v", status.Status) } - expected := commonAncestor.Hash() + // Expect 0x0 on INVALID block on top of PoW block + expected := common.Hash{} if !bytes.Equal(status.LatestValidHash[:], expected[:]) { t.Fatalf("invalid LVH: got %v want %v", status.LatestValidHash, expected) }