Skip to content

Commit 81c5b43

Browse files
core/rawdb: delete dead code to avoid more useless AI submissions (#33186)
Co-authored-by: Gary Rong <[email protected]>
1 parent 95273af commit 81c5b43

File tree

2 files changed

+0
-144
lines changed

2 files changed

+0
-144
lines changed

core/rawdb/accessors_chain.go

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -83,65 +83,6 @@ type NumberHash struct {
8383
Hash common.Hash
8484
}
8585

86-
// ReadAllHashesInRange retrieves all the hashes assigned to blocks at certain
87-
// heights, both canonical and reorged forks included.
88-
// This method considers both limits to be _inclusive_.
89-
func ReadAllHashesInRange(db ethdb.Iteratee, first, last uint64) []*NumberHash {
90-
var (
91-
start = encodeBlockNumber(first)
92-
keyLength = len(headerPrefix) + 8 + 32
93-
hashes = make([]*NumberHash, 0, 1+last-first)
94-
it = db.NewIterator(headerPrefix, start)
95-
)
96-
defer it.Release()
97-
for it.Next() {
98-
key := it.Key()
99-
if len(key) != keyLength {
100-
continue
101-
}
102-
num := binary.BigEndian.Uint64(key[len(headerPrefix) : len(headerPrefix)+8])
103-
if num > last {
104-
break
105-
}
106-
hash := common.BytesToHash(key[len(key)-32:])
107-
hashes = append(hashes, &NumberHash{num, hash})
108-
}
109-
return hashes
110-
}
111-
112-
// ReadAllCanonicalHashes retrieves all canonical number and hash mappings at the
113-
// certain chain range. If the accumulated entries reaches the given threshold,
114-
// abort the iteration and return the semi-finish result.
115-
func ReadAllCanonicalHashes(db ethdb.Iteratee, from uint64, to uint64, limit int) ([]uint64, []common.Hash) {
116-
// Short circuit if the limit is 0.
117-
if limit == 0 {
118-
return nil, nil
119-
}
120-
var (
121-
numbers []uint64
122-
hashes []common.Hash
123-
)
124-
// Construct the key prefix of start point.
125-
start, end := headerHashKey(from), headerHashKey(to)
126-
it := db.NewIterator(nil, start)
127-
defer it.Release()
128-
129-
for it.Next() {
130-
if bytes.Compare(it.Key(), end) >= 0 {
131-
break
132-
}
133-
if key := it.Key(); len(key) == len(headerPrefix)+8+1 && bytes.Equal(key[len(key)-1:], headerHashSuffix) {
134-
numbers = append(numbers, binary.BigEndian.Uint64(key[len(headerPrefix):len(headerPrefix)+8]))
135-
hashes = append(hashes, common.BytesToHash(it.Value()))
136-
// If the accumulated entries reaches the limit threshold, return.
137-
if len(numbers) >= limit {
138-
break
139-
}
140-
}
141-
}
142-
return numbers, hashes
143-
}
144-
14586
// ReadHeaderNumber returns the header number assigned to a hash.
14687
func ReadHeaderNumber(db ethdb.KeyValueReader, hash common.Hash) (uint64, bool) {
14788
data, _ := db.Get(headerNumberKey(hash))
@@ -886,40 +827,6 @@ func WriteBadBlock(db ethdb.KeyValueStore, block *types.Block) {
886827
}
887828
}
888829

889-
// DeleteBadBlocks deletes all the bad blocks from the database
890-
func DeleteBadBlocks(db ethdb.KeyValueWriter) {
891-
if err := db.Delete(badBlockKey); err != nil {
892-
log.Crit("Failed to delete bad blocks", "err", err)
893-
}
894-
}
895-
896-
// FindCommonAncestor returns the last common ancestor of two block headers
897-
func FindCommonAncestor(db ethdb.Reader, a, b *types.Header) *types.Header {
898-
for bn := b.Number.Uint64(); a.Number.Uint64() > bn; {
899-
a = ReadHeader(db, a.ParentHash, a.Number.Uint64()-1)
900-
if a == nil {
901-
return nil
902-
}
903-
}
904-
for an := a.Number.Uint64(); an < b.Number.Uint64(); {
905-
b = ReadHeader(db, b.ParentHash, b.Number.Uint64()-1)
906-
if b == nil {
907-
return nil
908-
}
909-
}
910-
for a.Hash() != b.Hash() {
911-
a = ReadHeader(db, a.ParentHash, a.Number.Uint64()-1)
912-
if a == nil {
913-
return nil
914-
}
915-
b = ReadHeader(db, b.ParentHash, b.Number.Uint64()-1)
916-
if b == nil {
917-
return nil
918-
}
919-
}
920-
return a
921-
}
922-
923830
// ReadHeadHeader returns the current canonical head header.
924831
func ReadHeadHeader(db ethdb.Reader) *types.Header {
925832
headHeaderHash := ReadHeadHeaderHash(db)

core/rawdb/accessors_chain_test.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"math/big"
2424
"math/rand"
2525
"os"
26-
"reflect"
2726
"testing"
2827

2928
"github.com/ethereum/go-ethereum/common"
@@ -249,13 +248,6 @@ func TestBadBlockStorage(t *testing.T) {
249248
t.Fatalf("The bad blocks are not sorted #[%d](%d) < #[%d](%d)", i, badBlocks[i].NumberU64(), i+1, badBlocks[i+1].NumberU64())
250249
}
251250
}
252-
253-
// Delete all bad blocks
254-
DeleteBadBlocks(db)
255-
badBlocks = ReadAllBadBlocks(db)
256-
if len(badBlocks) != 0 {
257-
t.Fatalf("Failed to delete bad blocks")
258-
}
259251
}
260252

