Skip to content

Commit

Permalink
[VM] fix account exists if account was previously deleted in cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer authored and evertonfraga committed Jul 31, 2020
1 parent a360a81 commit bdbc197
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/vm/lib/state/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ export default class Cache {
}
}

/**
* Returns true if the key was deleted and thus existed in the cache earlier
* @param key - trie key to lookup
*/
keyIsDeleted(key: Buffer): boolean {
const keyStr = key.toString('hex')
const it = this._cache.find(keyStr)
if (it.node) {
return it.value.deleted
}
return false
}

/**
* Looks up address in underlying trie.
* @param address - Address of account
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/lib/state/stateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ export default class DefaultStateManager implements StateManager {
*/
async accountExists(address: Buffer): Promise<boolean> {
const account = await this._cache.lookup(address)
if (account) {
if (account && !this._cache.keyIsDeleted(address)) {
return true
}
if (await this._cache._trie.get(address)) {
Expand Down

0 comments on commit bdbc197

Please sign in to comment.