Raise limit book walk caps: 1k scan steps, 100 maker fills #262
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
code/cl8y-dex-terraclassic#262
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Raise on-chain book-walk ceilings so taker hybrid swaps can traverse deeper books and fill more distinct makers per tx, while keeping simulation parity, gas estimates, and the ~30M block gas cap as hard guardrails.
Related (closed): #248 (CW20 transfer aggregation — lowers per-fill message cost, making higher fill counts more practical).
Current codebase
smartcontracts/packages/dex-common/src/pair.rs):MAX_MAKER_FILLS_HARD_CAP= 256 — clampsHybridSwapParams.max_maker_fillsinmatch_bids/match_asks/simulate_match_*(makers_usedcap).MAX_SCAN_STEPS_EXTRA= 32;MAX_SCAN_STEPS= 288 (MAX_MAKER_FILLS_HARD_CAP + EXTRA) — every DLL iteration (fills, expired parks, expired skips, zero-remaining continues) counts one step; walk stops when budget exhausted (#254).MAX_EXPIRED_PARKS_PER_SWAP= 15 — write-heavy parks per walk (#250).smartcontracts/contracts/pair/src/orderbook.rs):book_walk_step+makers_used < capwherecap = max_maker_fills.min(MAX_MAKER_FILLS_HARD_CAP).smartcontracts/contracts/pair/src/contract.rs): partial book consumption spills to pool; attrsscan_steps_capped,expired_parks_*.frontend-dapp/src/services/terraclassic/hybridBookWalkLimits.tsfrontend-dapp/src/services/terraclassic/hybridSwapGas.ts(#249, #260)packages/localnet-trading-swarm/src/gas.tsmax_maker_fillson hybrid routes; book sim mirrors execute caps.docs/contracts-security-audit.md): documents current 256 / 288 / 15 caps.Why this is needed
scan_steps_capped=true).max_maker_fills(up to 100) and rely on a 1k scan budget for taker-side book walks without unbounded gas (prior #254 motivation).Constraints and guardrails
MAX_SCAN_STEPSshould reach 1000 without implyingMAX_MAKER_FILLS_HARD_CAP= 1000. Recommended:MAX_MAKER_FILLS_HARD_CAP = 100,MAX_SCAN_STEPS = 1000(revisitMAX_SCAN_STEPS_EXTRAor define scan cap independently — document formula index-commonanddocs/limit-orders.md).MAX_EXPIRED_PARKS_PER_SWAPor parks-per-sweep if needed.simulate_match_*andHybridSimulationmust use the same caps as execute (#254).UpdateLimitOrderConfig/ factory patterns.MAX_MAKER_FILLS_HARD_CAPis 256; target 100 is a lower hard ceiling on fills but a higher scan budget — confirm product intent in review (may be intentional trade-off: fewer fills, deeper walks).Relevant files
smartcontracts/packages/dex-common/src/pair.rssmartcontracts/contracts/pair/src/orderbook.rssmartcontracts/contracts/pair/src/contract.rsdocs/limit-orders.md,docs/contracts-security-audit.md(L5)smartcontracts/tests/src/limit_order_tests.rs,orderbook::proptest_limits,orderbook::expired_park_cap_testsfrontend-dapp/src/services/terraclassic/hybridBookWalkLimits.ts,hybridSwapGas.tspackages/localnet-trading-swarm/src/gas.tsskills/AGENTS_TERRACLASSIC_GAS.mdRecommended solution direction
MAX_MAKER_FILLS_HARD_CAP = 100andMAX_SCAN_STEPS = 1000(adjustMAX_SCAN_STEPS_EXTRAor remove coupling — document rationale).MAX_EXPIRED_PARKS_PER_SWAPvs new scan budget (parks are write-heavy; may stay 15–32 or scale modestly with benchmarks).gas_usedfor M=1, 10, 50, 100 makers and scan-capped expired-prefix scenarios (#252 style).Acceptance criteria
max_maker_fills> 100 is clamped to 100 on execute and sim.scan_steps_cappedattr when binding.HybridSimulationmatches execute when either cap binds.make test-contractslimit-order tests updated/green.hybridBookWalkLimits.ts/hybridSwapGas.ts/localnet-trading-swarmgas constants matchdex-common.docs/limit-orders.mdand invariant L5 updated with new numbers.Test plan — functional paths
max_maker_fills=100fills 100 distinct makers (bid + ask sides).max_maker_fills=200→ clamped to 100; economics correct.simulate_match_*andHybridSimulationparity when scan cap binds (not only maker cap).prop_match_*maker cap; scan step never exceeds 1000.Test plan — attack / abuse vectors
ORDERSreads per swap via params (hard cap).max_maker_fills=100still bounds distinct fills; no extra CW20 transfers beyond L10.checked_add.assert_max_spread/ pool spill rules.scan_steps_capped/ fill events still consistent for analytics.Verification criteria
make test-contractsgreen.docs/limit-orders.md(100-maker hybrid, scan-capped walk).orderbook::aggregation_tests).marked as related to #248
marked as related to #254
mentioned in commit
eed8d177deImplementation summary (merged to
main—eed8d17)Raised on-chain hybrid book-walk ceilings per #262 and kept execute/sim/dApp/swarm in lockstep.
On-chain (
dex-common::pair)MAX_MAKER_FILLS_HARD_CAP: 256 → 100 (clamps callermax_maker_fillson execute +simulate_match_*)MAX_SCAN_STEPS: 288 → 1000, decoupled from the maker cap (removedMAX_MAKER_FILLS_HARD_CAP + MAX_SCAN_STEPS_EXTRAcoupling)MAX_EXPIRED_PARKS_PER_SWAP: unchanged at 15Match loops in
orderbook.rsalready usemax_maker_fills.min(MAX_MAKER_FILLS_HARD_CAP)andbook_walk_stepagainstMAX_SCAN_STEPS— no logic changes required beyond constants.Frontend / swarm gas
hybridBookWalkLimits.tsandlocalnet-trading-swarm/src/gas.tsHYBRID_SWAP_GAS_LIMIT(1.2M) ceiling for anybook_input > 0tx; unit tests updated accordinglyDocs / agent playbooks
docs/contracts-security-audit.mddocs/limit-orders.md(scan budget, gas formula,scan_steps_cappedattr table)docs/frontend.md,skills/AGENTS_TERRACLASSIC_GAS.md,skills/AGENTS_FRONTEND_LIMIT_PARKED_EXPIRED.md,gaps/GAP_1780200149.mdTests run (green)
make test-contracts(336 integration + 27 pair unit tests, incl. scan-step cap + sim parity + proptest maker caps)frontend-dapp—hybridSwapGas.test.ts,transactions.test.tslocalnet-trading-swarm—gas.test.tsVerification checklist
make test-contractsgreen on your machinemax_maker_fills=100fills up to 100 distinct makers (bid + ask)max_maker_fills=200→ clamped to 100 on-chain; economics unchangedscan_steps_capped=true, pool spilloverHybridSimulationmatches execute when scan cap binds (not only maker cap)orderbook::aggregation_tests)Follow-ups
gas_usedtable for M=1/10/50/100 makers and scan-capped expired-prefix scenarios is still outstanding (#252); constants are raised but on-chain gas benchmarks should be recorded before mainnet deploy.HYBRID_SWAP_GAS_LIMIT(1.2M) should be raised separately if LocalTerra shows 100-maker + deep-scan txs need more headroom — current dApp envelope saturates at 1.2M for all book legs under offline worst case.Please verify the checklist above on LocalTerra when convenient. QA agent team — this is ready for independent verification; issue left open until sign-off.
Gas math correction (#262 follow-up)
The prior #262 implementation set
MAX_SCAN_STEPS = 1000while keeping the dAppHYBRID_SWAP_GAS_LIMIT = 1.2M. That pairing was inconsistent with measured book-walk cost:1000 scan steps implies we expect the chain to honor walks near the block ceiling while the wallet only budgets 1.2M — users would pay for a tx that cannot complete, or hit
out of gasafter signing too low a limit.Corrected targets:
MAX_SCAN_STEPS = 500— conservative headroom under the 15M / ~19k ≈ 789 order budget (scan steps include parks/skips, not only fills).HYBRID_SWAP_GAS_LIMIT = 15_000_000— raise the offline hybrid envelope so quote-drivenFee.gascan cover deep book walks without saturating at 1.2M while staying well under the 30M block cap.On-chain
MAX_MAKER_FILLS_HARD_CAP = 100unchanged. Implementing in a follow-up commit tomain/master.mentioned in commit
2d07b8deabmentioned in commit
389a55bc5bmentioned in merge request !733
Verified #262 on
d6701c4(with the #264 proptest fix above applied — needed it for a green run).Caps land as the corrected spec (MAX_MAKER_FILLS_HARD_CAP=100, MAX_SCAN_STEPS=500 not 1000,
HYBRID_SWAP_GAS_LIMIT=15M), aligned across dex-common, hybridBookWalkLimits.ts, hybridSwapGas.ts,
swarm gas.ts, docs/limit-orders.md and L5.
Live 100-maker worst case on LocalTerra (fresh genesis, 99 distinct makers, single pair):
Feeds the #252 gas table. Good to close from my side once the #264 proptest fix is merged.
@PlasticDigits
mentioned in issue #269
mentioned in issue #263
mentioned in issue #260
mentioned in issue #249
mentioned in issue #252
mentioned in issue #289
mentioned in issue #708