perf(bifrost/xrp): read solvency vault accounts concurrently

🔎 Visual review: building it for 5139687c; the link appears here.

Problem

The XRP client reports solvency every solvency_blocks ledgers (10 by default) from the ordered scan loop, so the next ledger isn't scanned until the report is done. ReportSolvency reads each vault with GetAccount, one account_info request per vault at the solvency ledger, one vault after another.

Vaults with XRP funds Calls per report At 100 ms per round trip
6 6 0.6 s
12 (during a churn) 12 1.2 s

Ledgers close every 3–5 s, so a report holds up the scan for a sizeable part of a ledger interval.

rippled's JSON-RPC has no batch form, so, as in !5395 (closed) (TRON) and !5396 (closed) (GAIA), this change reads the vaults concurrently instead.

Changes

  • readVaultAccounts (new): reads each vault with the existing GetAccount call at the solvency ledger, at most solvencyReadConcurrency (8) vaults at a time (errgroup with SetLimit), and returns the accounts and errors aligned with the vaults.
  • ReportSolvency uses it in place of the serial loop. Everything after the reads is unchanged: the same coins per vault, the same report order and height, the same insolvent/all-clear logic. A vault whose read fails is still logged and skipped.

A report now costs one round trip for up to 8 vaults and two for up to 16, instead of one per vault. Each read is the same account_info request at the same ledger_index, so the balances don't change.

solvencyLock already serialises ReportSolvency. The goroutines share the xrpl-go RPC client, which builds a new request per call and only reads its config (including the shared header map), and bifrost's retryHTTPClient, which clones a request before retrying it.

Tests

solvency_reads_test.go adds tests to XrpTestSuite. They run ReportSolvency against a test server that answers account_info with a per-account balance. The server holds each read until a given number of them are in flight together, or 1 s has passed, and records the most it saw at once and the ledger each read asked for.

  • Concurrent reads: four vaults are all read at once, each pinned to the solvency ledger, and each report carries its own vault's balance, in vault order.
  • Cap: with 10 vaults the server holds reads until all 10 are in flight, which only an uncapped report reaches. At most 8 are seen together, and all 10 vaults are reported.
  • Failed read: a vault whose account_info fails is skipped, and the vaults on either side are reported with their own balances.
  • Bad pubkey: a vault whose pubkey has no XRP address is skipped, and the others are reported.

The existing ReportSolvency tests still pass.

Each of these made a test fail:

  • reading one vault at a time (SetLimit(1));
  • removing the cap;
  • ignoring a vault's read error;
  • storing results at the wrong index;
  • reading the current ledger instead of the solvency ledger.

go test -race is clean on the solvency tests.

Not covered

  • Real TSS module: tss-lib-private isn't available to me, so I ran the xrp package tests (with and without -tags=mocknet) against a local stub of it that isn't in this branch. CI needs to confirm.
  • make lint-ci and make generate: neither runs in full without that module. golangci-lint 1.63.4 with the repo config (default, mainnet and mocknet tags), trunk on the changed files, the chain-client skill lint and the float analyzer are clean against the stub. lint-tokens.bash didn't run, and this change touches no token lists or generated inputs.
  • Provider limits: a report now makes up to 8 requests at once. A provider that rate-limits that burst fails those reads, which are logged and skipped as before, so the vault isn't reported that round.
Edited by Huginn Ai

Merge request reports

Loading
Loading