Skip to content

Commit

Permalink
t8ntool: fix setting correct extraBlobGas (#3728)
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer authored Oct 8, 2024
1 parent 27b8e9f commit 036f63c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
9 changes: 6 additions & 3 deletions packages/vm/test/t8n/t8ntool.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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 = <PrefixedHexString>this.inputEnv.parentDifficulty

const builder = await buildBlock(this.vm, {
parentBlock: new Block(),
parentBlock,
headerData,
blockOpts: { putBlockIntoBlockchain: false },
})
Expand Down
43 changes: 32 additions & 11 deletions packages/vm/test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -309,9 +337,6 @@ export function makeBlockHeader(data: any, opts?: BlockOptions) {
currentNumber,
currentBaseFee,
currentRandom,
parentGasLimit,
parentGasUsed,
parentBaseFee,
} = data
const headerData: any = {
number: currentNumber,
Expand All @@ -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()
}
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 036f63c

Please sign in to comment.