Skip to content

Commit c8b1ef9

Browse files
author
Darioush Jalali
committed
statedb snapshot mods
1 parent fa0784f commit c8b1ef9

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

core/state/statedb.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package state
1919

2020
import (
2121
"fmt"
22+
"reflect"
2223
"sort"
2324
"time"
2425

@@ -47,6 +48,19 @@ type revision struct {
4748
journalIndex int
4849
}
4950

51+
type snapshotTree interface {
52+
Snapshot(root common.Hash) snapshot.Snapshot
53+
Update(
54+
blockRoot common.Hash,
55+
parentRoot common.Hash,
56+
destructs map[common.Hash]struct{},
57+
accounts map[common.Hash][]byte,
58+
storage map[common.Hash]map[common.Hash][]byte,
59+
) error
60+
StorageIterator(root common.Hash, account common.Hash, seek common.Hash) (snapshot.StorageIterator, error)
61+
Cap(root common.Hash, layers int) error
62+
}
63+
5064
// StateDB structs within the ethereum protocol are used to store anything
5165
// within the merkle trie. StateDBs take care of caching and storing
5266
// nested states. It's the general query interface to retrieve:
@@ -63,7 +77,7 @@ type StateDB struct {
6377
prefetcher *triePrefetcher
6478
trie Trie
6579
hasher crypto.KeccakState
66-
snaps *snapshot.Tree // Nil if snapshot is not available
80+
snaps snapshotTree // Nil if snapshot is not available
6781
snap snapshot.Snapshot // Nil if snapshot is not available
6882

6983
// originalRoot is the pre-state root, before any changes were made.
@@ -141,7 +155,15 @@ type StateDB struct {
141155
}
142156

143157
// New creates a new state from a given trie.
144-
func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) {
158+
func New(root common.Hash, db Database, snaps snapshotTree) (*StateDB, error) {
159+
if snaps != nil {
160+
// XXX: Make sure we treat incoming `nil` ptrs as `nil` values, not an
161+
// interface to a nil ptr
162+
v := reflect.ValueOf(snaps)
163+
if v.Kind() == reflect.Ptr && v.IsNil() {
164+
snaps = nil
165+
}
166+
}
145167
tr, err := db.OpenTrie(root)
146168
if err != nil {
147169
return nil, err

0 commit comments

Comments
 (0)