MCPcopy Create free account
hub / github.com/consensus-shipyard/ipc / missing_blocks

Function missing_blocks

ipld/resolver/src/missing_blocks.rs:16–38  ·  view source on GitHub ↗

Recursively find all [`Cid`] fields in the [`Block`] structures stored in the [`Blockstore`] and return all CIDs which could *not* be retrieved from the store. This function is available as a convenience, to be used by any [`BitswapStore`] implementation as they see fit.

(
    bs: &mut BS,
    cid: &Cid,
)

Source from the content-addressed store, hash-verified

14/// This function is available as a convenience, to be used by any [`BitswapStore`]
15/// implementation as they see fit.
16pub fn missing_blocks<BS: Blockstore, P: StoreParams>(
17 bs: &mut BS,
18 cid: &Cid,
19) -> anyhow::Result<Vec<Cid>>
20where
21 Ipld: References<<P as StoreParams>::Codecs>,
22{
23 let mut stack = vec![*cid];
24 let mut missing = vec![];
25 while let Some(cid) = stack.pop() {
26 // Convert libipld::Cid (cid 0.10) to fvm Cid (cid 0.11) for blockstore
27 let cid_bytes = cid.to_bytes();
28 let fvm_cid = FvmCid::try_from(cid_bytes.as_slice())?;
29
30 if let Some(data) = bs.get(&fvm_cid)? {
31 let block = libipld::Block::<P>::new_unchecked(cid, data);
32 block.references(&mut stack)?;
33 } else {
34 missing.push(cid);
35 }
36 }
37 Ok(missing)
38}

Callers

nothing calls this directly

Calls 3

to_bytesMethod · 0.45
getMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected