From cc914b49e0166f670283e0857af708ada8fae162 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 19 May 2025 16:56:14 +0200 Subject: [PATCH] core/rawdb, ethdb: remove HasAncient We don't use it anywhere. --- core/rawdb/ancienttest/testsuite.go | 21 --------------------- core/rawdb/database.go | 5 ----- core/rawdb/freezer.go | 9 --------- core/rawdb/freezer_memory.go | 11 ----------- core/rawdb/freezer_resettable.go | 9 --------- core/rawdb/freezer_test.go | 6 ------ core/rawdb/table.go | 6 ------ ethdb/database.go | 4 ---- ethdb/remotedb/remotedb.go | 7 ------- 9 files changed, 78 deletions(-) diff --git a/core/rawdb/ancienttest/testsuite.go b/core/rawdb/ancienttest/testsuite.go index 70de263c04..e33e768947 100644 --- a/core/rawdb/ancienttest/testsuite.go +++ b/core/rawdb/ancienttest/testsuite.go @@ -77,13 +77,6 @@ func basicRead(t *testing.T, newFn func(kinds []string) ethdb.AncientStore) { } for _, c := range cases { for i := c.start; i < c.limit; i++ { - exist, err := db.HasAncient("a", uint64(i)) - if err != nil { - t.Fatalf("Failed to check presence, %v", err) - } - if exist { - t.Fatalf("Item %d is already truncated", uint64(i)) - } _, err = db.Ancient("a", uint64(i)) if err == nil { t.Fatal("Error is expected for non-existent item") @@ -93,13 +86,6 @@ func basicRead(t *testing.T, newFn func(kinds []string) ethdb.AncientStore) { // Test the items in range should be reachable for i := 10; i < 90; i++ { - exist, err := db.HasAncient("a", uint64(i)) - if err != nil { - t.Fatalf("Failed to check presence, %v", err) - } - if !exist { - t.Fatalf("Item %d is missing", uint64(i)) - } blob, err := db.Ancient("a", uint64(i)) if err != nil { t.Fatalf("Failed to retrieve item, %v", err) @@ -110,13 +96,6 @@ func basicRead(t *testing.T, newFn func(kinds []string) ethdb.AncientStore) { } // Test the items in unknown table shouldn't be reachable - exist, err := db.HasAncient("b", uint64(0)) - if err != nil { - t.Fatalf("Failed to check presence, %v", err) - } - if exist { - t.Fatal("Item in unknown table shouldn't be found") - } _, err = db.Ancient("b", uint64(0)) if err == nil { t.Fatal("Error is expected for unknown table") diff --git a/core/rawdb/database.go b/core/rawdb/database.go index d56dc1df74..02b0d1bbc9 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -86,11 +86,6 @@ type nofreezedb struct { ethdb.KeyValueStore } -// HasAncient returns an error as we don't have a backing chain freezer. -func (db *nofreezedb) HasAncient(kind string, number uint64) (bool, error) { - return false, errNotSupported -} - // Ancient returns an error as we don't have a backing chain freezer. func (db *nofreezedb) Ancient(kind string, number uint64) ([]byte, error) { return nil, errNotSupported diff --git a/core/rawdb/freezer.go b/core/rawdb/freezer.go index d84700c0f2..a9600c1eef 100644 --- a/core/rawdb/freezer.go +++ b/core/rawdb/freezer.go @@ -180,15 +180,6 @@ func (f *Freezer) AncientDatadir() (string, error) { return f.datadir, nil } -// HasAncient returns an indicator whether the specified ancient data exists -// in the freezer. -func (f *Freezer) HasAncient(kind string, number uint64) (bool, error) { - if table := f.tables[kind]; table != nil { - return table.has(number), nil - } - return false, nil -} - // Ancient retrieves an ancient binary blob from the append-only immutable files. func (f *Freezer) Ancient(kind string, number uint64) ([]byte, error) { if table := f.tables[kind]; table != nil { diff --git a/core/rawdb/freezer_memory.go b/core/rawdb/freezer_memory.go index bd286f45f5..4688b11aea 100644 --- a/core/rawdb/freezer_memory.go +++ b/core/rawdb/freezer_memory.go @@ -232,17 +232,6 @@ func NewMemoryFreezer(readonly bool, tableName map[string]freezerTableConfig) *M } } -// HasAncient returns an indicator whether the specified data exists. -func (f *MemoryFreezer) HasAncient(kind string, number uint64) (bool, error) { - f.lock.RLock() - defer f.lock.RUnlock() - - if table := f.tables[kind]; table != nil { - return table.has(number), nil - } - return false, nil -} - // Ancient retrieves an ancient binary blob from the in-memory freezer. func (f *MemoryFreezer) Ancient(kind string, number uint64) ([]byte, error) { f.lock.RLock() diff --git a/core/rawdb/freezer_resettable.go b/core/rawdb/freezer_resettable.go index 01df2877d9..9db71cfd0e 100644 --- a/core/rawdb/freezer_resettable.go +++ b/core/rawdb/freezer_resettable.go @@ -105,15 +105,6 @@ func (f *resettableFreezer) Close() error { return f.freezer.Close() } -// HasAncient returns an indicator whether the specified ancient data exists -// in the freezer -func (f *resettableFreezer) HasAncient(kind string, number uint64) (bool, error) { - f.lock.RLock() - defer f.lock.RUnlock() - - return f.freezer.HasAncient(kind, number) -} - // Ancient retrieves an ancient binary blob from the append-only immutable files. func (f *resettableFreezer) Ancient(kind string, number uint64) ([]byte, error) { f.lock.RLock() diff --git a/core/rawdb/freezer_test.go b/core/rawdb/freezer_test.go index a7a3559ec4..b8a3d4a6d2 100644 --- a/core/rawdb/freezer_test.go +++ b/core/rawdb/freezer_test.go @@ -357,9 +357,6 @@ func checkAncientCount(t *testing.T, f *Freezer, kind string, n uint64) { // Check at index n-1. if n > 0 { index := n - 1 - if ok, _ := f.HasAncient(kind, index); !ok { - t.Errorf("HasAncient(%q, %d) returned false unexpectedly", kind, index) - } if _, err := f.Ancient(kind, index); err != nil { t.Errorf("Ancient(%q, %d) returned unexpected error %q", kind, index, err) } @@ -367,9 +364,6 @@ func checkAncientCount(t *testing.T, f *Freezer, kind string, n uint64) { // Check at index n. index := n - if ok, _ := f.HasAncient(kind, index); ok { - t.Errorf("HasAncient(%q, %d) returned true unexpectedly", kind, index) - } if _, err := f.Ancient(kind, index); err == nil { t.Errorf("Ancient(%q, %d) didn't return expected error", kind, index) } else if err != errOutOfBounds { diff --git a/core/rawdb/table.go b/core/rawdb/table.go index 9a342a8217..5eb3fe45d1 100644 --- a/core/rawdb/table.go +++ b/core/rawdb/table.go @@ -50,12 +50,6 @@ func (t *table) Get(key []byte) ([]byte, error) { return t.db.Get(append([]byte(t.prefix), key...)) } -// HasAncient is a noop passthrough that just forwards the request to the underlying -// database. -func (t *table) HasAncient(kind string, number uint64) (bool, error) { - return t.db.HasAncient(kind, number) -} - // Ancient is a noop passthrough that just forwards the request to the underlying // database. func (t *table) Ancient(kind string, number uint64) ([]byte, error) { diff --git a/ethdb/database.go b/ethdb/database.go index 7f421752c4..b8aef2ae1d 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -92,10 +92,6 @@ type KeyValueStore interface { // AncientReaderOp contains the methods required to read from immutable ancient data. type AncientReaderOp interface { - // HasAncient returns an indicator whether the specified data exists in the - // ancient store. - HasAncient(kind string, number uint64) (bool, error) - // Ancient retrieves an ancient binary blob from the append-only immutable files. Ancient(kind string, number uint64) ([]byte, error) diff --git a/ethdb/remotedb/remotedb.go b/ethdb/remotedb/remotedb.go index a417a25854..7fe154ea95 100644 --- a/ethdb/remotedb/remotedb.go +++ b/ethdb/remotedb/remotedb.go @@ -48,13 +48,6 @@ func (db *Database) Get(key []byte) ([]byte, error) { return resp, nil } -func (db *Database) HasAncient(kind string, number uint64) (bool, error) { - if _, err := db.Ancient(kind, number); err != nil { - return false, err - } - return true, nil -} - func (db *Database) Ancient(kind string, number uint64) ([]byte, error) { var resp hexutil.Bytes err := db.remote.Call(&resp, "debug_dbAncient", kind, number)