Draft: feat(thorchain): LUVI gate on store migrations
I'm checking which of the sibling luvi-guards MRs have already landed on develop, so the relation section stays accurate.
What
Every registered x/thorchain store migration now runs inside a report-only LUVI scope named migration/<from>to<to>. A CI gate also fails on undeclared LP-value losses in migrations.
- Runtime (report-only).
luviGuardMigrationsnapshots every pool before the migration runs, so it also catches raw store writes that bypassSetPool. A drop in a pool's hedged LP equity G emitsluvi_loss. A pool whose LPs lose everything emits kindremoved, orledgerwhen LP units vanish without withdraw events. Each changed pool gets a log line. The scope never fails an upgrade, and theLUVIGuardMimir turns it off. Migrations are now registered throughMigrator.luviMigrations()inluvi_migration.go, not one by one inmodule.go(seedocs/release.md). - CI gate.
LuviMigrateGateSuiteruns every registered migration against a fixture of mainnet-shaped pools (LPs, POL, synths).LuviMigrateMainnetGateSuiteruns the mainnet steps that move pools at mainnet depths: the 19to20 slash refunds (BTC, ZEC, TRON, SOL), the ETH.THOR restore and the low-synth burn, plus the 20to21 GAIA write-down. Both fail on any normalized G drop thatluviDeclaredWriteDownsdoes not declare. That list starts with 17to18 DOGE/GAIA (ADR-028) and 19to20 SOL/TRX (slash reversals).
The migration gate depends on the core LUVI guard (journal, luviScope, luvi_loss event, per-pool G accumulator and its luvi_* fields on the pool queries, LUVIGuard Mimir). This MR carries that guard too, with the parent branch's fixes and tests:
c9a69f6824: core guard, G accumulator andluvi_lossevents- guard, journal, accumulator and allowance tests, plus
LUVIGuarddocs;luvi_staris reported as ofluvi_height - the rounding allowance scales with swap legs (
RoundingOps) - accumulators advance at the end of EndBlock
- EndBlock scopes skip losses that an inner handler scope already reported
- the allowance now covers the virtual synth depth subsidy (
LuviSynthSubsidyAllowance). WhenVirtualMultSynthsBasisPointsis above 1x, each synth swap leg gets an allowance estimated from its slip, and the 1e-6 report threshold applies only past that subsidy. Synth swaps on mocknet (2x) therefore no longer report a configured transfer as a loss. At 1x, the mainnet default, both are zero. While the multiplier is above 1x, flows that change synth supply still only report and are not rejected. - the
docs/mimir.mdLUVIGuardentry now lists the covered EndBlock steps, theledgercheck and the synth-subsidy exception - lint fixes and a test helper rename (
luviMigrationLossEvents)
Relation to the other luvi-guards splits
This is one of several standalone MRs split out of odin/luvi-guards. It builds and passes its tests without the others:
odin/luvi-guards-overhang(!5295 (merged)): LP-unit overflow fix andLUVIOverhangGuard. Already on develop, and this branch sits on top of it.odin/luvi-guards-reward: reward allocation check. It also carries the core guard commit, but not the later guard fixes listed above.odin/luvi-guards-fairprice: oracle-priced fair LP unit value on pool queriesodin/luvi-guards-fuzz: fuzz targets and invariant spec
Whichever of this MR and the reward MR lands second drops the shared core commit at rebase. If the reward MR lands first, this MR's guard fixes still apply on top of it. Expect trivial adjacent-line conflicts in the /pool querier and query_pool.proto (the fair-value fields next to the luvi_* fields).
Left out on purpose: the parent's tc-debug luvi_forensics.py skill.
Regression fixtures
Fixtures were regenerated with EXPORT=1. Only two kinds of change remain:
- 14 added
luvi_lossevents (kinddrop,excess: false) in 9 fixtures undergas/,slash/,security/,tor/andvault-deficit/. These are gas and slash reimbursements onMsgOutboundTx,MsgRefundTxandendblock/gasthat the allowance covers but that exceed the 1e-6 report threshold. No fixture has an excess event. wasm/bindingsasserts the rawQueryPoolResponsebytes, which now carry theluvi_*fields 34–38.
An earlier regeneration also added report-only events on mocknet synth swaps. The synth-subsidy allowance removed all of them.
Risk
Consensus-visible through the core guard:
- user value flows that lower a pool's G beyond the allowance are rejected and refunded
- a new per-pool accumulator KV record is written in EndBlock
- there are new
luvi_lossevents - there are new
luvi_*fields on the pool queries
LUVIGuard (default 1) gates the guard and the events; the accumulator always runs. The synth-subsidy allowance only widens the allowance when VirtualMultSynthsBasisPoints is above 1x, so it has no effect on mainnet defaults. The migration scope itself only reports: it adds KV reads and events at upgrade time and never changes migration results.
Test plan
-
go test -tags=mocknet ./x/thorchain/... ./constants/... ./app/... - LUVI suites (
-check.f Luvi):LuviGuardSuite,LuviMigrateGateSuite,LuviMigrateMainnetGateSuite,LuviInvariantSuiteandLuviOverhangGuardSuite, plusLuviAllowanceSuiteinx/thorchain/types(including the synth-subsidy allowance tests) -
make lint-ci -
make generate, then a cleangit status - Regression fixtures regenerated with
EXPORT=1 - CI green (test-regression matches the regenerated fixtures)