From 863433cb77284a0ddb04a27bb5294cdac40b0f87 Mon Sep 17 00:00:00 2001 From: Alan Szepieniec Date: Wed, 13 Aug 2025 22:56:40 +0200 Subject: [PATCH] style: Simplify mock logic in UTXO RPC relayer Ignore the "MOCK" environment flag. Use the cache only if the node does not know the UTXO and the "mock" feature flag is set. It is safe to rely on node's response when the feature flag is not set because the only case in which the cache contains an entry that the node does not know about is when it was imagined previously, which can only happen if mocking is enabled. --- src/neptune_rpc.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/neptune_rpc.rs b/src/neptune_rpc.rs index 3d6c9dc..46748f5 100644 --- a/src/neptune_rpc.rs +++ b/src/neptune_rpc.rs @@ -105,21 +105,17 @@ impl AuthenticatedClient { return rpc_result; } - // if MOCK environment variable is set and feature is enabled, - // imagine some mock UTXO info + // If mocking is enabled, it is possible that the cache contains a UTXO + // for this index that was imagined in the past. #[cfg(feature = "mock")] - if std::env::var(MOCK_KEY).is_ok() { - let cache = _transparent_utxos_cache.lock().await; - tracing::warn!( - "RPC query failed and MOCK flag set, so seeing if we can return a cached utxo; cache has {} objects", cache.len() - ); - if let Some(entry) = cache - .iter() - .find(|tu| tu.aocl_leaf_index().is_some_and(|li| li == leaf_index)) - { - tracing::warn!("returning a cached utxo"); - return Ok(Ok(Some(entry.addition_record().canonical_commitment))); - } + if let Some(entry) = _transparent_utxos_cache + .lock() + .await + .iter() + .find(|tu| tu.aocl_leaf_index().is_some_and(|li| li == leaf_index)) + { + tracing::warn!("returning a cached utxo"); + return Ok(Ok(Some(entry.addition_record().canonical_commitment))); } rpc_result