Skip to content

Commit acd1eaa

Browse files
authored
core: remove bad block checks (ethereum#29609)
1 parent e6689fe commit acd1eaa

File tree

5 files changed

+0
-161
lines changed

5 files changed

+0
-161
lines changed

core/blockchain.go

-24
Original file line numberDiff line numberDiff line change
@@ -413,37 +413,18 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
413413
// it in advance.
414414
bc.engine.VerifyHeader(bc, bc.CurrentHeader())
415415

416-
// Check the current state of the block hashes and make sure that we do not have any of the bad blocks in our chain
417-
for hash := range BadHashes {
418-
if header := bc.GetHeaderByHash(hash); header != nil {
419-
// get the canonical block corresponding to the offending header's number
420-
headerByNumber := bc.GetHeaderByNumber(header.Number.Uint64())
421-
// make sure the headerByNumber (if present) is in our current canonical chain
422-
if headerByNumber != nil && headerByNumber.Hash() == header.Hash() {
423-
log.Error("Found bad hash, rewinding chain", "number", header.Number, "hash", header.ParentHash)
424-
if err := bc.SetHead(header.Number.Uint64() - 1); err != nil {
425-
return nil, err
426-
}
427-
log.Error("Chain rewind was successful, resuming normal operation")
428-
}
429-
}
430-
}
431-
432416
if bc.logger != nil && bc.logger.OnBlockchainInit != nil {
433417
bc.logger.OnBlockchainInit(chainConfig)
434418
}
435-
436419
if bc.logger != nil && bc.logger.OnGenesisBlock != nil {
437420
if block := bc.CurrentBlock(); block.Number.Uint64() == 0 {
438421
alloc, err := getGenesisState(bc.db, block.Hash())
439422
if err != nil {
440423
return nil, fmt.Errorf("failed to get genesis state: %w", err)
441424
}
442-
443425
if alloc == nil {
444426
return nil, errors.New("live blockchain tracer requires genesis alloc to be set")
445427
}
446-
447428
bc.logger.OnGenesisBlock(bc.genesisBlock, alloc)
448429
}
449430
}
@@ -1762,11 +1743,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
17621743
log.Debug("Abort during block processing")
17631744
break
17641745
}
1765-
// If the header is a banned one, straight out abort
1766-
if BadHashes[block.Hash()] {
1767-
bc.reportBlock(block, nil, ErrBannedHash)
1768-
return it.index, ErrBannedHash
1769-
}
17701746
// If the block is known (in the middle of the chain), it's a special case for
17711747
// Clique blocks where they can share state among each other, so importing an
17721748
// older block might complete the state of the subsequent one. In this case,

core/blockchain_test.go

-101
Original file line numberDiff line numberDiff line change
@@ -658,107 +658,6 @@ func testReorg(t *testing.T, first, second []int64, td int64, full bool, scheme
658658
}
659659
}
660660

