Introducing a new way to review your PRs.

Read the announcement

solana-foundation / pay

CLI for Agentic payments (x402, MPP, AP2).

View on GitHub

30 documents · Updated Nov 11, 2026

docs / runtime-benchmark-harness

Runtime benchmark harness

The runtime benchmark harness is a command-line tool that measures payment request throughput and checks the full payment lifecycle. It can rehearse a run on a local fork, drive a separate proxy for focused profiling, use reusable public-cluster fixtures, and leave enough durable evidence to recover funds or explain a result. For the runtime around the gateway and workers, see Rust payment runtime, client payment flows, and session channels and metering.

Operating model

Run configuration and safety

The run configuration is a YAML description of the payment scheme, network, funder, load shape, endpoint, and spend limits. The harness validates it before it creates clients or moves funds. Real-money runs also need an explicit --yes, and payment credentials use HTTPS unless the target is loopback or the operator enables the deliberate insecure-HTTP escape hatch.

The configuration separates measured load from setup policy. Load fields describe users, request rate, measured duration, concurrency, worker count, sharding, transport mode, and the minimum provisioning success rate. Session fields describe the channel deposit, voucher size, close policy, reuse mode, and optional signing isolation. RPC URLs and private CA paths can come from environment variables so shared YAML files do not need to contain secrets.

The supplied rust/…/session-load.yml is a fork-based proxy profiling profile. It models 100 users at 25 requests per second for 15 seconds with a 2,048-request in-flight limit. Its 1 USDC channel deposit and 0.001 USDC voucher show the required relationship between channel capacity and the measured window.

References: rust/…/config.rs• L1-6 rust/…/config.rs• L54-87 rust/…/config.rs• L99-175 rust/…/config.rs• L285-469 rust/…/main.rs• L33-59 rust/…/session-load.yml• L1-32

Payment schemes

The harness presents each payment method through one common run shape. It first learns the price from the endpoint's 402 Payment Required challenge, then creates the per-user request source used by the driver. The differences between schemes are the cost and lifecycle of that request source.

SchemePurposePayment lifecycle
mpp_sessionMeasure the high-rate session pathOpen one channel per user, send cumulative off-chain vouchers, then close and settle the channel.
mpp_chargeCheck end-to-end charge correctnessBuild a fresh on-chain-bound credential for each request. This path is expected to be chain-limited.
self_testFind the generator and proxy ceilingSend free requests through the proxy. It performs no funding, signing, or settlement.
x402_exactReserved for fixed-amount x402 measurementThe scheme is declared but its challenge parsing and request source are not implemented yet.

Successful HTTP responses count as accepted payments only when the request carried a logical payment. This keeps free-path capacity results separate from paid throughput. Native SOL and SPL-token challenges are also treated as distinct funding cases, with token decimals checked against the chain before a token budget is accepted.

References: rust/…/mod.rs• L23-38 rust/…/mod.rs• L145-207 rust/…/mpp_session.rs• L1-11 rust/…/mpp_charge.rs• L1-5 rust/…/selftest.rs• L1-8 rust/…/x402.rs• L1-9 rust/…/engine.rs• L58-105

Test lifecycle

Fixture and wallet lifecycle

The harness can create a reusable public-cluster fixture before repeated load runs. A fixture is a named, durable cohort of deterministic wallets and token accounts. Its setup plan has its own asset amounts and SOL cap, so preparing balances is an explicit operation rather than a hidden side effect of a load test.

The funder seed and a stable setup ID derive each user wallet. The same inputs reproduce the same wallet without storing user private keys in the journal. Setup reconciles current balances and can resume after interruption. Teardown returns token and SOL balances to the funder and closes derived token accounts so rent is reclaimed. A load run that uses --fixture-id validates the fixture's network, funder, and user count, then leaves fixture ownership to bench teardown for later reuse.

The fixture commands form a practical public-cluster workflow:

  1. bench setup creates or resumes the deterministic wallet and asset set.
  2. bench mint can extend the first asset's supply on devnet when the distributor needs more balance.
  3. bench run --fixture-id ... reuses the prepared wallets instead of funding a new cohort.
  4. bench export-fanout can publish recipient addresses without private keys.
  5. bench teardown returns balances and closes the derived accounts.

References: rust/…/fixtures.rs• L1-7 rust/…/fixtures.rs• L80-130 rust/…/fixtures.rs• L267-437 rust/…/fixtures.rs• L448-627 rust/…/wallet.rs• L1-15 rust/…/wallet.rs• L49-93 rust/…/wallet.rs• L126-143 rust/…/wallet.rs• L245-305

Pipeline stages

Every full run follows the same high-level sequence. The engine shares this sequence between fork rehearsal and public-cluster execution while the selected scheme supplies the payment-specific work.

