Skip to content

[EASY] Replay a failed quote bundle with its logs - #5318

Merged
squadgazzz merged 2 commits into
mainfrom
solana-orderbook/be-406-replay-quote-bundle
Nov 20, 2026
Merged

squadgazzz merged 2 commits into
mainfrom
solana-orderbook/be-406-replay-quote-bundle

Conversation

@squadgazzz

Copy link
Copy Markdown
Contributor

Description

A failed quote settlement can only be explained by simulating it together with its order creation as one transaction. The settlement needs the created order, and only simulateTransaction, which takes one transaction, returns a failed transaction's logs.

The verifier simulates the two with simulateBundle, which drops a failed transaction's logs. So the failed quote bundle trace from #5305 shows only a code like Custom(1), which may come from the settlement program or from a token transfer inside it.

This PR adds --simulate to the decode_bundle example. It merges the logged transactions in order and shifts the positions BeginSettle and FinalizeSettle use to find each other. Then it simulates the result and maps the failing instruction back to its transaction. It reads the current state, so replay soon after the capture.

Changes

  • decode_bundle --simulate replays a bundle as one transaction
  • decode_bundle reads the v1 transactions that orderbook v2.388 logs in bincode's layout

How to test

Replayed prod captures from 2026-11-18. asao's (3, Custom(1)) logs Error: insufficient funds in FinalizeSettle, and --compute-unit-limit 1061000 reproduces a Raydium CLMM route running out of compute units.

Related issues

BE-406

@linear-code

linear-code Bot commented Nov 19, 2026

Copy link
Copy Markdown

BE-406

@squadgazzz
squadgazzz marked this pull request as ready for review November 19, 2026 14:47
@squadgazzz
squadgazzz requested a review from a team as a code owner November 19, 2026 14:47
@claude

claude Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @squadgazzz's task in 1m 11s —— View job


Review

  • Read diff
  • Post inline findings
  • Summary

The merge looks correct. The counterpart offsets come from the merged instruction count and only touch settlement-program BeginSettle/FinalizeSettle, and the failing instruction maps back to its transaction correctly.

I left one inline comment: a wallet's ComputeBudget instructions in the order-creation transaction get copied into the merged v1 message. That can get the replay rejected or override --compute-unit-limit. Dropping them fixes it.

I couldn't open the Solana SDK source in this environment, so I haven't confirmed whether v1 rejects these instructions outright. Either way they clash with the budget in config. I didn't build or run the example.

let mut origins = Vec::new();
for (n, (transaction, keys)) in transactions.iter().enumerate() {
let offset = u16::try_from(instructions.len())?;
for (index, instruction) in transaction.message.instructions().iter().enumerate() {

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.

The creation transaction can carry the wallet's own ComputeBudget instructions: create_order accepts and reads them (routes/create_order/mod.rs:399). This loop copies them into the merged v1 message too. But v1 keeps its compute budget in config, and the driver builds settlements from their instructions alone (settlement.rs:1407). So when the user's wallet added a SetComputeUnitLimit/SetComputeUnitPrice, the replay is either rejected or fights --compute-unit-limit. That breaks the CU reproduction this PR is for.

I'd skip instructions whose program_id == solana_compute_budget_interface::ID and leave the budget to config. The offset already comes from instructions.len(), so the counterpart positions stay correct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SIMD-0385 says v1 ignores compute budget instructions for configuration, even invalid ones, and runs them as successful no-ops. So they can't override --compute-unit-limit or get the replay rejected, they only cost their compute units. I'll keep them.

@github-actions

Copy link
Copy Markdown

🤖 Claude reviewed this PR. Any issues are posted as inline comments on the relevant lines.

  • Runs automatically when a PR is opened or marked ready for review.
  • Re-run it: comment @claude on this PR (requires write access; bots and drafts are skipped).
  • Skip it: add the skip-claude-review label.

Won't run when: the PR is a draft, the author is a bot or lacks write access, or the skip-claude-review label is set.

@jmg-duarte jmg-duarte 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.

I think there's space to improve the code readability here but otherwise it looks ok to me

Comment on lines +147 to +155
if args.simulate {
let rpc = rpc.as_ref().context("--simulate needs --rpc-url")?;
simulate(
rpc,
&decoded,
args.settlement_program,
args.compute_unit_limit,
)
.await?;

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.

Not needed now but if more relationships like these start emerging you might want to check https://docs.rs/clap/latest/clap/_derive/index.html#arggroup-attributes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, good to know. I'll switch to it once more flags depend on each other.

Comment on lines +216 to +232
println!(
"simulated at slot {}, {} compute units used, the settlement declares {:?}",
response.context.slot,
result.units_consumed.unwrap_or_default(),
message.config.compute_unit_limit,
);
let err = result.err.map(TransactionError::from);
if let Some(TransactionError::InstructionError(at, failure)) = &err
&& let Some((n, index)) = origins.get(usize::from(*at))
{
println!(" fails at transaction {n} instruction {index}: {failure:?}");
} else if let Some(err) = err {
println!(" fails: {err:?}");
}
for line in result.logs.unwrap_or_default() {
println!(" {line}");
}

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.

you can extract this into a print_result function to separate reporting from execution

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, print_result does the reporting.

Comment on lines +168 to +173
let Some((settlement, _)) = transactions.last() else {
bail!("no transaction to simulate");
};
let VersionedMessage::V1(message) = &settlement.message else {
bail!("the last transaction is not a v1 settlement");
};

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.

this could be in a "pre-flight" function to validate that passed arguments are correct

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in a4a66a4, settlement_message checks the transactions before anything else runs.

Comment on lines +180 to +196
let program_id = keys[usize::from(instruction.program_id_index)];
let accounts = instruction
.accounts
.iter()
.map(|&account| {
let account = usize::from(account);
AccountMeta {
pubkey: keys[account],
is_signer: transaction.message.is_signer(account),
is_writable: transaction.message.is_maybe_writable(account, None),
}
})
.collect();
let mut data = instruction.data.clone();
if program_id == settlement_program {
shift_counterpart(&mut data, offset)?;
}

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.

this bit could be its own function if im not mistaken and would return the built instruction already

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, decompile returns the built instruction now.

signatures: vec![Signature::default(); usize::from(merged.header.num_required_signatures)],
message: VersionedMessage::V1(merged),
};
let response = rpc.simulate_unsigned_transaction(&transaction).await?;

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.

a lot of setup before even simulating, splitting the function would allow for easier comprehension here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Split it in a4a66a4 into settlement_message, merge, decompile and print_result, so simulate only compiles, sends and prints.

@squadgazzz
squadgazzz enabled auto-merge November 20, 2026 14:14
@squadgazzz
squadgazzz added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit 63b3df0 Nov 20, 2026
21 checks passed
@squadgazzz
squadgazzz deleted the solana-orderbook/be-406-replay-quote-bundle branch November 20, 2026 14:21
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants