Skip to content

Commit fd5078c

Browse files
author
Darioush Jalali
authored
trie/triedb: add Reader to backend interface (#29988)
1 parent 86150af commit fd5078c

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

triedb/database.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ type backend interface {
7474

7575
// Close closes the trie database backend and releases all held resources.
7676
Close() error
77+
78+
// Reader returns a reader for accessing all trie nodes with provided state
79+
// root. An error will be returned if the requested state is not available.
80+
Reader(root common.Hash) (database.Reader, error)
7781
}
7882

7983
// Database is the wrapper of the underlying backend which is shared by different
@@ -123,13 +127,7 @@ func NewDatabase(diskdb ethdb.Database, config *Config) *Database {
123127
// Reader returns a reader for accessing all trie nodes with provided state root.
124128
// An error will be returned if the requested state is not available.
125129
func (db *Database) Reader(blockRoot common.Hash) (database.Reader, error) {
126-
switch b := db.backend.(type) {
127-
case *hashdb.Database:
128-
return b.Reader(blockRoot)
129-
case *pathdb.Database:
130-
return b.Reader(blockRoot)
131-
}
132-
return nil, errors.New("unknown backend")
130+
return db.backend.Reader(blockRoot)
133131
}
134132

135133
// Update performs a state transition by committing dirty nodes contained in the

triedb/hashdb/database.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/ethereum/go-ethereum/rlp"
3434
"github.com/ethereum/go-ethereum/trie/trienode"
3535
"github.com/ethereum/go-ethereum/trie/triestate"
36+
"github.com/ethereum/go-ethereum/triedb/database"
3637
)
3738

3839
var (
@@ -625,7 +626,7 @@ func (db *Database) Close() error {
625626

626627
// Reader retrieves a node reader belonging to the given state root.
627628
// An error will be returned if the requested state is not available.
628-
func (db *Database) Reader(root common.Hash) (*reader, error) {
629+
func (db *Database) Reader(root common.Hash) (database.Reader, error) {
629630
if _, err := db.node(root); err != nil {
630631
return nil, fmt.Errorf("state %#x is not available, %v", root, err)
631632
}

0 commit comments

Comments
 (0)