@@ -21,13 +21,13 @@ import (
21
21
"maps"
22
22
23
23
"github.com/ethereum/go-ethereum/common"
24
- "github.com/ethereum/go-ethereum/core/state/snapshot"
25
24
"github.com/ethereum/go-ethereum/core/types"
26
25
"github.com/ethereum/go-ethereum/crypto"
27
26
"github.com/ethereum/go-ethereum/rlp"
28
27
"github.com/ethereum/go-ethereum/trie"
29
28
"github.com/ethereum/go-ethereum/trie/utils"
30
29
"github.com/ethereum/go-ethereum/triedb"
30
+ "github.com/ethereum/go-ethereum/triedb/database"
31
31
)
32
32
33
33
// Reader defines the interface for accessing accounts and storage slots
@@ -52,23 +52,18 @@ type Reader interface {
52
52
Copy () Reader
53
53
}
54
54
55
- // stateReader is a wrapper over the state snapshot and implements the Reader
56
- // interface. It provides an efficient way to access flat state.
55
+ // stateReader wraps a database state reader.
57
56
type stateReader struct {
58
- snap snapshot. Snapshot
59
- buff crypto.KeccakState
57
+ reader database. StateReader
58
+ buff crypto.KeccakState
60
59
}
61
60
62
- // newStateReader constructs a flat state reader with on the specified state root.
63
- func newStateReader (root common.Hash , snaps * snapshot.Tree ) (* stateReader , error ) {
64
- snap := snaps .Snapshot (root )
65
- if snap == nil {
66
- return nil , errors .New ("snapshot is not available" )
67
- }
61
+ // newStateReader constructs a state reader with on the given state root.
62
+ func newStateReader (reader database.StateReader ) * stateReader {
68
63
return & stateReader {
69
- snap : snap ,
70
- buff : crypto .NewKeccakState (),
71
- }, nil
64
+ reader : reader ,
65
+ buff : crypto .NewKeccakState (),
66
+ }
72
67
}
73
68
74
69
// Account implements Reader, retrieving the account specified by the address.
@@ -78,18 +73,18 @@ func newStateReader(root common.Hash, snaps *snapshot.Tree) (*stateReader, error
78
73
//
79
74
// The returned account might be nil if it's not existent.
80
75
func (r * stateReader ) Account (addr common.Address ) (* types.StateAccount , error ) {
81
- ret , err := r .snap .Account (crypto .HashData (r .buff , addr .Bytes ()))
76
+ account , err := r .reader .Account (crypto .HashData (r .buff , addr .Bytes ()))
82
77
if err != nil {
83
78
return nil , err
84
79
}
85
- if ret == nil {
80
+ if account == nil {
86
81
return nil , nil
87
82
}
88
83
acct := & types.StateAccount {
89
- Nonce : ret .Nonce ,
90
- Balance : ret .Balance ,
91
- CodeHash : ret .CodeHash ,
92
- Root : common .BytesToHash (ret .Root ),
84
+ Nonce : account .Nonce ,
85
+ Balance : account .Balance ,
86
+ CodeHash : account .CodeHash ,
87
+ Root : common .BytesToHash (account .Root ),
93
88
}
94
89
if len (acct .CodeHash ) == 0 {
95
90
acct .CodeHash = types .EmptyCodeHash .Bytes ()
@@ -110,7 +105,7 @@ func (r *stateReader) Account(addr common.Address) (*types.StateAccount, error)
110
105
func (r * stateReader ) Storage (addr common.Address , key common.Hash ) (common.Hash , error ) {
111
106
addrHash := crypto .HashData (r .buff , addr .Bytes ())
112
107
slotHash := crypto .HashData (r .buff , key .Bytes ())
113
- ret , err := r .snap .Storage (addrHash , slotHash )
108
+ ret , err := r .reader .Storage (addrHash , slotHash )
114
109
if err != nil {
115
110
return common.Hash {}, err
116
111
}
@@ -131,8 +126,8 @@ func (r *stateReader) Storage(addr common.Address, key common.Hash) (common.Hash
131
126
// Copy implements Reader, returning a deep-copied snap reader.
132
127
func (r * stateReader ) Copy () Reader {
133
128
return & stateReader {
134
- snap : r .snap ,
135
- buff : crypto .NewKeccakState (),
129
+ reader : r .reader ,
130
+ buff : crypto .NewKeccakState (),
136
131
}
137
132
}
138
133
0 commit comments