@@ -21,13 +21,13 @@ import (
2121 "maps"
2222
2323 "github.com/ethereum/go-ethereum/common"
24- "github.com/ethereum/go-ethereum/core/state/snapshot"
2524 "github.com/ethereum/go-ethereum/core/types"
2625 "github.com/ethereum/go-ethereum/crypto"
2726 "github.com/ethereum/go-ethereum/rlp"
2827 "github.com/ethereum/go-ethereum/trie"
2928 "github.com/ethereum/go-ethereum/trie/utils"
3029 "github.com/ethereum/go-ethereum/triedb"
30+ "github.com/ethereum/go-ethereum/triedb/database"
3131)
3232
3333// Reader defines the interface for accessing accounts and storage slots
@@ -52,23 +52,18 @@ type Reader interface {
5252 Copy () Reader
5353}
5454
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.
5756type stateReader struct {
58- snap snapshot. Snapshot
59- buff crypto.KeccakState
57+ reader database. StateReader
58+ buff crypto.KeccakState
6059}
6160
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 {
6863 return & stateReader {
69- snap : snap ,
70- buff : crypto .NewKeccakState (),
71- }, nil
64+ reader : reader ,
65+ buff : crypto .NewKeccakState (),
66+ }
7267}
7368
7469// Account implements Reader, retrieving the account specified by the address.
@@ -78,18 +73,18 @@ func newStateReader(root common.Hash, snaps *snapshot.Tree) (*stateReader, error
7873//
7974// The returned account might be nil if it's not existent.
8075func (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 ()))
8277 if err != nil {
8378 return nil , err
8479 }
85- if ret == nil {
80+ if account == nil {
8681 return nil , nil
8782 }
8883 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 ),
9388 }
9489 if len (acct .CodeHash ) == 0 {
9590 acct .CodeHash = types .EmptyCodeHash .Bytes ()
@@ -110,7 +105,7 @@ func (r *stateReader) Account(addr common.Address) (*types.StateAccount, error)
110105func (r * stateReader ) Storage (addr common.Address , key common.Hash ) (common.Hash , error ) {
111106 addrHash := crypto .HashData (r .buff , addr .Bytes ())
112107 slotHash := crypto .HashData (r .buff , key .Bytes ())
113- ret , err := r .snap .Storage (addrHash , slotHash )
108+ ret , err := r .reader .Storage (addrHash , slotHash )
114109 if err != nil {
115110 return common.Hash {}, err
116111 }
@@ -131,8 +126,8 @@ func (r *stateReader) Storage(addr common.Address, key common.Hash) (common.Hash
131126// Copy implements Reader, returning a deep-copied snap reader.
132127func (r * stateReader ) Copy () Reader {
133128 return & stateReader {
134- snap : r .snap ,
135- buff : crypto .NewKeccakState (),
129+ reader : r .reader ,
130+ buff : crypto .NewKeccakState (),
136131 }
137132}
138133
0 commit comments