diff --git a/packages/block/src/block/constructors.ts b/packages/block/src/block/constructors.ts index bab7a78495..62ac8ee0cb 100644 --- a/packages/block/src/block/constructors.ts +++ b/packages/block/src/block/constructors.ts @@ -119,6 +119,18 @@ export function createBlock(blockData: BlockData = {}, opts?: BlockOptions) { ) } +/** + * Simple static constructor if only an empty block is needed + * (tree shaking advantages since it does not draw all the tx constructors in) + * + * @param headerData + * @param opts + */ +export function createEmptyBlock(headerData: HeaderData, opts?: BlockOptions) { + const header = createBlockHeader(headerData, opts) + return new Block(header) +} + /** * Static constructor to create a block from an array of Bytes values * diff --git a/packages/block/test/block.spec.ts b/packages/block/test/block.spec.ts index e75feda9dc..6fc05bd7f5 100644 --- a/packages/block/test/block.spec.ts +++ b/packages/block/test/block.spec.ts @@ -20,6 +20,7 @@ import { createBlockFromBytesArray, createBlockFromRLPSerializedBlock, createBlockFromRPC, + createEmptyBlock, paramsBlock, } from '../src/index.js' @@ -46,6 +47,9 @@ describe('[Block]: block functions', () => { 'should use custom parameters provided', ) + const emptyBlock = createEmptyBlock({}, { common }) + assert.ok(bytesToHex(emptyBlock.hash()), 'block should initialize') + // test default freeze values // also test if the options are carried over to the constructor block = createBlock({}) diff --git a/packages/vm/src/runTx.ts b/packages/vm/src/runTx.ts index 79ca9b31ae..38d05486e0 100644 --- a/packages/vm/src/runTx.ts +++ b/packages/vm/src/runTx.ts @@ -1,4 +1,4 @@ -import { cliqueSigner, createBlock } from '@ethereumjs/block' +import { cliqueSigner, createEmptyBlock } from '@ethereumjs/block' import { ConsensusType, Hardfork } from '@ethereumjs/common' import { RLP } from '@ethereumjs/rlp' import { Blob4844Tx, Capability, isBlob4844Tx } from '@ethereumjs/tx' @@ -81,7 +81,7 @@ export async function runTx(vm: VM, opts: RunTxOpts): Promise { } // create a reasonable default if no block is given - opts.block = opts.block ?? createBlock({}, { common: vm.common }) + opts.block = opts.block ?? createEmptyBlock({}, { common: vm.common }) if (opts.skipHardForkValidation !== true) { // If block and tx don't have a same hardfork, set tx hardfork to block