feat(thorchain): LUVI reward allocation check around pool reward payout
🔎 Visual review of8cbf0412: explainer, review flags and prompts to ask an AI about the change
The parent squash (bd8ca9e2c7) has landed on develop, so this MR now holds only three small follow-up commits. I'm writing the new description around those.
What
Follow-ups to the LUVI guard and reward check that landed on develop with the parent squash (bd8ca9e2c7, "LUVI guard, G accumulator, overhang/overflow guard, migration gate, reward check and fair LP pricing"). The base guard, the accumulator, RemovePool accumulator cleanup, the luvi_reward check and the nil-safe luviStatesEqual are all on develop already. What's left is one fix, one test and a doc update.
EndBlock scopes ignore rejected inner losses (x/thorchain/types/type_luvi.go)
When a user flow inside a wrapped EndBlock step is rejected, runLuviGuarded emits its luvi_loss event on the step's context with rejected=true, but it reverts the flow's state changes. NewLuviStepEvents used to count that event as an inner report for the pool. The step's own loss on that pool then looked as if it had already been reported, so the enclosing scope never emitted it (see the ev.Reported / ev.ReportedExcess skip in luvi_guard.go). NewLuviStepEvents now skips luvi_loss events with rejected=true. Only reports from committed inner flows suppress the step's own report.
Tests (x/thorchain/luvi_guard_test.go)
TestEndBlockScopeIgnoresRejectedInnerReports: a theft inside an EndBlock scope is rejected and reported once. The step then causes its own loss, and the scope still reports it as a secondluvi_losswithscope=endblock/test,excess=true,rejected=false.TestLuviStatesEqualNil:luviStatesEqualtreats a nil value as equal only to nil. Two all-nilLuviStates are equal, and a fully populated state is not equal to an all-nil one in either order.
Docs (docs/mimir.md)
The LUVIGuard entry now also covers the report-only pool reward check. For each rewarded pool it compares the change in G with the expected LP share of the reward. It also checks that the pool rewards add up to the rewards event and to the RUNE Asgard received. It emits luvi_reward for every failure, plus a sample per rewarded pool every 600 blocks. 0 turns off the guards, the reward check and their events.
Relation to the other luvi-guards splits
Develop absorbed the whole parent branch: overhang, fair price, migration gate, fuzz targets, reward check and the tc-debug luvi_loss forensics script. The standalone splits are now redundant except for any follow-ups like these that aren't on develop yet. Nothing in this MR depends on another open split.
Risk
Consensus-visible, but only on a narrow path. When a rejected user flow and the step's own loss hit the same pool inside one wrapped EndBlock step, the block now gets a luvi_loss event it used to drop. Nothing else changes: no state writes, no new rejections, and no regression fixtures change. LUVIGuard=0 still turns all LUVI events off.
Test plan
-
go test -tags=mocknet ./x/thorchain/ ./x/thorchain/types/ ./x/thorchain/keeper/... ./constants/ -
LuviGuardSuite(x/thorchain/luvi_guard_test.go), includingTestEndBlockScopeIgnoresRejectedInnerReportsandTestLuviStatesEqualNil -
make lint-ci - CI regression and simulation green