give comment headers to all TransitionTrie methods

This commit is contained in:
Guillaume Ballet 2025-08-12 22:34:43 +02:00
parent 7b378bab39
commit b87aa75936

View file

@ -26,12 +26,17 @@ import (
"github.com/ethereum/go-verkle" "github.com/ethereum/go-verkle"
) )
// TransitionTrie is a trie that implements a façade design pattern, presenting
// a single interface to the old MPT trie and the new verkle/binary trie. Reads
// first from the overlay trie, and falls back to the base trie if the key isn't
// found. All writes go to the overlay trie.
type TransitionTrie struct { type TransitionTrie struct {
overlay *VerkleTrie overlay *VerkleTrie
base *SecureTrie base *SecureTrie
storage bool storage bool
} }
// NewTransitionTrie creates a new TransitionTrie.
func NewTransitionTree(base *SecureTrie, overlay *VerkleTrie, st bool) *TransitionTrie { func NewTransitionTree(base *SecureTrie, overlay *VerkleTrie, st bool) *TransitionTrie {
return &TransitionTrie{ return &TransitionTrie{
overlay: overlay, overlay: overlay,
@ -40,19 +45,18 @@ func NewTransitionTree(base *SecureTrie, overlay *VerkleTrie, st bool) *Transiti
} }
} }
// Base returns the base trie.
func (t *TransitionTrie) Base() *SecureTrie { func (t *TransitionTrie) Base() *SecureTrie {
return t.base return t.base
} }
// TODO(gballet/jsign): consider removing this API. // Overlay returns the overlay trie.
func (t *TransitionTrie) Overlay() *VerkleTrie { func (t *TransitionTrie) Overlay() *VerkleTrie {
return t.overlay return t.overlay
} }
// GetKey returns the sha3 preimage of a hashed key that was previously used // GetKey returns the sha3 preimage of a hashed key that was previously used
// to store a value. // to store a value.
//
// TODO(fjl): remove this when StateTrie is removed
func (t *TransitionTrie) GetKey(key []byte) []byte { func (t *TransitionTrie) GetKey(key []byte) []byte {
if key := t.overlay.GetKey(key); key != nil { if key := t.overlay.GetKey(key); key != nil {
return key return key
@ -60,9 +64,8 @@ func (t *TransitionTrie) GetKey(key []byte) []byte {
return t.base.GetKey(key) return t.base.GetKey(key)
} }
// Get returns the value for key stored in the trie. The value bytes must // GetStorage returns the value for key stored in the trie. The value bytes must
// not be modified by the caller. If a node was not found in the database, a // not be modified by the caller.
// trie.MissingNodeError is returned.
func (t *TransitionTrie) GetStorage(addr common.Address, key []byte) ([]byte, error) { func (t *TransitionTrie) GetStorage(addr common.Address, key []byte) ([]byte, error) {
val, err := t.overlay.GetStorage(addr, key) val, err := t.overlay.GetStorage(addr, key)
if err != nil { if err != nil {
@ -91,10 +94,9 @@ func (t *TransitionTrie) GetAccount(address common.Address) (*types.StateAccount
return t.base.GetAccount(address) return t.base.GetAccount(address)
} }
// Update associates key with value in the trie. If value has length zero, any // UpdateStorage associates key with value in the trie. If value has length zero, any
// existing value is deleted from the trie. The value bytes must not be modified // existing value is deleted from the trie. The value bytes must not be modified
// by the caller while they are stored in the trie. If a node was not found in the // by the caller while they are stored in the trie.
// database, a trie.MissingNodeError is returned.
func (t *TransitionTrie) UpdateStorage(address common.Address, key []byte, value []byte) error { func (t *TransitionTrie) UpdateStorage(address common.Address, key []byte, value []byte) error {
var v []byte var v []byte
if len(value) >= 32 { if len(value) >= 32 {
@ -115,7 +117,7 @@ func (t *TransitionTrie) UpdateAccount(addr common.Address, account *types.State
return t.overlay.UpdateAccount(addr, account, codeLen) return t.overlay.UpdateAccount(addr, account, codeLen)
} }
// Delete removes any existing value for key from the trie. If a node was not // DeleteStorage removes any existing value for key from the trie. If a node was not
// found in the database, a trie.MissingNodeError is returned. // found in the database, a trie.MissingNodeError is returned.
func (t *TransitionTrie) DeleteStorage(addr common.Address, key []byte) error { func (t *TransitionTrie) DeleteStorage(addr common.Address, key []byte) error {
return t.overlay.DeleteStorage(addr, key) return t.overlay.DeleteStorage(addr, key)
@ -171,6 +173,8 @@ func (t *TransitionTrie) IsVerkle() bool {
return true return true
} }
// UpdateStems updates a group of values, given the stem they are using. If
// a value already exists, it is overwritten.
func (t *TransitionTrie) UpdateStem(key []byte, values [][]byte) error { func (t *TransitionTrie) UpdateStem(key []byte, values [][]byte) error {
trie := t.overlay trie := t.overlay
switch root := trie.root.(type) { switch root := trie.root.(type) {
@ -181,6 +185,7 @@ func (t *TransitionTrie) UpdateStem(key []byte, values [][]byte) error {
} }
} }
// Copy creates a deep copy of the transition trie.
func (t *TransitionTrie) Copy() *TransitionTrie { func (t *TransitionTrie) Copy() *TransitionTrie {
return &TransitionTrie{ return &TransitionTrie{
overlay: t.overlay.Copy(), overlay: t.overlay.Copy(),
@ -189,6 +194,7 @@ func (t *TransitionTrie) Copy() *TransitionTrie {
} }
} }
// UpdateContractCode updates the contract code for the given address.
func (t *TransitionTrie) UpdateContractCode(addr common.Address, codeHash common.Hash, code []byte) error { func (t *TransitionTrie) UpdateContractCode(addr common.Address, codeHash common.Hash, code []byte) error {
return t.overlay.UpdateContractCode(addr, codeHash, code) return t.overlay.UpdateContractCode(addr, codeHash, code)
} }