Repository navigation
[EASY] Replay a failed quote bundle with its logs - #5318
Conversation
|
Claude finished @squadgazzz's task in 1m 11s —— View job Review
The merge looks correct. The counterpart offsets come from the merged instruction count and only touch settlement-program I left one inline comment: a wallet's 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 |
| 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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
🤖 Claude reviewed this PR. Any issues are posted as inline comments on the relevant lines.
Won't run when: the PR is a draft, the author is a bot or lacks write access, or the |
jmg-duarte
left a comment
There was a problem hiding this comment.
I think there's space to improve the code readability here but otherwise it looks ok to me
| if args.simulate { | ||
| let rpc = rpc.as_ref().context("--simulate needs --rpc-url")?; | ||
| simulate( | ||
| rpc, | ||
| &decoded, | ||
| args.settlement_program, | ||
| args.compute_unit_limit, | ||
| ) | ||
| .await?; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Thanks, good to know. I'll switch to it once more flags depend on each other.
| 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}"); | ||
| } |
There was a problem hiding this comment.
you can extract this into a print_result function to separate reporting from execution
There was a problem hiding this comment.
Done, print_result does the reporting.
| 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"); | ||
| }; |
There was a problem hiding this comment.
this could be in a "pre-flight" function to validate that passed arguments are correct
There was a problem hiding this comment.
Done in a4a66a4, settlement_message checks the transactions before anything else runs.
| 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)?; | ||
| } |
There was a problem hiding this comment.
this bit could be its own function if im not mistaken and would return the built instruction already
There was a problem hiding this comment.
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?; |
There was a problem hiding this comment.
a lot of setup before even simulating, splitting the function would allow for easier comprehension here
There was a problem hiding this comment.
Split it in a4a66a4 into settlement_message, merge, decompile and print_result, so simulate only compiles, sends and prints.
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 thefailed quote bundletrace from #5305 shows only a code likeCustom(1), which may come from the settlement program or from a token transfer inside it.This PR adds
--simulateto thedecode_bundleexample. It merges the logged transactions in order and shifts the positionsBeginSettleandFinalizeSettleuse 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 --simulatereplays a bundle as one transactiondecode_bundlereads the v1 transactions that orderbook v2.388 logs in bincode's layoutHow to test
Replayed prod captures from 2026-11-18. asao's
(3, Custom(1))logsError: insufficient fundsinFinalizeSettle, and--compute-unit-limit 1061000reproduces a Raydium CLMM route running out of compute units.Related issues
BE-406