Skip to content

Commit 8658f91

Browse files
committed
give comment headers to all TransitionTrie methods
1 parent 08430b5 commit 8658f91

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

trie/transition.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ import (
2626
"github.com/ethereum/go-verkle"
2727
)
2828

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.
2933
type TransitionTrie struct {
3034
overlay *VerkleTrie
3135
base *SecureTrie
3236
storage bool
3337
}
3438

39+
// NewTransitionTrie creates a new TransitionTrie.
3540
func NewTransitionTree(base *SecureTrie, overlay *VerkleTrie, st bool) *TransitionTrie {
3641
return &TransitionTrie{
3742
overlay: overlay,
@@ -40,29 +45,27 @@ func NewTransitionTree(base *SecureTrie, overlay *VerkleTrie, st bool) *Transiti
4045
}
4146
}
4247

48+
// Base returns the base trie.
4349
func (t *TransitionTrie) Base() *SecureTrie {
4450
return t.base
4551
}
4652

47-
// TODO(gballet/jsign): consider removing this API.
53+
// Overlay returns the overlay trie.
4854
func (t *TransitionTrie) Overlay() *VerkleTrie {
4955
return t.overlay
5056
}
5157

5258
// GetKey returns the sha3 preimage of a hashed key that was previously used
5359
// to store a value.
54-
//
55-
// TODO(fjl): remove this when StateTrie is removed
5660
func (t *TransitionTrie) GetKey(key []byte) []byte {
5761
if key := t.overlay.GetKey(key); key != nil {
5862
return key
5963
}
6064
return t.base.GetKey(key)
6165
}
6266

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.
6669
func (t *TransitionTrie) GetStorage(addr common.Address, key []byte) ([]byte, error) {
6770
val, err := t.overlay.GetStorage(addr, key)
6871
if err != nil {
@@ -91,10 +94,9 @@ func (t *TransitionTrie) GetAccount(address common.Address) (*types.StateAccount
9194
return t.base.GetAccount(address)
9295
}
9396

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
9598
// 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.
98100
func (t *TransitionTrie) UpdateStorage(address common.Address, key []byte, value []byte) error {
99101
var v []byte
100102
if len(value) >= 32 {
@@ -115,7 +117,7 @@ func (t *TransitionTrie) UpdateAccount(addr common.Address, account *types.State
115117
return t.overlay.UpdateAccount(addr, account, codeLen)
116118
}
117119

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
119121
// found in the database, a trie.MissingNodeError is returned.
120122
func (t *TransitionTrie) DeleteStorage(addr common.Address, key []byte) error {
121123
return t.overlay.DeleteStorage(addr, key)
@@ -171,6 +173,8 @@ func (t *TransitionTrie) IsVerkle() bool {
171173
return true
172174
}
173175

176+
// UpdateStems updates a group of values, given the stem they are using. If
177+
// a value already exists, it is overwritten.
174178
func (t *TransitionTrie) UpdateStem(key []byte, values [][]byte) error {
175179
trie := t.overlay
176180
switch root := trie.root.(type) {
@@ -181,6 +185,7 @@ func (t *TransitionTrie) UpdateStem(key []byte, values [][]byte) error {
181185
}
182186
}
183187

188+
// Copy creates a deep copy of the transition trie.
184189
func (t *TransitionTrie) Copy() *TransitionTrie {
185190
return &TransitionTrie{
186191
overlay: t.overlay.Copy(),
@@ -189,6 +194,7 @@ func (t *TransitionTrie) Copy() *TransitionTrie {
189194
}
190195
}
191196

197+
// UpdateContractCode updates the contract code for the given address.
192198
func (t *TransitionTrie) UpdateContractCode(addr common.Address, codeHash common.Hash, code []byte) error {
193199
return t.overlay.UpdateContractCode(addr, codeHash, code)
194200
}

0 commit comments

Comments
 (0)