/// Pipe the manifest (chunk 0) from src to dest and return the StateSyncMessage
/// if the state sync completes
Pipe the manifest (chunk 0) from src to dest and return the StateSyncMessage
if the state sync completes
Pipe the manifest ( chunk 0 ) from src to dest and return the StateSyncMessage if the state sync completes
pub fn pipe_manifest(src: &StateSyncMessage, dst: &mut dyn Chunkable) -> Option<StateSyncMessage> {
    let ids: Vec<_> = dst.chunks_to_download().collect();
    // Only the manifest should be requested
    assert_eq!(ids, vec! {ChunkId::new(0)});
    let id = ids[0];
    let chunk = Box::new(src.clone())
        .get_chunk(id)
        .unwrap_or_else(|| panic!("Requested unknown chunk {}", id));
    match dst.add_chunk(chunk) {
        Ok(Artifact::StateSync(msg)) => {
            assert!(
                dst.is_complete(),
                "add_chunk returned OK but the artifact is not complete"
            );
            Some(msg)
        }
        Ok(artifact) => {
            panic!("Unexpected artifact type: {:?}", artifact);
        }
        Err(ChunksMoreNeeded) => None,
        Err(ChunkVerificationFailed) => panic!("Encountered invalid chunk {}", id),
    }
}
pub fn pipe_manifest ( src : & StateSyncMessage , dst : & mut dyn Chunkable ) -> Option < StateSyncMessage > { let ids : Vec < _ > = dst . chunks_to_download ( ) . collect ( ) ; // Only the manifest should be requested assert_eq ! ( ids vec { ChunkId new ( 0 ) } ) ; let id = ids [ 0 ] ; let chunk = Box :: new ( src . clone ( ) ) . get_chunk ( id ) . unwrap_or_else ( | | panic ! ( " " id ) ) ; match dst . add_chunk ( chunk ) { Ok ( Artifact :: StateSync ( msg ) ) => { assert ! ( dst is_complete ( ) " " ) ; Some ( msg ) } Ok ( artifact ) => { panic ! ( " " artifact ) ; } Err ( ChunksMoreNeeded ) => None , Err ( ChunkVerificationFailed ) => panic ! ( " " id ) , } }
Pipe the manifest (chunk 0) from src to dest and return the StateSyncMessage
if the state sync completes
Pipe the manifest ( chunk 0 ) from src to dest and return the StateSyncMessage if the state sync completes
src
&StateSyncMessage
dst
&mut dyn Chunkable