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.
This commit is contained in:
Alan Szepieniec 2025-08-13 22:56:40 +02:00
parent e2740b05ee
commit 863433cb77

View File

@ -105,22 +105,18 @@ impl AuthenticatedClient {
return rpc_result; return rpc_result;
} }
// if MOCK environment variable is set and feature is enabled, // If mocking is enabled, it is possible that the cache contains a UTXO
// imagine some mock UTXO info // for this index that was imagined in the past.
#[cfg(feature = "mock")] #[cfg(feature = "mock")]
if std::env::var(MOCK_KEY).is_ok() { if let Some(entry) = _transparent_utxos_cache
let cache = _transparent_utxos_cache.lock().await; .lock()
tracing::warn!( .await
"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() .iter()
.find(|tu| tu.aocl_leaf_index().is_some_and(|li| li == leaf_index)) .find(|tu| tu.aocl_leaf_index().is_some_and(|li| li == leaf_index))
{ {
tracing::warn!("returning a cached utxo"); tracing::warn!("returning a cached utxo");
return Ok(Ok(Some(entry.addition_record().canonical_commitment))); return Ok(Ok(Some(entry.addition_record().canonical_commitment)));
} }
}
rpc_result rpc_result
} }