@@ -27,6 +27,7 @@ import (
2727 "github.com/ava-labs/libevm/core/state/snapshot"
2828 "github.com/ava-labs/libevm/core/types"
2929 "github.com/ava-labs/libevm/crypto"
30+ "github.com/ava-labs/libevm/libevm/stateconf"
3031 "github.com/ava-labs/libevm/log"
3132 "github.com/ava-labs/libevm/metrics"
3233 "github.com/ava-labs/libevm/params"
@@ -63,7 +64,7 @@ type StateDB struct {
6364 prefetcher * triePrefetcher
6465 trie Trie
6566 hasher crypto.KeccakState
66- snaps * snapshot. Tree // Nil if snapshot is not available
67+ snaps SnapshotTree // Nil if snapshot is not available
6768 snap snapshot.Snapshot // Nil if snapshot is not available
6869
6970 // originalRoot is the pre-state root, before any changes were made.
@@ -141,7 +142,8 @@ type StateDB struct {
141142}
142143
143144// New creates a new state from a given trie.
144- func New (root common.Hash , db Database , snaps * snapshot.Tree ) (* StateDB , error ) {
145+ func New (root common.Hash , db Database , snaps SnapshotTree ) (* StateDB , error ) {
146+ snaps = clearTypedNilPointer (snaps )
145147 tr , err := db .OpenTrie (root )
146148 if err != nil {
147149 return nil , err
@@ -175,13 +177,13 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
175177// StartPrefetcher initializes a new trie prefetcher to pull in nodes from the
176178// state trie concurrently while the state is mutated so that when we reach the
177179// commit phase, most of the needed data is already hot.
178- func (s * StateDB ) StartPrefetcher (namespace string ) {
180+ func (s * StateDB ) StartPrefetcher (namespace string , opts ... PrefetcherOption ) {
179181 if s .prefetcher != nil {
180182 s .prefetcher .close ()
181183 s .prefetcher = nil
182184 }
183185 if s .snap != nil {
184- s .prefetcher = newTriePrefetcher (s .db , s .originalRoot , namespace )
186+ s .prefetcher = newTriePrefetcher (s .db , s .originalRoot , namespace , opts ... )
185187 }
186188}
187189
@@ -1162,7 +1164,7 @@ func (s *StateDB) handleDestruction(nodes *trienode.MergedNodeSet) (map[common.A
11621164//
11631165// The associated block number of the state transition is also provided
11641166// for more chain context.
1165- func (s * StateDB ) Commit (block uint64 , deleteEmptyObjects bool ) (common.Hash , error ) {
1167+ func (s * StateDB ) Commit (block uint64 , deleteEmptyObjects bool , opts ... stateconf. SnapshotUpdateOption ) (common.Hash , error ) {
11661168 // Short circuit in case any database failure occurred earlier.
11671169 if s .dbErr != nil {
11681170 return common.Hash {}, fmt .Errorf ("commit aborted due to earlier error: %v" , s .dbErr )
@@ -1252,7 +1254,7 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
12521254 start := time .Now ()
12531255 // Only update if there's a state transition (skip empty Clique blocks)
12541256 if parent := s .snap .Root (); parent != root {
1255- if err := s .snaps .Update (root , parent , s .convertAccountSet (s .stateObjectsDestruct ), s .accounts , s .storages ); err != nil {
1257+ if err := s .snaps .Update (root , parent , s .convertAccountSet (s .stateObjectsDestruct ), s .accounts , s .storages , opts ... ); err != nil {
12561258 log .Warn ("Failed to update snapshot tree" , "from" , parent , "to" , root , "err" , err )
12571259 }
12581260 // Keep 128 diff layers in the memory, persistent layer is 129th.
0 commit comments