diff --git a/core/state/database.go b/core/state/database.go index a2d01f168c..a43485bcc9 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -126,13 +126,14 @@ type Trie interface { // be created with new root and updated trie database for following usage Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet, error) - // CommitAndObtainAccessList does the same thing as Commit and returns an - // access list map of trie nodes read from the database. - CommitAndObtainAccessList(collectLeaf bool) (common.Hash, *trienode.NodeSet, map[string][]byte, error) - - // AccessList returns a map of trie node read from the database. + // AccessList returns a map of path->blob containing all trie nodes that have + // been accessed. 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 // starts at the key after the given start key. And error will be returned // if fails to create node iterator. diff --git a/core/state/state_witness.go b/core/state/state_witness.go index e83e46dc81..7cc9833b79 100644 --- a/core/state/state_witness.go +++ b/core/state/state_witness.go @@ -2,7 +2,6 @@ package state import ( "bytes" - "crypto/sha256" "fmt" "sort" @@ -317,16 +316,6 @@ func (w *Witness) PrettyPrint() 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. func NewWitness(root common.Hash) *Witness { return &Witness{ diff --git a/core/state/statedb.go b/core/state/statedb.go index 93d267a533..6f4373ab99 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -918,13 +918,13 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash { // Finalise all the dirty storage states and write them into the tries s.Finalise(deleteEmptyObjects) - // If there was a trie prefetcher operating, it gets aborted and irrevocably - // modified after we start retrieving tries. Remove it from the statedb after - // this round of use. - // - // This is weird pre-byzantium since the first tx runs with a prefetcher and - // the remainder without, but pre-byzantium even the initial prefetcher is - // useless, so no sleep lost. + // If there was a trie prefetcher operating, it gets aborted and irrevocably + // modified after we start retrieving tries. Remove it from the statedb after + // this round of use. + // + // This is weird pre-byzantium since the first tx runs with a prefetcher and + // the remainder without, but pre-byzantium even the initial prefetcher is + // useless, so no sleep lost. prefetcher := s.prefetcher if s.prefetcher != nil { defer func() { @@ -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.stateObjectsDirty = make(map[common.Address]struct{}) s.stateObjectsDestruct = make(map[common.Address]*types.StateAccount) - return root, nil } diff --git a/core/types/block.go b/core/types/block.go index 1a357baa3a..eef7970919 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -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. // Note the returned data is not an independent copy. func (b *Block) Body() *Body {