From af096237126531e8723cf067258ed843eb4dd209 Mon Sep 17 00:00:00 2001 From: Jochem Brouwer Date: Tue, 8 Oct 2024 15:36:55 +0200 Subject: [PATCH] t8ntool: fix setting correct extraBlobGas --- packages/vm/test/t8n/t8ntool.ts | 9 ++++--- packages/vm/test/util.ts | 43 ++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/packages/vm/test/t8n/t8ntool.ts b/packages/vm/test/t8n/t8ntool.ts index 52d9cae6cb..e322d9a241 100644 --- a/packages/vm/test/t8n/t8ntool.ts +++ b/packages/vm/test/t8n/t8ntool.ts @@ -1,4 +1,4 @@ -import { Block } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { EVMMockBlockchain, NobleBLS } from '@ethereumjs/evm' import { RLP } from '@ethereumjs/rlp' import { createTx } from '@ethereumjs/tx' @@ -12,7 +12,7 @@ import { join } from 'path' import { buildBlock, createVM } from '../../src/index.js' import { rewardAccount } from '../../src/runBlock.js' import { getCommon } from '../tester/config.js' -import { makeBlockFromEnv, setupPreConditions } from '../util.js' +import { makeBlockFromEnv, makeParentBlockHeader, setupPreConditions } from '../util.js' import { normalizeNumbers } from './helpers.js' import { StateTracker } from './stateTracker.js' @@ -21,6 +21,7 @@ import type { PostByzantiumTxReceipt } from '../../dist/esm/types.js' import type { BlockBuilder, VM } from '../../src/index.js' import type { AfterTxEvent } from '../../src/types.js' import type { T8NAlloc, T8NEnv, T8NOptions, T8NOutput, T8NReceipt, T8NRejectedTx } from './types.js' +import type { Block } from '@ethereumjs/block' import type { Common } from '@ethereumjs/common' import type { Log } from '@ethereumjs/evm' import type { TypedTxData } from '@ethereumjs/tx' @@ -80,12 +81,14 @@ export class TransitionTool { await this.setup(args) const block = makeBlockFromEnv(this.inputEnv, { common: this.common }) + const parentBlockHeader = makeParentBlockHeader(this.inputEnv, { common: this.common }) + const parentBlock = createBlock({ header: parentBlockHeader }, { common: this.common }) const headerData = block.header.toJSON() headerData.difficulty = this.inputEnv.parentDifficulty const builder = await buildBlock(this.vm, { - parentBlock: new Block(), + parentBlock, headerData, blockOpts: { putBlockIntoBlockchain: false }, }) diff --git a/packages/vm/test/util.ts b/packages/vm/test/util.ts index c2b8497a2b..8666624793 100644 --- a/packages/vm/test/util.ts +++ b/packages/vm/test/util.ts @@ -297,6 +297,34 @@ export function verifyGas(results: any, testData: any, t: tape.Test) { } } +export function makeParentBlockHeader(data: any, opts: BlockOptions) { + const { + parentGasLimit, + parentGasUsed, + parentBaseFee, + parentDifficulty, + parentTimestamp, + parentUncleHash, + parentBlobGasUsed, + parentExcessBlobGas, + parentBeaconBlockRoot, + } = data + return createBlockHeader( + { + gasLimit: parentGasLimit, + gasUsed: parentGasUsed, + baseFeePerGas: parentBaseFee, + difficulty: parentDifficulty, + timestamp: parentTimestamp, + uncleHash: parentUncleHash, + blobGasUsed: parentBlobGasUsed, + excessBlobGas: parentExcessBlobGas, + parentBeaconBlockRoot, + }, + { common: opts.common }, + ) +} + export function makeBlockHeader(data: any, opts?: BlockOptions) { const { currentTimestamp, @@ -309,9 +337,6 @@ export function makeBlockHeader(data: any, opts?: BlockOptions) { currentNumber, currentBaseFee, currentRandom, - parentGasLimit, - parentGasUsed, - parentBaseFee, } = data const headerData: any = { number: currentNumber, @@ -321,17 +346,10 @@ export function makeBlockHeader(data: any, opts?: BlockOptions) { gasLimit: currentGasLimit, timestamp: currentTimestamp, } + const parentBlockHeader = makeParentBlockHeader(data, { common: opts?.common }) if (opts?.common && opts.common.gteHardfork('london')) { headerData['baseFeePerGas'] = currentBaseFee if (currentBaseFee === undefined) { - const parentBlockHeader = createBlockHeader( - { - gasLimit: parentGasLimit, - gasUsed: parentGasUsed, - baseFeePerGas: parentBaseFee, - }, - { common: opts.common }, - ) headerData['baseFeePerGas'] = parentBlockHeader.calcNextBaseFee() } } @@ -344,6 +362,9 @@ export function makeBlockHeader(data: any, opts?: BlockOptions) { } if (opts?.common && opts.common.gteHardfork('cancun')) { headerData['excessBlobGas'] = currentExcessBlobGas + if (currentExcessBlobGas === undefined) { + headerData['excessBlobGas'] = parentBlockHeader.calcNextExcessBlobGas() + } } return createBlockHeader(headerData, opts) }