Skip to content

Commit 0fa60a6

Browse files
committed
Fix take-order reselection after preflight failures (#2829)
## Dependent PRs - Rainix CI prerequisite (merge first): rainlanguage/rainix#295 - REST integration (merge after this): ST0x-Technology/st0x.rest.api#171 ## Motivation Take-order preflight could identify a reverting leg and remove it from the encoded config while retaining the original simulation totals. The returned calldata could therefore report `expectedSell` and `expectedBuy` for liquidity that was no longer executable. The old retry path also could not activate an unused fallback candidate or move to another Raindex. In the production incident at block 49,797,519, the initial two-leg simulation nearly filled a `0.05` spend. After one leg failed preflight, only `0.04310434222334697689407343024988324343123847171843280166595003948319` remained executable, but the response still reported the stale near-`0.05` total. ## Solution - Remove the exact failed candidate, including Raindex, order, IO indices, signed context, maximum output, and ratio. - Re-simulate the remaining global candidate pool and rebuild calldata, selected legs, and aggregate totals together. - Re-run Raindex selection after each removal so unused candidates and cross-Raindex fallbacks can be selected. - Re-check token approval whenever reselection changes the Raindex spender. - Distinguish recovered transient simulations from deterministic order failures. - Probe individual orders without the aggregate `minimumIO`, preventing healthy partial legs from being blamed in exact modes. - Skip a Raindex when an aggregate-only failure cannot be attributed to a single order. - Rank `SpendExact` simulations by fulfilled input, then output, before price and address tie-breaks. - Keep exact modes strict when remaining liquidity cannot meet the contract minimum. ## Regression coverage The incident regression reconstructs the logged two-leg values and verifies that removing the reverting leg rebuilds the result with the surviving executable input instead of the stale initial total. Additional tests cover partial spend and buy totals, unused fallbacks, duplicate executable orders, signed-context identity, cross-Raindex reselection, aggregate Raindex fallback, exact-mode insufficiency, and `SpendExact` ranking. ## Checks - `nix develop -c cargo test -p raindex_common` — 1,169 passed - `nix develop -c rainix-rs-static` - `nix develop -c cargo check -p raindex_common --target wasm32-unknown-unknown`
1 parent 4e5de9f commit 0fa60a6

5 files changed

Lines changed: 713 additions & 130 deletions

File tree

0 commit comments

Comments
 (0)