Skip to content

TxPool

Tx pool (mempool)

Memberof

module:service

Constructors

new TxPool()

new TxPool(options): TxPool

Create new tx pool

Parameters

options: TxPoolOptions

constructor parameters

Returns

TxPool

Defined in

TxPool.ts:118

Properties

BLOCKS_BEFORE_TARGET_HEIGHT_ACTIVATION

BLOCKS_BEFORE_TARGET_HEIGHT_ACTIVATION: number = 20

Activate before chain head is reached to start tx pool preparation (sorting out included txs)

Defined in

TxPool.ts:101


HANDLED_CLEANUP_TIME_LIMIT

HANDLED_CLEANUP_TIME_LIMIT: number = 60

Number of minutes to forget about handled txs (for cleanup/memory reasons)

Defined in

TxPool.ts:112


POOLED_STORAGE_TIME_LIMIT

POOLED_STORAGE_TIME_LIMIT: number = 20

Number of minutes to keep txs in the pool

Defined in

TxPool.ts:106


pool

pool: Map<string, TxPoolObject[]>

The central pool dataset.

Maps an address to a TxPoolObject

Defined in

TxPool.ts:80


running

running: boolean

Defined in

TxPool.ts:69


txsInPool

txsInPool: number

The number of txs currently in the pool

Defined in

TxPool.ts:85

Methods

_logPoolStats()

_logPoolStats(): void

Returns

void

Defined in

TxPool.ts:588


add()

add(tx, requireSignature, skipBalance): Promise<void>

Adds a tx to the pool.

If there is a tx in the pool with the same address and nonce it will be replaced by the new tx, if it has a sufficient gas bump. This also verifies certain constraints, if these are not met, tx will not be added to the pool.

Parameters

tx: TypedTransaction | ImpersonatedTx

Transaction

requireSignature: boolean = true

skipBalance: boolean = false

Returns

Promise<void>

Defined in

TxPool.ts:310


addUnverified()

addUnverified(tx): Promise<void>

Adds a tx to the pool without validating it.

If there is a tx in the pool with the same address and nonce it will be replaced by the new tx, if it has a sufficient gas bump. This also verifies certain constraints, if these are not met, tx will not be added to the pool.

Parameters

tx: TypedTransaction | ImpersonatedTx

Transaction

Returns

Promise<void>

Defined in

TxPool.ts:280


cleanup()

cleanup(): void

Regular tx pool cleanup

Returns

void

Defined in

TxPool.ts:374


close()

close(): void

Close pool

Returns

void

Defined in

TxPool.ts:581


deepCopy()

deepCopy(opt): TxPool

Parameters

opt: TxPoolOptions

Returns

TxPool

Defined in

TxPool.ts:128


getByHash()

getByHash(txHashes): (TypedTransaction | ImpersonatedTx)[]

Returns the available txs from the pool

Parameters

txHashes: readonly Uint8Array[]

Returns

(TypedTransaction | ImpersonatedTx)[]

Array with tx objects

Defined in

TxPool.ts:320


getBySenderAddress()

getBySenderAddress(address): Promise<TxPoolObject[]>

Parameters

address: EthjsAddress

Returns

Promise<TxPoolObject[]>

Defined in

TxPool.ts:456


open()

open(): boolean

Open pool

Returns

boolean

Defined in

TxPool.ts:141


removeByHash()

removeByHash(txHash): void

Removes the given tx from the pool

Parameters

txHash: string

Hash of the transaction

Returns

void

Defined in

TxPool.ts:341


removeNewBlockTxs()

removeNewBlockTxs(newBlocks): void

Remove txs included in the latest blocks from the tx pool

Parameters

newBlocks: Block[]

Returns

void

Defined in

TxPool.ts:361


start()

start(): boolean

Start tx processing

Returns

boolean

Defined in

TxPool.ts:153


stop()

stop(): boolean

Stop pool execution

Returns

boolean

Defined in

TxPool.ts:570


txsByPriceAndNonce()

txsByPriceAndNonce(baseFee): Promise<(TypedTransaction | ImpersonatedTx)[]>

Returns eligible txs to be mined sorted by price in such a way that the nonce orderings within a single account are maintained.

Note, this is not as trivial as it seems from the first look as there are three different criteria that need to be taken into account (price, nonce, account match), which cannot be done with any plain sorting method, as certain items cannot be compared without context.

This method first sorts the separates the list of transactions into individual sender accounts and sorts them by nonce. After the account nonce ordering is satisfied, the results are merged back together by price, always comparing only the head transaction from each account. This is done via a heap to keep it fast.

Parameters

baseFee = {}

Provide a baseFee to exclude txs with a lower gasPrice

baseFee.allowedBlobs?: number

baseFee.baseFee?: bigint

Returns

Promise<(TypedTransaction | ImpersonatedTx)[]>

Defined in

TxPool.ts:477