From 1bae9a606ce13aea47db71145cd369419b2a69b5 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 14 Apr 2020 10:57:03 +0200 Subject: [PATCH] all: rename Iteratee.NewIteratorWith -> NewIterator --- cmd/utils/cmd.go | 2 +- core/rawdb/accessors_chain.go | 2 +- core/rawdb/accessors_snapshot.go | 2 +- core/rawdb/database.go | 2 +- core/rawdb/table.go | 12 +++--------- core/rawdb/table_test.go | 10 +++++----- core/state/iterator_test.go | 2 +- core/state/snapshot/iterator.go | 2 +- core/state/snapshot/wipe.go | 4 ++-- core/state/snapshot/wipe_test.go | 10 +++++----- core/state/statedb_test.go | 6 +++--- eth/filters/bench_test.go | 2 +- eth/handler_test.go | 2 +- ethdb/dbtest/testsuite.go | 18 +++++++++--------- ethdb/iterator.go | 8 ++------ ethdb/leveldb/leveldb.go | 10 ++-------- ethdb/memorydb/memorydb.go | 10 ++-------- les/clientpool.go | 4 ++-- trie/iterator_test.go | 4 ++-- trie/proof_test.go | 2 +- trie/sync_bloom.go | 4 ++-- 21 files changed, 48 insertions(+), 70 deletions(-) diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 79913637c6..a40978bcb7 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -301,7 +301,7 @@ func ExportPreimages(db ethdb.Database, fn string) error { defer writer.(*gzip.Writer).Close() } // Iterate over the preimages and export them - it := db.NewIteratorWith([]byte("secure-key-"), nil) + it := db.NewIterator([]byte("secure-key-"), nil) defer it.Release() for it.Next() { diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index b7538e3926..9fa327062a 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -69,7 +69,7 @@ func ReadAllHashes(db ethdb.Iteratee, number uint64) []common.Hash { prefix := headerKeyPrefix(number) hashes := make([]common.Hash, 0, 1) - it := db.NewIteratorWith(prefix, nil) + it := db.NewIterator(prefix, nil) defer it.Release() for it.Next() { diff --git a/core/rawdb/accessors_snapshot.go b/core/rawdb/accessors_snapshot.go index 63a76929f6..ecd4e65978 100644 --- a/core/rawdb/accessors_snapshot.go +++ b/core/rawdb/accessors_snapshot.go @@ -93,7 +93,7 @@ func DeleteStorageSnapshot(db ethdb.KeyValueWriter, accountHash, storageHash com // IterateStorageSnapshots returns an iterator for walking the entire storage // space of a specific account. func IterateStorageSnapshots(db ethdb.Iteratee, accountHash common.Hash) ethdb.Iterator { - return db.NewIteratorWith(storageSnapshotsKey(accountHash), nil) + return db.NewIterator(storageSnapshotsKey(accountHash), nil) } // ReadSnapshotJournal retrieves the serialized in-memory diff layers saved at diff --git a/core/rawdb/database.go b/core/rawdb/database.go index b74d8e2e39..cc05491b84 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -221,7 +221,7 @@ func NewLevelDBDatabaseWithFreezer(file string, cache int, handles int, freezer // InspectDatabase traverses the entire database and checks the size // of all different categories of data. func InspectDatabase(db ethdb.Database) error { - it := db.NewIterator() + it := db.NewIterator(nil, nil) defer it.Release() var ( diff --git a/core/rawdb/table.go b/core/rawdb/table.go index 36c4f851a2..323ef6293c 100644 --- a/core/rawdb/table.go +++ b/core/rawdb/table.go @@ -103,18 +103,12 @@ func (t *table) Delete(key []byte) error { return t.db.Delete(append([]byte(t.prefix), key...)) } -// NewIterator creates a binary-alphabetical iterator over the entire keyspace -// contained within the database. -func (t *table) NewIterator() ethdb.Iterator { - return t.NewIteratorWith(nil, nil) -} - -// NewIteratorWith creates a binary-alphabetical iterator over a subset +// NewIterator creates a binary-alphabetical iterator over a subset // of database content with a particular key prefix, starting at a particular // initial key (or after, if it does not exist). -func (t *table) NewIteratorWith(prefix []byte, start []byte) ethdb.Iterator { +func (t *table) NewIterator(prefix []byte, start []byte) ethdb.Iterator { innerPrefix := append([]byte(t.prefix), prefix...) - iter := t.db.NewIteratorWith(innerPrefix, start) + iter := t.db.NewIterator(innerPrefix, start) return &tableIterator{ iter: iter, prefix: t.prefix, diff --git a/core/rawdb/table_test.go b/core/rawdb/table_test.go index 34d1f96ee6..aa6adf3e72 100644 --- a/core/rawdb/table_test.go +++ b/core/rawdb/table_test.go @@ -117,12 +117,12 @@ func testTableDatabase(t *testing.T, prefix string) { iter.Release() } // Test iterators - check(db.NewIterator(), 6, 0) + check(db.NewIterator(nil, nil), 6, 0) // Test iterators with prefix - check(db.NewIteratorWith([]byte{0xff, 0xff}, nil), 3, 3) + check(db.NewIterator([]byte{0xff, 0xff}, nil), 3, 3) // Test iterators with start point - check(db.NewIteratorWith(nil, []byte{0xff, 0xff, 0x02}), 2, 4) + check(db.NewIterator(nil, []byte{0xff, 0xff, 0x02}), 2, 4) // Test iterators with prefix and start point - check(db.NewIteratorWith([]byte{0xee}, nil), 0, 0) - check(db.NewIteratorWith(nil, []byte{0x00}), 6, 0) + check(db.NewIterator([]byte{0xee}, nil), 0, 0) + check(db.NewIterator(nil, []byte{0x00}), 6, 0) } diff --git a/core/state/iterator_test.go b/core/state/iterator_test.go index e9946e9b31..5060f7a651 100644 --- a/core/state/iterator_test.go +++ b/core/state/iterator_test.go @@ -51,7 +51,7 @@ func TestNodeIteratorCoverage(t *testing.T) { t.Errorf("state entry not reported %x", hash) } } - it := db.TrieDB().DiskDB().(ethdb.Database).NewIterator() + it := db.TrieDB().DiskDB().(ethdb.Database).NewIterator(nil, nil) for it.Next() { key := it.Key() if bytes.HasPrefix(key, []byte("secure-key-")) { diff --git a/core/state/snapshot/iterator.go b/core/state/snapshot/iterator.go index 80391796b8..84cc5c3bca 100644 --- a/core/state/snapshot/iterator.go +++ b/core/state/snapshot/iterator.go @@ -151,7 +151,7 @@ func (dl *diskLayer) AccountIterator(seek common.Hash) AccountIterator { pos := common.TrimRightZeroes(seek[:]) return &diskAccountIterator{ layer: dl, - it: dl.diskdb.NewIteratorWith(rawdb.SnapshotAccountPrefix, pos), + it: dl.diskdb.NewIterator(rawdb.SnapshotAccountPrefix, pos), } } diff --git a/core/state/snapshot/wipe.go b/core/state/snapshot/wipe.go index 8ffc2ccb14..53eb18a2d1 100644 --- a/core/state/snapshot/wipe.go +++ b/core/state/snapshot/wipe.go @@ -92,7 +92,7 @@ func wipeKeyRange(db ethdb.KeyValueStore, kind string, prefix []byte, keylen int // Iterate over the key-range and delete all of them start, logged := time.Now(), time.Now() - it := db.NewIteratorWith(prefix, nil) + it := db.NewIterator(prefix, nil) for it.Next() { // Skip any keys with the correct prefix but wrong lenth (trie nodes) key := it.Key() @@ -114,7 +114,7 @@ func wipeKeyRange(db ethdb.KeyValueStore, kind string, prefix []byte, keylen int } batch.Reset() seekPos := key[len(prefix):] - it = db.NewIteratorWith(prefix, seekPos) + it = db.NewIterator(prefix, seekPos) if time.Since(logged) > 8*time.Second { log.Info("Deleting state snapshot leftovers", "kind", kind, "wiped", items, "elapsed", common.PrettyDuration(time.Since(start))) diff --git a/core/state/snapshot/wipe_test.go b/core/state/snapshot/wipe_test.go index 4ccfb47fda..2c45652a96 100644 --- a/core/state/snapshot/wipe_test.go +++ b/core/state/snapshot/wipe_test.go @@ -60,7 +60,7 @@ func TestWipe(t *testing.T) { // Sanity check that all the keys are present var items int - it := db.NewIteratorWith(rawdb.SnapshotAccountPrefix, nil) + it := db.NewIterator(rawdb.SnapshotAccountPrefix, nil) defer it.Release() for it.Next() { @@ -69,7 +69,7 @@ func TestWipe(t *testing.T) { items++ } } - it = db.NewIteratorWith(rawdb.SnapshotStoragePrefix, nil) + it = db.NewIterator(rawdb.SnapshotStoragePrefix, nil) defer it.Release() for it.Next() { @@ -88,7 +88,7 @@ func TestWipe(t *testing.T) { <-wipeSnapshot(db, true) // Iterate over the database end ensure no snapshot information remains - it = db.NewIteratorWith(rawdb.SnapshotAccountPrefix, nil) + it = db.NewIterator(rawdb.SnapshotAccountPrefix, nil) defer it.Release() for it.Next() { @@ -97,7 +97,7 @@ func TestWipe(t *testing.T) { t.Errorf("snapshot entry remained after wipe: %x", key) } } - it = db.NewIteratorWith(rawdb.SnapshotStoragePrefix, nil) + it = db.NewIterator(rawdb.SnapshotStoragePrefix, nil) defer it.Release() for it.Next() { @@ -112,7 +112,7 @@ func TestWipe(t *testing.T) { // Iterate over the database and ensure miscellaneous items are present items = 0 - it = db.NewIterator() + it = db.NewIterator(nil, nil) defer it.Release() for it.Next() { diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index ad6aeb22e7..1cb73f015e 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -60,7 +60,7 @@ func TestUpdateLeaks(t *testing.T) { } // Ensure that no data was leaked into the database - it := db.NewIterator() + it := db.NewIterator(nil, nil) for it.Next() { t.Errorf("State leaked into database: %x -> %x", it.Key(), it.Value()) } @@ -118,7 +118,7 @@ func TestIntermediateLeaks(t *testing.T) { t.Errorf("can not commit trie %v to persistent database", finalRoot.Hex()) } - it := finalDb.NewIterator() + it := finalDb.NewIterator(nil, nil) for it.Next() { key, fvalue := it.Key(), it.Value() tvalue, err := transDb.Get(key) @@ -131,7 +131,7 @@ func TestIntermediateLeaks(t *testing.T) { } it.Release() - it = transDb.NewIterator() + it = transDb.NewIterator(nil, nil) for it.Next() { key, tvalue := it.Key(), it.Value() fvalue, err := finalDb.Get(key) diff --git a/eth/filters/bench_test.go b/eth/filters/bench_test.go index 251362ee4b..4f70d6d04a 100644 --- a/eth/filters/bench_test.go +++ b/eth/filters/bench_test.go @@ -147,7 +147,7 @@ var bloomBitsPrefix = []byte("bloomBits-") func clearBloomBits(db ethdb.Database) { fmt.Println("Clearing bloombits data...") - it := db.NewIteratorWith(bloomBitsPrefix, nil) + it := db.NewIterator(bloomBitsPrefix, nil) for it.Next() { db.Delete(it.Key()) } diff --git a/eth/handler_test.go b/eth/handler_test.go index 5914f4c643..dc889c0487 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -317,7 +317,7 @@ func testGetNodeData(t *testing.T, protocol int) { // Fetch for now the entire chain db hashes := []common.Hash{} - it := db.NewIterator() + it := db.NewIterator(nil, nil) for it.Next() { if key := it.Key(); len(key) == common.HashLength { hashes = append(hashes, common.BytesToHash(key)) diff --git a/ethdb/dbtest/testsuite.go b/ethdb/dbtest/testsuite.go index a7863f40d0..06ee2211e6 100644 --- a/ethdb/dbtest/testsuite.go +++ b/ethdb/dbtest/testsuite.go @@ -104,7 +104,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) { } } // Iterate over the database with the given configs and verify the results - it, idx := db.NewIteratorWith([]byte(tt.prefix), []byte(tt.start)), 0 + it, idx := db.NewIterator([]byte(tt.prefix), []byte(tt.start)), 0 for it.Next() { if len(tt.order) <= idx { t.Errorf("test %d: prefix=%q more items than expected: checking idx=%d (key %q), expecting len=%d", i, tt.prefix, idx, it.Key(), len(tt.order)) @@ -142,7 +142,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) { } { - it := db.NewIterator() + it := db.NewIterator(nil, nil) got, want := iterateKeys(it), keys if err := it.Error(); err != nil { t.Fatal(err) @@ -153,7 +153,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) { } { - it := db.NewIteratorWith([]byte("1"), nil) + it := db.NewIterator([]byte("1"), nil) got, want := iterateKeys(it), []string{"1", "10", "11", "12"} if err := it.Error(); err != nil { t.Fatal(err) @@ -164,7 +164,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) { } { - it := db.NewIteratorWith([]byte("5"), nil) + it := db.NewIterator([]byte("5"), nil) got, want := iterateKeys(it), []string{} if err := it.Error(); err != nil { t.Fatal(err) @@ -175,7 +175,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) { } { - it := db.NewIteratorWith(nil, []byte("2")) + it := db.NewIterator(nil, []byte("2")) got, want := iterateKeys(it), []string{"2", "20", "21", "22", "3", "4", "6"} if err := it.Error(); err != nil { t.Fatal(err) @@ -186,7 +186,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) { } { - it := db.NewIteratorWith(nil, []byte("5")) + it := db.NewIterator(nil, []byte("5")) got, want := iterateKeys(it), []string{"6"} if err := it.Error(); err != nil { t.Fatal(err) @@ -259,7 +259,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) { } { - it := db.NewIterator() + it := db.NewIterator(nil, nil) if got, want := iterateKeys(it), []string{"1", "2", "3", "4"}; !reflect.DeepEqual(got, want) { t.Errorf("got: %s; want: %s", got, want) } @@ -279,7 +279,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) { } { - it := db.NewIterator() + it := db.NewIterator(nil, nil) if got, want := iterateKeys(it), []string{"2", "3", "4", "5", "6"}; !reflect.DeepEqual(got, want) { t.Errorf("got: %s; want: %s", got, want) } @@ -307,7 +307,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) { t.Fatal(err) } - it := db.NewIterator() + it := db.NewIterator(nil, nil) if got := iterateKeys(it); !reflect.DeepEqual(got, want) { t.Errorf("got: %s; want: %s", got, want) } diff --git a/ethdb/iterator.go b/ethdb/iterator.go index d2cd33859d..80e2a31dce 100644 --- a/ethdb/iterator.go +++ b/ethdb/iterator.go @@ -51,12 +51,8 @@ type Iterator interface { // Iteratee wraps the NewIterator methods of a backing data store. type Iteratee interface { - // NewIterator creates a binary-alphabetical iterator over the entire keyspace - // contained within the key-value database. - NewIterator() Iterator - - // NewIteratorWith creates a binary-alphabetical iterator over a subset + // NewIterator creates a binary-alphabetical iterator over a subset // of database content with a particular key prefix, starting at a particular // initial key (or after, if it does not exist). - NewIteratorWith(prefix []byte, start []byte) Iterator + NewIterator(prefix []byte, start []byte) Iterator } diff --git a/ethdb/leveldb/leveldb.go b/ethdb/leveldb/leveldb.go index ce0fd0af5f..fd253a9732 100644 --- a/ethdb/leveldb/leveldb.go +++ b/ethdb/leveldb/leveldb.go @@ -183,16 +183,10 @@ func (db *Database) NewBatch() ethdb.Batch { } } -// NewIterator creates a binary-alphabetical iterator over the entire keyspace -// contained within the leveldb database. -func (db *Database) NewIterator() ethdb.Iterator { - return db.db.NewIterator(new(util.Range), nil) -} - -// NewIteratorWith creates a binary-alphabetical iterator over a subset +// NewIterator creates a binary-alphabetical iterator over a subset // of database content with a particular key prefix, starting at a particular // initial key (or after, if it does not exist). -func (db *Database) NewIteratorWith(prefix []byte, start []byte) ethdb.Iterator { +func (db *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator { return db.db.NewIterator(BytesPrefixRange(prefix, start), nil) } diff --git a/ethdb/memorydb/memorydb.go b/ethdb/memorydb/memorydb.go index e4ac45007c..ecb364c6b3 100644 --- a/ethdb/memorydb/memorydb.go +++ b/ethdb/memorydb/memorydb.go @@ -129,18 +129,12 @@ func (db *Database) NewBatch() ethdb.Batch { } } -// NewIterator creates a binary-alphabetical iterator over the entire keyspace -// contained within the memory database. -func (db *Database) NewIterator() ethdb.Iterator { - return db.NewIteratorWith(nil, nil) -} - -// NewIteratorWith creates a binary-alphabetical iterator over a subset +// NewIterator creates a binary-alphabetical iterator over a subset // of database content with a particular key prefix, starting at a particular // initial key (or after, if it does not exist). // Note: This method assumes that the prefix is NOT part of the start, so there's // no need for the caller to prepend the prefix to the start -func (db *Database) NewIteratorWith(prefix []byte, start []byte) ethdb.Iterator { +func (db *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator { db.lock.RLock() defer db.lock.RUnlock() diff --git a/les/clientpool.go b/les/clientpool.go index 8d5432859b..c862649501 100644 --- a/les/clientpool.go +++ b/les/clientpool.go @@ -770,7 +770,7 @@ func (db *nodeDB) getPosBalanceIDs(start, stop enode.ID, maxCount int) (result [ return } prefix := db.getPrefix(false) - it := db.db.NewIteratorWith(prefix, start.Bytes()) + it := db.db.NewIterator(prefix, start.Bytes()) defer it.Release() for i := len(stop[:]) - 1; i >= 0; i-- { stop[i]-- @@ -851,7 +851,7 @@ func (db *nodeDB) expireNodes() { start = time.Now() prefix = db.getPrefix(true) ) - iter := db.db.NewIteratorWith(prefix, nil) + iter := db.db.NewIterator(prefix, nil) for iter.Next() { visited += 1 var balance negBalance diff --git a/trie/iterator_test.go b/trie/iterator_test.go index 88b8103fb3..54dd3069f9 100644 --- a/trie/iterator_test.go +++ b/trie/iterator_test.go @@ -120,7 +120,7 @@ func TestNodeIteratorCoverage(t *testing.T) { } } } - it := db.diskdb.NewIterator() + it := db.diskdb.NewIterator(nil, nil) for it.Next() { key := it.Key() if _, ok := hashes[common.BytesToHash(key)]; !ok { @@ -312,7 +312,7 @@ func testIteratorContinueAfterError(t *testing.T, memonly bool) { if memonly { memKeys = triedb.Nodes() } else { - it := diskdb.NewIterator() + it := diskdb.NewIterator(nil, nil) for it.Next() { diskKeys = append(diskKeys, it.Key()) } diff --git a/trie/proof_test.go b/trie/proof_test.go index c488f342c8..4caae73381 100644 --- a/trie/proof_test.go +++ b/trie/proof_test.go @@ -106,7 +106,7 @@ func TestBadProof(t *testing.T) { if proof == nil { t.Fatalf("prover %d: nil proof", i) } - it := proof.NewIterator() + it := proof.NewIterator(nil, nil) for i, d := 0, mrand.Intn(proof.Len()); i <= d; i++ { it.Next() } diff --git a/trie/sync_bloom.go b/trie/sync_bloom.go index e792e6f75a..3108b05935 100644 --- a/trie/sync_bloom.go +++ b/trie/sync_bloom.go @@ -99,7 +99,7 @@ func (b *SyncBloom) init(database ethdb.Iteratee) { // Note, this is fine, because everything inserted into leveldb by fast sync is // also pushed into the bloom directly, so we're not missing anything when the // iterator is swapped out for a new one. - it := database.NewIterator() + it := database.NewIterator(nil, nil) var ( start = time.Now() @@ -116,7 +116,7 @@ func (b *SyncBloom) init(database ethdb.Iteratee) { key := common.CopyBytes(it.Key()) it.Release() - it = database.NewIteratorWith(nil, key) + it = database.NewIterator(nil, key) log.Info("Initializing fast sync bloom", "items", b.bloom.N(), "errorrate", b.errorRate(), "elapsed", common.PrettyDuration(time.Since(start))) swap = time.Now()