Skip to content

fix(dex): cap DEX order settlement per block to prevent consensus livelock#475

Merged
pablocampogo merged 1 commit into
mainfrom
add-cap-orders
Jul 17, 2026
Merged

fix(dex): cap DEX order settlement per block to prevent consensus livelock#475
pablocampogo merged 1 commit into
mainfrom
add-cap-orders

Conversation

@pablocampogo

Copy link
Copy Markdown
Collaborator

fix(dex): cap DEX order settlement per block to prevent consensus livelock

A released order backlog was locked into a single 830-order batch. Settling
it in begin_block took ~5.5s per ApplyBlock (paid twice on a single-validator
nested chain: once building, once validating), pushing the full BFT cycle past
the ~20s round budget. Because every root block resets the nested chain to
round 0 (NEW_COMMITTEE -> NewHeight(true)), the (2*round+1) timer escalation
could never kick in, so the chain livelocked at height 736327 and never
committed.

Bound the work per block with MaxOrdersSettledPerBlock (250). After the
pseudorandom sort, HandleDexBatchOrders settles only the first N orders and
breaks; overflow orders keep a zero receipt and are refunded to the seller on
the origin chain via HandleOrderReceipts (same path as a slippage failure).
The overflow path does no work on the nested chain (no AMM math, pool writes,
or events), so begin_block stays within the round budget while the oversized
batch still fully resolves - and rotates - in a single block.

Tests: add TestHandleDexBatchOrdersEnforcesSettlementCap (exactly the cap
settles; the remainder gets zero receipts for refund).

@pablocampogo
pablocampogo requested a review from ezeike July 17, 2026 05:04
@pablocampogo
pablocampogo merged commit 097ada9 into main Jul 17, 2026
2 checks passed
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