From fd35014283c7d3a7a85c77b9fd647c9f09de12c9 Mon Sep 17 00:00:00 2001 From: Nadav Ivgi Date: Sun, 30 Jul 2023 00:50:38 +0300 Subject: [PATCH] Avoid asset registry deadlocks when looking up assets When the metadata was already provided by the caller, don't obtain a lock at all - there's no need to. In cases where acquiring the lock is necessary, release it immediately after reading the asset's metadata. --- src/elements/asset.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/elements/asset.rs b/src/elements/asset.rs index 98d9ccff9..f626996aa 100644 --- a/src/elements/asset.rs +++ b/src/elements/asset.rs @@ -377,10 +377,9 @@ pub fn lookup_asset( Ok(if let Some(row) = row { let reissuance_token = parse_asset_id(&row.reissuance_token); - let registry = registry.map(|r| r.read().unwrap()); let meta = meta - .or_else(|| registry.as_ref().and_then(|r| r.get(asset_id))) - .cloned(); + .cloned() + .or_else(|| registry.and_then(|r| r.read().unwrap().get(asset_id).cloned())); let stats = issued_asset_stats(query.chain(), &mempool, asset_id, &reissuance_token); let status = query.get_tx_status(&deserialize(&row.issuance_txid).unwrap());