feat(thorchain): pending-liquidity receipts and errata reversal of reverted adds and swaps

🔎 Visual review: building it for 8867571a; 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 the ObservedTxVoter (pending_receipt = 13), with a pending_batch label on LiquidityProvider. Errata of an add removes the exact pending claim, or socializes through pool balances via a fallback when there's no receipt.
  • processErrataTx is 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 on UpdatedVault (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 an emitStreamingSwapEvent helper.

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:

  1. processErrataTxAttestation keeps develop's queueObservationTally(...) call (the observation-tally / excused-observers work that postdates 3.21.1 and isn't in the shipped tree). Only the processErrataTx body + new helpers were taken from shipped; the attestation path is develop's.
  2. ObservedTxVoter gains pending_receipt = 13 while keeping develop's excused_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 regenerated

Known 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: TestErrataOfAddInboundUndoesTheDeposit now 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 tx Status_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_rune key (additive, default "0"; no existing value/order changed). Needs the goldens-reviewed label from a non-author reviewer (Itz is author).
Edited by Huginn Ai

Merge request reports

Loading
Loading