Skip to content

Commit 7a62eb6

Browse files
committed
refactor: use "DB" instead of "backend" in names
1 parent 4404e70 commit 7a62eb6

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

triedb/database.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type Config struct {
3737
HashDB *hashdb.Config // Configs for hash-based scheme
3838
PathDB *pathdb.Config // Configs for experimental path-based scheme
3939

40-
DBOverride BackendConstructor // Injects an arbitrary backend implementation
40+
DBOverride DBConstructor // Injects an arbitrary backend-database implementation
4141
}
4242

4343
// HashDefaults represents a config for using hash-based scheme with
@@ -228,7 +228,7 @@ func (db *Database) InsertPreimage(preimages map[common.Hash][]byte) {
228228
//
229229
// It's only supported by hash-based database and will return an error for others.
230230
func (db *Database) Cap(limit common.StorageSize) error {
231-
hdb, ok := db.backend.(HashBackend)
231+
hdb, ok := db.backend.(HashDB)
232232
if !ok {
233233
return errors.New("not supported")
234234
}
@@ -244,7 +244,7 @@ func (db *Database) Cap(limit common.StorageSize) error {
244244
//
245245
// It's only supported by hash-based database and will return an error for others.
246246
func (db *Database) Reference(root common.Hash, parent common.Hash) error {
247-
hdb, ok := db.backend.(HashBackend)
247+
hdb, ok := db.backend.(HashDB)
248248
if !ok {
249249
return errors.New("not supported")
250250
}
@@ -255,7 +255,7 @@ func (db *Database) Reference(root common.Hash, parent common.Hash) error {
255255
// Dereference removes an existing reference from a root node. It's only
256256
// supported by hash-based database and will return an error for others.
257257
func (db *Database) Dereference(root common.Hash) error {
258-
hdb, ok := db.backend.(HashBackend)
258+
hdb, ok := db.backend.(HashDB)
259259
if !ok {
260260
return errors.New("not supported")
261261
}
@@ -268,7 +268,7 @@ func (db *Database) Dereference(root common.Hash) error {
268268
// corresponding trie histories are existent. It's only supported by path-based
269269
// database and will return an error for others.
270270
func (db *Database) Recover(target common.Hash) error {
271-
pdb, ok := db.backend.(PathBackend)
271+
pdb, ok := db.backend.(PathDB)
272272
if !ok {
273273
return errors.New("not supported")
274274
}
@@ -286,7 +286,7 @@ func (db *Database) Recover(target common.Hash) error {
286286
// recovered. It's only supported by path-based database and will return an
287287
// error for others.
288288
func (db *Database) Recoverable(root common.Hash) (bool, error) {
289-
pdb, ok := db.backend.(PathBackend)
289+
pdb, ok := db.backend.(PathDB)
290290
if !ok {
291291
return false, errors.New("not supported")
292292
}
@@ -299,7 +299,7 @@ func (db *Database) Recoverable(root common.Hash) (bool, error) {
299299
//
300300
// It's only supported by path-based database and will return an error for others.
301301
func (db *Database) Disable() error {
302-
pdb, ok := db.backend.(PathBackend)
302+
pdb, ok := db.backend.(PathDB)
303303
if !ok {
304304
return errors.New("not supported")
305305
}
@@ -309,7 +309,7 @@ func (db *Database) Disable() error {
309309
// Enable activates database and resets the state tree with the provided persistent
310310
// state root once the state sync is finished.
311311
func (db *Database) Enable(root common.Hash) error {
312-
pdb, ok := db.backend.(PathBackend)
312+
pdb, ok := db.backend.(PathDB)
313313
if !ok {
314314
return errors.New("not supported")
315315
}
@@ -321,7 +321,7 @@ func (db *Database) Enable(root common.Hash) error {
321321
// flattening everything down (bad for reorgs). It's only supported by path-based
322322
// database and will return an error for others.
323323
func (db *Database) Journal(root common.Hash) error {
324-
pdb, ok := db.backend.(PathBackend)
324+
pdb, ok := db.backend.(PathDB)
325325
if !ok {
326326
return errors.New("not supported")
327327
}
@@ -332,7 +332,7 @@ func (db *Database) Journal(root common.Hash) error {
332332
// It's only supported by path-based database and will return an error for
333333
// others.
334334
func (db *Database) SetBufferSize(size int) error {
335-
pdb, ok := db.backend.(PathBackend)
335+
pdb, ok := db.backend.(PathDB)
336336
if !ok {
337337
return errors.New("not supported")
338338
}

triedb/database.libevm.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,28 @@ import (
2626
"github.com/ava-labs/libevm/triedb/pathdb"
2727
)
2828

29-
// Backend defines the intersection of methods shared by [hashdb.Database] and
30-
// [pathdb.Database].
31-
type Backend backend
29+
// BackendDB defines the intersection of methods shared by [hashdb.Database] and
30+
// [pathdb.Database]. It is defined to export an otherwise internal type used by
31+
// the non-libevm geth implementation.
32+
type BackendDB backend
3233

3334
// A ReaderProvider exposes its underlying Reader as an interface. Both
3435
// [hashdb.Database] and [pathdb.Database] return concrete types so Go's lack of
3536
// support for [covariant types] means that this method can't be defined on
36-
// [Backend].
37+
// [BackendDB].
3738
//
3839
// [covariant types]: https://go.dev/doc/faq#covariant_types
3940
type ReaderProvider interface {
4041
Reader(common.Hash) (database.Reader, error)
4142
}
4243

43-
// A BackendConstructor constructs alternative backend implementations.
44-
type BackendConstructor func(ethdb.Database, *Config) BackendOverride
44+
// A DBConstructor constructs alternative backend-database implementations.
45+
type DBConstructor func(ethdb.Database, *Config) DBOverride
4546

46-
// A BackendOverride is an arbitrary implementation of a [Database] backend. It
47-
// MUST be either a [HashBackend] or a [PathBackend].
48-
type BackendOverride interface {
49-
Backend
47+
// A DBOverride is an arbitrary implementation of a [Database] backend. It MUST
48+
// be either a [HashDB] or a [PathDB].
49+
type DBOverride interface {
50+
BackendDB
5051
ReaderProvider
5152
}
5253

@@ -60,8 +61,8 @@ func (db *Database) overrideBackend(diskdb ethdb.Database, config *Config) bool
6061

6162
db.backend = config.DBOverride(diskdb, config)
6263
switch db.backend.(type) {
63-
case HashBackend:
64-
case PathBackend:
64+
case HashDB:
65+
case PathDB:
6566
default:
6667
log.Crit("Database override is neither hash- nor path-based")
6768
}
@@ -70,22 +71,22 @@ func (db *Database) overrideBackend(diskdb ethdb.Database, config *Config) bool
7071

7172
var (
7273
// If either of these break then the respective interface SHOULD be updated.
73-
_ HashBackend = (*hashdb.Database)(nil)
74-
_ PathBackend = (*pathdb.Database)(nil)
74+
_ HashDB = (*hashdb.Database)(nil)
75+
_ PathDB = (*pathdb.Database)(nil)
7576
)
7677

77-
// A HashBackend mirrors the functionality of a [hashdb.Database].
78-
type HashBackend interface {
79-
Backend
78+
// A HashDB mirrors the functionality of a [hashdb.Database].
79+
type HashDB interface {
80+
BackendDB
8081

8182
Cap(limit common.StorageSize) error
8283
Reference(root common.Hash, parent common.Hash)
8384
Dereference(root common.Hash)
8485
}
8586

86-
// A PathBackend mirrors the functionality of a [pathdb.Database].
87-
type PathBackend interface {
88-
Backend
87+
// A PathDB mirrors the functionality of a [pathdb.Database].
88+
type PathDB interface {
89+
BackendDB
8990

9091
Recover(root common.Hash, loader triestate.TrieLoader) error
9192
Recoverable(root common.Hash) bool

triedb/database.libevm_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828

2929
func TestDBOverride(t *testing.T) {
3030
config := &Config{
31-
DBOverride: func(d ethdb.Database, c *Config) BackendOverride {
31+
DBOverride: func(d ethdb.Database, c *Config) DBOverride {
3232
return override{}
3333
},
3434
}
@@ -42,7 +42,7 @@ func TestDBOverride(t *testing.T) {
4242
}
4343

4444
type override struct {
45-
PathBackend
45+
PathDB
4646
}
4747

4848
type reader struct {

0 commit comments

Comments
 (0)