mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-15 12:36:48 +00:00
core: fix storage deletion
This commit is contained in:
parent
ed0af73154
commit
e4a6a5ab75
2 changed files with 9 additions and 9 deletions
|
|
@ -265,7 +265,7 @@ func (s *BALStateTransition) CommitWithUpdate(block uint64, deleteEmptyObjects b
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
deletes, delNodes, err := handleDestruction(s.db, s.stateTrie, noStorageWiping, maps.Keys(s.deletions), destructedPrestates)
|
deletes, delNodes, err := handleDestruction(s.db, s.stateTrie, s.parentRoot, noStorageWiping, maps.Keys(s.deletions), destructedPrestates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, nil, err
|
return common.Hash{}, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1141,8 +1141,8 @@ func fastDeleteStorage(originalRoot common.Hash, snaps *snapshot.Tree, addrHash
|
||||||
// slowDeleteStorage serves as a less-efficient alternative to "fastDeleteStorage,"
|
// slowDeleteStorage serves as a less-efficient alternative to "fastDeleteStorage,"
|
||||||
// employed when the associated state snapshot is not available. It iterates the
|
// employed when the associated state snapshot is not available. It iterates the
|
||||||
// storage slots along with all internal trie nodes via trie directly.
|
// storage slots along with all internal trie nodes via trie directly.
|
||||||
func slowDeleteStorage(db Database, trie Trie, originalRoot common.Hash, addr common.Address, addrHash common.Hash, root common.Hash) (map[common.Hash][]byte, map[common.Hash][]byte, *trienode.NodeSet, error) {
|
func slowDeleteStorage(db Database, trie Trie, stateRoot common.Hash, addr common.Address, addrHash common.Hash, storageRoot common.Hash) (map[common.Hash][]byte, map[common.Hash][]byte, *trienode.NodeSet, error) {
|
||||||
tr, err := db.OpenStorageTrie(originalRoot, addr, root, trie)
|
tr, err := db.OpenStorageTrie(stateRoot, addr, storageRoot, trie)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, fmt.Errorf("failed to open storage trie, err: %w", err)
|
return nil, nil, nil, fmt.Errorf("failed to open storage trie, err: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -1177,7 +1177,7 @@ func slowDeleteStorage(db Database, trie Trie, originalRoot common.Hash, addr co
|
||||||
// The function will make an attempt to utilize an efficient strategy if the
|
// The function will make an attempt to utilize an efficient strategy if the
|
||||||
// associated state snapshot is reachable; otherwise, it will resort to a less
|
// associated state snapshot is reachable; otherwise, it will resort to a less
|
||||||
// efficient approach.
|
// efficient approach.
|
||||||
func deleteStorage(db Database, trie Trie, addr common.Address, addrHash common.Hash, root, originalRoot common.Hash) (map[common.Hash][]byte, map[common.Hash][]byte, *trienode.NodeSet, error) {
|
func deleteStorage(db Database, trie Trie, stateRoot common.Hash, addr common.Address, addrHash common.Hash, storageRoot common.Hash) (map[common.Hash][]byte, map[common.Hash][]byte, *trienode.NodeSet, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
nodes *trienode.NodeSet // the set for trie node mutations (value is nil)
|
nodes *trienode.NodeSet // the set for trie node mutations (value is nil)
|
||||||
|
|
@ -1189,10 +1189,10 @@ func deleteStorage(db Database, trie Trie, addr common.Address, addrHash common.
|
||||||
// one just in case.
|
// one just in case.
|
||||||
snaps := db.Snapshot()
|
snaps := db.Snapshot()
|
||||||
if snaps != nil {
|
if snaps != nil {
|
||||||
storages, storageOrigins, nodes, err = fastDeleteStorage(originalRoot, snaps, addrHash, root)
|
storages, storageOrigins, nodes, err = fastDeleteStorage(stateRoot, snaps, addrHash, storageRoot)
|
||||||
}
|
}
|
||||||
if snaps == nil || err != nil {
|
if snaps == nil || err != nil {
|
||||||
storages, storageOrigins, nodes, err = slowDeleteStorage(db, trie, originalRoot, addr, addrHash, root)
|
storages, storageOrigins, nodes, err = slowDeleteStorage(db, trie, stateRoot, addr, addrHash, storageRoot)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
|
|
@ -1218,7 +1218,7 @@ func deleteStorage(db Database, trie Trie, addr common.Address, addrHash common.
|
||||||
// with their values be tracked as original value.
|
// with their values be tracked as original value.
|
||||||
// In case (d), **original** account along with its storages should be deleted,
|
// In case (d), **original** account along with its storages should be deleted,
|
||||||
// with their values be tracked as original value.
|
// with their values be tracked as original value.
|
||||||
func handleDestruction(db Database, trie Trie, noStorageWiping bool, destructions iter.Seq[common.Address], prestates map[common.Address]*types.StateAccount) (map[common.Hash]*accountDelete, []*trienode.NodeSet, error) {
|
func handleDestruction(db Database, trie Trie, root common.Hash, noStorageWiping bool, destructions iter.Seq[common.Address], prestates map[common.Address]*types.StateAccount) (map[common.Hash]*accountDelete, []*trienode.NodeSet, error) {
|
||||||
var (
|
var (
|
||||||
nodes []*trienode.NodeSet
|
nodes []*trienode.NodeSet
|
||||||
deletes = make(map[common.Hash]*accountDelete)
|
deletes = make(map[common.Hash]*accountDelete)
|
||||||
|
|
@ -1249,7 +1249,7 @@ func handleDestruction(db Database, trie Trie, noStorageWiping bool, destruction
|
||||||
return nil, nil, fmt.Errorf("unexpected storage wiping, %x", addr)
|
return nil, nil, fmt.Errorf("unexpected storage wiping, %x", addr)
|
||||||
}
|
}
|
||||||
// Remove storage slots belonging to the account.
|
// Remove storage slots belonging to the account.
|
||||||
storages, storagesOrigin, set, err := deleteStorage(db, trie, addr, addrHash, prestate.Root, prestate.Root)
|
storages, storagesOrigin, set, err := deleteStorage(db, trie, root, addr, addrHash, prestate.Root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to delete storage, err: %w", err)
|
return nil, nil, fmt.Errorf("failed to delete storage, err: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -1329,7 +1329,7 @@ func (s *StateDB) commit(deleteEmptyObjects bool, noStorageWiping bool, blockNum
|
||||||
stateAccountsDestruct[addr] = &obj.data
|
stateAccountsDestruct[addr] = &obj.data
|
||||||
destructAccountsOrigins[addr] = obj.origin
|
destructAccountsOrigins[addr] = obj.origin
|
||||||
}
|
}
|
||||||
deletes, delNodes, err := handleDestruction(s.db, s.trie, noStorageWiping, maps.Keys(stateAccountsDestruct), destructAccountsOrigins)
|
deletes, delNodes, err := handleDestruction(s.db, s.trie, s.originalRoot, noStorageWiping, maps.Keys(stateAccountsDestruct), destructAccountsOrigins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue