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
use super::{
BackedCandidate, Config, DisputeStatementSet, UncheckedSignedAvailabilityBitfield, Weight,
};
pub trait WeightInfo {
fn enter_variable_disputes(v: u32) -> Weight;
fn enter_bitfields() -> Weight;
fn enter_backed_candidates_variable(v: u32) -> Weight;
fn enter_backed_candidate_code_upgrade() -> Weight;
}
pub struct TestWeightInfo;
#[cfg(not(feature = "runtime-benchmarks"))]
impl WeightInfo for TestWeightInfo {
fn enter_variable_disputes(v: u32) -> Weight {
Weight::from_ref_time(80_000 * v as u64 + 80_000)
}
fn enter_bitfields() -> Weight {
Weight::from_ref_time(40_000u64)
}
fn enter_backed_candidates_variable(v: u32) -> Weight {
Weight::from_ref_time(40_000 * v as u64 + 40_000)
}
fn enter_backed_candidate_code_upgrade() -> Weight {
Weight::zero()
}
}
#[cfg(feature = "runtime-benchmarks")]
impl WeightInfo for TestWeightInfo {
fn enter_variable_disputes(_v: u32) -> Weight {
Weight::zero()
}
fn enter_bitfields() -> Weight {
Weight::zero()
}
fn enter_backed_candidates_variable(_v: u32) -> Weight {
Weight::zero()
}
fn enter_backed_candidate_code_upgrade() -> Weight {
Weight::zero()
}
}
pub fn paras_inherent_total_weight<T: Config>(
backed_candidates: &[BackedCandidate<<T as frame_system::Config>::Hash>],
bitfields: &[UncheckedSignedAvailabilityBitfield],
disputes: &[DisputeStatementSet],
) -> Weight {
backed_candidates_weight::<T>(backed_candidates)
.saturating_add(signed_bitfields_weight::<T>(bitfields.len()))
.saturating_add(multi_dispute_statement_sets_weight::<T, _, _>(disputes))
}
pub fn dispute_statement_set_weight<T: Config, S: AsRef<DisputeStatementSet>>(
statement_set: S,
) -> Weight {
<<T as Config>::WeightInfo as WeightInfo>::enter_variable_disputes(
statement_set.as_ref().statements.len() as u32,
)
}
pub fn multi_dispute_statement_sets_weight<
T: Config,
D: AsRef<[S]>,
S: AsRef<DisputeStatementSet>,
>(
disputes: D,
) -> Weight {
disputes
.as_ref()
.iter()
.map(|d| dispute_statement_set_weight::<T, &S>(d))
.fold(Weight::zero(), |acc_weight, weight| acc_weight.saturating_add(weight))
}
pub fn signed_bitfields_weight<T: Config>(bitfields_len: usize) -> Weight {
<<T as Config>::WeightInfo as WeightInfo>::enter_bitfields()
.saturating_mul(bitfields_len as u64)
}
pub fn backed_candidate_weight<T: frame_system::Config + Config>(
candidate: &BackedCandidate<T::Hash>,
) -> Weight {
if candidate.candidate.commitments.new_validation_code.is_some() {
<<T as Config>::WeightInfo as WeightInfo>::enter_backed_candidate_code_upgrade()
} else {
<<T as Config>::WeightInfo as WeightInfo>::enter_backed_candidates_variable(
candidate.validity_votes.len() as u32,
)
}
}
pub fn backed_candidates_weight<T: frame_system::Config + Config>(
candidates: &[BackedCandidate<T::Hash>],
) -> Weight {
candidates
.iter()
.map(|c| backed_candidate_weight::<T>(c))
.fold(Weight::zero(), |acc, x| acc.saturating_add(x))
}