From c34b6de9d6cee015feceb3d88e169c7f8ea478b5 Mon Sep 17 00:00:00 2001 From: Conor Schaefer Date: Mon, 22 Jul 2024 14:58:45 -0700 Subject: [PATCH] [backport] pd: fix behavior of simulation RPC (#4733) ## Describe your changes Backports the RPC fix in https://github.com/penumbra-zone/penumbra/pull/4731 to the `release/v0.79.x` branch, in preparation for `v0.79.2`. ## Issue ticket number and link Only https://github.com/penumbra-zone/penumbra/pull/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 --- .../core/component/dex/src/component/rpc.rs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/core/component/dex/src/component/rpc.rs b/crates/core/component/dex/src/component/rpc.rs index d44de29cb9..89cef38079 100644 --- a/crates/core/component/dex/src/component/rpc.rs +++ b/crates/core/component/dex/src/component/rpc.rs @@ -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, @@ -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 {