From 25b2b5fd9ee614cbd4085abbb16d2e859b311767 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Wed, 5 Feb 2020 23:07:05 -0800 Subject: [PATCH] Fix the one-off beacon bad block fully (#2191) * update testnet epochs * Fix the one-off error fully * Add const for the bad block num --- core/block_validator.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/block_validator.go b/core/block_validator.go index 0df9e2dc6..2ffb85e3b 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -34,6 +34,9 @@ import ( "github.com/harmony-one/harmony/internal/params" ) +// Beacon chain block 1213181 is a one-off block with empty receipts which is expected to be non-empty. +const beaconBadBlock = 1213181 + // BlockValidator is responsible for validating block headers, uncles and // processed state. // @@ -93,14 +96,16 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.DB, re // Validate the received block's bloom with the one derived from the generated receipts. // For valid blocks this should always validate to true. rbloom := types.CreateBloom(receipts) - // Beacon chain block 1213181 is a one-off block with empty bloom which is expected to be non-empty. + // Beacon chain block 1213181 is a one-off block with empty receipts which is expected to be non-empty. // Skip the validation for it to avoid failure. - if rbloom != header.Bloom() && (block.NumberU64() != 1213181 || block.ShardID() != 0) { + if rbloom != header.Bloom() && (block.NumberU64() != beaconBadBlock || block.ShardID() != 0) { return fmt.Errorf("invalid bloom (remote: %x local: %x)", header.Bloom(), rbloom) } // Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, R1]])) receiptSha := types.DeriveSha(receipts) - if receiptSha != header.ReceiptHash() { + // Beacon chain block 1213181 is a one-off block with empty receipts which is expected to be non-empty. + // Skip the validation for it to avoid failure. + if receiptSha != header.ReceiptHash() && (block.NumberU64() != beaconBadBlock || block.ShardID() != 0) { return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash(), receiptSha) }