Skip to content

Commit 0c20c94

Browse files
jochem-brouwerevertonfraga
authored andcommitted
[VM] cleanup some changes made in the TangerineWhistle PR
1 parent 2009f18 commit 0c20c94

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

packages/vm/lib/evm/opFns.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -680,12 +680,9 @@ export const handlers: { [k: string]: OpHandler } = {
680680
runState.eei.useGas(new BN(runState._common.param('gasPrices', 'callNewAccount')))
681681
}
682682
} else if (!(await runState.stateManager.accountExists(toAddressBuf))) {
683-
// We are before Spurious Dragon
683+
// We are before Spurious Dragon and the account does not exist.
684684
// Call new account gas: account does not exist (it is not in the state trie, not even as an "empty" account)
685-
const accountDoesNotExist = !(await runState.stateManager.accountExists(toAddressBuf))
686-
if (accountDoesNotExist) {
687-
runState.eei.useGas(new BN(runState._common.param('gasPrices', 'callNewAccount')))
688-
}
685+
runState.eei.useGas(new BN(runState._common.param('gasPrices', 'callNewAccount')))
689686
}
690687

691688
if (!value.isZero()) {

packages/vm/lib/state/cache.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,23 @@ export default class Cache {
5454
/**
5555
* Looks up address in underlying trie.
5656
* @param address - Address of account
57-
* @param create - Create emtpy account if non-existent
5857
*/
59-
async _lookupAccount(address: Buffer, create: boolean = true): Promise<Account | undefined> {
58+
async _lookupAccount(address: Buffer): Promise<Account> {
6059
const raw = await this._trie.get(address)
61-
if (raw || create) {
62-
const account = new Account(raw)
63-
return account
64-
}
60+
const account = new Account(raw)
61+
return account
6562
}
6663

6764
/**
6865
* Looks up address in cache, if not found, looks it up
6966
* in the underlying trie.
7067
* @param key - Address of account
71-
* @param create - Create emtpy account if non-existent
7268
*/
73-
async getOrLoad(key: Buffer, create: boolean = true): Promise<Account | undefined> {
69+
async getOrLoad(key: Buffer): Promise<Account> {
7470
let account = this.lookup(key)
7571

7672
if (!account) {
77-
account = await this._lookupAccount(key, create)
73+
account = await this._lookupAccount(key)
7874
if (account) {
7975
this._update(key, account as Account, false, false)
8076
}

packages/vm/lib/state/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface StorageDump {
1010
export interface StateManager {
1111
copy(): StateManager
1212
getAccount(address: Buffer): Promise<Account>
13-
putAccount(address: Buffer, account: Account | null): Promise<void>
13+
putAccount(address: Buffer, account: Account): Promise<void>
1414
deleteAccount(address: Buffer): Promise<void>
1515
touchAccount(address: Buffer): void
1616
putContractCode(address: Buffer, value: Buffer): Promise<void>

packages/vm/lib/state/stateManager.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ export default class DefaultStateManager implements StateManager {
8989
this.touchAccount(address)
9090
}
9191

92+
/**
93+
* Deletes an [`@ethereumjs/account`](https://github.com/ethereumjs/ethereumjs-vm/tree/master/packages/account)
94+
* from state under the provided `address`. The account will also be removed from the state trie.
95+
* @param address - Address of the account which should be deleted
96+
*/
9297
async deleteAccount(address: Buffer) {
9398
this._cache.del(address)
9499
this.touchAccount(address)
@@ -115,7 +120,7 @@ export default class DefaultStateManager implements StateManager {
115120
const codeHash = keccak256(value)
116121

117122
if (codeHash.equals(KECCAK256_NULL)) {
118-
//return
123+
return
119124
}
120125

121126
const account = await this.getAccount(address)

0 commit comments

Comments
 (0)