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
use polkadot_erasure_coding::{obtain_chunks, reconstruct};
use polkadot_node_core_pvf::{sc_executor_common, sp_maybe_compressed_blob};
use std::time::{Duration, Instant};
mod constants;
pub use constants::*;
pub use polkadot_node_primitives::VALIDATION_CODE_BOMB_LIMIT;
pub const ERASURE_CODING_N_VALIDATORS: usize = 1024;
pub use kusama_runtime::WASM_BINARY;
#[allow(missing_docs)]
#[derive(thiserror::Error, Debug)]
pub enum PerfCheckError {
#[error("This subcommand is only available in release mode")]
WrongBuildType,
#[error("This subcommand is only available when compiled with `{feature}`")]
FeatureNotEnabled { feature: &'static str },
#[error("No wasm code found for running the performance test")]
WasmBinaryMissing,
#[error("Failed to decompress wasm code")]
CodeDecompressionFailed,
#[error(transparent)]
Wasm(#[from] sc_executor_common::error::WasmError),
#[error(transparent)]
ErasureCoding(#[from] polkadot_erasure_coding::Error),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(
"Performance check not passed: exceeded the {limit:?} time limit, elapsed: {elapsed:?}"
)]
TimeOut { elapsed: Duration, limit: Duration },
}
pub fn measure_pvf_prepare(wasm_code: &[u8]) -> Result<Duration, PerfCheckError> {
let start = Instant::now();
let code = sp_maybe_compressed_blob::decompress(wasm_code, VALIDATION_CODE_BOMB_LIMIT)
.or(Err(PerfCheckError::CodeDecompressionFailed))?;
let blob = polkadot_node_core_pvf::prevalidate(code.as_ref()).map_err(PerfCheckError::from)?;
polkadot_node_core_pvf::prepare(blob).map_err(PerfCheckError::from)?;
Ok(start.elapsed())
}
pub fn measure_erasure_coding(
n_validators: usize,
data: &[u8],
) -> Result<Duration, PerfCheckError> {
let start = Instant::now();
let chunks = obtain_chunks(n_validators, &data)?;
let indexed_chunks = chunks.iter().enumerate().map(|(i, chunk)| (chunk.as_slice(), i));
let _: Vec<u8> = reconstruct(n_validators, indexed_chunks)?;
Ok(start.elapsed())
}