@@ -26,12 +26,17 @@ import (
26
26
"github.com/ethereum/go-verkle"
27
27
)
28
28
29
+ // TransitionTrie is a trie that implements a façade design pattern, presenting
30
+ // a single interface to the old MPT trie and the new verkle/binary trie. Reads
31
+ // first from the overlay trie, and falls back to the base trie if the key isn't
32
+ // found. All writes go to the overlay trie.
29
33
type TransitionTrie struct {
30
34
overlay * VerkleTrie
31
35
base * SecureTrie
32
36
storage bool
33
37
}
34
38
39
+ // NewTransitionTrie creates a new TransitionTrie.
35
40
func NewTransitionTree (base * SecureTrie , overlay * VerkleTrie , st bool ) * TransitionTrie {
36
41
return & TransitionTrie {
37
42
overlay : overlay ,
@@ -40,29 +45,27 @@ func NewTransitionTree(base *SecureTrie, overlay *VerkleTrie, st bool) *Transiti
40
45
}
41
46
}
42
47
48
+ // Base returns the base trie.
43
49
func (t * TransitionTrie ) Base () * SecureTrie {
44
50
return t .base
45
51
}
46
52
47
- // TODO(gballet/jsign): consider removing this API .
53
+ // Overlay returns the overlay trie .
48
54
func (t * TransitionTrie ) Overlay () * VerkleTrie {
49
55
return t .overlay
50
56
}
51
57
52
58
// GetKey returns the sha3 preimage of a hashed key that was previously used
53
59
// to store a value.
54
- //
55
- // TODO(fjl): remove this when StateTrie is removed
56
60
func (t * TransitionTrie ) GetKey (key []byte ) []byte {
57
61
if key := t .overlay .GetKey (key ); key != nil {
58
62
return key
59
63
}
60
64
return t .base .GetKey (key )
61
65
}
62
66
63
- // Get returns the value for key stored in the trie. The value bytes must
64
- // not be modified by the caller. If a node was not found in the database, a
65
- // trie.MissingNodeError is returned.
67
+ // GetStorage returns the value for key stored in the trie. The value bytes must
68
+ // not be modified by the caller.
66
69
func (t * TransitionTrie ) GetStorage (addr common.Address , key []byte ) ([]byte , error ) {
67
70
val , err := t .overlay .GetStorage (addr , key )
68
71
if err != nil {
@@ -91,10 +94,9 @@ func (t *TransitionTrie) GetAccount(address common.Address) (*types.StateAccount
91
94
return t .base .GetAccount (address )
92
95
}
93
96
94
- // Update associates key with value in the trie. If value has length zero, any
97
+ // UpdateStorage associates key with value in the trie. If value has length zero, any
95
98
// existing value is deleted from the trie. The value bytes must not be modified
96
- // by the caller while they are stored in the trie. If a node was not found in the
97
- // database, a trie.MissingNodeError is returned.
99
+ // by the caller while they are stored in the trie.
98
100
func (t * TransitionTrie ) UpdateStorage (address common.Address , key []byte , value []byte ) error {
99
101
var v []byte
100
102
if len (value ) >= 32 {
@@ -115,7 +117,7 @@ func (t *TransitionTrie) UpdateAccount(addr common.Address, account *types.State
115
117
return t .overlay .UpdateAccount (addr , account , codeLen )
116
118
}
117
119
118
- // Delete removes any existing value for key from the trie. If a node was not
120
+ // DeleteStorage removes any existing value for key from the trie. If a node was not
119
121
// found in the database, a trie.MissingNodeError is returned.
120
122
func (t * TransitionTrie ) DeleteStorage (addr common.Address , key []byte ) error {
121
123
return t .overlay .DeleteStorage (addr , key )
@@ -171,6 +173,8 @@ func (t *TransitionTrie) IsVerkle() bool {
171
173
return true
172
174
}
173
175
176
+ // UpdateStems updates a group of values, given the stem they are using. If
177
+ // a value already exists, it is overwritten.
174
178
func (t * TransitionTrie ) UpdateStem (key []byte , values [][]byte ) error {
175
179
trie := t .overlay
176
180
switch root := trie .root .(type ) {
@@ -181,6 +185,7 @@ func (t *TransitionTrie) UpdateStem(key []byte, values [][]byte) error {
181
185
}
182
186
}
183
187
188
+ // Copy creates a deep copy of the transition trie.
184
189
func (t * TransitionTrie ) Copy () * TransitionTrie {
185
190
return & TransitionTrie {
186
191
overlay : t .overlay .Copy (),
@@ -189,6 +194,7 @@ func (t *TransitionTrie) Copy() *TransitionTrie {
189
194
}
190
195
}
191
196
197
+ // UpdateContractCode updates the contract code for the given address.
192
198
func (t * TransitionTrie ) UpdateContractCode (addr common.Address , codeHash common.Hash , code []byte ) error {
193
199
return t .overlay .UpdateContractCode (addr , codeHash , code )
194
200
}
0 commit comments