From 27e2d880a11215bb959524843482889d6bfb916c Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Mon, 31 Jul 2023 14:55:18 +0300 Subject: [PATCH] Proper `.expect()` proofs and TODOs to do proper handling in other places --- crates/sc-proof-of-time/src/clock_master.rs | 4 +++- crates/sc-proof-of-time/src/lib.rs | 5 +++-- crates/subspace-proof-of-time/benches/pot.rs | 12 +++++------- crates/subspace-proof-of-time/src/lib.rs | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/crates/sc-proof-of-time/src/clock_master.rs b/crates/sc-proof-of-time/src/clock_master.rs index 08c1812620..93f1c5c268 100644 --- a/crates/sc-proof-of-time/src/clock_master.rs +++ b/crates/sc-proof-of-time/src/clock_master.rs @@ -137,6 +137,7 @@ where .spawn(move || { Self::produce_proofs(proof_of_time, pot_state, local_proof_sender); }) + // TODO: Proper error handling or proof .expect("Failed to spawn PoT proof producer thread"); loop { @@ -172,6 +173,7 @@ where ) { loop { // Build the next proof on top of the latest tip. + // TODO: Proper error handling or proof let last_proof = state.tip().expect("Clock master chain cannot be empty"); // TODO: injected block hash from consensus @@ -226,7 +228,7 @@ where params.slot, params.genesis_hash, ); - let proofs = NonEmptyVec::new(vec![proof]).expect("Vec is non empty"); + let proofs = NonEmptyVec::new(vec![proof]).expect("Vec is non empty; qed"); self.pot_state.reset(proofs); } } diff --git a/crates/sc-proof-of-time/src/lib.rs b/crates/sc-proof-of-time/src/lib.rs index 8bec6c2568..0c2b505981 100644 --- a/crates/sc-proof-of-time/src/lib.rs +++ b/crates/sc-proof-of-time/src/lib.rs @@ -56,8 +56,8 @@ impl Default for PotConfig { global_randomness_reveal_lag_slots: 6, pot_injection_lag_slots: 6, max_future_slots: 10, - pot_iterations: NonZeroU32::new(16 * 200_000).expect("pot_iterations cannot be zero"), - num_checkpoints: NonZeroU8::new(16).expect("num_checkpoints cannot be zero"), + pot_iterations: NonZeroU32::new(16 * 200_000).expect("Not zero; qed"), + num_checkpoints: NonZeroU8::new(16).expect("Not zero; qed"), } } } @@ -79,6 +79,7 @@ impl PotComponents { pub fn new() -> Self { let config = PotConfig::default(); let proof_of_time = ProofOfTime::new(config.pot_iterations, config.num_checkpoints) + // TODO: Proper error handling or proof .expect("Failed to initialize proof of time"); let (protocol_state, consensus_state) = init_pot_state(config, proof_of_time.clone()); diff --git a/crates/subspace-proof-of-time/benches/pot.rs b/crates/subspace-proof-of-time/benches/pot.rs index aecc95495a..eaa32c8ba6 100644 --- a/crates/subspace-proof-of-time/benches/pot.rs +++ b/crates/subspace-proof-of-time/benches/pot.rs @@ -12,14 +12,12 @@ fn criterion_benchmark(c: &mut Criterion) { let slot_number = 1; let mut injected_block_hash = BlockHash::default(); thread_rng().fill(injected_block_hash.as_mut()); - let checkpoints_1 = NonZeroU8::new(1).expect("Creating checkpoints cannot fail"); - let checkpoints_8 = NonZeroU8::new(8).expect("Creating checkpoints cannot fail"); + let checkpoints_1 = NonZeroU8::new(1).expect("Not zero; qed"); + let checkpoints_8 = NonZeroU8::new(8).expect("Not zero; qed"); // About 1s on 5.5 GHz Raptor Lake CPU - let pot_iterations = NonZeroU32::new(166_000_000).expect("Creating pot_iterations cannot fail"); - let proof_of_time_sequential = ProofOfTime::new(pot_iterations, checkpoints_1) - .expect("Failed to create proof_of_time_sequential"); - let proof_of_time = - ProofOfTime::new(pot_iterations, checkpoints_8).expect("Failed to create proof_of_time"); + let pot_iterations = NonZeroU32::new(166_000_000).expect("Not zero; qed"); + let proof_of_time_sequential = ProofOfTime::new(pot_iterations, checkpoints_1).unwrap(); + let proof_of_time = ProofOfTime::new(pot_iterations, checkpoints_8).unwrap(); c.bench_function("prove/sequential", |b| { b.iter(|| { diff --git a/crates/subspace-proof-of-time/src/lib.rs b/crates/subspace-proof-of-time/src/lib.rs index a49348249a..e07d277d49 100644 --- a/crates/subspace-proof-of-time/src/lib.rs +++ b/crates/subspace-proof-of-time/src/lib.rs @@ -79,7 +79,7 @@ impl ProofOfTime { self.num_checkpoints, self.checkpoint_iterations, )) - .expect("Failed to create proof of time"); + .expect("List of checkpoints is never empty; qed"); PotProof::new(slot_number, seed, key, checkpoints, injected_block_hash) }