Indexer hybrid route optimizer: pass book_start_hint for first live-side order (GitLab #289 follow-up) #332
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#332
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?
Parent
Follow-up to GitLab #289 (book head-clog / hybrid scan cap — open). Product hardening: indexer route optimizer should pass
book_start_hintfor hybrid hops.Current codebase
HybridSwapParams.book_start_hint: Option<u64>(smartcontracts/packages/dex-common/src/pair.rs) — optional start order id for book walk; validated for side (#272). Wrong-side hints fall back to head without cross-escrow drain.hybrid_route_opt.rshybrid_sim_queryalways sends"book_start_hint": nullto LCDHybridSimulation(line ~110). Optimized plan setsbook_start_hint: Noneon outputHybridHopJson(line ~327).route_solver.rsforwardsbook_start_hintfrom hop JSON torouter_operationswhen non-null — but optimizer never populates it.book_start_hintto start past a clogged expired head once side validation exists — indexer should supply first live order id on the matching side when mirror/LCD book snapshot is available.Why this is needed
book_start_hint: null,degraded: true) when head simulation fails, even when live liquidity exists deeper in the book.Constraints / guardrails
book_snapshot_max_staleness_ms) — do not emit hint from stale mirror; degrade tonull.HybridSimulationmust match hint in finalrouter_operationspayload.nullhint remains valid default; no contract change required.Relevant files
indexer/src/api/hybrid_route_opt.rs—hybrid_sim_query,optimize_hop_hybrid,HybridHopJsonindexer/src/api/db_orderbook_sim.rs,indexer/src/indexer/book_snapshot.rsindexer/src/api/route_solver.rs,best_execution.rsindexer/tests/api_route_solve.rs,api_route_solve_db_hybrid.rssmartcontracts/contracts/pair/src/orderbook.rs—resolve_book_start_hintdocs/route-solver.md,skills/AGENTS_INDEXER_HYBRID_BEST_EXECUTION.mdRecommended direction
order_idasbook_start_hintinhybrid_sim_queryand in returnedHybridHopJsonwhenbook_input > 0.null.Acceptance criteria
optimize_hop_hybridsetsbook_start_hintto first live-side order id when book leg > 0 and mirror fresh.HybridSimulationqueries use same hint as output ops.book_start_hint: null(no regression).api_route_solvetests updated (replace hard-codednullexpectations where hint expected).Test plan — all paths
book_start_hintnullTest plan — attack / abuse / hack vectors
Verification criteria
cargo test --test api_route_solvegreen.EXPLAINnot required — functional book tests pass.POST /route/solvereturns non-nullbook_start_hinton book hop when live orders exist.marked as related to #289
mentioned in commit
63640f1c74mentioned in merge request !816
Implementation complete in !816.
Summary:
global_v2optimizer now emitsbook_start_hintfrom the first live same-side resting order when the mirror is fresh andbook_input > 0. Stale mirror / LCD fallback omits hint.Verification:
cd indexer && cargo test --lib db_orderbook_sim— PASScd indexer && cargo test --test api_route_solve --test api_route_solve_db_hybrid -- --test-threads=1— PASS (26 tests)Issue left open pending MR review/merge.
mentioned in commit
8edf0509e5#332 verified — checked on current main (merged #332 commit
63640f1). Indexer route-optimizer change; I covered source + unit + integration AND the live LocalTerra /route/solve check the implementation note marked SKIP.The skipped manual check — done. Brought the indexer up in DB-hybrid mode (ROUTE_SOLVER_DB_HYBRID=1, global_v4), seeded a resting bid on a leaf pair (IRON/EMBER — IRON only routes through that one pair, so no multi-hop can steal the route), let the book_snapshot loop mirror it, then GET /api/v1/route/solve token_in=IRON token_out=EMBER amount_in=10000000:
Output ~2.97 EMBER/IRON sits between the pool (2.0) and the bid (3.0), so the book leg is really being priced with the hint. Negative case also checked live: when the global solver routed EMBER->CORAL through a pool-only multi-hop (no book leg on the winning path), book_start_hint stayed null — no false hint.
Acceptance criteria:
Verification criteria:
One note: the hint path is DB-mirror-only (Lcd source -> None), so it only surfaces with ROUTE_SOLVER_DB_HYBRID=1 (global_v4), which is the #319+ production mode. Side safety stays on-chain authoritative (#272 / L17). @PlasticDigits — over to you for the verify-agent + close.
Verification — GitLab #332 (agent:verify)
Verified on branch
cursor/gitlab-issue-verification-5f14(includes merged commit63640f1).Issue: https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/work_items/332
Acceptance criteria
optimize_hop_hybridsetsbook_start_hintto first live-side order id whenbook_input > 0and mirror freshresolve_hop_book_start_hint→first_live_book_start_hintinhybrid_route_opt.rs; set onHybridHopJsonwhenbest_book > 0. Unit:first_live_book_start_hint_picks_match_side,first_live_book_start_hint_omits_wrong_side_in_bid_list. Integration: live head → hint42, expired head → hint77.HybridSimulationqueries use same hint as output opsbook_start_hintresolved once per hop; passed toquery_hybrid_sim_unified(DB mirror + LCD fallback) and stored on returnedHybridHopJson. LCD path omits hint whenbook_input == 0.book_start_hint: nullfirst_live_book_start_hintreturnsNonewhenfreshness != Fresh; integration stale case assertsbook_start_hintnull;HybridSimSource::Lcd→Noneby construction.api_route_solvetests updatedroute_solve_db_hybrid_book_start_hint_pathscovers live head, expired-head skip, stale mirror.docs/route-solver.mdglossary entry forbook_start_hint;skills/AGENTS_INDEXER_HYBRID_BEST_EXECUTION.md+skills/AGENTS_BOOK_MATCH_HINT_SECURITY.md.Verification criteria
cargo test --test api_route_solvecargo test --test api_route_solve_db_hybridroute_solve_db_hybrid_book_start_hint_paths)cargo test --lib db_orderbook_sim/route/solvenon-null hint on book hopmainby @Brouie (hint=1 on IRON→EMBER book hop,ROUTE_SOLVER_DB_HYBRID=1/global_v4). This run did not re-provision LocalTerra (no.env.local); integration test exercises the same HTTP + DB-mirror path.Test plan paths (automated coverage)
Nonehop json; hint only whenbest_book > 0)first_live_book_start_hint→None)42)77)first_live_book_start_hint_omits_wrong_side_in_bid_list)HopDescriptorinoptimize_one_hop)All acceptance and verification criteria pass. Closing #332.
mentioned in commit
bb38c9c219mentioned in commit
eaa159e0b4mentioned in commit
9dff5487b1mentioned in commit
9b1c1e3e30mentioned in issue #707
mentioned in issue #708