core/state: remove Copy function

This commit is contained in:
Gary Rong 2024-11-27 16:18:23 +08:00
parent e0deac7f6f
commit 5f8322c964
2 changed files with 2 additions and 38 deletions

View file

@ -18,7 +18,6 @@ package state
import ( import (
"errors" "errors"
"maps"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
@ -47,9 +46,6 @@ type Reader interface {
// - Returns an error only if an unexpected issue occurs // - Returns an error only if an unexpected issue occurs
// - The returned storage slot is safe to modify after the call // - The returned storage slot is safe to modify after the call
Storage(addr common.Address, slot common.Hash) (common.Hash, error) Storage(addr common.Address, slot common.Hash) (common.Hash, error)
// Copy returns a deep-copied state reader.
Copy() Reader
} }
// stateReader wraps a database state reader. // stateReader wraps a database state reader.
@ -123,14 +119,6 @@ func (r *stateReader) Storage(addr common.Address, key common.Hash) (common.Hash
return value, nil return value, nil
} }
// Copy implements Reader, returning a deep-copied snap reader.
func (r *stateReader) Copy() Reader {
return &stateReader{
reader: r.reader,
buff: crypto.NewKeccakState(),
}
}
// trieReader implements the Reader interface, providing functions to access // trieReader implements the Reader interface, providing functions to access
// state from the referenced trie. // state from the referenced trie.
type trieReader struct { type trieReader struct {
@ -227,22 +215,6 @@ func (r *trieReader) Storage(addr common.Address, key common.Hash) (common.Hash,
return value, nil return value, nil
} }
// Copy implements Reader, returning a deep-copied trie reader.
func (r *trieReader) Copy() Reader {
tries := make(map[common.Address]Trie)
for addr, tr := range r.subTries {
tries[addr] = mustCopyTrie(tr)
}
return &trieReader{
root: r.root,
db: r.db,
buff: crypto.NewKeccakState(),
mainTrie: mustCopyTrie(r.mainTrie),
subRoots: maps.Clone(r.subRoots),
subTries: tries,
}
}
// multiReader is the aggregation of a list of Reader interface, providing state // multiReader is the aggregation of a list of Reader interface, providing state
// access by leveraging all readers. The checking priority is determined by the // access by leveraging all readers. The checking priority is determined by the
// position in the reader list. // position in the reader list.
@ -297,12 +269,3 @@ func (r *multiReader) Storage(addr common.Address, slot common.Hash) (common.Has
} }
return common.Hash{}, errors.Join(errs...) return common.Hash{}, errors.Join(errs...)
} }
// Copy implementing Reader interface, returning a deep-copied state reader.
func (r *multiReader) Copy() Reader {
var readers []Reader
for _, reader := range r.readers {
readers = append(readers, reader.Copy())
}
return &multiReader{readers: readers}
}

View file

@ -650,10 +650,11 @@ func (s *StateDB) CreateContract(addr common.Address) {
// Snapshots of the copied state cannot be applied to the copy. // Snapshots of the copied state cannot be applied to the copy.
func (s *StateDB) Copy() *StateDB { func (s *StateDB) Copy() *StateDB {
// Copy all the basic fields, initialize the memory ones // Copy all the basic fields, initialize the memory ones
reader, _ := s.db.Reader(s.originalRoot) // impossible to fail
state := &StateDB{ state := &StateDB{
db: s.db, db: s.db,
trie: mustCopyTrie(s.trie), trie: mustCopyTrie(s.trie),
reader: s.reader.Copy(), reader: reader,
originalRoot: s.originalRoot, originalRoot: s.originalRoot,
stateObjects: make(map[common.Address]*stateObject, len(s.stateObjects)), stateObjects: make(map[common.Address]*stateObject, len(s.stateObjects)),
stateObjectsDestruct: make(map[common.Address]*stateObject, len(s.stateObjectsDestruct)), stateObjectsDestruct: make(map[common.Address]*stateObject, len(s.stateObjectsDestruct)),