Skip to content

feat: add fynd-benchmark generate-requests subcommand - #314

Open
tvinagre wants to merge 2 commits into
mainfrom
tl/generate-requests
Open

feat: add fynd-benchmark generate-requests subcommand#314
tvinagre wants to merge 2 commits into
mainfrom
tl/generate-requests

Conversation

@tvinagre

@tvinagre tvinagre commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Adds a generate-requests subcommand to fynd-benchmark that produces a per-chain synthetic swap-request dataset (JSON) for capacity load testing. The existing download-trades dataset is Ethereum-only; this covers other chains.

What it does

  • Fetches token and pool-count data from Tycho via the new fynd_rpc::protocols::fetch_token_pool_stats, which reuses the pool-count query behind derive-connector-tokens (counts pools per token, joins Tycho token metadata for symbols and decimals).
  • Samples token pairs weighted by pool count, excluding same-token pairs, using a seeded StdRng so output is deterministic for a given --seed and token set.
  • Log-spaces amounts across ~4 orders of magnitude around one whole token, scaled by each token's decimals.
  • Writes a JSON array loadable by the existing --requests-file loaders (load_request_templates / load_requests_from_file).

CLI

fynd-benchmark generate-requests --chain base [--tycho-url <url>] \
  --top-n-tokens 50 --num-requests 2000 --seed 42 --output trades.json

Accepted --chain values: ethereum, base, unichain, bsc, arbitrum, polygon (case-insensitive). zksync parses but has no default Tycho URL, so pass --tycho-url. The Tycho URL defaults to the chain's Fynd endpoint; auth uses TYCHO_API_KEY.

Tests and validation

Sampling and serialization are covered with fixture token data (no network): amount scaling, weighted pair sampling with no self-pairs, seed determinism, minimum-token guard, and a round-trip that loads the generated dataset back through load_request_templates.

The Tycho fetch is a thin network layer. Against a hosted endpoint it was exercised only up to the authentication boundary (the RPC call is made and auth is enforced). Live end-to-end generation against ethereum and base is validated in-cluster, where a one-off Job in the staging-fynd namespace runs the command with TYCHO_API_KEY mounted from the existing secret, so the key never leaves the cluster.

🤖 Generated with Claude Code

Generate a per-chain synthetic swap-request dataset for capacity load
testing, covering chains the Ethereum-only download-trades set does not.

Adds fynd_rpc::protocols::fetch_token_pool_stats, which reuses the Tycho
pool-count query behind derive-connector-tokens to return per-token pool
counts and decimals. The new subcommand samples token pairs weighted by
pool count (seeded StdRng, no self-pairs), log-spaces amounts around one
whole token, and writes a --requests-file-compatible JSON array.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

No API Breaking Changes Detected

The PR title signals breaking changes, but cargo-semver-checks found none.
If the breaking change is behavioral, CLI, or config-level (not public Rust API), this is expected.
Otherwise, consider using fix: instead of feat: in the PR title.

Add a client-side per-fetch timeout (--fetch-timeout-secs, default 300s)
so a degraded Tycho indexer fails fast with an error naming the stalled
protocol system, instead of hanging indefinitely (observed 18-minute
byte-flat stalls). Add --min-tvl, passed to the component query as
tvl_gt, which the dedicated tycho-fynd-* indexer endpoints require.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@tvinagre

Copy link
Copy Markdown
Collaborator Author

Two robustness fixes from production use on 2026-07-15 (commit e782f59):

Client-side fetch timeout. Against a degraded indexer (tycho-base-beta), the per-protocol-system component fetches hung indefinitely (18+ min byte-flat stalls). Each Tycho component fetch and the token-metadata fetch now run under a client-side deadline. New --fetch-timeout-secs flag (default 300s per fetch). On timeout the run fails fast with an error naming the protocol system that stalled and suggesting --protocols to exclude it, rather than hanging.

--min-tvl flag. The dedicated tycho-fynd-* indexers plan-gate component queries ("tvl_gt parameter is required on this plan"), so generate-requests previously could not query them at all. New optional --min-tvl passes tvl_gt to the component query (reusing the same with_tvl_gt mechanism the scale subcommand's --min-tvl builds on). The flag help notes that tycho-fynd-* endpoints require it.

Both new knobs are carried on a new TokenPoolStatsParams struct threaded into fynd_rpc::protocols::fetch_token_pool_stats.

Verification (nightly-2026-06-28): cargo fmt --check, clippy --all --all-features --all-targets -D warnings, and rustdoc all clean; cargo nextest run -p fynd-rpc -p fynd-benchmark = 126 passed. New tests cover the timeout error path (deadline reported, inner error surfaced, success passthrough) and CLI parsing of both flags.

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