Skip to content

Commit c138efe

Browse files
committed
all: remove two iterator methods
1 parent 573f62f commit c138efe

File tree

12 files changed

+39
-93
lines changed

12 files changed

+39
-93
lines changed

cmd/utils/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func ExportPreimages(db ethdb.Database, fn string) error {
301301
defer writer.(*gzip.Writer).Close()
302302
}
303303
// Iterate over the preimages and export them
304-
it := db.NewIteratorWithPrefix([]byte("secure-key-"))
304+
it := db.NewIteratorWith([]byte("secure-key-"), nil)
305305
defer it.Release()
306306

307307
for it.Next() {

core/rawdb/accessors_chain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func ReadAllHashes(db ethdb.Iteratee, number uint64) []common.Hash {
6969
prefix := headerKeyPrefix(number)
7070

7171
hashes := make([]common.Hash, 0, 1)
72-
it := db.NewIteratorWithPrefix(prefix)
72+
it := db.NewIteratorWith(prefix, nil)
7373
defer it.Release()
7474

7575
for it.Next() {

core/rawdb/accessors_snapshot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func DeleteStorageSnapshot(db ethdb.KeyValueWriter, accountHash, storageHash com
9393
// IterateStorageSnapshots returns an iterator for walking the entire storage
9494
// space of a specific account.
9595
func IterateStorageSnapshots(db ethdb.Iteratee, accountHash common.Hash) ethdb.Iterator {
96-
return db.NewIteratorWithPrefix(storageSnapshotsKey(accountHash))
96+
return db.NewIteratorWith(storageSnapshotsKey(accountHash), nil)
9797
}
9898

9999
// ReadSnapshotJournal retrieves the serialized in-memory diff layers saved at

core/rawdb/table.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,7 @@ func (t *table) Delete(key []byte) error {
106106
// NewIterator creates a binary-alphabetical iterator over the entire keyspace
107107
// contained within the database.
108108
func (t *table) NewIterator() ethdb.Iterator {
109-
return t.NewIteratorWithPrefix(nil)
110-
}
111-
112-
// NewIteratorWithStart creates a binary-alphabetical iterator over a subset of
113-
// database content starting at a particular initial key (or after, if it does
114-
// not exist).
115-
func (t *table) NewIteratorWithStart(start []byte) ethdb.Iterator {
116-
return t.NewIteratorWith(nil, start)
117-
}
118-
119-
// NewIteratorWithPrefix creates a binary-alphabetical iterator over a subset
120-
// of database content with a particular key prefix.
121-
func (t *table) NewIteratorWithPrefix(prefix []byte) ethdb.Iterator {
122-
return t.NewIteratorWith(prefix, nil)
109+
return t.NewIteratorWith(nil, nil)
123110
}
124111

125112
// NewIteratorWith creates a binary-alphabetical iterator over a subset

core/state/snapshot/disklayer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ package snapshot
1818

1919
import (
2020
"bytes"
21-
"github.com/ethereum/go-ethereum/ethdb/leveldb"
2221
"io/ioutil"
2322
"testing"
2423

2524
"github.com/VictoriaMetrics/fastcache"
2625
"github.com/ethereum/go-ethereum/common"
2726
"github.com/ethereum/go-ethereum/core/rawdb"
2827
"github.com/ethereum/go-ethereum/ethdb"
28+
"github.com/ethereum/go-ethereum/ethdb/leveldb"
2929
"github.com/ethereum/go-ethereum/ethdb/memorydb"
3030
)
3131

@@ -454,9 +454,9 @@ func tempDB() (ethdb.Database, error) {
454454
func TestDiskSeek(t *testing.T) {
455455
// Create some accounts in the disk layer
456456
//db := memorydb.New()
457-
db ,err := tempDB()
457+
db, err := tempDB()
458458
if err != nil {
459-
t.Fatal( err)
459+
t.Fatal(err)
460460
}
461461
// Fill even keys [0,2,4...]
462462
for i := 0; i < 0xff; i += 2 {

core/state/snapshot/wipe_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestWipe(t *testing.T) {
6060
// Sanity check that all the keys are present
6161
var items int
6262

63-
it := db.NewIteratorWithPrefix(rawdb.SnapshotAccountPrefix)
63+
it := db.NewIteratorWith(rawdb.SnapshotAccountPrefix, nil)
6464
defer it.Release()
6565

6666
for it.Next() {
@@ -69,7 +69,7 @@ func TestWipe(t *testing.T) {
6969
items++
7070
}
7171
}
72-
it = db.NewIteratorWithPrefix(rawdb.SnapshotStoragePrefix)
72+
it = db.NewIteratorWith(rawdb.SnapshotStoragePrefix, nil)
7373
defer it.Release()
7474

7575
for it.Next() {
@@ -88,7 +88,7 @@ func TestWipe(t *testing.T) {
8888
<-wipeSnapshot(db, true)
8989

9090
// Iterate over the database end ensure no snapshot information remains
91-
it = db.NewIteratorWithPrefix(rawdb.SnapshotAccountPrefix)
91+
it = db.NewIteratorWith(rawdb.SnapshotAccountPrefix, nil)
9292
defer it.Release()
9393

9494
for it.Next() {
@@ -97,7 +97,7 @@ func TestWipe(t *testing.T) {
9797
t.Errorf("snapshot entry remained after wipe: %x", key)
9898
}
9999
}
100-
it = db.NewIteratorWithPrefix(rawdb.SnapshotStoragePrefix)
100+
it = db.NewIteratorWith(rawdb.SnapshotStoragePrefix, nil)
101101
defer it.Release()
102102

103103
for it.Next() {

eth/filters/bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ var bloomBitsPrefix = []byte("bloomBits-")
147147

148148
func clearBloomBits(db ethdb.Database) {
149149
fmt.Println("Clearing bloombits data...")
150-
it := db.NewIteratorWithPrefix(bloomBitsPrefix)
150+
it := db.NewIteratorWith(bloomBitsPrefix, nil)
151151
for it.Next() {
152152
db.Delete(it.Key())
153153
}

ethdb/dbtest/testsuite.go

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,32 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
3232
tests := []struct {
3333
content map[string]string
3434
prefix string
35-
start string
35+
start string
3636
order []string
3737
}{
3838
// Empty databases should be iterable
39-
{map[string]string{}, "","", nil},
40-
{map[string]string{}, "non-existent-prefix","", nil},
39+
{map[string]string{}, "", "", nil},
40+
{map[string]string{}, "non-existent-prefix", "", nil},
4141

4242
// Single-item databases should be iterable
43-
{map[string]string{"key": "val"}, "","", []string{"key"}},
44-
{map[string]string{"key": "val"}, "k","", []string{"key"}},
45-
{map[string]string{"key": "val"}, "l","", nil},
43+
{map[string]string{"key": "val"}, "", "", []string{"key"}},
44+
{map[string]string{"key": "val"}, "k", "", []string{"key"}},
45+
{map[string]string{"key": "val"}, "l", "", nil},
4646

4747
// Multi-item databases should be fully iterable
4848
{
4949
map[string]string{"k1": "v1", "k5": "v5", "k2": "v2", "k4": "v4", "k3": "v3"},
50-
"","",
50+
"", "",
5151
[]string{"k1", "k2", "k3", "k4", "k5"},
5252
},
5353
{
5454
map[string]string{"k1": "v1", "k5": "v5", "k2": "v2", "k4": "v4", "k3": "v3"},
55-
"k","",
55+
"k", "",
5656
[]string{"k1", "k2", "k3", "k4", "k5"},
5757
},
5858
{
5959
map[string]string{"k1": "v1", "k5": "v5", "k2": "v2", "k4": "v4", "k3": "v3"},
60-
"l","",
60+
"l", "",
6161
nil,
6262
},
6363
// Multi-item databases should be prefix-iterable
@@ -66,15 +66,15 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
6666
"ka1": "va1", "ka5": "va5", "ka2": "va2", "ka4": "va4", "ka3": "va3",
6767
"kb1": "vb1", "kb5": "vb5", "kb2": "vb2", "kb4": "vb4", "kb3": "vb3",
6868
},
69-
"ka","",
69+
"ka", "",
7070
[]string{"ka1", "ka2", "ka3", "ka4", "ka5"},
7171
},
7272
{
7373
map[string]string{
7474
"ka1": "va1", "ka5": "va5", "ka2": "va2", "ka4": "va4", "ka3": "va3",
7575
"kb1": "vb1", "kb5": "vb5", "kb2": "vb2", "kb4": "vb4", "kb3": "vb3",
7676
},
77-
"kc","",
77+
"kc", "",
7878
nil,
7979
},
8080
// Multi-item databases should be prefix-iterable with start position
@@ -83,15 +83,15 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
8383
"ka1": "va1", "ka5": "va5", "ka2": "va2", "ka4": "va4", "ka3": "va3",
8484
"kb1": "vb1", "kb5": "vb5", "kb2": "vb2", "kb4": "vb4", "kb3": "vb3",
8585
},
86-
"ka","3",
86+
"ka", "3",
8787
[]string{"ka3", "ka4", "ka5"},
8888
},
8989
{
9090
map[string]string{
9191
"ka1": "va1", "ka5": "va5", "ka2": "va2", "ka4": "va4", "ka3": "va3",
9292
"kb1": "vb1", "kb5": "vb5", "kb2": "vb2", "kb4": "vb4", "kb3": "vb3",
9393
},
94-
"ka","8",
94+
"ka", "8",
9595
nil,
9696
},
9797
}
@@ -147,57 +147,52 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
147147
if err := it.Error(); err != nil {
148148
t.Fatal(err)
149149
}
150-
it.Release()
151150
if !reflect.DeepEqual(got, want) {
152151
t.Errorf("Iterator: got: %s; want: %s", got, want)
153152
}
154153
}
155154

156155
{
157-
it := db.NewIteratorWithPrefix([]byte("1"))
156+
it := db.NewIteratorWith([]byte("1"), nil)
158157
got, want := iterateKeys(it), []string{"1", "10", "11", "12"}
159158
if err := it.Error(); err != nil {
160159
t.Fatal(err)
161160
}
162-
it.Release()
163161
if !reflect.DeepEqual(got, want) {
164-
t.Errorf("IteratorWithPrefix(1): got: %s; want: %s", got, want)
162+
t.Errorf("IteratorWith(1,nil): got: %s; want: %s", got, want)
165163
}
166164
}
167165

168166
{
169-
it := db.NewIteratorWithPrefix([]byte("5"))
167+
it := db.NewIteratorWith([]byte("5"), nil)
170168
got, want := iterateKeys(it), []string{}
171169
if err := it.Error(); err != nil {
172170
t.Fatal(err)
173171
}
174-
it.Release()
175172
if !reflect.DeepEqual(got, want) {
176-
t.Errorf("IteratorWithPrefix(1): got: %s; want: %s", got, want)
173+
t.Errorf("IteratorWith(5,nil): got: %s; want: %s", got, want)
177174
}
178175
}
179176

180177
{
181-
it := db.NewIteratorWithStart([]byte("2"))
178+
it := db.NewIteratorWith(nil, []byte("2"))
182179
got, want := iterateKeys(it), []string{"2", "20", "21", "22", "3", "4", "6"}
183180
if err := it.Error(); err != nil {
184181
t.Fatal(err)
185182
}
186-
it.Release()
187183
if !reflect.DeepEqual(got, want) {
188-
t.Errorf("IteratorWithStart(2): got: %s; want: %s", got, want)
184+
t.Errorf("IteratorWith(nil,2): got: %s; want: %s", got, want)
189185
}
190186
}
191187

192188
{
193-
it := db.NewIteratorWithStart([]byte("5"))
189+
it := db.NewIteratorWith(nil, []byte("5"))
194190
got, want := iterateKeys(it), []string{"6"}
195191
if err := it.Error(); err != nil {
196192
t.Fatal(err)
197193
}
198-
it.Release()
199194
if !reflect.DeepEqual(got, want) {
200-
t.Errorf("IteratorWithStart(2): got: %s; want: %s", got, want)
195+
t.Errorf("IteratorWith(nil,5): got: %s; want: %s", got, want)
201196
}
202197
}
203198
})
@@ -268,7 +263,6 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
268263
if got, want := iterateKeys(it), []string{"1", "2", "3", "4"}; !reflect.DeepEqual(got, want) {
269264
t.Errorf("got: %s; want: %s", got, want)
270265
}
271-
it.Release()
272266
}
273267

274268
b.Reset()
@@ -289,7 +283,6 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
289283
if got, want := iterateKeys(it), []string{"2", "3", "4", "5", "6"}; !reflect.DeepEqual(got, want) {
290284
t.Errorf("got: %s; want: %s", got, want)
291285
}
292-
it.Release()
293286
}
294287
})
295288

@@ -318,7 +311,6 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
318311
if got := iterateKeys(it); !reflect.DeepEqual(got, want) {
319312
t.Errorf("got: %s; want: %s", got, want)
320313
}
321-
it.Release()
322314
})
323315

