Skip to content

Commit 5aead89

Browse files
[VM] fix account exists if account was previously deleted in cache
1 parent 02300d6 commit 5aead89

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/vm/lib/state/cache.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ export default class Cache {
5151
}
5252
}
5353

54+
/**
55+
* Returns true if the key was deleted and thus existed in the cache earlier
56+
* @param key - trie key to lookup
57+
*/
58+
keyIsDeleted(key: Buffer): boolean {
59+
const keyStr = key.toString('hex')
60+
const it = this._cache.find(keyStr)
61+
if (it.node) {
62+
return it.value.deleted
63+
}
64+
return false
65+
}
66+
5467
/**
5568
* Looks up address in underlying trie.
5669
* @param address - Address of account

packages/vm/lib/state/stateManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ export default class DefaultStateManager implements StateManager {
494494
*/
495495
async accountExists(address: Buffer): Promise<boolean> {
496496
const account = await this._cache.lookup(address)
497-
if (account) {
497+
if (account && !this._cache.keyIsDeleted(address)) {
498498
return true
499499
}
500500
if (await this._cache._trie.get(address)) {

0 commit comments

Comments
 (0)