Skip to content

Commit

Permalink
[backport] pd: fix behavior of simulation RPC (#4733)
Browse files Browse the repository at this point in the history
## Describe your changes
Backports the RPC fix in
#4731 to the
`release/v0.79.x` branch, in preparation for `v0.79.2`.

## Issue ticket number and link
Only #4731

## Checklist before requesting a review

- [x] If this code contains consensus-breaking changes, I have added the
"consensus-breaking" label. Otherwise, I declare my belief that there
are not consensus-breaking changes, for the following reason:

> RPC-only changes, already reviewed in #4731, and should be exactly the
same here.

Co-authored-by: Henry de Valence <[email protected]>
  • Loading branch information
conorsch and hdevalence authored Jul 22, 2024
1 parent 5cf137e commit c34b6de
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions crates/core/component/dex/src/component/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,8 @@ impl SimulationService for Server {

let mut state_tx = Arc::new(StateDelta::new(state));
let execution_circuit_breaker = ExecutionCircuitBreaker::new(execution_budget);
let Some(swap_execution) = state_tx

let swap_execution = match state_tx
.route_and_fill(
input.asset_id,
output_id,
Expand All @@ -655,10 +656,19 @@ impl SimulationService for Server {
)
.await
.map_err(|e| tonic::Status::internal(format!("error simulating trade: {:#}", e)))?
else {
return Err(tonic::Status::failed_precondition(
"there are no orders to fulfill this swap",
));
{
Some(swap_execution) => swap_execution,
None => SwapExecution {
traces: vec![],
input: Value {
amount: 0u64.into(),
asset_id: input.asset_id,
},
output: Value {
amount: 0u64.into(),
asset_id: output_id,
},
},
};

let unfilled = Value {
Expand Down

0 comments on commit c34b6de

Please sign in to comment.