Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 6b7b45d

Browse files
committed
refactor: remove ts-ignores and fix types (#3778)
1 parent 2b0487c commit 6b7b45d

File tree

3 files changed

+43
-38
lines changed

3 files changed

+43
-38
lines changed

src/chains/ethereum/ethereum/src/blockchain.ts

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ import type { InterpreterStep } from "@ethereumjs/evm";
2323
import { decode } from "@ganache/rlp";
2424
import { KECCAK256_RLP } from "@ethereumjs/util";
2525
import { Common } from "@ethereumjs/common";
26-
import { VM } from "@ethereumjs/vm";
26+
import { EEI, VM } from "@ethereumjs/vm";
2727
import {
2828
EvmError as VmError,
2929
EvmErrorMessage as ERROR,
30-
EVMResult
30+
EVMResult,
31+
EVM
3132
} from "@ethereumjs/evm";
3233
import { EthereumInternalOptions, Hardfork } from "@ganache/ethereum-options";
3334
import {
@@ -684,26 +685,27 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
684685
};
685686

686687
common = common || this.common;
687-
688-
// @ts-ignore
689-
const vm = new VM({
688+
const stateManager = this.fallback
689+
? // TODO: prefixCodeHashes should eventually be conditional
690+
// https://github.com/trufflesuite/ganache/issues/3701
691+
new ForkStateManager({
692+
trie: stateTrie as ForkTrie,
693+
prefixCodeHashes: false
694+
})
695+
: // TODO: prefixCodeHashes should eventually be conditional
696+
// https://github.com/trufflesuite/ganache/issues/3701
697+
new DefaultStateManager({ trie: stateTrie, prefixCodeHashes: false });
698+
699+
const eei = new EEI(stateManager, common, blockchain);
700+
const evm = new EVM({ common, allowUnlimitedContractSize, eei });
701+
const vm = await VM.create({
690702
activatePrecompiles: false,
691703
common,
692-
allowUnlimitedContractSize,
693704
blockchain,
694-
stateManager: this.fallback
695-
? // TODO: prefixCodeHashes should eventually be conditional
696-
// https://github.com/trufflesuite/ganache/issues/3701
697-
new ForkStateManager({
698-
trie: stateTrie as ForkTrie,
699-
prefixCodeHashes: false
700-
})
701-
: // TODO: prefixCodeHashes should eventually be conditional
702-
// https://github.com/trufflesuite/ganache/issues/3701
703-
new DefaultStateManager({ trie: stateTrie, prefixCodeHashes: false })
704-
}) as VM;
705-
// @ts-ignore
706-
vm.evm._allowUnlimitedContractSize = allowUnlimitedContractSize;
705+
stateManager,
706+
evm
707+
});
708+
707709
if (activatePrecompile) {
708710
await activatePrecompiles(vm.eei);
709711

@@ -1166,7 +1168,6 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
11661168
await vm.eei.putAccount(callerAddress, fromAccount);
11671169

11681170
// finally, run the call
1169-
// @ts-ignore types are dumbs
11701171
result = await vm.evm.runCall({
11711172
caller: callerAddress,
11721173
data: transaction.data && transaction.data.toBuffer(),
@@ -1189,7 +1190,6 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
11891190
context: transactionContext
11901191
});
11911192
if (result.execResult.exceptionError) {
1192-
// @ts-ignore types are dumbs
11931193
throw new CallError(result);
11941194
} else {
11951195
return Data.from(result.execResult.returnValue || "0x");
@@ -1225,23 +1225,31 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
12251225
)
12261226
: this.common;
12271227

1228+
const stateManager = this.fallback
1229+
? // TODO: prefixCodeHashes should eventually be conditional
1230+
// https://github.com/trufflesuite/ganache/issues/3701
1231+
new ForkStateManager({
1232+
trie: trie as ForkTrie,
1233+
prefixCodeHashes: false
1234+
})
1235+
: // TODO: prefixCodeHashes should eventually be conditional
1236+
// https://github.com/trufflesuite/ganache/issues/3701
1237+
new DefaultStateManager({ trie, prefixCodeHashes: false });
1238+
1239+
const eei = new EEI(stateManager, common, blockchain);
1240+
const evm = new EVM({
1241+
common,
1242+
allowUnlimitedContractSize:
1243+
this.#options.chain.allowUnlimitedContractSize,
1244+
eei
1245+
});
12281246
const vm = await VM.create({
12291247
activatePrecompiles: false,
12301248
common,
12311249
blockchain,
1232-
stateManager: this.fallback
1233-
? // TODO: prefixCodeHashes should eventually be conditional
1234-
// https://github.com/trufflesuite/ganache/issues/3701
1235-
new ForkStateManager({
1236-
trie: trie as ForkTrie,
1237-
prefixCodeHashes: false
1238-
})
1239-
: // TODO: prefixCodeHashes should eventually be conditional
1240-
// https://github.com/trufflesuite/ganache/issues/3701
1241-
new DefaultStateManager({ trie: trie, prefixCodeHashes: false })
1250+
stateManager,
1251+
evm
12421252
});
1243-
//@ts-ignore
1244-
vm._allowUnlimitedContractSize = this.vm.evm._allowUnlimitedContractSize;
12451253

12461254
const storage: StorageRecords = {};
12471255

@@ -1641,7 +1649,7 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
16411649
};
16421650

16431651
const rs = storageTrie.createReadStream();
1644-
// @ts-ignore
1652+
// @ts-ignore TODO: remove once https://github.com/ethereumjs/ethereumjs-monorepo/pull/2318 is released
16451653
rs.on("data", handleData).on("error", reject).on("end", handleEnd);
16461654
});
16471655
};

src/chains/ethereum/ethereum/src/helpers/precompiles.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ const makeAccount = (i: number): Address => {
3232
*/
3333
export const activatePrecompiles = async (eei: EEIInterface) => {
3434
await eei.checkpoint();
35-
const cache = (eei as any)._stateManager._cache;
3635
for (let i = 1; i <= NUM_PRECOMPILES; i++) {
3736
const account = makeAccount(i);
38-
cache.put(account, PRECOMPILED_ACCOUNT);
39-
(eei as any).touchAccount(account);
37+
eei.putAccount(account, PRECOMPILED_ACCOUNT);
4038
}
4139
await eei.commit();
4240
};

src/chains/ethereum/ethereum/src/miner/miner.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ export default class Miner extends Emittery<{
485485
returnValue: BUFFER_EMPTY
486486
}
487487
} as EVMResult;
488-
//@ts-ignore
489488
const error = new RuntimeError(tx.hash, e, RETURN_TYPES.TRANSACTION_HASH);
490489
tx.finalize("rejected", error);
491490
return null;

0 commit comments

Comments
 (0)