Skip to content

Commit

Permalink
Check storage in get_blobs (#2609)
Browse files Browse the repository at this point in the history
## Motivation

`get_blobs` is used when we process confirmed blocks, so it's actually wrong to not check storage here.

## Proposal

Check storage also when searching for the blobs.

## Test Plan

CI but this will also be more triggered in following PRs

## Release Plan

- Nothing to do / These changes follow the usual release cycle.
  • Loading branch information
Andre da Silva authored Oct 14, 2024
1 parent 36cb370 commit 50e86cc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions linera-core/src/chain_worker/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,20 +345,29 @@ where
}

/// Returns the blobs requested by their `blob_ids` that are either in pending in the
/// chain or in the `recent_blobs` cache.
/// chain, in the `recent_blobs` cache or in storage.
async fn get_blobs(&self, blob_ids: HashSet<BlobId>) -> Result<Vec<Blob>, WorkerError> {
let pending_blobs = &self.chain.manager.get().pending_blobs;
let (found_blobs, not_found_blobs): (HashMap<BlobId, Blob>, HashSet<BlobId>) =
self.recent_blobs.try_get_many(blob_ids).await;

let mut blobs = found_blobs.into_values().collect::<Vec<_>>();
let mut missing_blobs = Vec::new();
for blob_id in not_found_blobs {
if let Some(blob) = pending_blobs.get(&blob_id) {
blobs.push(blob.clone());
} else if let Ok(blob) = self.storage.read_blob(blob_id).await {
blobs.push(blob);
} else {
missing_blobs.push(blob_id);
}
}

Ok(blobs)
if missing_blobs.is_empty() {
Ok(blobs)
} else {
Err(WorkerError::BlobsNotFound(missing_blobs))
}
}

/// Inserts a [`Blob`] into the worker's cache.
Expand Down

0 comments on commit 50e86cc

Please sign in to comment.