feat(thorchain): pending-liquidity receipts and errata reversal of reverted adds and swaps
🔎 Visual review: building it for8867571a; the link appears here.
What and why
Brings public develop to parity with the errata-reversal and pending-liquidity receipt handling shipped in mainnet 3.21.1.
- A
LiquidityPendingReceipt(new type) records a direct external ADD's pending primary share on theObservedTxVoter(pending_receipt = 13), with apending_batchlabel onLiquidityProvider. Errata of an add removes the exact pending claim, or socializes through pool balances via a fallback when there's no receipt. processErrataTxis rewritten to drop and unwind reverted advanced-swap queue items — returning never-paid outputs, burning stranded synth outputs, moving intermediate RUNE back between pools — to gate the add fallback onUpdatedVault(an inbound that never credited custody has no loss to fund), and to make the revert idempotent.- Supporting additions: keeper
GetAdvSwapQueueItemIndices,SwapState.IntermediateRune+GetIntermediateRuneOrZero, and anemitStreamingSwapEventhelper.
Stacked on the garbled-build parity MR (!5338); review/merge that first.
Parity notes for reviewers
This is a faithful port of already-shipped 3.21.1 code onto public develop, which has diverged. Two reconciliations worth a close look:
processErrataTxAttestationkeeps develop'squeueObservationTally(...)call (the observation-tally / excused-observers work that postdates 3.21.1 and isn't in the shipped tree). Only theprocessErrataTxbody + new helpers were taken from shipped; the attestation path is develop's.ObservedTxVotergainspending_receipt = 13while keeping develop'sexcused_observers = 16(field 13 was free on develop; this matches mainnet's wire layout).exact_memo_consensus (12)/first_observed_height (14)were intentionally not ported (not needed here).
⚠️ One open consensus-math question for the authors
x/thorchain/luvi_invariant_paths_test.go → TestErrataOfAddInboundUndoesTheDeposit (the assertBetween at ~line 628, "errata bounded below by the slip"):
With the new errata-of-add fallback (debitLiquidityErrataPool), reversing an asset-only external add returns the deposit's slip, but the resulting normalized dG lands just outside this public LUVI-invariant tolerance bound that was written against the old LP-unit-zeroing behaviour. I did not adjust the bound on my own judgment.
Please confirm which is correct:
- (a) the new debit is right and this public LUVI tolerance bound should be updated for the new behaviour, or
- (b) the fallback debit diverges from the invariant and needs a fix.
I also set UpdatedVault: true in that file's e.errata test helper (a real errata'd inbound credited its vault before reversal), which the new guard requires.
Risk
- Changes consensus / state (errata handling, a stored proto field on ObservedTxVoter) — faithful port of shipped-3.21.1 consensus code; the two reconciliations + the LUVI bound above are the items to verify.
Self-verification
go build -tags mainnet ./x/thorchain/... ./api/... # rc=0
go build -tags mocknet <touched pkgs> # rc=0
go test -tags mocknet -check.f 'ErrataPendingLiquiditySuite|HandlerErrataTxSuite|LuviInvariant' # 75/76 (the one above)
gofmt -l <changed .go> # clean
make proto-gen # pb/pulsar regeneratedKnown red test (reviewer call): LuviInvariantSuite.TestErrataOfAddInboundUndoesTheDeposit is left red and unwidened. The ported errata-of-add now debits the pool (debitLiquidityErrataPool), and its G-effect sits just below the public LUVI lower bound; this test does not exist in shipped-3.21.1. Whether to widen the bound for the corrected behaviour or treat it as a divergence is the errata authors call (son-of-odin).
Update (2026-11-10):
- New proto field #12 (closed)
SwapState.IntermediateRune(customtype Uint, default "0") — the double-swap RUNE-moved-between-pools accounting. Additive; serializes on every adv-swap-queue item ("0" when no double swap). - LUVI invariant test resolved:
TestErrataOfAddInboundUndoesTheDepositnow passes. The fix was in the test harness, not the bounds —luviEnv.errata()seeded the voter without a consensus status, so the reversal took the uncredited no-op path; marking the consensus txStatus_done(as an executed ADD really is) takes the unit-burn path. son-of-odin's invariant bounds are unchanged. - Regression goldens regenerated for the adv-swap-queue suites to carry the new
intermediate_runekey (additive, default "0"; no existing value/order changed). Needs thegoldens-reviewedlabel from a non-author reviewer (Itz is author).