Skip to content

Commit

Permalink
Avoid asset registry deadlocks when looking up assets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shesek committed Aug 1, 2023
1 parent 69fee9c commit fd35014
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/elements/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit fd35014

Please sign in to comment.