Use derived trades table for trade queries#113
Conversation
📝 WalkthroughWalkthroughThis PR replaces "orderbook" references with "raindex": dependency package names and submodule pointer updated; health snapshot mapping now iterates raindexes and uses a helper to produce orderbook-facing sync info; API responses and swap/cancel flows source identifiers/addresses from raindex(); tests and fixtures updated to registry schema v6 with raindexes. ChangesRaindex Terminology Migration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
How to use the Graphite Merge QueueAdd the label add-to-gt-merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
ad7af04 to
a1572a9
Compare
6ca6ad4 to
3bc07c8
Compare
a1572a9 to
f34b7a5
Compare
5996c20 to
a4dcac7
Compare
0fa10d5 to
8bfebed
Compare
a4dcac7 to
b106217
Compare
8bfebed to
22ed617
Compare
|
Preview validation passed for derived trades local DB sync. Context:
Validation:
Public-network benchmark from local machine:
The main improvement is on token/owner trade reads, where preview is roughly 10-25x faster than current production for the tested fixtures. |
e1625dc to
b9e930a
Compare
b106217 to
a7f8106
Compare
a7f8106 to
7678452
Compare
b9e930a to
7fdd35f
Compare
7fdd35f to
3fab88a
Compare
7678452 to
1c151e2
Compare
3fab88a to
c718e18
Compare
c718e18 to
80e940d
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/rain.orderbook`:
- Line 1: The submodule pointer for lib/rain.orderbook references an unreachable
commit (da24ba21571c...) instead of the actual current submodule HEAD
(80e940d7ad22...), so update the gitlink to a reachable commit that contains the
raindex#2590 "derived-trades" changes: fetch the submodule remote for
lib/rain.orderbook, identify the commit that implements raindex#2590, update the
submodule to that reachable commit (replace the bad hash with the real commit),
stage the submodule change in the superproject and commit the updated pointer so
the submodule update will succeed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 95c13372-0559-4e2f-8c65-508df8833c94
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (12)
Cargo.tomlinfra/terraform.tfstate.agelib/rain.orderbooksrc/routes/health.rssrc/routes/order/cancel.rssrc/routes/order/get_order.rssrc/routes/order/mod.rssrc/routes/orders/mod.rssrc/routes/swap/mod.rssrc/routes/tests.rssrc/routes/tokens.rssrc/test_helpers.rs
| @@ -1 +1 @@ | |||
| Subproject commit a18f47529657d793a76ee8ccecc12166d68aaac1 | |||
| Subproject commit da24ba21571c71015b69f41cf10782dba356c997 | |||
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Verify the rain.orderbook submodule commit is accessible and contains expected changes
cd lib/rain.orderbook || exit 1
# Check if the commit exists and is reachable
if git cat-file -e da24ba21571c71015b69f41cf10782dba356c997^{commit} 2>/dev/null; then
echo "✓ Commit da24ba21571c71015b69f41cf10782dba356c997 exists"
# Show commit message to verify it's the derived-trades implementation
echo -e "\n=== Commit message ==="
git log -1 --oneline da24ba21571c71015b69f41cf10782dba356c997
# Check for derived_trades or raindex related changes in recent history
echo -e "\n=== Recent commits referencing derived-trades or raindex ==="
git log --oneline --all --grep="derived.*trade\|raindex" -10
# List modified files in this commit to verify scope
echo -e "\n=== Files changed in target commit ==="
git show --stat --oneline da24ba21571c71015b69f41cf10782dba356c997
else
echo "✗ Commit da24ba21571c71015b69f41cf10782dba356c997 not found or not accessible"
echo "Fetch latest changes with: git fetch --all"
exit 1
fiRepository: ST0x-Technology/st0x.rest.api
Length of output: 194
🏁 Script executed:
#!/bin/bash
set -euo pipefail
cd lib/rain.orderbook
echo "== Submodule gitdir =="
git rev-parse --git-dir
echo "== Current HEAD =="
git rev-parse HEAD
git log -1 --oneline
echo "== Remotes =="
git remote -v || true
echo "== Commit presence checks =="
git cat-file -e da24ba21571c71015b69f41cf10782dba356c997^{commit} && echo "present" || echo "NOT present"
echo "== Any refs containing the hash (local only) =="
git branch --contains da24ba21571c71015b69f41cf10782dba356c997 2>/dev/null || true
echo "== Grep local objects (may be large; just check loose refs first) =="
git show-ref | rg -n 'da24ba21571c71015b69f41cf10782dba356c997' || echo "no local refs match"Repository: ST0x-Technology/st0x.rest.api
Length of output: 757
Fix submodule pointer to a reachable derived-trades commit
- The target submodule commit
da24ba21571c71015b69f41cf10782dba356c997is not present/reachable inlib/rain.orderbook; git reportsupload-pack: not our ref ..., so the commit can’t be inspected and the submodule update may fail. - Current submodule HEAD is
80e940d7ad22d9e9f8891f10f2f1ddfea0d896a9(“Use derived trades table from orderbook”), which doesn’t match the proposed hash. Update the pointer to an existing commit that matches the intendedraindex#2590derived-trades changes.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@lib/rain.orderbook` at line 1, The submodule pointer for lib/rain.orderbook
references an unreachable commit (da24ba21571c...) instead of the actual current
submodule HEAD (80e940d7ad22...), so update the gitlink to a reachable commit
that contains the raindex#2590 "derived-trades" changes: fetch the submodule
remote for lib/rain.orderbook, identify the commit that implements raindex#2590,
update the submodule to that reachable commit (replace the bad hash with the
real commit), stage the submodule change in the superproject and commit the
updated pointer so the submodule update will succeed.
Merge activity
|
## Dependent PRs This REST API PR depends on the raindex stack landing first: - [rainlanguage/raindex#2590: Test derived trades integration](rainlanguage/raindex#2590) - Graphite: https://app.graphite.com/github/pr/rainlanguage/raindex/2590 The submodule pointer in this PR is expected to reference the derived-trades implementation from that raindex stack. ## Summary - bump the orderbook submodule to the derived-trades implementation - alias the renamed raindex crates under the existing REST dependency names - update REST call sites and health mapping for the orderbook-to-raindex API rename ## Linear Part of RAI-580. ## Benchmark context Local server was run against the copied producer DB and localhost-served manifest/dump for the Base raindex. Health showed local DB sync active and the trade endpoints returned data from the SDK derived_trades path. HTTP timings from the local server: | Endpoint | Fixture | Rows returned / total | Time | Payload | | --- | --- | ---: | ---: | ---: | | GET /v1/trades/token/{USDC}?pageSize=20 | USDC | 20 / 9,813 | 0.315s | 10 KB | | GET /v1/trades/token/{USDC}?pageSize=50 | USDC | 50 / 9,813 | 0.412s | 25 KB | | GET /v1/trades/token/{USDC}?pageSize=500 | USDC | 500 / 9,813 | 1.703s | 253 KB | | GET /v1/trades/{owner}?pageSize=20 | top owner | 20 / 3,439 | 0.305s | 11 KB | | GET /v1/trades/{owner}?pageSize=50 | top owner | 50 / 3,439 | 0.397s | 27 KB | | GET /v1/trades/{owner}?pageSize=500 | top owner | 500 / 3,439 | 1.700s | 264 KB | | GET /v1/trades/taker/{address}?pageSize=20 | top taker | 20 / 1,921 | 0.311s | 10 KB | | GET /v1/trades/taker/{address}?pageSize=50 | top taker | 50 / 1,921 | 0.391s | 26 KB | | GET /v1/trades/taker/{address}?pageSize=500 | top taker | 500 / 1,921 | 1.652s | 264 KB | | GET /v1/trades/tx/{txHash} | 3-trade tx | 3 | 0.250s | 2 KB | | POST /v1/trades/query | 1 high-volume order hash | 587 | 1.848s | 291 KB | | POST /v1/trades/query | 5 high-volume order hashes | 2,600 | 7.133s | 1.36 MB | The direct SDK benchmark on the same copied DB returned USDC page size 20 in roughly 20 ms warm, with 9,813 matching trades. ## Validation - nix develop -c cargo check - nix develop -c cargo fmt - nix develop -c rainix-rs-static - local Rocket server health: /health/detailed returned active local DB sync - local authenticated trade endpoint benchmarks above returned data from derived_trades <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Reorganized internal data source references throughout the service, transitioning from orderbook-based to raindex-based identifier mapping for improved data consistency and architectural alignment. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/ST0x-Technology/st0x.rest.api/pull/113?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
80e940d to
4063edd
Compare
## Chained PRs Stacked on: - #113: Use derived trades table for trade queries ## Linear Fixes RAI-645. Part of RAI-580. ## Motivation `POST /v1/swap/quote` was spending quote/RPC time on orders whose requested output side had no positive vault balance. Those orders cannot contribute executable liquidity for the swap, so they are rejected later after the expensive candidate-building path has already run. ## Solution - Add `has_positive_output_vault_balance: Some(true)` to the swap quote order-pair query before building take-order candidates. - Keep response behavior unchanged for valid liquidity; the endpoint now avoids quoting empty-output orders earlier. ## Benchmark context Local benchmark against a ready Base local DB using a high-order pair: | Endpoint | Pair direction | Before | After | | --- | --- | ---: | ---: | | `POST /v1/swap/quote` | USDC -> `0x5cda...2204` | ~5.02s | ~3.21s | | `POST /v1/swap/quote` | `0x5cda...2204` -> USDC | ~4.56s | ~0.28s | The same positive-output-vault filter was temporarily tested in the raindex SDK `fetch_orders_for_pair` path for `POST /v1/swap/calldata`, then reverted locally because submodule changes need to land upstream: | Endpoint | Pair direction | Before | With SDK filter | | --- | --- | ---: | ---: | | `POST /v1/swap/calldata` | USDC -> `0x5cda...2204` | ~4.25s | ~2.25s | | `POST /v1/swap/calldata` | `0x5cda...2204` -> USDC | ~4.17s | ~0.26s | Follow-up: apply the same filter upstream in raindex `fetch_orders_for_pair`, then bump the submodule here so calldata gets the same benefit. ## Checks - `nix develop -c cargo fmt` - `nix develop -c cargo check` - `nix develop -c rainix-rs-static`
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/routes/tests.rs (1)
9-20:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAdd tracing/span propagation to
shared_client_contract
src/routes/tests.rs’s#[get("/shared-client")] async fn shared_client_contract(...)has noTracingSpan, no.instrument(span.0), and notracing::...logs. Update it to accept aspan: TracingSpanrequest guard (like other route handlers) and instrument the async client call with.instrument(span.0), with tracing for “request received” and error paths.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/routes/tests.rs` around lines 9 - 20, shared_client_contract currently lacks tracing/span propagation and logs; update the handler signature to accept a TracingSpan request guard (like other handlers), log a "request received" message with tracing::info! at the start of shared_client_contract, call provider.client().get_raindex_subgraph_client(orderbook_address) inside the async flow instrumented with .instrument(span.0), and on failure emit a tracing::error! with the error before mapping to ApiError::Internal (keep the existing return mapping but add the trace logging and span instrumentation around the client call).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/routes/tests.rs`:
- Around line 9-20: shared_client_contract currently lacks tracing/span
propagation and logs; update the handler signature to accept a TracingSpan
request guard (like other handlers), log a "request received" message with
tracing::info! at the start of shared_client_contract, call
provider.client().get_raindex_subgraph_client(orderbook_address) inside the
async flow instrumented with .instrument(span.0), and on failure emit a
tracing::error! with the error before mapping to ApiError::Internal (keep the
existing return mapping but add the trace logging and span instrumentation
around the client call).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1cc07759-c684-44c7-bdd9-4182a2b511d2
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (12)
Cargo.tomlinfra/terraform.tfstate.agelib/rain.orderbooksrc/routes/health.rssrc/routes/order/cancel.rssrc/routes/order/get_order.rssrc/routes/order/mod.rssrc/routes/orders/mod.rssrc/routes/swap/mod.rssrc/routes/tests.rssrc/routes/tokens.rssrc/test_helpers.rs
✅ Files skipped from review due to trivial changes (1)
- src/routes/tokens.rs
## Chained PRs Stacked on: - #113: Use derived trades table for trade queries ## Linear Fixes RAI-645. Part of RAI-580. ## Motivation `POST /v1/swap/quote` was spending quote/RPC time on orders whose requested output side had no positive vault balance. Those orders cannot contribute executable liquidity for the swap, so they are rejected later after the expensive candidate-building path has already run. ## Solution - Add `has_positive_output_vault_balance: Some(true)` to the swap quote order-pair query before building take-order candidates. - Keep response behavior unchanged for valid liquidity; the endpoint now avoids quoting empty-output orders earlier. ## Benchmark context Local benchmark against a ready Base local DB using a high-order pair: | Endpoint | Pair direction | Before | After | | --- | --- | ---: | ---: | | `POST /v1/swap/quote` | USDC -> `0x5cda...2204` | ~5.02s | ~3.21s | | `POST /v1/swap/quote` | `0x5cda...2204` -> USDC | ~4.56s | ~0.28s | The same positive-output-vault filter was temporarily tested in the raindex SDK `fetch_orders_for_pair` path for `POST /v1/swap/calldata`, then reverted locally because submodule changes need to land upstream: | Endpoint | Pair direction | Before | With SDK filter | | --- | --- | ---: | ---: | | `POST /v1/swap/calldata` | USDC -> `0x5cda...2204` | ~4.25s | ~2.25s | | `POST /v1/swap/calldata` | `0x5cda...2204` -> USDC | ~4.17s | ~0.26s | Follow-up: apply the same filter upstream in raindex `fetch_orders_for_pair`, then bump the submodule here so calldata gets the same benefit. ## Checks - `nix develop -c cargo fmt` - `nix develop -c cargo check` - `nix develop -c rainix-rs-static`

Dependent PRs
This REST API PR depends on the raindex stack landing first:
The submodule pointer in this PR is expected to reference the derived-trades implementation from that raindex stack.
Summary
Linear
Part of RAI-580.
Benchmark context
Local server was run against the copied producer DB and localhost-served manifest/dump for the Base raindex. Health showed local DB sync active and the trade endpoints returned data from the SDK derived_trades path.
HTTP timings from the local server:
The direct SDK benchmark on the same copied DB returned USDC page size 20 in roughly 20 ms warm, with 9,813 matching trades.
Validation
Summary by CodeRabbit