flowchart LR
    A[Load and validate YAML] --> B[Probe 402 challenge]
    B --> C[Plan spend and enforce caps]
    C --> D[Derive and fund users]
    D --> E[Open or reuse payment state]
    E --> F[Prepare bounded request sources]
    F --> G[Measured unleash]
    G --> H[Close and settle channels]
    H --> I[Sweep residual balances]
    I --> J[Write report and complete journal]

Provisioning and settlement use separate concurrency limits because chain transactions have different capacity from request traffic. A run can tolerate some transient provisioning failures when its success threshold is below 1.0. Those users are excluded from the measured set, but any funding attempt remains part of cleanup so an ambiguous network response cannot silently strand a balance.

References: rust/…/engine.rs• L1-3 rust/…/engine.rs• L47-75 rust/…/engine.rs• L77-105 rust/…/engine.rs• L158-297 rust/…/engine.rs• L299-363 rust/…/engine.rs• L362-431

Request-driving engine

The driver turns each provisioned user into one bounded request source. A fixed set of workers owns disjoint source groups, which keeps session voucher order stable without creating one task and timer for every logical user. The default mode schedules requests at the configured per-user rate and limits total in-flight work.

The driver can instead use a closed-loop model. In that mode, a fixed lane sends the next request as soon as the prior request completes. Stable HTTP/2 mode keeps a fixed set of persistent connections open before timing starts. These options isolate gateway capacity from connection setup churn and are most useful for high-rate single-host tests.

The measured window excludes client and connection setup. The driver drains requests already in flight after the window, records requests that were scheduled but never dispatched as dropped, and keeps service, signing, scheduling, and end-to-end latency as separate measures.

References: rust/…/driver.rs• L1-6 rust/…/driver.rs• L53-100 rust/…/driver.rs• L345-435 rust/…/driver.rs• L473-558 rust/…/driver.rs• L560-624 rust/…/driver.rs• L640-790

Session recovery

Session recovery protects the gap between a client process and the live payment channel on chain. The run journal records channel IDs and funding intent before the related network calls complete. Wallet and session keys remain derivable from the funder seed and wallet namespace, so recovery can rebuild the client identity without a private-key export.

Normal session recovery discovers open fixture channels by their deterministic payer and expected session signer. It then obtains a fresh challenge and sends a close authorization through the live gateway. Reuse follows the same discovery path and selects the channel with the greatest settled watermark for each user, so a later run continues from the chain's last accepted amount.

If the gateway's session store is lost, recover-sessions --assume-no-vouchers is a separate, explicit path. It checks that channels have no non-zero settlement watermark or distribution plan unless --allow-settled is also given. It then moves channels through settle, distribute, and rent reclaim while refreshing blockhashes in bounded batches. A live session with close_after_run: false cannot be marked clean or swept by the normal pipeline because doing so could strand its channel deposit.

References: rust/…/session_recovery.rs• L41-99 rust/…/session_recovery.rs• L154-221 rust/…/session_recovery.rs• L224-415 rust/…/session_recovery.rs• L617-755 rust/…/mpp_session.rs• L323-417 rust/…/mpp_session.rs• L491-564 rust/…/config.rs• L188-245

Evidence and operations

Observability and reports

The harness emits console logs for run phases and can export traces and metrics to an OTLP collector. It uses a different service identity for the proxy-only serve process and the load generator, which keeps proxy measurements distinct from generator work. Optional Pyroscope profiling sends CPU samples for flamegraphs and stops the profiler before the process exits.

Each completed measured run prints a compact summary and writes bench-report-<run-id>.json in the current directory. The JSON records the selected measurement basis, target and achieved rates, request counts, status and error counts, latency percentiles, per-second rate series, and maximum in-flight work. It also includes a hash of the parsed configuration plus code and host fingerprints so results can be compared with their test environment.

Run journals live under ~/.config/pay/bench. They track phase transitions and per-user funding, channel, and sweep state. bench list-runs shows recorded runs and unswept users. The process warns when incomplete real-money runs exist, while bench recover currently closes the bookkeeping loop for ephemeral fork runs and reports that public-cluster sweep support is not yet implemented.

References: rust/…/observability.rs• L1-5 rust/…/observability.rs• L9-52 rust/…/main.rs• L206-239 rust/…/main.rs• L306-313 rust/…/main.rs• L365-454 rust/…/report.rs• L14-76 rust/…/report.rs• L78-147 rust/…/journal.rs• L1-7 rust/…/journal.rs• L157-218 rust/…/journal.rs• L227-375

Deployment workflow

