Skip to content

Test derived trades integration#2590

Closed
findolor wants to merge 1 commit into
arda/derived-trades-read-pathfrom
arda/derived-trades-tests
Closed

Test derived trades integration#2590
findolor wants to merge 1 commit into
arda/derived-trades-read-pathfrom
arda/derived-trades-tests

Conversation

@findolor
Copy link
Copy Markdown
Collaborator

@findolor findolor commented May 22, 2026

Chained PRs

Depends on #2589. Stack order: #2587 -> #2588 -> #2589 -> #2590

Motivation

The derived read model touches schema, sync maintenance, bootstrap/export, and trade reads. The stack needs focused coverage for incremental replacement, clear/reset behavior, and read equivalence expectations.

Solution

  • Add SQLite integration coverage for rebuilding take rows from older active orders.
  • Cover clear trades producing distinct alice and bob derived rows.
  • Cover incremental windows replacing only their block range while preserving older rows.
  • Update export fixtures so bootstrap dumps include derived_trades.

Checks

  • COMMIT_SHA=local nix develop -c cargo test -p raindex_common local_db::query --lib
  • COMMIT_SHA=local nix develop -c cargo test -p raindex_common local_db::pipeline::adapters::apply --lib
  • COMMIT_SHA=local nix develop -c cargo test -p raindex_common local_db::export --lib
  • COMMIT_SHA=local nix develop -c cargo test -p raindex_common raindex_client::trades --lib

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f045bd54-29b4-469b-bd38-a158b69d345f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch arda/derived-trades-tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Collaborator Author

findolor commented May 22, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label Raindex-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.

@findolor findolor changed the base branch from arda/derived-trades-read-path to graphite-base/2590 May 23, 2026 13:46
@linear
Copy link
Copy Markdown

linear Bot commented May 23, 2026

RAI-644

@findolor findolor force-pushed the graphite-base/2590 branch from 1abc55d to aac028c Compare May 23, 2026 13:47
@findolor findolor force-pushed the arda/derived-trades-tests branch from 6bf1396 to 2334e5b Compare May 23, 2026 13:47
@findolor findolor changed the base branch from graphite-base/2590 to arda/derived-trades-read-path May 23, 2026 13:47
@findolor
Copy link
Copy Markdown
Collaborator Author

Folded into #2587 so the derived-trades local DB schema generation lands atomically.

@findolor findolor closed this May 23, 2026
graphite-app Bot pushed a commit to ST0x-Technology/st0x.rest.api that referenced this pull request May 26, 2026
## 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 -->

[![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](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 -->
graphite-app Bot pushed a commit that referenced this pull request May 26, 2026
## Motivation

Trade-list reads should use a pipeline-maintained local DB read model instead of reconstructing trades from source event tables on every request. This keeps producer bootstrap DBs and client incremental syncs on the same schema generation and avoids landing partial local DB protocol changes on `main`.

## Solution

- Add `derived_trades` as the derived/read-model table for local DB trades.
- Maintain `derived_trades` in the shared local DB apply pipeline in the same transaction as source event/state writes.
- Rebuild derived rows by sync window while allowing order resolution to look back to older active `AddOrderV3` events.
- Include the table in required-table checks, clear/reset paths, bootstrap export/import, and schema versioning.
- Update trade local DB read/count queries to read from `derived_trades` instead of reconstructing from event tables.
- Cover maintenance, incremental sync, bootstrap/export, clear/reset, and fetch equivalence with tests.

## Review note

This was folded from the previous split stack (#2588, #2589, #2590) so the local DB schema generation lands atomically.

## Checks

- `COMMIT_SHA=local nix develop -c cargo test -p raindex_app_settings --lib`
- `COMMIT_SHA=local nix develop -c cargo test -p raindex_common local_db::query --lib`
- `COMMIT_SHA=local nix develop -c cargo fmt --all`
- `git diff --check`

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Added a pipeline-maintained "derived trades" table with multiple indexes and an upsert refresh to speed and simplify trade queries.
  * Queries and exports now read from the derived-trades read model for faster, more consistent results.

* **Chores**
  * Database schema version bumped to 4; local DBs must be migrated/reinitialized to match the new schema.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

1 participant