Skip to content

Commit ab2980e

Browse files
authored
fix: PoSt partition batching (#813)
1 parent 9721630 commit ab2980e

File tree

15 files changed

+73
-41
lines changed

15 files changed

+73
-41
lines changed

lib/polka-storage-proofs/src/post/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ pub fn generate_window_post<S: MerkleTreeTrait + 'static>(
172172
randomness: randomness_safe,
173173
prover_id: prover_id_safe,
174174
sectors: pub_sectors,
175+
// This is all-right.
176+
// FallbackPoStCompound::prove overrides this parameter and sets it for each partition.
177+
// As long as the verification logic also is compatible with this logic, it's good.
178+
// k is local to each pair of the verification/generation batch.
179+
// i.e. if we have 20 partitions to prove, two batches of 10 partitions, k = 0..10 in each batch.
175180
k: None,
176181
};
177182

pallets/proofs/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ pub mod pallet {
4040
pallets::ProofVerification,
4141
proofs::{ProverId, PublicReplicaInfo, RegisteredPoStProof, RegisteredSealProof, Ticket},
4242
sector::SectorNumber,
43-
MAX_POST_PROOF_BYTES, MAX_PROOFS_PER_BLOCK, MAX_REPLICAS_PER_BLOCK, MAX_SEAL_PROOF_BYTES,
43+
MAX_POREP_PROOFS_PER_BLOCK, MAX_POST_PROOFS_PER_BLOCK, MAX_POST_PROOF_BYTES,
44+
MAX_REPLICAS_PER_BLOCK, MAX_SEAL_PROOF_BYTES,
4445
};
4546
use sp_std::collections::btree_map::BTreeMap;
4647

