Skip to content

Commit 036f63c

Browse files
t8ntool: fix setting correct extraBlobGas (#3728)
1 parent 27b8e9f commit 036f63c

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

packages/vm/test/t8n/t8ntool.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Block } from '@ethereumjs/block'
1+
import { createBlock } from '@ethereumjs/block'
22
import { EVMMockBlockchain, NobleBLS } from '@ethereumjs/evm'
33
import { RLP } from '@ethereumjs/rlp'
44
import { createTx } from '@ethereumjs/tx'
@@ -12,7 +12,7 @@ import { join } from 'path'
1212
import { buildBlock, createVM } from '../../src/index.js'
1313
import { rewardAccount } from '../../src/runBlock.js'
1414
import { getCommon } from '../tester/config.js'
15-
import { makeBlockFromEnv, setupPreConditions } from '../util.js'
15+
import { makeBlockFromEnv, makeParentBlockHeader, setupPreConditions } from '../util.js'
1616

1717
import { normalizeNumbers } from './helpers.js'
1818
import { StateTracker } from './stateTracker.js'
@@ -21,6 +21,7 @@ import type { PostByzantiumTxReceipt } from '../../dist/esm/types.js'
2121
import type { BlockBuilder, VM } from '../../src/index.js'
2222
import type { AfterTxEvent } from '../../src/types.js'
2323
import type { T8NAlloc, T8NEnv, T8NOptions, T8NOutput, T8NReceipt, T8NRejectedTx } from './types.js'
24+
import type { Block } from '@ethereumjs/block'
2425
import type { Common } from '@ethereumjs/common'
2526
import type { Log } from '@ethereumjs/evm'
2627
import type { TypedTxData } from '@ethereumjs/tx'
@@ -80,12 +81,14 @@ export class TransitionTool {
8081
await this.setup(args)
8182

8283
const block = makeBlockFromEnv(this.inputEnv, { common: this.common })
84+
const parentBlockHeader = makeParentBlockHeader(this.inputEnv, { common: this.common })
85+
const parentBlock = createBlock({ header: parentBlockHeader }, { common: this.common })
8386

8487
const headerData = block.header.toJSON()
8588
headerData.difficulty = <PrefixedHexString>this.inputEnv.parentDifficulty
8689

8790
const builder = await buildBlock(this.vm, {
88-
parentBlock: new Block(),
91+
parentBlock,
8992
headerData,
9093
blockOpts: { putBlockIntoBlockchain: false },
9194
})

packages/vm/test/util.ts

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,34 @@ export function verifyGas(results: any, testData: any, t: tape.Test) {
297297
}
298298
}
299299

300+
export function makeParentBlockHeader(data: any, opts: BlockOptions) {
301+
const {
302+
parentGasLimit,
303+
parentGasUsed,
304+
parentBaseFee,
305+
parentDifficulty,
306+
parentTimestamp,
307+
parentUncleHash,
308+
parentBlobGasUsed,
309+
parentExcessBlobGas,
310+
parentBeaconBlockRoot,
311+
} = data
312+
return createBlockHeader(
313+
{
314+
gasLimit: parentGasLimit,
315+
gasUsed: parentGasUsed,
316+
baseFeePerGas: parentBaseFee,
317+
difficulty: parentDifficulty,
318+
timestamp: parentTimestamp,
319+
uncleHash: parentUncleHash,
320+
blobGasUsed: parentBlobGasUsed,
321+
excessBlobGas: parentExcessBlobGas,
322+
parentBeaconBlockRoot,
323+
},
324+
{ common: opts.common },
325+
)
326+
}
327+
300328
export function makeBlockHeader(data: any, opts?: BlockOptions) {
301329
const {
302330
currentTimestamp,
@@ -309,9 +337,6 @@ export function makeBlockHeader(data: any, opts?: BlockOptions) {
309337
currentNumber,
310338
currentBaseFee,
311339
currentRandom,
312-
parentGasLimit,
313-
parentGasUsed,
314-
parentBaseFee,
315340
} = data
316341
const headerData: any = {
317342
number: currentNumber,
@@ -321,17 +346,10 @@ export function makeBlockHeader(data: any, opts?: BlockOptions) {
321346
gasLimit: currentGasLimit,
322347
timestamp: currentTimestamp,
323348
}
349+
const parentBlockHeader = makeParentBlockHeader(data, { common: opts?.common })
324350
if (opts?.common && opts.common.gteHardfork('london')) {
325351
headerData['baseFeePerGas'] = currentBaseFee
326352
if (currentBaseFee === undefined) {
327-
const parentBlockHeader = createBlockHeader(
328-
{
329-
gasLimit: parentGasLimit,
330-
gasUsed: parentGasUsed,
331-
baseFeePerGas: parentBaseFee,
332-
},
333-
{ common: opts.common },
334-
)
335353
headerData['baseFeePerGas'] = parentBlockHeader.calcNextBaseFee()
336354
}
337355
}
@@ -344,6 +362,9 @@ export function makeBlockHeader(data: any, opts?: BlockOptions) {
344362
}
345363
if (opts?.common && opts.common.gteHardfork('cancun')) {
346364
headerData['excessBlobGas'] = currentExcessBlobGas
365+
if (currentExcessBlobGas === undefined) {
366+
headerData['excessBlobGas'] = parentBlockHeader.calcNextExcessBlobGas()
367+
}
347368
}
348369
return createBlockHeader(headerData, opts)
349370
}

0 commit comments

Comments
 (0)