This commit is contained in:
Jared Wasinger 2024-02-19 21:16:37 -08:00
parent d6d48f3713
commit 3a121ee65e
4 changed files with 25 additions and 24 deletions

View file

@ -126,13 +126,14 @@ type Trie interface {
// be created with new root and updated trie database for following usage // be created with new root and updated trie database for following usage
Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet, error) Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet, error)
// CommitAndObtainAccessList does the same thing as Commit and returns an // AccessList returns a map of path->blob containing all trie nodes that have
// access list map of trie nodes read from the database. // been accessed.
CommitAndObtainAccessList(collectLeaf bool) (common.Hash, *trienode.NodeSet, map[string][]byte, error)
// AccessList returns a map of trie node read from the database.
AccessList() map[string][]byte AccessList() map[string][]byte
// CommitAndObtainAccessList does the same thing as Commit, but also returns
// the access list of the trie.
CommitAndObtainAccessList(collectLeaf bool) (common.Hash, *trienode.NodeSet, map[string][]byte, error)
// NodeIterator returns an iterator that returns nodes of the trie. Iteration // NodeIterator returns an iterator that returns nodes of the trie. Iteration
// starts at the key after the given start key. And error will be returned // starts at the key after the given start key. And error will be returned
// if fails to create node iterator. // if fails to create node iterator.

View file

@ -2,7 +2,6 @@ package state
import ( import (
"bytes" "bytes"
"crypto/sha256"
"fmt" "fmt"
"sort" "sort"
@ -317,16 +316,6 @@ func (w *Witness) PrettyPrint() string {
return b.String() return b.String()
} }
// Hash returns the sha256 hash of a witness
func (w *Witness) Hash() common.Hash {
res, err := rlp.EncodeToBytes(w.sortedWitness())
if err != nil {
panic(err)
}
return common.Hash(sha256.Sum256(res[:]))
}
// NewWitness returns a new witness object. // NewWitness returns a new witness object.
func NewWitness(root common.Hash) *Witness { func NewWitness(root common.Hash) *Witness {
return &Witness{ return &Witness{

View file

@ -1412,7 +1412,6 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
s.storagesOrigin = make(map[common.Address]map[common.Hash][]byte) s.storagesOrigin = make(map[common.Address]map[common.Hash][]byte)
s.stateObjectsDirty = make(map[common.Address]struct{}) s.stateObjectsDirty = make(map[common.Address]struct{})
s.stateObjectsDestruct = make(map[common.Address]*types.StateAccount) s.stateObjectsDestruct = make(map[common.Address]*types.StateAccount)
return root, nil return root, nil
} }

View file

@ -329,6 +329,18 @@ func (b *Block) EncodeRLP(w io.Writer) error {
}) })
} }
// EncodeRLPWithZeroRoot encodes a block (with header state root set to 0x00...0) to RLP
func (b *Block) EncodeRLPWithZeroRoot(w io.Writer) error {
old := b.header.Root
b.header.Root = common.Hash{}
err := b.EncodeRLP(w)
b.header.Root = old
if err != nil {
return err
}
return nil
}
// Body returns the non-header content of the block. // Body returns the non-header content of the block.
// Note the returned data is not an independent copy. // Note the returned data is not an independent copy.
func (b *Block) Body() *Body { func (b *Block) Body() *Body {