661-
// Tests that the insertion functions detect banned hashes.
662-
func TestBadHeaderHashes(t *testing.T) {
663-
testBadHashes(t, false, rawdb.HashScheme)
664-
testBadHashes(t, false, rawdb.PathScheme)
665-
}
666-
func TestBadBlockHashes(t *testing.T) {
667-
testBadHashes(t, true, rawdb.HashScheme)
668-
testBadHashes(t, true, rawdb.PathScheme)
669-
}
670-
671-
func testBadHashes(t *testing.T, full bool, scheme string) {
672-
// Create a pristine chain and database
673-
genDb, _, blockchain, err := newCanonical(ethash.NewFaker(), 0, full, scheme)
674-
if err != nil {
675-
t.Fatalf("failed to create pristine chain: %v", err)
676-
}
677-
defer blockchain.Stop()
678-
679-
// Create a chain, ban a hash and try to import
680-
if full {
681-
blocks := makeBlockChain(blockchain.chainConfig, blockchain.GetBlockByHash(blockchain.CurrentBlock().Hash()), 3, ethash.NewFaker(), genDb, 10)
682-
683-
BadHashes[blocks[2].Header().Hash()] = true
684-
defer func() { delete(BadHashes, blocks[2].Header().Hash()) }()
685-
686-
_, err = blockchain.InsertChain(blocks)
687-
} else {
688-
headers := makeHeaderChain(blockchain.chainConfig, blockchain.CurrentHeader(), 3, ethash.NewFaker(), genDb, 10)
689-
690-
BadHashes[headers[2].Hash()] = true
691-
defer func() { delete(BadHashes, headers[2].Hash()) }()
692-
693-
_, err = blockchain.InsertHeaderChain(headers)
694-
}
695-
if !errors.Is(err, ErrBannedHash) {
696-
t.Errorf("error mismatch: have: %v, want: %v", err, ErrBannedHash)
697-
}
698-
}
699-
700-
// Tests that bad hashes are detected on boot, and the chain rolled back to a
701-
// good state prior to the bad hash.
702-
func TestReorgBadHeaderHashes(t *testing.T) {
703-
testReorgBadHashes(t, false, rawdb.HashScheme)
704-
testReorgBadHashes(t, false, rawdb.PathScheme)
705-
}
706-
func TestReorgBadBlockHashes(t *testing.T) {
707-
testReorgBadHashes(t, true, rawdb.HashScheme)
708-
testReorgBadHashes(t, true, rawdb.PathScheme)
709-
}
710-
711-
func testReorgBadHashes(t *testing.T, full bool, scheme string) {
712-
// Create a pristine chain and database
713-
genDb, gspec, blockchain, err := newCanonical(ethash.NewFaker(), 0, full, scheme)
714-
if err != nil {
715-
t.Fatalf("failed to create pristine chain: %v", err)
716-
}
717-
// Create a chain, import and ban afterwards
718-
headers := makeHeaderChain(blockchain.chainConfig, blockchain.CurrentHeader(), 4, ethash.NewFaker(), genDb, 10)
719-
blocks := makeBlockChain(blockchain.chainConfig, blockchain.GetBlockByHash(blockchain.CurrentBlock().Hash()), 4, ethash.NewFaker(), genDb, 10)
720-
721-
if full {
722-
if _, err = blockchain.InsertChain(blocks); err != nil {
723-
t.Errorf("failed to import blocks: %v", err)
724-
}
725-
if blockchain.CurrentBlock().Hash() != blocks[3].Hash() {
726-
t.Errorf("last block hash mismatch: have: %x, want %x", blockchain.CurrentBlock().Hash(), blocks[3].Header().Hash())
727-
}
728-
BadHashes[blocks[3].Header().Hash()] = true
729-
defer func() { delete(BadHashes, blocks[3].Header().Hash()) }()
730-
} else {
731-
if _, err = blockchain.InsertHeaderChain(headers); err != nil {
732-
t.Errorf("failed to import headers: %v", err)
733-
}
734-
if blockchain.CurrentHeader().Hash() != headers[3].Hash() {
735-
t.Errorf("last header hash mismatch: have: %x, want %x", blockchain.CurrentHeader().Hash(), headers[3].Hash())
736-
}
737-
BadHashes[headers[3].Hash()] = true
738-
defer func() { delete(BadHashes, headers[3].Hash()) }()
739-
}
740-
blockchain.Stop()
741-
742-
// Create a new BlockChain and check that it rolled back the state.
743-
ncm, err := NewBlockChain(blockchain.db, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
744-
if err != nil {
745-
t.Fatalf("failed to create new chain manager: %v", err)
746-
}
747-
if full {
748-
if ncm.CurrentBlock().Hash() != blocks[2].Header().Hash() {
749-
t.Errorf("last block hash mismatch: have: %x, want %x", ncm.CurrentBlock().Hash(), blocks[2].Header().Hash())
750-
}
751-
if blocks[2].Header().GasLimit != ncm.GasLimit() {
752-
t.Errorf("last block gasLimit mismatch: have: %d, want %d", ncm.GasLimit(), blocks[2].Header().GasLimit)
753-
}
754-
} else {
755-
if ncm.CurrentHeader().Hash() != headers[2].Hash() {
756-
t.Errorf("last header hash mismatch: have: %x, want %x", ncm.CurrentHeader().Hash(), headers[2].Hash())
757-
}
758-
}
759-
ncm.Stop()
760-
}
761-
762661
// Tests chain insertions in the face of one entity containing an invalid nonce.
763662
func TestHeadersInsertNonceError(t *testing.T) {
764663
testInsertNonceError(t, false, rawdb.HashScheme)

core/blocks.go

-25
This file was deleted.

core/error.go

-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ var (
2626
// ErrKnownBlock is returned when a block to import is already known locally.
2727
ErrKnownBlock = errors.New("block already known")
2828

29-
// ErrBannedHash is returned if a block to import is on the banned list.
30-
ErrBannedHash = errors.New("banned hash")
31-
3229
// ErrNoGenesis is returned when there is no Genesis Block.
3330
ErrNoGenesis = errors.New("genesis not found in chain")
3431

core/headerchain.go

-8
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,6 @@ func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header) (int, error) {
305305
return 0, fmt.Errorf("non contiguous insert: item %d is #%d [%x..], item %d is #%d [%x..] (parent [%x..])", i-1, chain[i-1].Number,
306306
parentHash.Bytes()[:4], i, chain[i].Number, hash.Bytes()[:4], chain[i].ParentHash[:4])
307307
}
308-
// If the header is a banned one, straight out abort
309-
if BadHashes[chain[i].ParentHash] {
310-
return i - 1, ErrBannedHash
311-
}
312-
// If it's the last header in the cunk, we need to check it too
313-
if i == len(chain)-1 && BadHashes[chain[i].Hash()] {
314-
return i, ErrBannedHash
315-
}
316308
}
317309
// Start the parallel verifier
318310
abort, results := hc.engine.VerifyHeaders(hc, chain)

0 commit comments

Comments
 (0)