perf(bifrost/gaia): read solvency vault balances concurrently, without auth account reads
🔎 Visual review: building it for3a784508; the link appears here.
Problem
The GAIA client reports solvency every 10 blocks from FetchTxs, so the block at that height isn't handed on until the report is done. ReportSolvency reads each vault with GetAccount, one vault after another, and each GetAccount makes two gRPC queries in series: bank AllBalances and auth Account.
| Vaults with GAIA funds | Calls per report | At 100 ms per round trip |
|---|---|---|
| 8 | 16 | 1.6 s |
| 12 (during a churn) | 24 | 2.4 s |
Solvency compares coins only (IsVaultSolvent, Solvency.Coins), so the auth Account read, which returns the sequence and account number, is unused there.
!5387 (closed) (ETH) and !5394 (closed) (the shared EVM client) fix the same pattern with JSON-RPC batches. gRPC has no batch form, so this change reads the vaults concurrently instead.
Changes
getBalances(new): the bankAllBalancesquery and whitelist conversion, moved out ofGetAccountByAddress, which now calls it.GetAccountByAddressstill reads the auth account and returns the sameAccount.heightContext(new): the 10 s timeout andx-cosmos-block-heightmetadataGetAccountByAddressset up inline, shared by both paths, so a solvency read asks for the same height as before.readVaultCoins(new): reads each vault's balances withgetBalancesat the solvency height, at mostsolvencyReadConcurrency(8) vaults at a time (errgroupwithSetLimit), and returns the coins and errors aligned with the vaults.ReportSolvencyuses it in place of the serialGetAccountloop. 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 balance 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 two per vault.
Behaviour change in an edge case: a vault whose balance read succeeds but whose auth read would have failed is now reported. Before, the failed auth read skipped it.
solvencyLock already serialises ReportSolvency. The goroutines only read client state (bankClient, the scanner's whitelist).
Tests
cosmos_solvency_reads_test.go runs ReportSolvency with a bank client that answers AllBalances per address. It 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 height each read asked for. The auth client fails and counts every Account read.
- Concurrent reads, no auth reads: four vaults are all read at once, one balance read per vault, each pinned to the solvency height, with no auth reads. Each report carries its own vault's balance, in vault order.
- Cap: with 10 vaults the client 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 balance read fails is skipped, and the vaults on either side are reported with their own balances.
- Bad pubkey: a vault whose pubkey has no GAIA address is skipped, and the others are reported.
The existing GetAccountByAddress tests still cover the account path.
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 at the latest height instead of the solvency height;
- reading the auth account again.
go test -race is clean on the new tests.
Not covered
- Real TSS module:
tss-lib-privateisn't available to me, so I ran thegaiapackage tests (with and without-tags=mocknet) against a local stub of it that isn't in this branch. CI needs to confirm. make lint-ciandmake generate: neither runs in full without that module.golangci-lint1.63.4 with the repo config (default,mainnetandmocknettags), trunk on the changed files, the handler and chain-client skill lints, and the float analyzer are clean against the stub.lint-tokens.bashdidn't run, and this change touches no token lists or generated inputs.- Provider limits: a report now makes up to 8 gRPC queries at once, multiplexed on the client's existing connection. 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.