refactor: optimize check whether all blobs ready (#20711)

Co-authored-by: weixie.cui <weixie.cui@okg.com>
This commit is contained in:
cui
2026-01-05 19:53:06 +08:00
committed by GitHub
parent e8cc91ebc2
commit 58b0125784
2 changed files with 14 additions and 5 deletions

View File

@@ -75,7 +75,7 @@ impl DiskFileBlobStore {
// we must return the blobs in order but we don't necessarily find them in the requested
// order
let mut result = vec![None; versioned_hashes.len()];
let mut missing_count = result.len();
// first scan all cached full sidecars
for (_tx_hash, blob_sidecar) in self.inner.blob_cache.lock().iter() {
if let Some(blob_sidecar) = blob_sidecar.as_eip7594() {
@@ -83,12 +83,16 @@ impl DiskFileBlobStore {
blob_sidecar.match_versioned_hashes(versioned_hashes)
{
result[hash_idx] = Some(match_result);
missing_count -= 1;
}
}
// return early if all blobs are found.
if result.iter().all(|blob| blob.is_some()) {
return Ok(result);
if missing_count == 0 {
// since versioned_hashes may have duplicates, we double check here
if result.iter().all(|blob| blob.is_some()) {
return Ok(result);
}
}
}

View File

@@ -24,18 +24,23 @@ impl InMemoryBlobStore {
versioned_hashes: &[B256],
) -> Vec<Option<BlobAndProofV2>> {
let mut result = vec![None; versioned_hashes.len()];
let mut missing_count = result.len();
for (_tx_hash, blob_sidecar) in self.inner.store.read().iter() {
if let Some(blob_sidecar) = blob_sidecar.as_eip7594() {
for (hash_idx, match_result) in
blob_sidecar.match_versioned_hashes(versioned_hashes)
{
result[hash_idx] = Some(match_result);
missing_count -= 1;
}
}
// Return early if all blobs are found.
if result.iter().all(|blob| blob.is_some()) {
break;
if missing_count == 0 {
// since versioned_hashes may have duplicates, we double check here
if result.iter().all(|blob| blob.is_some()) {
break;
}
}
}
result