Skip to content

[EASY] Decode custom program error codes back into SettlementError - #160

Merged
squadgazzz merged 3 commits into
mainfrom
interface/settlement-error-tryfrom
Sep 18, 2026
Merged

squadgazzz merged 3 commits into
mainfrom
interface/settlement-error-tryfrom

Conversation

@squadgazzz

Copy link
Copy Markdown
Contributor

The conversions only went one way: a consumer reading a simulation result or transaction meta gets InstructionError(index, Custom(16)) and has to open this file to learn it means OrderExpired. This adds the reverse, TryFrom<u32> for SettlementError, so the services driver can log the variant name next to raw errors. An unknown code (a newer program than the consumer's interface crate) comes back unchanged in the Err. A test round-trips the whole contiguous discriminant range so a new variant cannot silently miss the mapping.

@squadgazzz squadgazzz changed the title Decode custom program error codes back into SettlementError [EASY] Decode custom program error codes back into SettlementError Sep 18, 2026
@squadgazzz
squadgazzz marked this pull request as ready for review September 18, 2026 12:21
@squadgazzz
squadgazzz requested a review from a team as a code owner September 18, 2026 12:21

@kaze-cow kaze-cow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so easy

@squadgazzz
squadgazzz merged commit d20b482 into main Sep 18, 2026
18 checks passed
@squadgazzz
squadgazzz deleted the interface/settlement-error-tryfrom branch September 18, 2026 12:29
PeterHackz pushed a commit to nexroute/services that referenced this pull request Sep 22, 2026
…rotocol#4940)

# Description
A settlement that fails simulation or submission surfaces as
`InstructionError(2, Custom(16))`, and whoever reads it opens the
interface crate to learn that 16 means `OrderExpired`.
cowprotocol/solana-programs#160 added the reverse conversion, so the
failed-simulation and failed-submission errors now carry the decoded
`SettlementError` inside them, and the settle task's single failure log
prints it, for example `settlement simulation failed: ..., settlement
error Some(OrderExpired)`. The simulation's own log line keeps only the
raw program logs, which removed a duplicate: previously every simulation
failure logged twice, once with the details and once from the settle
task. Only the settlement program's own instruction is decoded: a
foreign instruction (a Jupiter route step, for example) fails with its
own custom codes, and a code newer than the interface crate decodes to
nothing. The interface crate is patched to the merged commit until the
next release, the patch section carries the pointer. The wire error body
the autopilot receives keeps its static per-kind description.

# Changes
- `FailedToSubmit` and `SimulationFailed` carry the decoded
`SettlementError` when the failing instruction belongs to the settlement
program, and the settle failure log prints it
- Simulation failures log once, the simulation line keeps only the
program logs
- `cow-settlement-interface` patched to the commit with the decoding
until it releases

# How to test
New unit tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants