From c1f1ade52eb589d7495accf3abc4a607eb84d8bd Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Fri, 25 Oct 2024 13:38:25 +0200 Subject: [PATCH] ethdb: moved DeleteRange from KeyValueWriter to RangeDeleter --- core/rawdb/table.go | 11 ----------- core/rawdb/table_test.go | 4 ---- core/state/pruner/bloom.go | 2 -- eth/protocols/snap/gentrie_test.go | 22 +++++++++------------- ethdb/database.go | 5 +++++ ethdb/leveldb/leveldb.go | 5 ----- ethdb/memorydb/memorydb.go | 5 ----- ethdb/pebble/pebble.go | 5 ----- internal/ethapi/api.go | 4 ---- trie/sync_test.go | 4 ---- trie/trie_test.go | 1 - trie/trienode/proof.go | 4 ---- triedb/hashdb/database.go | 4 ---- 13 files changed, 14 insertions(+), 62 deletions(-) diff --git a/core/rawdb/table.go b/core/rawdb/table.go index 705d842eab..1a9060b636 100644 --- a/core/rawdb/table.go +++ b/core/rawdb/table.go @@ -217,11 +217,6 @@ func (b *tableBatch) Delete(key []byte) error { return b.batch.Delete(append([]byte(b.prefix), key...)) } -// DeleteRange implements KeyValueWriter (not supported on batches). -func (b *tableBatch) DeleteRange(start, end []byte) error { - panic("DeleteRange is not supported on batches") -} - // ValueSize retrieves the amount of data queued up for writing. func (b *tableBatch) ValueSize() int { return b.batch.ValueSize() @@ -256,12 +251,6 @@ func (r *tableReplayer) Delete(key []byte) error { return r.w.Delete(trimmed) } -// DeleteRange implements the interface KeyValueWriter. -func (r *tableReplayer) DeleteRange(start, end []byte) error { - trimmedStart, trimmedEnd := start[len(r.prefix):], end[len(r.prefix):] - return r.w.DeleteRange(trimmedStart, trimmedEnd) -} - // Replay replays the batch contents. func (b *tableBatch) Replay(w ethdb.KeyValueWriter) error { return b.batch.Replay(&tableReplayer{w: w, prefix: b.prefix}) diff --git a/core/rawdb/table_test.go b/core/rawdb/table_test.go index 333d7960e7..aa6adf3e72 100644 --- a/core/rawdb/table_test.go +++ b/core/rawdb/table_test.go @@ -41,10 +41,6 @@ func (r *testReplayer) Delete(key []byte) error { return nil } -func (r *testReplayer) DeleteRange(start, end []byte) error { - panic("not implemented") -} - func testTableDatabase(t *testing.T, prefix string) { db := NewTable(NewMemoryDatabase(), prefix) diff --git a/core/state/pruner/bloom.go b/core/state/pruner/bloom.go index df1881b45f..dad2b5b2a8 100644 --- a/core/state/pruner/bloom.go +++ b/core/state/pruner/bloom.go @@ -116,8 +116,6 @@ func (bloom *stateBloom) Put(key []byte, value []byte) error { // Delete removes the key from the key-value data store. func (bloom *stateBloom) Delete(key []byte) error { panic("not supported") } -func (bloom *stateBloom) DeleteRange(start, end []byte) error { panic("not supported") } - // Contain is the wrapper of the underlying contains function which // reports whether the key is contained. // - If it says yes, the key may be contained diff --git a/eth/protocols/snap/gentrie_test.go b/eth/protocols/snap/gentrie_test.go index 8c9174e32b..193d4eef3d 100644 --- a/eth/protocols/snap/gentrie_test.go +++ b/eth/protocols/snap/gentrie_test.go @@ -97,10 +97,6 @@ func (r *replayer) Delete(key []byte) error { return nil } -func (r *replayer) DeleteRange(start, end []byte) error { - panic("not implemented") -} - func byteToHex(str []byte) []byte { l := len(str) * 2 var nibbles = make([]byte, l) @@ -245,7 +241,7 @@ func TestPartialGentree(t *testing.T) { {2, len(entries) - 2}, // no left and right {2, len(entries) - 2}, // no left and right {len(entries) / 2, len(entries) / 2}, // single - {0, 0}, // single first + {0, 0}, // single first {len(entries) - 1, len(entries) - 1}, // single last } for _, c := range cases { @@ -354,7 +350,7 @@ func TestGentreeDanglingClearing(t *testing.T) { {2, len(entries) - 2}, // no left and right {2, len(entries) - 2}, // no left and right {len(entries) / 2, len(entries) / 2}, // single - {0, 0}, // single first + {0, 0}, // single first {len(entries) - 1, len(entries) - 1}, // single last } for _, c := range cases { @@ -394,13 +390,13 @@ func TestFlushPartialTree(t *testing.T) { first int last int }{ - {0, len(entries) - 1}, // full - {1, len(entries) - 1}, // no left - {10, len(entries) - 1}, // no left - {10, len(entries) - 2}, // no left and right - {10, len(entries) - 10}, // no left and right - {11, 11}, // single - {0, 0}, // single first + {0, len(entries) - 1}, // full + {1, len(entries) - 1}, // no left + {10, len(entries) - 1}, // no left + {10, len(entries) - 2}, // no left and right + {10, len(entries) - 10}, // no left and right + {11, 11}, // single + {0, 0}, // single first {len(entries) - 1, len(entries) - 1}, // single last } for _, c := range cases { diff --git a/ethdb/database.go b/ethdb/database.go index 0c7ea60cb6..1389178d47 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -35,7 +35,10 @@ type KeyValueWriter interface { // Delete removes the key from the key-value data store. Delete(key []byte) error +} +// RangeDeleter wraps the DeleteRange method of a backing data store. +type RangeDeleter interface { // DeleteRange deletes all of the keys (and values) in the range [start,end) // (inclusive on start, exclusive on end). DeleteRange(start, end []byte) error @@ -65,6 +68,7 @@ type KeyValueStore interface { KeyValueReader KeyValueWriter KeyValueStater + RangeDeleter Batcher Iteratee Compacter @@ -193,6 +197,7 @@ type ResettableAncientStore interface { type Database interface { Reader Writer + RangeDeleter Batcher Iteratee Stater diff --git a/ethdb/leveldb/leveldb.go b/ethdb/leveldb/leveldb.go index bc29f95de5..7bd45287c3 100644 --- a/ethdb/leveldb/leveldb.go +++ b/ethdb/leveldb/leveldb.go @@ -441,11 +441,6 @@ func (b *batch) Delete(key []byte) error { return nil } -// DeleteRange implements KeyValueWriter (not supported on batches). -func (b *batch) DeleteRange(start, end []byte) error { - panic("DeleteRange is not supported on batches") -} - // ValueSize retrieves the amount of data queued up for writing. func (b *batch) ValueSize() int { return b.size diff --git a/ethdb/memorydb/memorydb.go b/ethdb/memorydb/memorydb.go index 369cd28bad..b17a4d5410 100644 --- a/ethdb/memorydb/memorydb.go +++ b/ethdb/memorydb/memorydb.go @@ -229,11 +229,6 @@ func (b *batch) Delete(key []byte) error { return nil } -// DeleteRange implements KeyValueWriter (not supported on batches). -func (b *batch) DeleteRange(start, end []byte) error { - panic("DeleteRange is not supported on batches") -} - // ValueSize retrieves the amount of data queued up for writing. func (b *batch) ValueSize() int { return b.size diff --git a/ethdb/pebble/pebble.go b/ethdb/pebble/pebble.go index c20c402f3a..a881750441 100644 --- a/ethdb/pebble/pebble.go +++ b/ethdb/pebble/pebble.go @@ -550,11 +550,6 @@ func (b *batch) Delete(key []byte) error { return nil } -// DeleteRange implements KeyValueWriter (not supported on batches). -func (b *batch) DeleteRange(start, end []byte) error { - panic("DeleteRange is not supported on batches") -} - // ValueSize retrieves the amount of data queued up for writing. func (b *batch) ValueSize() int { return b.size diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 3a590809e3..10d79c85ae 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -704,10 +704,6 @@ func (n *proofList) Delete(key []byte) error { panic("not supported") } -func (n *proofList) DeleteRange(start, end []byte) error { - panic("not supported") -} - // GetProof returns the Merkle-proof for a given account and optionally some storage keys. func (api *BlockChainAPI) GetProof(ctx context.Context, address common.Address, storageKeys []string, blockNrOrHash rpc.BlockNumberOrHash) (*AccountResult, error) { var ( diff --git a/trie/sync_test.go b/trie/sync_test.go index 787a02b5fa..2ff02576d4 100644 --- a/trie/sync_test.go +++ b/trie/sync_test.go @@ -918,10 +918,6 @@ func (w *hookWriter) Delete(key []byte) error { return w.db.Delete(key) } -func (w *hookWriter) DeleteRange(start, end []byte) error { - panic("not supported") -} - func testSyncAbort(t *testing.T, scheme string) { var ( srcDisk = rawdb.NewMemoryDatabase() diff --git a/trie/trie_test.go b/trie/trie_test.go index acfbf9db0a..423ed30fe8 100644 --- a/trie/trie_test.go +++ b/trie/trie_test.go @@ -868,7 +868,6 @@ func (b *spongeBatch) Put(key, value []byte) error { return nil } func (b *spongeBatch) Delete(key []byte) error { panic("implement me") } -func (b *spongeBatch) DeleteRange(start, end []byte) error { panic("implement me") } func (b *spongeBatch) ValueSize() int { return 100 } func (b *spongeBatch) Write() error { return nil } func (b *spongeBatch) Reset() {} diff --git a/trie/trienode/proof.go b/trie/trienode/proof.go index 112e74a764..01a07c05b0 100644 --- a/trie/trienode/proof.go +++ b/trie/trienode/proof.go @@ -156,10 +156,6 @@ func (n *ProofList) Delete(key []byte) error { panic("not supported") } -func (n *ProofList) DeleteRange(start, end []byte) error { - panic("not supported") -} - // DataSize returns the aggregated data size of nodes in the list func (n ProofList) DataSize() int { var size int diff --git a/triedb/hashdb/database.go b/triedb/hashdb/database.go index 2768f01d05..5de7805c31 100644 --- a/triedb/hashdb/database.go +++ b/triedb/hashdb/database.go @@ -532,10 +532,6 @@ func (c *cleaner) Delete(key []byte) error { panic("not implemented") } -func (c *cleaner) DeleteRange(start, end []byte) error { - panic("not supported") -} - // Initialized returns an indicator if state data is already initialized // in hash-based scheme by checking the presence of genesis state. func (db *Database) Initialized(genesisRoot common.Hash) bool {