fix(thorchain): VolumeMgr skips pools without volume quietly

🔎 Visual review of 05adf998: explainer, review flags and prompts to ask an AI about the change

Summary

VolumeMgr.EndBlock walks every pool and reads its 24h volume record. A pool that has not been swapped since volume tracking began has no record, so GetVolume returns Total volume not found and the manager logs fail to get volume at error level, for each such pool, every block. Then it skips the pool.

On mainnet that is 29 pools: the 16 derived THOR.* pools (never swapped directly), plus 13 old or suspended token pools (ETH.MKR-…, ETH.SNX-…, ETH.AAAA, …). That makes 29 error lines per block, about a quarter of everything a node logs during block execution (the replay below logged 58,000 of them in 2,000 blocks). Each line also costs the block thread real time: thornode's console log format JSON-encodes the event, then zerolog's ConsoleWriter decodes it again, calls os.Getwd (a stat syscall) to shorten the caller path, and writes it.

This makes GetVolume wrap a sentinel, keeperv1.ErrVolumeNotFound (the message is unchanged), and VolumeMgr skips those pools without logging. Other GetVolume errors (decode failures) still log.

Risk: low. The state path is identical: the pool was skipped before as well.

What changes

  • keeper/v1/keeper_volume.go: ErrVolumeNotFound. GetVolume returns fmt.Errorf("%w: pool=%s", …), so the text Total volume not found: pool=X is unchanged. The other callers (swap volume accounting and the pool queries) fall back to a new volume on any error, as before.
  • manager_volume_current.go: errors.Is(err, ErrVolumeNotFound) → continue without logging.

Evidence

Mainnet replay (scripts/perf/mainnet-replay.sh, 1,999 blocks 28124001..28125999 through the CometBFT handshake, which checks every block's app hash against mainnet). The same change was applied to the v3.20.3-based replay lab stack, 3 interleaved rounds per side.

CPU profiles summed over the 3 rounds:

before after Δ
VolumeMgr.EndBlock 14.5 s 8.1 s −44%
zerolog event writes (all log lines) 30.9 s 24.7 s −20%
FinalizeBlock 567.0 s 551.0 s −2.8%

Wall time: 286.6 → 271.9, 261.7 → 248.4, 231.6 → 229.2 s; median −5.1%. The host's load was falling through these runs (from about 50 down to 5) and each round runs the "before" side first, which favours "after". So I'd read the CPU numbers (about −3% of block execution) as the effect, not the wall median.

scripts/perf/guard.sh (unit tests, then unfiltered regtest vs develop): PASS, all 2,481 regression output files identical (state, events, gas_used).

Tests

  • keeper_volume_test.go: a missing volume matches errors.Is(err, ErrVolumeNotFound), and its message is exactly Total volume not found: pool=ETH.ETH.
  • manager_volume_current_test.go TestEndBlockSkipsPoolsWithoutVolume: one pool with a volume and one without. EndBlock logs no fail to get volume. The pool with a volume still rolls over (change into the bucket and total). The other still has no volume and no buckets. It fails without the manager change.

🤖 Generated with Claude Code

Edited by Huginn Ai

Merge request reports

Loading
Loading