The safest workflow starts with a fork rehearsal because it runs the same lifecycle against an ephemeral ledger and avoids real funds. For proxy-only profiling, bench serve starts the proxy and any fork in one process, while a second bench load process drives it. This split keeps the proxy's CPU profile free of generator work.

For a public devnet benchmark, prepare a fixture first and run the gateway as a separate service. The supplied rust/bench/deploy/pay-bench-devnet.service starts the release pay server from the devnet Pingora configuration, loads its environment from etc/…/devnet.env, binds TLS on port 1402, and restarts after failure. The benchmark executable is a separate load client; its package is not a workspace default member, so builds and runs must select pay-bench explicitly.

A typical validation path is:

  1. Build the release gateway and benchmark binaries explicitly.
  2. Start the devnet gateway with its system service or start a fork with bench serve.
  3. Run bench estimate against the YAML to inspect parsed settings.
  4. Use bench rehearse for a complete local lifecycle or bench load for an external proxy.
  5. Run the public fixture load only after checking the funder and spend caps.
  6. Inspect the JSON report and trace data, then close or tear down all reusable state.

References: rust/…/main.rs• L61-176 rust/…/main.rs• L242-303 rust/…/rehearsal.rs• L1-5 rust/…/rehearsal.rs• L210-275 rust/…/rehearsal.rs• L464-507 rust/…/Cargo.toml• L1-14 rust/…/pay-bench-devnet.service• L1-19

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to a scheme's challenge fields must stay aligned with funding caps, token-decimal checks, request headers, and report payment counts.
  • Changes to wallet derivation or a fixture's wallet-set identity must preserve the ability to find existing channels and reclaim balances from old journals.
  • Changes to session close or settlement behavior must update both the normal run cleanup and the gateway-store-loss recovery guards.
  • Changes to worker sharding, stable connections, or closed-loop timing must preserve the report's target, measurement basis, drain time, and dropped-request meaning.
  • Changes to the devnet service's bind address, TLS files, or environment contract must be reflected in the proxy URL, client transport checks, and deployment runbook.

Important failure modes

TriggerConsequenceGuard
A real-money run omits --yesThe run stops before funding begins.Require explicit confirmation when the network uses real funds.
Estimated SOL or token spend exceeds a capThe run is rejected before user funding.Resolve the challenge, verify token decimals on chain, and enforce finite hard caps.
A payment credential targets public cleartext HTTPThe request is refused before credentials are sent.Use HTTPS or loopback; use the insecure override only for a controlled benchmark.
A session open reaches chain but its response is lostA channel can remain open while the user looks provisioned failed.Persist the deterministic channel ID and close it before wallet sweep.
A reused fixture has the wrong funder, network, or sizeThe load run refuses to use it.Validate the fixture journal against the run configuration.
A live session run disables close after the measured windowThe run cannot safely sweep or report completion.Close the channels first or leave the journal outstanding for recovery.
The gateway session store is lost during provisioningNormal HTTP close recovery may not have voucher state.Use the explicit zero-voucher recovery path only when its chain-state checks pass.
x402_exact is selectedThe run stops because that scheme has no challenge or request source.Use mpp_session, mpp_charge, or self_test until x402 support is added.
Public-cluster recovery is requested through bench recoverThe command reports that mainnet and devnet recovery is not implemented.Use session-specific recovery where supported and retain the journal for follow-up.

Key files

FileWhy to read it
rust/…/main.rsDefines the operator-facing commands and connects rehearsal, load, fixture, recovery, reporting, and telemetry flows.
rust/…/config.rsDefines the YAML contract, network and safety rules, load controls, and session options.
rust/…/engine.rsShows the shared lifecycle from challenge probe through provisioning, measurement, settlement, and sweep.
rust/…/driver.rsExplains rate-paced and closed-loop request generation plus throughput and latency accounting.
rust/…/mpp_session.rsDescribes channel opening, voucher production, reuse, close behavior, and background signing.
rust/…/fixtures.rsDescribes reusable wallet and token-account setup, resume behavior, fanout export, minting, and teardown.
rust/…/session_recovery.rsDefines channel discovery, gateway-assisted close, direct recovery checks, and channel top-up.
rust/…/wallet.rsDefines deterministic wallet derivation and the funder roles used by fork, fixture, offline, and public runs.
rust/…/journal.rsDefines durable run and fixture state used to identify outstanding balances and resume cleanup.
rust/…/report.rsDefines the human summary and machine-readable report evidence.
rust/…/rehearsal.rsShows how the local fork, embedded proxy, offline verifier, and split serve/load workflow fit together.
rust/…/session-load.ymlProvides the focused high-concurrency session profile for proxy-only profiling.
rust/bench/deploy/pay-bench-devnet.serviceShows the systemd contract for running the devnet gateway that the benchmark drives.