perf: TVL cap only when due, ASCII store keys, active validator count, GetPools pool memo

Four behavior-preserving speedups to hot thornode paths. Each one was measured on its own against the mainnet-weighted BenchmarkPerf* suite (scripts/perf/ab.sh: 10 interleaved base/candidate rounds, benchstat, and a KEEP that had to reproduce on an independent confirmation pass) and guarded with scripts/perf/guard.sh: unfiltered regtest with exports, block events, app_hash, gas_used and last_results_hash identical to the base. None of them changes store access inside a tx, so tx gas is unchanged.

commit change measured (pass 1 / confirmation)
perf(thorchain): check the TVL cap only when pending liquidity is due cleanupPendingLiquidity ran atTVLCap (every asgard vault, a pool per coin, every active validator) on every EndBlock. Its result only gates committing a due pool, so it now runs after the due pools are found, still once and before any commit. EndBlock store access is not part of gas_used. EndBlock/idle sec/op −9.5% / −10.7%, allocs −9.3%
perf(keeper): upper-case ASCII store keys straight into the key buffer GetKey upper-cases ASCII key parts byte by byte into the key buffer instead of building a strings.ToUpper copy; non-ASCII parts still go through strings.ToUpper, so keys are byte-identical. TorAnchorMimirKey drops fmt.Sprintf. DepositStreamingSwap allocs −5.2% / −5.2%
perf(thorchain): count active validators for the keysign-fail blame check TssKeysignHandler.validate only used len(ListActiveValidators), and the listing clones every active node account. The new Keeper.CountActiveValidators uses the same per-block cache, or walks the node account store with exactly the listing's Key/Value calls (same gas, asserted by the oracle test), and counts on the memoized decodings. TssKeysignFail sec/op −39.6% / −38.4%, allocs −44.2%
perf(keeper): memoize pool decodes in GetPools scans GetPools (GetAnchors per stable-swap check, EndBlock managers) decodes through a memo keyed by store key and checked against the exact bytes read, like the vault and node-account memos. Callers get a clone that shares no big.Int. Point reads in getPool stay uncached: they often follow a SetPool and would only miss. DepositStreamingSwap sec/op −19.6% / −19.9%, allocs −17.6%; EndBlock/streaming allocs −11.7%

Each commit's message carries its full benchstat table. Tests:

  • TestCleanupPendingLiquidityDueAndTVLCap: due or not due, crossed with capped or not capped. It passes on both the old and the new code.
  • TestGetKeyMatchesToUpper and TestTorAnchorMimirKey: compare against the old formula, including non-ASCII input, invalid UTF-8 input and both edges of the a–z range.
  • TestCountActiveValidators, plus a count check in TestListValidatorsByStatusMatchesOracle: same count, error and gas as the listing, through memo hits and misses, changed records and records that fail to decode.
  • TestPoolMatchesCodec, TestGetPoolsMatchCodec, TestPoolMutationIsolation and TestPoolRefFields: decoding matches the codec, gas is the same on hits and misses, callers get copies, and the test fails if a new reference field is added to Pool.

A consensus-safety review of each diff (map iteration, floats, wall-clock time, goroutines, panics, gas, protobuf/WASM) found no issues.

🤖 Generated with Claude Code

Merge request reports

Loading
Loading