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
pull/2194/head
Rongjian Lan 5 years ago committed by GitHub
parent b194241bc3
commit 25b2b5fd9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      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)
}

Loading…
Cancel
Save