mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-09 07:17:56 -05:00
refactor: optimize check whether all blobs ready (#20711)
Co-authored-by: weixie.cui <weixie.cui@okg.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user