Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: Provide txPool.txsByPriceAndNonce with correct vm for fetching txs to build block #2333

Merged
merged 1 commit into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/client/lib/miner/miner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions packages/client/lib/miner/pendingBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`
)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/client/lib/service/txpool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, TypedTransaction[]>()
Expand All @@ -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
Expand Down