261253
// Tests that canonical numbers can be mapped to hashes and retrieved.
@@ -516,37 +508,6 @@ func TestWriteAncientHeaderChain(t *testing.T) {
516508
}
517509
}
518510

519-
func TestCanonicalHashIteration(t *testing.T) {
520-
var cases = []struct {
521-
from, to uint64
522-
limit int
523-
expect []uint64
524-
}{
525-
{1, 8, 0, nil},
526-
{1, 8, 1, []uint64{1}},
527-
{1, 8, 10, []uint64{1, 2, 3, 4, 5, 6, 7}},
528-
{1, 9, 10, []uint64{1, 2, 3, 4, 5, 6, 7, 8}},
529-
{2, 9, 10, []uint64{2, 3, 4, 5, 6, 7, 8}},
530-
{9, 10, 10, nil},
531-
}
532-
// Test empty db iteration
533-
db := NewMemoryDatabase()
534-
numbers, _ := ReadAllCanonicalHashes(db, 0, 10, 10)
535-
if len(numbers) != 0 {
536-
t.Fatalf("No entry should be returned to iterate an empty db")
537-
}
538-
// Fill database with testing data.
539-
for i := uint64(1); i <= 8; i++ {
540-
WriteCanonicalHash(db, common.Hash{}, i)
541-
}
542-
for i, c := range cases {
543-
numbers, _ := ReadAllCanonicalHashes(db, c.from, c.to, c.limit)
544-
if !reflect.DeepEqual(numbers, c.expect) {
545-
t.Fatalf("Case %d failed, want %v, got %v", i, c.expect, numbers)
546-
}
547-
}
548-
}
549-
550511
func TestHashesInRange(t *testing.T) {
551512
mkHeader := func(number, seq int) *types.Header {
552513
h := types.Header{
@@ -565,18 +526,6 @@ func TestHashesInRange(t *testing.T) {
565526
total++
566527
}
567528
}
568-
if have, want := len(ReadAllHashesInRange(db, 10, 10)), 10; have != want {
569-
t.Fatalf("Wrong number of hashes read, want %d, got %d", want, have)
570-
}
571-
if have, want := len(ReadAllHashesInRange(db, 10, 9)), 0; have != want {
572-
t.Fatalf("Wrong number of hashes read, want %d, got %d", want, have)
573-
}
574-
if have, want := len(ReadAllHashesInRange(db, 0, 100)), total; have != want {
575-
t.Fatalf("Wrong number of hashes read, want %d, got %d", want, have)
576-
}
577-
if have, want := len(ReadAllHashesInRange(db, 9, 10)), 9+10; have != want {
578-
t.Fatalf("Wrong number of hashes read, want %d, got %d", want, have)
579-
}
580529
if have, want := len(ReadAllHashes(db, 10)), 10; have != want {
581530
t.Fatalf("Wrong number of hashes read, want %d, got %d", want, have)
582531
}

0 commit comments

Comments
 (0)