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

Allow transaction simulation to read blocks after the fork point #4425

Draft
wants to merge 14 commits into
base: poc/transaction_simulation
Choose a base branch
from
Prev Previous commit
Next Next commit
maybe fix. maybe make worse.
davidmurdoch committed May 30, 2023
commit a966e513073e8bde005ade29cf1ea9af4f9598a7
31 changes: 14 additions & 17 deletions src/chains/ethereum/ethereum/src/blockchain.ts
Original file line number Diff line number Diff line change
@@ -1459,12 +1459,12 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
const generateVM = async () => {
// note(hack): blockchain.vm.copy() doesn't work so we just do it this way
// /shrug
const trie = this.trie.copy(false);
trie.setContext(
parentBlock.header.stateRoot.toBuffer(),
null,
parentBlock.header.number
);
const trie = stateTrie.copy(false);
// trie.setContext(
// parentBlock.header.stateRoot.toBuffer(),
// null,
// parentBlock.header.number
// );

const vm = await this.createVmFromStateTrie(
trie,
@@ -1488,27 +1488,25 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
data: transaction.data?.toString(),
gas: transaction.gas?.toString(),
gasPrice: transaction.gasPrice?.toString(),
value: transaction.value?.toString()
//accesslists,
maxFeePerGas: runtimeBlock.header.baseFeePerGas.toString()
// maxFeePerGas: runtimeBlock.header.baseFeePerGas.toString()
} as any,
common
);

if (tx.from == null) {
tx.from = this.coinbase;
}
if (tx.gas.isNull()) {
// eth_estimateGas isn't subject to regular transaction gas limits
tx.gas = options.miner.callGasLimit;
}
tx.gas = options.miner.callGasLimit;

const block = new RuntimeBlock(
common,
Quantity.from(runtimeBlock.header.number),
Data.from(runtimeBlock.header.parentHash),
runtimeBlock.header.coinbase,
Quantity.from(runtimeBlock.header.gasLimit),
Quantity.from(runtimeBlock.header.gasUsed),
Quantity.Zero,
Quantity.from(runtimeBlock.header.timestamp),
Quantity.from(runtimeBlock.header.difficulty),
Quantity.from(runtimeBlock.header.totalDifficulty),
@@ -1518,10 +1516,7 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
);

const runArgs = {
tx: {
...tx.toVmTransaction(),
gasLimit: this.#options.miner.callGasLimit.toBigInt()
},
tx: tx.toVmTransaction(),
block,
skipBalance: true,
skipNonce: true,
@@ -1538,7 +1533,9 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
try {
const gasEstimate = await estimateProm;
results[i].gasEstimate = gasEstimate?.toBigInt();
} catch {}
} catch (e) {
console.error(e);
}
}
} else {
results[i] = {
8 changes: 7 additions & 1 deletion src/chains/ethereum/ethereum/src/helpers/gas-estimator.ts
Original file line number Diff line number Diff line change
@@ -310,7 +310,13 @@ const exactimate = async (
};
await vm.eei.checkpoint();
const result = await vm
.runTx({ ...runArgs, skipNonce: true } as unknown as RunTxOpts)
.runTx({
...runArgs,
skipNonce: true,
skipBalance: true,
skipBlockGasLimitValidation: true,
skipHardForkValidation: true
} as unknown as RunTxOpts)
.catch(vmerr => ({ vmerr }));
await vm.eei.revert();
if ("vmerr" in result) {