fn run_resumable_seal<Tree: 'static + MerkleTreeTrait>(
    skip_proofs: bool,
    layer_to_delete: usize,
    porep_id: &[u8; 32],
) {
    init_logger();

    let sector_size = SECTOR_SIZE_2_KIB;
    let rng = &mut XorShiftRng::from_seed(TEST_SEED);
    let prover_fr: DefaultTreeDomain = Fr::random(rng).into();
    let mut prover_id = [0u8; 32];
    prover_id.copy_from_slice(AsRef::<[u8]>::as_ref(&prover_fr));

    let (mut piece_file, piece_bytes) =
        generate_piece_file(sector_size).expect("failed to generate piece file");
    let sealed_sector_file = NamedTempFile::new().expect("failed to created sealed sector file");
    let cache_dir = tempfile::tempdir().expect("failed to create temp dir");

    let config = porep_config(sector_size, *porep_id);
    let ticket = rng.gen();
    let sector_id = rng.gen::<u64>().into();

    // First create seals as expected
    run_seal_pre_commit_phase1::<Tree>(
        config,
        prover_id,
        sector_id,
        ticket,
        &cache_dir,
        &mut piece_file,
        &sealed_sector_file,
    )
    .expect("failed to run seal pre commit phase1");
    let layers = get_layer_file_paths(&cache_dir);
    assert_eq!(layers.len(), 2, "not all expected layers were created");

    // Delete one layer, keep the other
    clear_cache_dir_keep_data_layer(&cache_dir);
    std::fs::remove_file(&layers[layer_to_delete]).expect("failed to remove layer");
    let layers_remaining = get_layer_file_paths(&cache_dir);
    assert_eq!(layers_remaining.len(), 1, "expected one layer only");
    if layer_to_delete == 0 {
        assert_eq!(layers_remaining[0], layers[1], "wrong layer was removed");
    } else {
        assert_eq!(layers_remaining[0], layers[0], "wrong layer was removed");
    }

    // Resume the seal
    piece_file
        .seek(SeekFrom::Start(0))
        .expect("failed to seek piece file to start");
    let (piece_infos, phase1_output) = run_seal_pre_commit_phase1::<Tree>(
        config,
        prover_id,
        sector_id,
        ticket,
        &cache_dir,
        &mut piece_file,
        &sealed_sector_file,
    )
    .expect("failed to run seal pre commit phase1");

    // Running proofs clears the cache, hence we can only check for existence of files if we don't
    // run them
    if skip_proofs {
        let layers_recreated = get_layer_file_paths(&cache_dir);
        assert_eq!(
            layers_recreated.len(),
            2,
            "not all expected layers were recreated"
        );
        assert_eq!(
            layers_recreated, layers,
            "recreated layers don't match original ones"
        );
    } else {
        let pre_commit_output = seal_pre_commit_phase2(
            config,
            phase1_output,
            cache_dir.path(),
            sealed_sector_file.path(),
        )
        .expect("failed to run seal pre commit phase2");

        validate_cache_for_commit::<_, _, Tree>(cache_dir.path(), sealed_sector_file.path())
            .expect("failed to validate cache for commit");

        let seed = rng.gen();
        proof_and_unseal::<Tree>(
            config,
            cache_dir.path(),
            &sealed_sector_file,
            prover_id,
            sector_id,
            ticket,
            seed,
            pre_commit_output,
            &piece_infos,
            &piece_bytes,
        )
        .expect("failed to proof");
    }
}
/// Create a seal, delete a layer and resume
///
/// The current code works on two layers only. The `layer_to_delete` specifies (zero-based) which
/// layer should be deleted.
Create a seal, delete a layer and resume
The current code works on two layers only. The `layer_to_delete` specifies (zero-based) which
layer should be deleted.
Create a seal delete a layer and resume The current code works on two layers only . The ` layer_to_delete ` specifies ( zero - based ) which layer should be deleted .
fn run_resumable_seal<Tree: 'static + MerkleTreeTrait>(
    skip_proofs: bool,
    layer_to_delete: usize,
    porep_id: &[u8; 32],
) {
    init_logger();
    let sector_size = SECTOR_SIZE_2_KIB;
    let rng = &mut XorShiftRng::from_seed(TEST_SEED);
    let prover_fr: DefaultTreeDomain = Fr::random(rng).into();
    let mut prover_id = [0u8; 32];
    prover_id.copy_from_slice(AsRef::<[u8]>::as_ref(&prover_fr));
    let (mut piece_file, piece_bytes) =
        generate_piece_file(sector_size).expect("failed to generate piece file");
    let sealed_sector_file = NamedTempFile::new().expect("failed to created sealed sector file");
    let cache_dir = tempfile::tempdir().expect("failed to create temp dir");
    let config = porep_config(sector_size, *porep_id);
    let ticket = rng.gen();
    let sector_id = rng.gen::<u64>().into();
    // First create seals as expected
    run_seal_pre_commit_phase1::<Tree>(
        config,
        prover_id,
        sector_id,
        ticket,
        &cache_dir,
        &mut piece_file,
        &sealed_sector_file,
    )
    .expect("failed to run seal pre commit phase1");
    let layers = get_layer_file_paths(&cache_dir);
    assert_eq!(layers.len(), 2, "not all expected layers were created");
    // Delete one layer, keep the other
    clear_cache_dir_keep_data_layer(&cache_dir);
    std::fs::remove_file(&layers[layer_to_delete]).expect("failed to remove layer");
    let layers_remaining = get_layer_file_paths(&cache_dir);
    assert_eq!(layers_remaining.len(), 1, "expected one layer only");
    if layer_to_delete == 0 {
        assert_eq!(layers_remaining[0], layers[1], "wrong layer was removed");
    } else {
        assert_eq!(layers_remaining[0], layers[0], "wrong layer was removed");
    }
    // Resume the seal
    piece_file
        .seek(SeekFrom::Start(0))
        .expect("failed to seek piece file to start");
    let (piece_infos, phase1_output) = run_seal_pre_commit_phase1::<Tree>(
        config,
        prover_id,
        sector_id,
        ticket,
        &cache_dir,
        &mut piece_file,
        &sealed_sector_file,
    )
    .expect("failed to run seal pre commit phase1");
    // Running proofs clears the cache, hence we can only check for existence of files if we don't
    // run them
    if skip_proofs {
        let layers_recreated = get_layer_file_paths(&cache_dir);
        assert_eq!(
            layers_recreated.len(),
            2,
            "not all expected layers were recreated"
        );
        assert_eq!(
            layers_recreated, layers,
            "recreated layers don't match original ones"
        );
    } else {
        let pre_commit_output = seal_pre_commit_phase2(
            config,
            phase1_output,
            cache_dir.path(),
            sealed_sector_file.path(),
        )
        .expect("failed to run seal pre commit phase2");
        validate_cache_for_commit::<_, _, Tree>(cache_dir.path(), sealed_sector_file.path())
            .expect("failed to validate cache for commit");
        let seed = rng.gen();
        proof_and_unseal::<Tree>(
            config,
            cache_dir.path(),
            &sealed_sector_file,
            prover_id,
            sector_id,
            ticket,
            seed,
            pre_commit_output,
            &piece_infos,
            &piece_bytes,
        )
        .expect("failed to proof");
    }
}
fn run_resumable_seal < Tree : ' static + MerkleTreeTrait > ( skip_proofs : bool , layer_to_delete : usize , porep_id : & [ u8 ; 32 ] , ) { init_logger ( ) ; let sector_size = SECTOR_SIZE_2_KIB ; let rng = & mut XorShiftRng :: from_seed ( TEST_SEED ) ; let prover_fr : DefaultTreeDomain = Fr :: random ( rng ) . into ( ) ; let mut prover_id = [ 0u8 ; 32 ] ; prover_id . copy_from_slice ( AsRef :: < [ u8 ] > :: as_ref ( & prover_fr ) ) ; let ( mut piece_file , piece_bytes ) = generate_piece_file ( sector_size ) . expect ( " " ) ; let sealed_sector_file = NamedTempFile :: new ( ) . expect ( " " ) ; let cache_dir = tempfile :: tempdir ( ) . expect ( " " ) ; let config = porep_config ( sector_size , * porep_id ) ; let ticket = rng . gen ( ) ; let sector_id = rng . gen :: < u64 > ( ) . into ( ) ; // First create seals as expected run_seal_pre_commit_phase1 :: < Tree > ( config , prover_id , sector_id , ticket , & cache_dir , & mut piece_file , & sealed_sector_file , ) . expect ( " " ) ; let layers = get_layer_file_paths ( & cache_dir ) ; assert_eq ! ( layers len ( ) 2 " " ) ; // Delete one layer, keep the other clear_cache_dir_keep_data_layer ( & cache_dir ) ; std :: fs :: remove_file ( & layers [ layer_to_delete ] ) . expect ( " " ) ; let layers_remaining = get_layer_file_paths ( & cache_dir ) ; assert_eq ! ( layers_remaining len ( ) 1 " " ) ; if layer_to_delete == 0 { assert_eq ! ( layers_remaining [ 0 ] layers [ 1 ] " " ) ; } else { assert_eq ! ( layers_remaining [ 0 ] layers [ 0 ] " " ) ; } // Resume the seal piece_file . seek ( SeekFrom :: Start ( 0 ) ) . expect ( " " ) ; let ( piece_infos , phase1_output ) = run_seal_pre_commit_phase1 :: < Tree > ( config , prover_id , sector_id , ticket , & cache_dir , & mut piece_file , & sealed_sector_file , ) . expect ( " " ) ; // Running proofs clears the cache, hence we can only check for existence of files if we don't // run them if skip_proofs { let layers_recreated = get_layer_file_paths ( & cache_dir ) ; assert_eq ! ( layers_recreated len ( ) 2 " " ) ; assert_eq ! ( layers_recreated layers " " ) ; } else { let pre_commit_output = seal_pre_commit_phase2 ( config , phase1_output , cache_dir . path ( ) , sealed_sector_file . path ( ) , ) . expect ( " " ) ; validate_cache_for_commit :: < _ , _ , Tree > ( cache_dir . path ( ) , sealed_sector_file . path ( ) ) . expect ( " " ) ; let seed = rng . gen ( ) ; proof_and_unseal :: < Tree > ( config , cache_dir . path ( ) , & sealed_sector_file , prover_id , sector_id , ticket , seed , pre_commit_output , & piece_infos , & piece_bytes , ) . expect ( " " ) ; } }
Create a seal, delete a layer and resume
The current code works on two layers only.
Create a seal delete a layer and resume The current code works on two layers only .
skip_proofs
bool
layer_to_delete
usize
porep_id
&[u8; 32]
skip_proofs
bool
layer_to_delete
usize
porep_id
&[u8; 32]