324316
}
@@ -329,5 +321,6 @@ func iterateKeys(it ethdb.Iterator) []string {
329321
keys = append(keys, string(it.Key()))
330322
}
331323
sort.Strings(keys)
324+
it.Release()
332325
return keys
333326
}

ethdb/iterator.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,8 @@ type Iteratee interface {
5555
// contained within the key-value database.
5656
NewIterator() Iterator
5757

58-
// NewIteratorWithStart creates a binary-alphabetical iterator over a subset of
59-
// database content starting at a particular initial key (or after, if it does
60-
// not exist).
61-
NewIteratorWithStart(start []byte) Iterator
62-
63-
// NewIteratorWithPrefix creates a binary-alphabetical iterator over a subset
64-
// of database content with a particular key prefix.
65-
NewIteratorWithPrefix(prefix []byte) Iterator
66-
67-
// NewIteratorWithPrefix creates a binary-alphabetical iterator over a subset
58+
// NewIteratorWith creates a binary-alphabetical iterator over a subset
6859
// of database content with a particular key prefix, starting at a particular
69-
//initial key (or after, if it does not exist).
60+
// initial key (or after, if it does not exist).
7061
NewIteratorWith(prefix []byte, start []byte) Iterator
7162
}

ethdb/leveldb/leveldb.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,6 @@ func (db *Database) NewIterator() ethdb.Iterator {
189189
return db.db.NewIterator(new(util.Range), nil)
190190
}
191191

192-
// NewIteratorWithStart creates a binary-alphabetical iterator over a subset of
193-
// database content starting at a particular initial key (or after, if it does
194-
// not exist).
195-
func (db *Database) NewIteratorWithStart(start []byte) ethdb.Iterator {
196-
return db.db.NewIterator(&util.Range{Start: start}, nil)
197-
}
198-
199-
// NewIteratorWithPrefix creates a binary-alphabetical iterator over a subset
200-
// of database content with a particular key prefix.
201-
func (db *Database) NewIteratorWithPrefix(prefix []byte) ethdb.Iterator {
202-
return db.db.NewIterator(util.BytesPrefix(prefix), nil)
203-
}
204-
205192
// NewIteratorWith creates a binary-alphabetical iterator over a subset
206193
// of database content with a particular key prefix, starting at a particular
207194
// initial key (or after, if it does not exist).

0 commit comments

Comments
 (0)