@@ -658,107 +658,6 @@ func testReorg(t *testing.T, first, second []int64, td int64, full bool, scheme
658
658
}
659
659
}
660
660
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
-
762
661
// Tests chain insertions in the face of one entity containing an invalid nonce.
763
662
func TestHeadersInsertNonceError (t * testing.T ) {
764
663
testInsertNonceError (t , false , rawdb .HashScheme )
0 commit comments