Skip to content

Commit 18f37f9

Browse files
committed
core/state, trie: add DeleteAccount method ethereum#25531
1 parent 100369b commit 18f37f9

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

core/state/database.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ type Trie interface {
8686
// found in the database, a trie.MissingNodeError is returned.
8787
TryDelete(key []byte) error
8888

89+
// TryDeleteAccount abstracts an account deletion from the trie.
90+
TryDeleteAccount(key []byte) error
91+
8992
// Hash returns the root hash of the trie. It does not write to the database and
9093
// can be used even if the trie doesn't have one.
9194
Hash() common.Hash

core/state/statedb.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,9 @@ func (s *StateDB) deleteStateObject(obj *stateObject) {
498498

499499
// Delete the account from the trie
500500
addr := obj.Address()
501-
s.setError(s.trie.TryDelete(addr[:]))
501+
if err := s.trie.TryDeleteAccount(addr[:]); err != nil {
502+
s.setError(fmt.Errorf("deleteStateObject (%x) error: %v", addr[:], err))
503+
}
502504
}
503505

504506
// DeleteAddress removes the address from the state trie.

trie/secure_trie.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ func (t *StateTrie) TryDelete(key []byte) error {
189189
return t.trie.TryDelete(hk)
190190
}
191191

192+
// TryDeleteACcount abstracts an account deletion from the trie.
193+
func (t *StateTrie) TryDeleteAccount(key []byte) error {
194+
hk := t.hashKey(key)
195+
delete(t.getSecKeyCache(), string(hk))
196+
return t.trie.TryDelete(hk)
197+
}
198+
192199
// GetKey returns the sha3 Preimage of a hashed key that was
193200
// previously used to store a value.
194201
func (t *StateTrie) GetKey(shaKey []byte) []byte {

0 commit comments

Comments
 (0)