From 54a623db759746d589709799daa96556e8760d1a Mon Sep 17 00:00:00 2001 From: harkamal Date: Thu, 6 Oct 2022 21:47:50 +0530 Subject: [PATCH] client: Provide txPool.txsByPriceAndNonce with correct vm for fetching txs to build block --- packages/client/lib/miner/miner.ts | 2 +- packages/client/lib/miner/pendingBlock.ts | 7 +++---- packages/client/lib/service/txpool.ts | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/client/lib/miner/miner.ts b/packages/client/lib/miner/miner.ts index 5f744138b3..46dee212b0 100644 --- a/packages/client/lib/miner/miner.ts +++ b/packages/client/lib/miner/miner.ts @@ -271,7 +271,7 @@ export class Miner { }, }) - const txs = await this.service.txPool.txsByPriceAndNonce(baseFeePerGas) + const txs = await this.service.txPool.txsByPriceAndNonce(vmCopy, baseFeePerGas) this.config.logger.info( `Miner: Assembling block from ${txs.length} eligible txs ${ typeof baseFeePerGas === 'bigint' && baseFeePerGas !== BigInt(0) diff --git a/packages/client/lib/miner/pendingBlock.ts b/packages/client/lib/miner/pendingBlock.ts index ea1ef072bf..79d43bef94 100644 --- a/packages/client/lib/miner/pendingBlock.ts +++ b/packages/client/lib/miner/pendingBlock.ts @@ -69,7 +69,7 @@ export class PendingBlock { this.pendingPayloads.push([payloadId, builder]) // Add current txs in pool - const txs = await this.txPool.txsByPriceAndNonce(baseFeePerGas) + const txs = await this.txPool.txsByPriceAndNonce(vm, baseFeePerGas) this.config.logger.info( `Pending: Assembling block from ${txs.length} eligible txs (baseFee: ${baseFeePerGas})` ) @@ -122,11 +122,10 @@ export class PendingBlock { return } const builder = payload[1] + const { vm, headerData } = builder as any // Add new txs that the pool received - const txs = ( - await this.txPool.txsByPriceAndNonce((builder as any).headerData.baseFeePerGas) - ).filter( + const txs = (await this.txPool.txsByPriceAndNonce(vm, headerData.baseFeePerGas)).filter( (tx) => (builder as any).transactions.some((t: TypedTransaction) => t.hash().equals(tx.hash())) === false diff --git a/packages/client/lib/service/txpool.ts b/packages/client/lib/service/txpool.ts index 07c0f630e5..3f6b293000 100644 --- a/packages/client/lib/service/txpool.ts +++ b/packages/client/lib/service/txpool.ts @@ -638,7 +638,7 @@ export class TxPool { * * @param baseFee Provide a baseFee to exclude txs with a lower gasPrice */ - async txsByPriceAndNonce(baseFee?: bigint) { + async txsByPriceAndNonce(vm: VM, baseFee?: bigint) { const txs: TypedTransaction[] = [] // Separate the transactions by account and sort by nonce const byNonce = new Map() @@ -647,7 +647,7 @@ export class TxPool { .map((obj) => obj.tx) .sort((a, b) => Number(a.nonce - b.nonce)) // Check if the account nonce matches the lowest known tx nonce - const { nonce } = await this.vm.eei.getAccount(new Address(Buffer.from(address, 'hex'))) + const { nonce } = await vm.eei.getAccount(new Address(Buffer.from(address, 'hex'))) if (txsSortedByNonce[0].nonce !== nonce) { // Account nonce does not match the lowest known tx nonce, // therefore no txs from this address are currently executable