@@ -191,7 +192,7 @@ pub mod pallet {
191192
seed: Ticket,
192193
proofs: BoundedVec<
193194
BoundedVec<u8, ConstU32<MAX_SEAL_PROOF_BYTES>>,
194-
ConstU32<MAX_PROOFS_PER_BLOCK>,
195+
ConstU32<MAX_POREP_PROOFS_PER_BLOCK>,
195196
>,
196197
) -> DispatchResult {
197198
log::info!(target: LOG_TARGET, "verifying PoRep proofs: {}", proofs.len());
@@ -249,7 +250,7 @@ pub mod pallet {
249250
>,
250251
proofs: BoundedVec<
251252
BoundedVec<u8, ConstU32<MAX_POST_PROOF_BYTES>>,
252-
ConstU32<MAX_PROOFS_PER_BLOCK>,
253+
ConstU32<MAX_POST_PROOFS_PER_BLOCK>,
253254
>,
254255
) -> DispatchResult {
255256
let replica_count = replicas.len();

pallets/proofs/src/porep/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use primitives::{
66
commitment::RawCommitment,
77
proofs::{ProverId, RegisteredSealProof, Ticket},
88
sector::SectorNumber,
9-
MAX_PROOFS_PER_BLOCK,
9+
MAX_POREP_PROOFS_PER_BLOCK,
1010
};
1111
use sha2::{Digest, Sha256};
1212

@@ -156,7 +156,7 @@ impl ProofScheme {
156156
seed: &Ticket,
157157
groth_randomness: &Ticket,
158158
vk: VerifyingKey<Bls12>,
159-
proofs: BoundedVec<Proof<Bls12>, ConstU32<MAX_PROOFS_PER_BLOCK>>,
159+
proofs: BoundedVec<Proof<Bls12>, ConstU32<MAX_POREP_PROOFS_PER_BLOCK>>,
160160
) -> Result<(), ProofError> {
161161
let comm_d_fr = fr32::bytes_into_fr(comm_d).map_err(|_| ProofError::Conversion)?;
162162
let comm_r_fr = fr32::bytes_into_fr(comm_r).map_err(|_| ProofError::Conversion)?;

pallets/proofs/src/post/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use primitives::{
77
commitment::RawCommitment,
88
proofs::{PublicReplicaInfo, RegisteredPoStProof, Ticket},
99
sector::SectorNumber,
10-
MAX_PROOFS_PER_BLOCK, MAX_REPLICAS_PER_BLOCK, NODE_SIZE,
10+
MAX_POST_PROOFS_PER_BLOCK, MAX_REPLICAS_PER_BLOCK, NODE_SIZE,
1111
};
1212
use sha2::{Digest, Sha256};
1313

@@ -50,7 +50,7 @@ impl ProofScheme {
5050
>,
5151
groth_randomness: Ticket,
5252
vk: VerifyingKey<Bls12>,
53-
proofs: BoundedVec<Proof<Bls12>, ConstU32<MAX_PROOFS_PER_BLOCK>>,
53+
proofs: BoundedVec<Proof<Bls12>, ConstU32<MAX_POST_PROOFS_PER_BLOCK>>,
5454
) -> Result<(), ProofError> {
5555
let randomness = fr32::bytes_into_fr(&randomness)
5656
.map_err(|_| ProofError::Conversion)?

pallets/proofs/src/tests/mod.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::str::FromStr;
33
use cid::Cid;
44
use codec::Decode;
55
use polka_storage_proofs::{Bls12, Proof};
6-
use primitives::{MAX_POST_PROOF_BYTES, MAX_PROOFS_PER_BLOCK};
6+
use primitives::{MAX_POREP_PROOFS_PER_BLOCK, MAX_POST_PROOFS_PER_BLOCK, MAX_POST_PROOF_BYTES};
77
use sp_core::ConstU32;
88
use sp_runtime::BoundedVec;
99

@@ -24,9 +24,30 @@ pub fn raw_commitment_from_hex(hex_str: &str) -> [u8; 32] {
2424
}
2525

2626
/// Loads a proof file generated by polka-storage-provider-client either with porep or post command.
27-
pub fn load_proof_file(
27+
pub fn load_porep_proof_file(
2828
path: &str,
29-
) -> BoundedVec<BoundedVec<u8, ConstU32<MAX_POST_PROOF_BYTES>>, ConstU32<MAX_PROOFS_PER_BLOCK>> {
29+
) -> BoundedVec<BoundedVec<u8, ConstU32<MAX_POST_PROOF_BYTES>>, ConstU32<MAX_POREP_PROOFS_PER_BLOCK>>
30+
{
31+
let proof_bytes = std::fs::read(path).unwrap();
32+
let proofs: Vec<Proof<Bls12>> = Decode::decode(&mut &proof_bytes[..]).unwrap();
33+
let mut bounded_proofs = BoundedVec::new();
34+
35+
for proof in proofs {
36+
let mut bytes_regular = vec![0u8; Proof::<Bls12>::serialised_bytes()];
37+
proof.into_bytes(bytes_regular.as_mut_slice()).unwrap();
38+
bounded_proofs
39+
.try_push(bytes_regular.try_into().unwrap())
40+
.unwrap();
41+
}
42+
43+
bounded_proofs
44+
}
45+
46+
/// Loads a proof file generated by polka-storage-provider-client either with porep or post command.
47+
pub fn load_post_proof_file(
48+
path: &str,
49+
) -> BoundedVec<BoundedVec<u8, ConstU32<MAX_POST_PROOF_BYTES>>, ConstU32<MAX_POST_PROOFS_PER_BLOCK>>
50+
{
3051
let proof_bytes = std::fs::read(path).unwrap();
3152
let proofs: Vec<Proof<Bls12>> = Decode::decode(&mut &proof_bytes[..]).unwrap();
3253
let mut bounded_proofs = BoundedVec::new();

pallets/proofs/src/tests/porep.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use sp_runtime::BoundedVec;
1515

1616
use crate::{
1717
mock::*,
18-
tests::{load_proof_file, raw_commitment_from_hex, TEST_SEED},
18+
tests::{load_porep_proof_file, raw_commitment_from_hex, TEST_SEED},
1919
Error, PoRepVerifyingKeys,
2020
};
2121

@@ -126,7 +126,7 @@ fn porep_verification_for_1gib_succeeds() {
126126
let comm_d = raw_commitment_from_hex(
127127
"baga6ea4seaqcjdzgezdmdynwaoursai6zwafbxjmz7k4r3fnwwioizcwbq3zwki",
128128
);
129-
let proofs = load_proof_file("../../examples/1.sector.proof.porep.scale");
129+
let proofs = load_porep_proof_file("../../examples/1.sector.proof.porep.scale");
130130

131131
assert_ok!(<ProofsModule as ProofVerification>::verify_porep(
132132
prover_id, seal_proof, comm_r, comm_d, sector, ticket, seed, proofs

pallets/proofs/src/tests/post.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use sp_std::collections::btree_map::BTreeMap;
1616

1717
use crate::{
1818
mock::*,
19-
tests::{load_proof_file, raw_commitment_from_hex, TEST_SEED},
19+
tests::{load_post_proof_file, raw_commitment_from_hex, TEST_SEED},
2020
Error, PoStVerifyingKeys,
2121
};
2222

@@ -105,7 +105,7 @@ fn post_verification_for_1gib_succeeds() {
105105
},
106106
);
107107

108-
let proofs = load_proof_file("../../examples/1.sector.proof.post.scale");
108+
let proofs = load_post_proof_file("../../examples/1.sector.proof.post.scale");
109109

110110
log::debug!("Verifying PoSt...");
111111
assert_ok!(<ProofsModule as ProofVerification>::verify_post(

pallets/storage-provider/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ pub mod pallet {
5959
proofs::{derive_prover_id, PublicReplicaInfo, RegisteredPoStProof},
6060
randomness::{draw_randomness, AuthorVrfHistory, DomainSeparationTag},
6161
sector::{ProveCommitSector, SectorNumber, SectorPreCommitInfo},
62-
PartitionNumber, MAX_PARTITIONS_PER_DEADLINE, MAX_PROOFS_PER_BLOCK, MAX_SEAL_PROOF_BYTES,
63-
MAX_SECTORS, MAX_SECTORS_PER_CALL,
62+
PartitionNumber, MAX_PARTITIONS_PER_DEADLINE, MAX_POREP_PROOFS_PER_BLOCK,
63+
MAX_SEAL_PROOF_BYTES, MAX_SECTORS, MAX_SECTORS_PER_CALL,
6464
};
6565
use scale_info::TypeInfo;
6666
use sp_arithmetic::traits::Zero;
@@ -1641,7 +1641,7 @@ pub mod pallet {
16411641
precommit: &SectorPreCommitOnChainInfo<BalanceOf<T>, BlockNumberFor<T>>,
16421642
proofs: BoundedVec<
16431643
BoundedVec<u8, ConstU32<MAX_SEAL_PROOF_BYTES>>,
1644-
ConstU32<MAX_PROOFS_PER_BLOCK>,
1644+
ConstU32<MAX_POREP_PROOFS_PER_BLOCK>,
16451645
>,
16461646
) -> Result<(), DispatchError> {
16471647
let max_proof_size = precommit.info.seal_proof.proof_size();

pallets/storage-provider/src/proofs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use frame_support::{
55
};
66
use primitives::{
77
proofs::RegisteredPoStProof, PartitionNumber, MAX_PARTITIONS_PER_DEADLINE,
8-
MAX_POST_PROOF_BYTES, MAX_PROOFS_PER_BLOCK,
8+
MAX_POST_PROOFS_PER_BLOCK, MAX_POST_PROOF_BYTES,
99
};
1010
use scale_info::TypeInfo;
1111
use sp_core::blake2_64;
@@ -30,7 +30,7 @@ pub struct SubmitWindowedPoStParams {
3030
/// The partition being proven.
3131
pub partitions: BoundedVec<PartitionNumber, ConstU32<MAX_PARTITIONS_PER_DEADLINE>>,
3232
/// The proof submission.
33-
pub proofs: BoundedVec<PoStProof, ConstU32<MAX_PROOFS_PER_BLOCK>>,
33+
pub proofs: BoundedVec<PoStProof, ConstU32<MAX_POST_PROOFS_PER_BLOCK>>,
3434
}
3535

3636
/// Error type for proof operations.

primitives/src/lib.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ pub const NODE_SIZE: usize = 32;
2323
/// ref: <https://github.com/filecoin-project/builtin-actors/blob/82d02e58f9ef456aeaf2a6c737562ac97b22b244/runtime/src/runtime/policy.rs#L283>
2424
pub const MAX_PARTITIONS_PER_DEADLINE: u32 = 3000;
2525

26+
/// Establishes how many PoRep partitions can we verify in a single extrinsic.
27+
/// It's determined by the Groth16 timing limitations.
28+
/// Verification of 10 PoRep partitions (1GiB sector size) takes a whole block.
29+
pub const MAX_POREP_PROOFS_PER_BLOCK: u32 = 10;
30+
2631
/// Establishes how many partitions can we verify in a single extrinsic.
27-
/// It's determined by the timing limitations, storage provider have an upper limit of 3000 partitions per deadline.
28-
/// With our current verification solution, it'll take around ~30 extrinsic calls to verify all of them.
29-
/// Verification of a single proof takes around ~100ms, block time is ~6000ms.
30-
/// This means 10 partitions will be verified in a ~1 sec.
31-
// TODO(@th7nder,#659,27/12/2024): possibly speed it up
32-
pub const MAX_PROOFS_PER_BLOCK: u32 = 10;
32+
/// It's determined by the timing limitations, storage provider have an upper limit of 300 partitions per deadline.
33+
/// With our current verification solution, it'll take around ~300 extrinsic calls to verify all of them.
34+
/// Verification of a single proof takes around ~2s, takes a whole block.
35+
pub const MAX_POST_PROOFS_PER_BLOCK: u32 = 1;
3336

3437
/// Max number of sectors.
3538
/// <https://github.com/filecoin-project/builtin-actors/blob/17ede2b256bc819dc309edf38e031e246a516486/runtime/src/runtime/policy.rs#L262>
@@ -57,15 +60,15 @@ pub const MAX_DEALS_FOR_ALL_SECTORS: u32 = MAX_SECTORS_PER_CALL * MAX_DEALS_PER_
5760
pub const MAX_TERMINATIONS_PER_CALL: u32 = 32; // TODO(@jmg-duarte,25/07/2024): change for a better value
5861

5962
/// The maximum amount of sectors allowed in proofs and replicas.
60-
/// This value is the absolute max, when the sector size is 32 GiB.
63+
/// This value is the absolute max, when the sector size is 1 GiB.
6164
/// Proofs and replicas are still dynamically checked for their size depending on the sector size.
6265
///
6366
/// References:
6467
/// * Filecoin docs about PoSt: <https://spec.filecoin.io/algorithms/pos/post/#section-algorithms.pos.post.windowpost>
65-
pub const MAX_SECTORS_PER_PROOF: u32 = 2349;
68+
pub const MAX_SECTORS_PER_PROOF: u32 = 25;
6669

6770
/// The maximum amount of replicas that can be processed in a single block.
68-
pub const MAX_REPLICAS_PER_BLOCK: u32 = MAX_SECTORS_PER_PROOF * MAX_PROOFS_PER_BLOCK;
71+
pub const MAX_REPLICAS_PER_BLOCK: u32 = MAX_SECTORS_PER_PROOF * MAX_POST_PROOFS_PER_BLOCK;
6972

7073
/// The absolute maximum length, in bytes, a seal proof should be for the largest sector size.
7174
/// NOTE: Taken the value from `StackedDRG32GiBV1`,

primitives/src/pallets.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::{
99
proofs::{ProverId, PublicReplicaInfo, RegisteredPoStProof, RegisteredSealProof, Ticket},
1010
sector::SectorNumber,
1111
DealId, PartitionNumber, MAX_DEALS_PER_SECTOR, MAX_PARTITIONS_PER_DEADLINE,
12-
MAX_POST_PROOF_BYTES, MAX_PROOFS_PER_BLOCK, MAX_REPLICAS_PER_BLOCK, MAX_SEAL_PROOF_BYTES,
13-
MAX_SECTORS, MAX_SECTORS_PER_CALL,
12+
MAX_POREP_PROOFS_PER_BLOCK, MAX_POST_PROOFS_PER_BLOCK, MAX_POST_PROOF_BYTES,
13+
MAX_REPLICAS_PER_BLOCK, MAX_SEAL_PROOF_BYTES, MAX_SECTORS, MAX_SECTORS_PER_CALL,
1414
};
1515

1616
pub trait StorageProviderValidation<AccountId> {
@@ -30,7 +30,7 @@ pub trait ProofVerification {
3030
seed: Ticket,
3131
proofs: BoundedVec<
3232
BoundedVec<u8, ConstU32<MAX_SEAL_PROOF_BYTES>>,
33-
ConstU32<MAX_PROOFS_PER_BLOCK>,
33+
ConstU32<MAX_POREP_PROOFS_PER_BLOCK>,
3434
>,
3535
) -> DispatchResult;
3636

@@ -44,7 +44,7 @@ pub trait ProofVerification {
4444
>,
4545
proof: BoundedVec<
4646
BoundedVec<u8, ConstU32<MAX_POST_PROOF_BYTES>>,
47-
ConstU32<MAX_PROOFS_PER_BLOCK>,
47+
ConstU32<MAX_POST_PROOFS_PER_BLOCK>,
4848
>,
4949
) -> DispatchResult;
5050
}

primitives/src/proofs.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ pub mod testing {
286286
Ticket,
287287
},
288288
sector::SectorNumber,
289-
MAX_POST_PROOF_BYTES, MAX_PROOFS_PER_BLOCK, MAX_REPLICAS_PER_BLOCK, MAX_SEAL_PROOF_BYTES,
289+
MAX_POREP_PROOFS_PER_BLOCK, MAX_POST_PROOFS_PER_BLOCK, MAX_POST_PROOF_BYTES,
290+
MAX_REPLICAS_PER_BLOCK, MAX_SEAL_PROOF_BYTES,
290291
};
291292

292293
/// A sentinel value for an invalid proof, everything else will be considered valid.
@@ -308,7 +309,7 @@ pub mod testing {
308309
_seed: Ticket,
309310
_proofs: BoundedVec<
310311
BoundedVec<u8, ConstU32<MAX_SEAL_PROOF_BYTES>>,
311-
ConstU32<MAX_PROOFS_PER_BLOCK>,
312+
ConstU32<MAX_POREP_PROOFS_PER_BLOCK>,
312313
>,
313314
) -> sp_runtime::DispatchResult {
314315
Ok(())
@@ -324,7 +325,7 @@ pub mod testing {
324325
>,
325326
proofs: BoundedVec<
326327
BoundedVec<u8, ConstU32<MAX_POST_PROOF_BYTES>>,
327-
ConstU32<MAX_PROOFS_PER_BLOCK>,
328+
ConstU32<MAX_POST_PROOFS_PER_BLOCK>,
328329
>,
329330
) -> sp_runtime::DispatchResult {
330331
if *proofs[0] == INVALID_PROOF {

primitives/src/sector/prove_commit.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ use scale_info::TypeInfo;
33
use sp_core::{ConstU32, RuntimeDebug};
44
use sp_runtime::BoundedVec;
55

6-
use crate::{sector::SectorNumber, MAX_PROOFS_PER_BLOCK, MAX_SEAL_PROOF_BYTES};
6+
use crate::{sector::SectorNumber, MAX_POREP_PROOFS_PER_BLOCK, MAX_SEAL_PROOF_BYTES};
77

88
/// Arguments passed into the `prove_commit_sector` extrinsic.
99
#[derive(Clone, RuntimeDebug, Decode, Encode, PartialEq, TypeInfo)]
1010
pub struct ProveCommitSector {
1111
pub sector_number: SectorNumber,
12-
pub proofs:
13-
BoundedVec<BoundedVec<u8, ConstU32<MAX_SEAL_PROOF_BYTES>>, ConstU32<MAX_PROOFS_PER_BLOCK>>,
12+
pub proofs: BoundedVec<
13+
BoundedVec<u8, ConstU32<MAX_SEAL_PROOF_BYTES>>,
14+
ConstU32<MAX_POREP_PROOFS_PER_BLOCK>,
15+
>,
1416
}

storage-provider/common/src/deadline.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use primitives::{
1111
proofs::{derive_prover_id, RegisteredPoStProof},
1212
randomness::{draw_randomness, DomainSeparationTag},
1313
sector::SectorNumber,
14-
PartitionNumber, MAX_PROOFS_PER_BLOCK,
14+
PartitionNumber, MAX_POST_PROOFS_PER_BLOCK,
1515
};
1616
use storagext::{
1717
runtime::runtime_types::primitives::pallets::DeadlineInfo,
@@ -144,7 +144,7 @@ impl Deadline {
144144
let chunked_partitions = deadline_state
145145
.partitions
146146
.into_iter()
147-
.chunks(MAX_PROOFS_PER_BLOCK as usize);
147+
.chunks(MAX_POST_PROOFS_PER_BLOCK as usize);
148148

149149
// Prepare the proofs for required partitions
150150
let proving_futures = chunked_partitions
@@ -247,7 +247,6 @@ impl Deadline {
247247
where
248248
F: Fn(SectorNumber) -> Option<ProvenSector>,
249249
{
250-
// Get replicas for sectors part of the partitions
251250
let replicas = partitions
252251
.iter()
253252
.flat_map(|(_id, state)| {
-35 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)