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:
parent
e2740b05ee
commit
863433cb77
@ -105,21 +105,17 @@ 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()
|
.iter()
|
||||||
);
|
.find(|tu| tu.aocl_leaf_index().is_some_and(|li| li == leaf_index))
|
||||||
if let Some(entry) = cache
|
{
|
||||||
.iter()
|
tracing::warn!("returning a cached utxo");
|
||||||
.find(|tu| tu.aocl_leaf_index().is_some_and(|li| li == leaf_index))
|
return Ok(Ok(Some(entry.addition_record().canonical_commitment)));
|
||||||
{
|
|
||||||
tracing::warn!("returning a cached utxo");
|
|
||||||
return Ok(Ok(Some(entry.addition_record().canonical_commitment)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rpc_result
|
rpc_result
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user