Skip to content

fix(sequencer): gate waitForMinTxs on age-eligible pending tx count - #24315

Merged
spalladino merged 3 commits into
merge-train/spartan-v5from
spl/a-1251-waitformintxs-gates-on-non-age-filtered-pending-count
Jun 29, 2026
Merged

fix(sequencer): gate waitForMinTxs on age-eligible pending tx count#24315
spalladino merged 3 commits into
merge-train/spartan-v5from
spl/a-1251-waitformintxs-gates-on-non-age-filtered-pending-count

Conversation

@spalladino

@spalladino spalladino commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Context

waitForMinTxs decided whether enough txs were available to build a block by polling p2pClient.getPendingTxCount(), which counts all pending txs regardless of age. The block builder, however, only iterates txs older than minTxPoolAgeMs (2000ms in production). When a fresh burst lands on a near-empty mempool the gate returned canStartBuilding: true immediately while the eligible iterator yielded zero txs, so the builder threw InsufficientValidTxsError and the sub-slot was wasted (worst case on the last sub-slot: an empty checkpoint and a skipped slot). The gate never actually waited for txs to age in.

Approach

Add an age-aware predicate hasEligiblePendingTxs(minCount) through the tx-pool → P2P → client layers and gate block building on it instead of the raw pending count, so the gate and the builder agree on age eligibility and the poll loop waits for aging (bounded by the existing startBuildingDeadline).

A predicate rather than an eligible count: the gate only needs to know whether at least minTxs eligible txs exist, and minTxs is typically 0 or 1. hasEligiblePendingTxs early-exits as soon as the threshold is met and short-circuits in O(1) when the total pending count is already below minCount (eligible txs are a subset of pending), instead of scanning the whole pool on every poll. getPendingTxCount() stays O(1) and is reused only for the informational tx count in logs/events; its semantics are unchanged. The two automine sequencer gates switch to the same predicate (a no-op under automine's minTxPoolAgeMs=0, kept for consistency).

API changes

New hasEligiblePendingTxs(minCount): Promise<boolean> on the internal TxPoolV2 and P2P interfaces (and the TxPoolIndices/TxPoolV2Impl layers). No public RPC change — stdlib's P2PApi is untouched.

Fixes A-1251

@spalladino spalladino added the S-do-not-merge Status: Do not merge this PR label Jun 26, 2026
@spalladino spalladino removed the S-do-not-merge Status: Do not merge this PR label Jun 26, 2026
@spalladino
spalladino enabled auto-merge (squash) June 26, 2026 12:57
@spalladino
spalladino merged commit e3f5386 into merge-train/spartan-v5 Jun 29, 2026
13 checks passed
@spalladino
spalladino deleted the spl/a-1251-waitformintxs-gates-on-non-age-filtered-pending-count branch June 29, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants