pub fn from_duplicate_slot_proof(
    proof: &DuplicateSlotProof,
    self_pubkey: Pubkey, // Pubkey of my node broadcasting crds value.
    leader_schedule: Option<impl LeaderScheduleFn>,
    wallclock: u64,
    max_size: usize, // Maximum serialized size of each DuplicateShred.
) -> Result<impl Iterator<Item = DuplicateShred>, Error> {
    if proof.shred1 == proof.shred2 {
        return Err(Error::InvalidDuplicateSlotProof);
    }
    let shred1 = Shred::new_from_serialized_shred(proof.shred1.clone())?;
    let shred2 = Shred::new_from_serialized_shred(proof.shred2.clone())?;
    check_shreds(leader_schedule, &shred1, &shred2)?;
    let (slot, shred_index, shred_type) = (shred1.slot(), shred1.index(), shred1.shred_type());
    let data = bincode::serialize(proof)?;
    let chunk_size = if DUPLICATE_SHRED_HEADER_SIZE < max_size {
        max_size - DUPLICATE_SHRED_HEADER_SIZE
    } else {
        return Err(Error::InvalidSizeLimit);
    };
    let chunks: Vec<_> = data.chunks(chunk_size).map(Vec::from).collect();
    let num_chunks = u8::try_from(chunks.len())?;
    let chunks = chunks
        .into_iter()
        .enumerate()
        .map(move |(i, chunk)| DuplicateShred {
            from: self_pubkey,
            wallclock,
            slot,
            shred_index,
            shred_type,
            num_chunks,
            chunk_index: i as u8,
            chunk,
        });
    Ok(chunks)
}
/// Splits a DuplicateSlotProof into DuplicateShred
/// chunks with a size limit on each chunk.
Splits a DuplicateSlotProof into DuplicateShred
chunks with a size limit on each chunk.
Splits a DuplicateSlotProof into DuplicateShred chunks with a size limit on each chunk .
pub fn from_duplicate_slot_proof(
    proof: &DuplicateSlotProof,
    self_pubkey: Pubkey, // Pubkey of my node broadcasting crds value.
    leader_schedule: Option<impl LeaderScheduleFn>,
    wallclock: u64,
    max_size: usize, // Maximum serialized size of each DuplicateShred.
) -> Result<impl Iterator<Item = DuplicateShred>, Error> {
    if proof.shred1 == proof.shred2 {
        return Err(Error::InvalidDuplicateSlotProof);
    }
    let shred1 = Shred::new_from_serialized_shred(proof.shred1.clone())?;
    let shred2 = Shred::new_from_serialized_shred(proof.shred2.clone())?;
    check_shreds(leader_schedule, &shred1, &shred2)?;
    let (slot, shred_index, shred_type) = (shred1.slot(), shred1.index(), shred1.shred_type());
    let data = bincode::serialize(proof)?;
    let chunk_size = if DUPLICATE_SHRED_HEADER_SIZE < max_size {
        max_size - DUPLICATE_SHRED_HEADER_SIZE
    } else {
        return Err(Error::InvalidSizeLimit);
    };
    let chunks: Vec<_> = data.chunks(chunk_size).map(Vec::from).collect();
    let num_chunks = u8::try_from(chunks.len())?;
    let chunks = chunks
        .into_iter()
        .enumerate()
        .map(move |(i, chunk)| DuplicateShred {
            from: self_pubkey,
            wallclock,
            slot,
            shred_index,
            shred_type,
            num_chunks,
            chunk_index: i as u8,
            chunk,
        });
    Ok(chunks)
}
pub fn from_duplicate_slot_proof ( proof : & DuplicateSlotProof , self_pubkey : Pubkey , // Pubkey of my node broadcasting crds value. leader_schedule : Option < impl LeaderScheduleFn > , wallclock : u64 , max_size : usize , // Maximum serialized size of each DuplicateShred. ) -> Result < impl Iterator < Item = DuplicateShred > , Error > { if proof . shred1 == proof . shred2 { return Err ( Error :: InvalidDuplicateSlotProof ) ; } let shred1 = Shred :: new_from_serialized_shred ( proof . shred1 . clone ( ) ) ? ; let shred2 = Shred :: new_from_serialized_shred ( proof . shred2 . clone ( ) ) ? ; check_shreds ( leader_schedule , & shred1 , & shred2 ) ? ; let ( slot , shred_index , shred_type ) = ( shred1 . slot ( ) , shred1 . index ( ) , shred1 . shred_type ( ) ) ; let data = bincode :: serialize ( proof ) ? ; let chunk_size = if DUPLICATE_SHRED_HEADER_SIZE < max_size { max_size - DUPLICATE_SHRED_HEADER_SIZE } else { return Err ( Error :: InvalidSizeLimit ) ; } ; let chunks : Vec < _ > = data . chunks ( chunk_size ) . map ( Vec :: from ) . collect ( ) ; let num_chunks = u8 :: try_from ( chunks . len ( ) ) ? ; let chunks = chunks . into_iter ( ) . enumerate ( ) . map ( move | ( i , chunk ) | DuplicateShred { from : self_pubkey , wallclock , slot , shred_index , shred_type , num_chunks , chunk_index : i as u8 , chunk , } ) ; Ok ( chunks ) }
Splits a DuplicateSlotProof into DuplicateShred
chunks with a size limit on each chunk.
Splits a DuplicateSlotProof into DuplicateShred chunks with a size limit on each chunk .
proof
&DuplicateSlotProof
self_pubkey
Pubkey
leader_schedule
Option<impl LeaderScheduleFn>
wallclock
u64
max_size
usize