From 8805012152d2b4a91b15ffcf0259952c89f16cc0 Mon Sep 17 00:00:00 2001 From: Konrad Stepniak Date: Mon, 30 Dec 2024 15:01:39 +0100 Subject: [PATCH 1/2] feat: generate multiple proofs --- storage-provider/server/src/pipeline/mod.rs | 47 ++++++++++----------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/storage-provider/server/src/pipeline/mod.rs b/storage-provider/server/src/pipeline/mod.rs index f9df2e1ed..ff184cd97 100644 --- a/storage-provider/server/src/pipeline/mod.rs +++ b/storage-provider/server/src/pipeline/mod.rs @@ -1,6 +1,6 @@ pub mod types; -use std::{path::PathBuf, sync::Arc}; +use std::{collections::BTreeSet, path::PathBuf, sync::Arc}; use polka_storage_proofs::{ porep::{ @@ -667,9 +667,6 @@ async fn submit_windowed_post( return Err(PipelineError::DeadlineStateNotFound); }; - if deadline_state.partitions.len() > 1 { - todo!("I don't know what to do: polka-storage#595"); - } if deadline_state.partitions.len() == 0 { tracing::info!("There are not partitions in this deadline yet. Nothing to prove here."); schedule_post(state, deadline_index)?; @@ -677,26 +674,26 @@ async fn submit_windowed_post( } let partitions = deadline_state.partitions.keys().cloned().collect(); - let (_partition_number, PartitionState { sectors }) = deadline_state - .partitions - .first_key_value() - .expect("1 partition to be there"); + let mut all_sectors = BTreeSet::new(); + for (_, PartitionState { sectors }) in deadline_state.partitions { + all_sectors.extend(sectors); + } - if sectors.len() == 0 { + if all_sectors.len() == 0 { tracing::info!("Every sector expired... Nothing to prove here."); schedule_post(state, deadline_index)?; return Ok(()); } let mut replicas = Vec::new(); - for sector_number in sectors { + for sector_number in all_sectors { let sector = state .db - .get_sector::(*sector_number)? + .get_sector::(sector_number)? .ok_or(PipelineError::SectorNotFound)?; replicas.push(ReplicaInfo { - sector_id: *sector_number, + sector_id: sector_number, comm_r: sector.comm_r.raw(), cache_path: sector.cache_path.clone(), replica_path: sector.sealed_path.clone(), @@ -714,16 +711,19 @@ async fn submit_windowed_post( }) }; let proofs = handle.await??; + tracing::info!("Generated PoSt proof for partitions: {:?}", partitions); - // TODO(@th7nder,#595,06/12/2024): how many proofs are for how many partitions and why - // don't now why yet, need to figure this out - let proof: SubstrateProof = proofs[0] - .clone() - .try_into() - .expect("converstion between rust-fil-proofs and polka-storage-proofs to work"); - let proof = codec::Encode::encode(&proof); + let proofs = proofs + .into_iter() + .map(|p| PoStProof { + post_proof: state.server_info.post_proof, + proof_bytes: codec::Encode::encode( + &TryInto::::try_into(p.clone()) + .expect("converstion between rust-fil-proofs and polka-storage-proofs to work"), + ), + }) + .collect::>(); - tracing::info!("Generated PoSt proof for partitions: {:?}", partitions); tracing::info!("Wait for block {} for open deadline", deadline.start,); state @@ -737,11 +737,8 @@ async fn submit_windowed_post( &state.xt_keypair, SubmitWindowedPoStParams { deadline: deadline_index, - partitions: partitions, - proofs: vec![PoStProof { - post_proof: state.server_info.post_proof, - proof_bytes: proof, - }], + partitions, + proofs, }, true, ) From 4a1df519b72788506ee70d65c370c3e6a60e08b7 Mon Sep 17 00:00:00 2001 From: Konrad Stepniak Date: Thu, 2 Jan 2025 14:14:29 +0100 Subject: [PATCH 2/2] make use of flat_map --- storage-provider/server/src/pipeline/mod.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/storage-provider/server/src/pipeline/mod.rs b/storage-provider/server/src/pipeline/mod.rs index ff184cd97..6f9c768dd 100644 --- a/storage-provider/server/src/pipeline/mod.rs +++ b/storage-provider/server/src/pipeline/mod.rs @@ -674,10 +674,12 @@ async fn submit_windowed_post( } let partitions = deadline_state.partitions.keys().cloned().collect(); - let mut all_sectors = BTreeSet::new(); - for (_, PartitionState { sectors }) in deadline_state.partitions { - all_sectors.extend(sectors); - } + let all_sectors = BTreeSet::from_iter( + deadline_state + .partitions + .into_iter() + .flat_map(|(_, PartitionState { sectors })| sectors), + ); if all_sectors.len() == 0 { tracing::info!("Every sector expired... Nothing to prove here."); @@ -724,7 +726,6 @@ async fn submit_windowed_post( }) .collect::>(); - tracing::info!("Wait for block {} for open deadline", deadline.start,); state .xt_client