-
Notifications
You must be signed in to change notification settings - Fork 20.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
all: implement state history v2 #30107
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1051,7 +1051,7 @@ func (s *StateDB) deleteStorage(addr common.Address, addrHash common.Hash, root | |
// with their values be tracked as original value. | ||
// In case (d), **original** account along with its storages should be deleted, | ||
// with their values be tracked as original value. | ||
func (s *StateDB) handleDestruction() (map[common.Hash]*accountDelete, []*trienode.NodeSet, error) { | ||
func (s *StateDB) handleDestruction(noStorageWiping bool) (map[common.Hash]*accountDelete, []*trienode.NodeSet, error) { | ||
var ( | ||
nodes []*trienode.NodeSet | ||
buf = crypto.NewKeccakState() | ||
|
@@ -1080,6 +1080,9 @@ func (s *StateDB) handleDestruction() (map[common.Hash]*accountDelete, []*trieno | |
if prev.Root == types.EmptyRootHash || s.db.TrieDB().IsVerkle() { | ||
continue | ||
} | ||
if noStorageWiping { | ||
return nil, nil, fmt.Errorf("unexpected storage wiping, %x", addr) | ||
} | ||
// Remove storage slots belonging to the account. | ||
storages, storagesOrigin, set, err := s.deleteStorage(addr, addrHash, prev.Root) | ||
if err != nil { | ||
|
@@ -1101,7 +1104,7 @@ func (s *StateDB) GetTrie() Trie { | |
|
||
// commit gathers the state mutations accumulated along with the associated | ||
// trie changes, resetting all internal flags with the new state as the base. | ||
func (s *StateDB) commit(deleteEmptyObjects bool) (*stateUpdate, error) { | ||
func (s *StateDB) commit(deleteEmptyObjects bool, noStorageWiping bool) (*stateUpdate, error) { | ||
// Short circuit in case any database failure occurred earlier. | ||
if s.dbErr != nil { | ||
return nil, fmt.Errorf("commit aborted due to earlier error: %v", s.dbErr) | ||
|
@@ -1155,7 +1158,7 @@ func (s *StateDB) commit(deleteEmptyObjects bool) (*stateUpdate, error) { | |
// the same block, account deletions must be processed first. This ensures | ||
// that the storage trie nodes deleted during destruction and recreated | ||
// during subsequent resurrection can be combined correctly. | ||
deletes, delNodes, err := s.handleDestruction() | ||
deletes, delNodes, err := s.handleDestruction(noStorageWiping) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -1252,13 +1255,14 @@ func (s *StateDB) commit(deleteEmptyObjects bool) (*stateUpdate, error) { | |
|
||
origin := s.originalRoot | ||
s.originalRoot = root | ||
return newStateUpdate(origin, root, deletes, updates, nodes), nil | ||
|
||
return newStateUpdate(noStorageWiping, origin, root, deletes, updates, nodes), nil | ||
} | ||
|
||
// commitAndFlush is a wrapper of commit which also commits the state mutations | ||
// to the configured data stores. | ||
func (s *StateDB) commitAndFlush(block uint64, deleteEmptyObjects bool) (*stateUpdate, error) { | ||
ret, err := s.commit(deleteEmptyObjects) | ||
func (s *StateDB) commitAndFlush(block uint64, deleteEmptyObjects bool, noStorageWiping bool) (*stateUpdate, error) { | ||
ret, err := s.commit(deleteEmptyObjects, noStorageWiping) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -1310,8 +1314,13 @@ func (s *StateDB) commitAndFlush(block uint64, deleteEmptyObjects bool) (*stateU | |
// | ||
// The associated block number of the state transition is also provided | ||
// for more chain context. | ||
func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, error) { | ||
ret, err := s.commitAndFlush(block, deleteEmptyObjects) | ||
// | ||
// noStorageWiping is a flag indicating whether storage wiping is permitted. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find it a bit unintuitive with reverse bools, "no XXX". Couldn't you flip it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we set that flag when we construct the state? We have acces to the ruleset then (block number etfc), don't we? If so a lot of the diffs in this PR goes away (?) |
||
// Since self-destruction was deprecated with the Cancun fork and there are | ||
// no empty accounts left that could be deleted by EIP-158, storage wiping | ||
// should not occur. | ||
func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool, noStorageWiping bool) (common.Hash, error) { | ||
ret, err := s.commitAndFlush(block, deleteEmptyObjects, noStorageWiping) | ||
if err != nil { | ||
return common.Hash{}, err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The case here is that the caller is saying that we're operating in "no selfdestruct-mode", but still tells us to destruct something (which has storage), is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I feel we might shot ourselves in the foot.
At least what I can imagine is that: for EIP7610, there are 28 accounts which are eligible for contract deployment but has no empty storage.
We plan to remove the leftover storage of them during the verkle transition, or a preceding fork. In this case, we will have storage deletion unfortunately.