-
Notifications
You must be signed in to change notification settings - Fork 316
/
Copy pathwindow_post.rs
660 lines (590 loc) · 24.7 KB
/
window_post.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
use std::collections::BTreeMap;
use std::fs::{create_dir_all, read, read_to_string, remove_dir_all, File, OpenOptions};
use std::io::{stdout, Seek, Write};
use std::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH};
use anyhow::{ensure, Context};
use bincode::{deserialize, serialize};
use fil_proofs_tooling::measure::FuncMeasurement;
use fil_proofs_tooling::shared::{self, PROVER_ID, RANDOMNESS, TICKET_BYTES};
use fil_proofs_tooling::{measure, Metadata};
use filecoin_proofs::constants::{WINDOW_POST_CHALLENGE_COUNT, WINDOW_POST_SECTOR_COUNT};
use filecoin_proofs::types::{
PaddedBytesAmount, PieceInfo, PoStConfig, SealCommitPhase1Output, SealPreCommitOutput,
SealPreCommitPhase1Output, SectorSize, UnpaddedBytesAmount,
};
use filecoin_proofs::{
add_piece, generate_piece_commitment, generate_synth_proofs, generate_window_post,
seal_commit_phase1, seal_commit_phase2, seal_pre_commit_phase1, seal_pre_commit_phase2,
validate_cache_for_commit, validate_cache_for_precommit_phase2, verify_window_post, with_shape,
PoStType, PrivateReplicaInfo, PublicReplicaInfo,
};
use log::info;
use serde::{Deserialize, Serialize};
use storage_proofs_core::{
api_version::{ApiFeature, ApiVersion},
merkle::MerkleTreeTrait,
sector::SectorId,
};
const SECTOR_ID: u64 = 0;
const PIECE_FILE: &str = "piece-file";
const PIECE_INFOS_FILE: &str = "piece-infos-file";
const STAGED_FILE: &str = "staged-file";
const SEALED_FILE: &str = "sealed-file";
const PRECOMMIT_PHASE1_OUTPUT_FILE: &str = "precommit-phase1-output";
const PRECOMMIT_PHASE2_OUTPUT_FILE: &str = "precommit-phase2-output";
const COMMIT_PHASE1_OUTPUT_FILE: &str = "commit-phase1-output";
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
struct Inputs {
sector_size: u64,
}
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
struct Outputs {
seal_pre_commit_phase1_cpu_time_ms: u64,
seal_pre_commit_phase1_wall_time_ms: u64,
validate_cache_for_precommit_phase2_cpu_time_ms: u64,
validate_cache_for_precommit_phase2_wall_time_ms: u64,
seal_pre_commit_phase2_cpu_time_ms: u64,
seal_pre_commit_phase2_wall_time_ms: u64,
validate_cache_for_commit_cpu_time_ms: u64,
validate_cache_for_commit_wall_time_ms: u64,
seal_commit_phase1_cpu_time_ms: u64,
seal_commit_phase1_wall_time_ms: u64,
seal_commit_phase2_cpu_time_ms: u64,
seal_commit_phase2_wall_time_ms: u64,
gen_window_post_cpu_time_ms: u64,
gen_window_post_wall_time_ms: u64,
verify_window_post_cpu_time_ms: u64,
verify_window_post_wall_time_ms: u64,
}
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
struct Report {
inputs: Inputs,
outputs: Outputs,
}
impl Report {
/// Print all results to stdout
pub fn print(&self) {
let wrapped = Metadata::wrap(&self).expect("failed to retrieve metadata");
serde_json::to_writer(stdout(), &wrapped).expect("cannot write report JSON to stdout");
}
}
#[allow(clippy::too_many_arguments)]
fn run_pre_commit_phases<Tree: 'static + MerkleTreeTrait>(
sector_size: u64,
api_version: ApiVersion,
cache_dir: PathBuf,
skip_precommit_phase1: bool,
skip_precommit_phase2: bool,
test_resume: bool,
skip_staging: bool,
features: Vec<ApiFeature>,
) -> anyhow::Result<((u64, u64), (u64, u64), (u64, u64))> {
let (seal_pre_commit_phase1_measurement_cpu_time, seal_pre_commit_phase1_measurement_wall_time): (u64, u64) = if skip_precommit_phase1 {
// generate no-op measurements
(0, 0)
} else {
// Create files for the staged and sealed sectors.
let staged_file_path = cache_dir.join(STAGED_FILE);
let mut staged_file = if skip_staging {
info!("*** Re-using staged file");
OpenOptions::new().read(true).write(true).open(&staged_file_path)
} else {
info!("*** Creating staged file");
OpenOptions::new().read(true).write(true).create(true).truncate(true).open(&staged_file_path)
}?;
let sealed_file_path = cache_dir.join(SEALED_FILE);
let _sealed_file = if skip_staging {
info!("*** Re-using sealed file");
OpenOptions::new().read(true).write(true).open(&sealed_file_path)
} else {
info!("*** Creating sealed file");
OpenOptions::new().read(true).write(true).create(true).truncate(true).open(&sealed_file_path)
}?;
let sector_size_unpadded_bytes_amount =
UnpaddedBytesAmount::from(PaddedBytesAmount(sector_size));
let piece_file_path = cache_dir.join(PIECE_FILE);
let mut piece_file = if skip_staging {
info!("*** Re-using piece file");
OpenOptions::new().read(true).write(true).open(&piece_file_path)?
} else {
// Generate the data from which we will create a replica, we will then prove the continued
// storage of that replica using the PoSt.
let piece_bytes: Vec<u8> = (0..usize::from(sector_size_unpadded_bytes_amount))
.map(|_| rand::random::<u8>())
.collect();
info!("*** Created piece file");
let mut piece_file = OpenOptions::new().read(true).write(true).create(true).truncate(true).open(&piece_file_path)?;
piece_file.write_all(&piece_bytes)?;
piece_file.sync_all()?;
piece_file.rewind()?;
piece_file
};
let piece_info =
generate_piece_commitment(&mut piece_file, sector_size_unpadded_bytes_amount)?;
piece_file.rewind()?;
add_piece(
&mut piece_file,
&mut staged_file,
sector_size_unpadded_bytes_amount,
&[],
)?;
let piece_infos = vec![piece_info];
let sector_id = SectorId::from(SECTOR_ID);
let porep_config = shared::get_porep_config(sector_size, api_version, features.clone());
let seal_pre_commit_phase1_measurement: FuncMeasurement<SealPreCommitPhase1Output<Tree>> = measure(|| {
seal_pre_commit_phase1::<_, _, _, Tree>(
&porep_config,
cache_dir.clone(),
staged_file_path.clone(),
sealed_file_path.clone(),
PROVER_ID,
sector_id,
TICKET_BYTES,
&piece_infos,
)
})
.expect("failed in seal_pre_commit_phase1");
let precommit_phase1_output = seal_pre_commit_phase1_measurement.return_value;
if test_resume {
// Locate the last layer and delete it.
//
// NOTE: We should select a random layer to determine if
// the code will properly resume and re-write later layer
// files that exist beyond the missing one.
let mut layers = Vec::new();
for entry in std::fs::read_dir(&cache_dir)? {
let cur = entry?;
let entry_path = cur.path();
let entry_str = entry_path.to_str().expect("failed to get string from path");
if entry_str.contains("data-layer") {
layers.push(entry_path.clone());
}
}
assert!(!layers.is_empty());
// Delete the last layer only.
info!("Test resume requested. Removing last layer {:?}", layers[layers.len() - 1]);
std::fs::remove_file(&layers[layers.len() - 1])?;
return run_pre_commit_phases::<Tree>(sector_size, api_version, cache_dir, skip_precommit_phase1, skip_precommit_phase2, false, true, features);
}
// Persist piece_infos here
let piece_infos_path = cache_dir.join(PIECE_INFOS_FILE);
let mut f = File::create(&piece_infos_path)
.with_context(|| format!("could not create file piece_infos_path={:?}", piece_infos_path))?;
info!("*** Created piece infos file");
let piece_infos_json = serde_json::to_string(&piece_infos.to_vec())?;
f.write_all(piece_infos_json.as_bytes())
.with_context(|| format!("could not write to file piece_infos_path={:?}", piece_infos_path))?;
info!("Persisted piece_infos to {:?} of size{}", piece_infos_path, f.metadata()?.len());
// Persist precommit phase1_output here
let precommit_phase1_output_path = cache_dir.join(PRECOMMIT_PHASE1_OUTPUT_FILE);
let mut f = File::create(&precommit_phase1_output_path)
.with_context(|| format!("could not create file precommit_phase1_output_path={:?}", precommit_phase1_output_path))?;
info!("*** Created precommit phase1 output file");
let precommit_phase1_output_bytes = serialize(&precommit_phase1_output)?;
f.write_all(&precommit_phase1_output_bytes)
.with_context(|| format!("could not write to file precommit_phase1_output_path={:?}", precommit_phase1_output_path))?;
info!("Persisted pre-commit phase1 output to {:?}", precommit_phase1_output_path);
(seal_pre_commit_phase1_measurement.cpu_time.as_millis() as u64, seal_pre_commit_phase1_measurement.wall_time.as_millis() as u64)
};
let (
(
validate_cache_for_precommit_phase2_measurement_cpu_time,
validate_cache_for_precommit_phase2_measurement_wall_time,
),
(seal_pre_commit_phase2_measurement_cpu_time, seal_pre_commit_phase2_measurement_wall_time),
) = if skip_precommit_phase2 {
// generate no-op measurements
((0, 0), (0, 0))
} else {
// Restore precommit phase1_output here
let precommit_phase1_output = {
let precommit_phase1_output_path = cache_dir.join(PRECOMMIT_PHASE1_OUTPUT_FILE);
info!("*** Restoring precommit phase1 output file");
let precommit_phase1_output_bytes =
read(&precommit_phase1_output_path).with_context(|| {
format!(
"could not read file precommit_phase1_output_path={:?}",
precommit_phase1_output_path
)
})?;
let res: SealPreCommitPhase1Output<Tree> = deserialize(&precommit_phase1_output_bytes)?;
res
};
let sealed_file_path = cache_dir.join(SEALED_FILE);
let porep_config = shared::get_porep_config(sector_size, api_version, features);
let validate_cache_for_precommit_phase2_measurement: FuncMeasurement<()> = measure(|| {
validate_cache_for_precommit_phase2::<_, _, Tree>(
cache_dir.clone(),
sealed_file_path.clone(),
&precommit_phase1_output,
)
})
.expect("failed to validate cache for precommit phase2");
let seal_pre_commit_phase2_measurement: FuncMeasurement<SealPreCommitOutput> =
measure(|| {
seal_pre_commit_phase2::<_, _, Tree>(
&porep_config,
precommit_phase1_output,
cache_dir.clone(),
sealed_file_path.clone(),
)
})
.expect("failed in seal_pre_commit_phase2");
let precommit_phase2_output = seal_pre_commit_phase2_measurement.return_value;
// Persist precommit phase2_output here
let precommit_phase2_output_path = cache_dir.join(PRECOMMIT_PHASE2_OUTPUT_FILE);
let mut f = File::create(&precommit_phase2_output_path).with_context(|| {
format!(
"could not create file precommit_phase2_output_path={:?}",
precommit_phase2_output_path
)
})?;
info!("*** Created precommit phase2 output file");
let precommit_phase2_output_bytes = serialize(&precommit_phase2_output)?;
f.write_all(&precommit_phase2_output_bytes)
.with_context(|| {
format!(
"could not write to file precommit_phase2_output_path={:?}",
precommit_phase2_output_path
)
})?;
info!(
"Persisted pre-commit phase2 output to {:?}",
precommit_phase2_output_path
);
(
(
validate_cache_for_precommit_phase2_measurement
.cpu_time
.as_millis() as u64,
validate_cache_for_precommit_phase2_measurement
.wall_time
.as_millis() as u64,
),
(
seal_pre_commit_phase2_measurement.cpu_time.as_millis() as u64,
seal_pre_commit_phase2_measurement.wall_time.as_millis() as u64,
),
)
};
Ok((
(
seal_pre_commit_phase1_measurement_cpu_time,
seal_pre_commit_phase1_measurement_wall_time,
),
(
validate_cache_for_precommit_phase2_measurement_cpu_time,
validate_cache_for_precommit_phase2_measurement_wall_time,
),
(
seal_pre_commit_phase2_measurement_cpu_time,
seal_pre_commit_phase2_measurement_wall_time,
),
))
}
#[allow(clippy::too_many_arguments)]
pub fn run_window_post_bench<Tree: 'static + MerkleTreeTrait>(
sector_size: u64,
api_version: ApiVersion,
cache_dir: PathBuf,
preserve_cache: bool,
skip_precommit_phase1: bool,
skip_precommit_phase2: bool,
skip_commit_phase1: bool,
skip_commit_phase2: bool,
test_resume: bool,
api_features: Vec<ApiFeature>,
) -> anyhow::Result<()> {
let (
(seal_pre_commit_phase1_cpu_time_ms, seal_pre_commit_phase1_wall_time_ms),
(
validate_cache_for_precommit_phase2_cpu_time_ms,
validate_cache_for_precommit_phase2_wall_time_ms,
),
(seal_pre_commit_phase2_cpu_time_ms, seal_pre_commit_phase2_wall_time_ms),
) = if skip_precommit_phase1 && skip_precommit_phase2 {
// generate no-op measurements
Ok(((0, 0), (0, 0), (0, 0)))
} else {
run_pre_commit_phases::<Tree>(
sector_size,
api_version,
cache_dir.clone(),
skip_precommit_phase1,
skip_precommit_phase2,
test_resume,
false, // skip staging
api_features.clone(),
)
}?;
let piece_infos = {
let piece_infos_path = cache_dir.join(PIECE_INFOS_FILE);
info!("*** Restoring piece infos file");
let piece_infos_json = read_to_string(&piece_infos_path).with_context(|| {
format!(
"could not read file piece_infos_path={:?}",
piece_infos_path
)
})?;
let res: Vec<PieceInfo> = serde_json::from_str(&piece_infos_json)?;
res
};
let seal_pre_commit_output = {
let phase2_output_path = cache_dir.join(PRECOMMIT_PHASE2_OUTPUT_FILE);
info!("*** Restoring precommit phase2 output file");
let phase2_output_bytes = read(&phase2_output_path).with_context(|| {
format!(
"could not read file phase2_output_path={:?}",
phase2_output_path
)
})?;
let res: SealPreCommitOutput = deserialize(&phase2_output_bytes)?;
res
};
let seed = [1u8; 32];
let comm_r = seal_pre_commit_output.comm_r;
let sector_id = SectorId::from(SECTOR_ID);
let porep_config = shared::get_porep_config(sector_size, api_version, api_features);
let sealed_file_path = cache_dir.join(SEALED_FILE);
let (
validate_cache_for_commit_cpu_time_ms,
validate_cache_for_commit_wall_time_ms,
seal_commit_phase1_cpu_time_ms,
seal_commit_phase1_wall_time_ms,
) = if skip_commit_phase1 {
// generate no-op measurements
(0, 0, 0, 0)
} else {
let validate_cache_for_commit_measurement = measure(|| {
validate_cache_for_commit::<_, _, Tree>(cache_dir.clone(), sealed_file_path.clone())
})
.expect("failed to validate cache for commit");
if porep_config.feature_enabled(ApiFeature::SyntheticPoRep) {
info!("SyntheticPoRep is enabled");
generate_synth_proofs::<_, Tree>(
&porep_config,
&cache_dir,
&sealed_file_path,
PROVER_ID,
sector_id,
TICKET_BYTES,
seal_pre_commit_output.clone(),
&piece_infos,
)?;
} else {
info!("SyntheticPoRep is NOT enabled");
}
let seal_commit_phase1_measurement = measure(|| {
seal_commit_phase1::<_, Tree>(
&porep_config,
cache_dir.clone(),
sealed_file_path.clone(),
PROVER_ID,
sector_id,
TICKET_BYTES,
seed,
seal_pre_commit_output,
&piece_infos,
)
})
.expect("failed in seal_commit_phase1");
let phase1_output = seal_commit_phase1_measurement.return_value;
// Persist commit phase1_output here
let phase1_output_path = cache_dir.join(COMMIT_PHASE1_OUTPUT_FILE);
let mut f = File::create(&phase1_output_path).with_context(|| {
format!(
"could not create file phase1_output_path={:?}",
phase1_output_path
)
})?;
info!("*** Created commit phase1 output file");
let phase1_output_bytes = serialize(&phase1_output)?;
f.write_all(&phase1_output_bytes).with_context(|| {
format!(
"could not write to file phase1_output_path={:?}",
phase1_output_path
)
})?;
info!("Persisted commit phase1 output to {:?}", phase1_output_path);
(
validate_cache_for_commit_measurement.cpu_time.as_millis() as u64,
validate_cache_for_commit_measurement.wall_time.as_millis() as u64,
seal_commit_phase1_measurement.cpu_time.as_millis() as u64,
seal_commit_phase1_measurement.wall_time.as_millis() as u64,
)
};
let (seal_commit_phase2_cpu_time_ms, seal_commit_phase2_wall_time_ms) = if skip_commit_phase2 {
// generate no-op measurements
(0, 0)
} else {
let commit_phase1_output = {
let commit_phase1_output_path = cache_dir.join(COMMIT_PHASE1_OUTPUT_FILE);
info!("*** Restoring commit phase1 output file");
let commit_phase1_output_bytes =
read(&commit_phase1_output_path).with_context(|| {
format!(
"could not read file commit_phase1_output_path={:?}",
commit_phase1_output_path
)
})?;
let res: SealCommitPhase1Output<Tree> = deserialize(&commit_phase1_output_bytes)?;
res
};
let seal_commit_phase2_measurement = measure(|| {
seal_commit_phase2::<Tree>(&porep_config, commit_phase1_output, PROVER_ID, sector_id)
})
.expect("failed in seal_commit_phase2");
(
seal_commit_phase2_measurement.cpu_time.as_millis() as u64,
seal_commit_phase2_measurement.wall_time.as_millis() as u64,
)
};
let pub_replica = PublicReplicaInfo::new(comm_r).expect("failed to create public replica info");
let priv_replica = PrivateReplicaInfo::<Tree>::new(sealed_file_path, comm_r, cache_dir.clone())
.expect("failed to create private replica info");
// Store the replica's private and publicly facing info for proving and verifying respectively.
let mut pub_replica_info: BTreeMap<SectorId, PublicReplicaInfo> = BTreeMap::new();
let mut priv_replica_info: BTreeMap<SectorId, PrivateReplicaInfo<Tree>> = BTreeMap::new();
pub_replica_info.insert(sector_id, pub_replica);
priv_replica_info.insert(sector_id, priv_replica);
// Measure PoSt generation and verification.
let post_config = PoStConfig {
sector_size: SectorSize(sector_size),
challenge_count: WINDOW_POST_CHALLENGE_COUNT,
sector_count: *WINDOW_POST_SECTOR_COUNT
.read()
.expect("WINDOW_POST_SECTOR_COUNT poisoned")
.get(§or_size)
.expect("unknown sector size"),
typ: PoStType::Window,
priority: true,
api_version,
};
let gen_window_post_measurement = measure(|| {
generate_window_post::<Tree>(&post_config, &RANDOMNESS, &priv_replica_info, PROVER_ID)
})
.expect("failed to generate window post");
let proof = &gen_window_post_measurement.return_value;
// warmup cache
verify_window_post::<Tree>(
&post_config,
&RANDOMNESS,
&pub_replica_info,
PROVER_ID,
proof,
)
.unwrap();
let verify_window_post_measurement = measure(|| {
verify_window_post::<Tree>(
&post_config,
&RANDOMNESS,
&pub_replica_info,
PROVER_ID,
proof,
)
})
.expect("failed to verify window post proof");
if preserve_cache {
info!("Preserving cache directory {:?}", cache_dir);
} else {
info!("Removing cache directory {:?}", cache_dir);
remove_dir_all(cache_dir)?;
}
let report = Report {
inputs: Inputs { sector_size },
outputs: Outputs {
seal_pre_commit_phase1_cpu_time_ms,
seal_pre_commit_phase1_wall_time_ms,
validate_cache_for_precommit_phase2_cpu_time_ms,
validate_cache_for_precommit_phase2_wall_time_ms,
seal_pre_commit_phase2_cpu_time_ms,
seal_pre_commit_phase2_wall_time_ms,
validate_cache_for_commit_cpu_time_ms,
validate_cache_for_commit_wall_time_ms,
seal_commit_phase1_cpu_time_ms,
seal_commit_phase1_wall_time_ms,
seal_commit_phase2_cpu_time_ms,
seal_commit_phase2_wall_time_ms,
gen_window_post_cpu_time_ms: gen_window_post_measurement.cpu_time.as_millis() as u64,
gen_window_post_wall_time_ms: gen_window_post_measurement.wall_time.as_millis() as u64,
verify_window_post_cpu_time_ms: verify_window_post_measurement.cpu_time.as_millis()
as u64,
verify_window_post_wall_time_ms: verify_window_post_measurement.wall_time.as_millis()
as u64,
},
};
// Create a JSON serializable report that we print to stdout (that will later be parsed using
// the CLI JSON parser `jq`).
report.print();
Ok(())
}
#[allow(clippy::too_many_arguments)]
pub fn run(
sector_size: usize,
api_version: ApiVersion,
cache: String,
preserve_cache: bool,
skip_precommit_phase1: bool,
skip_precommit_phase2: bool,
skip_commit_phase1: bool,
skip_commit_phase2: bool,
test_resume: bool,
api_features: Vec<ApiFeature>,
) -> anyhow::Result<()> {
let api_features_str = api_features
.iter()
.map(|api_feature| api_feature.to_string())
.collect::<Vec<String>>()
.join(",");
info!("Benchy Window PoSt: sector-size={}, api_version={}, preserve_cache={}, skip_precommit_phase1={}, skip_precommit_phase2={}, skip_commit_phase1={}, skip_commit_phase2={}, test_resume={}, api_features={}", sector_size, api_version, preserve_cache, skip_precommit_phase1, skip_precommit_phase2, skip_commit_phase1, skip_commit_phase2, test_resume, api_features_str);
let cache_dir_specified = !cache.is_empty();
// If 'preserve_cache' is specified, the 'cache' option must be specified and must not exist on disk.
if preserve_cache {
ensure!(
cache_dir_specified && !PathBuf::from(&cache).exists(),
"The 'preserve_cache' option cannot be used with a cache_dir that already exists"
);
}
if skip_precommit_phase1 || skip_precommit_phase2 || skip_commit_phase1 || skip_commit_phase2 {
ensure!(
!preserve_cache,
"Preserve cache cannot be used if skipping any stages"
);
ensure!(
cache_dir_specified,
"Cache dir is required if skipping any stages"
);
}
let (cache_dir, preserve_cache) = if cache_dir_specified {
// If a cache dir was specified, automatically preserve it.
(PathBuf::from(cache), true)
} else {
let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis();
(
std::env::temp_dir().join(format!("window-post-bench-{}", timestamp)),
preserve_cache,
)
};
if !cache_dir.exists() {
create_dir_all(&cache_dir)?;
}
info!("Using cache directory {:?}", cache_dir);
with_shape!(
sector_size as u64,
run_window_post_bench,
sector_size as u64,
api_version,
cache_dir,
preserve_cache,
skip_precommit_phase1,
skip_precommit_phase2,
skip_commit_phase1,
skip_commit_phase2,
test_resume,
api_features,
)
}