mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 23:21:06 +00:00
Move Staking Weights to T::WeightInfo (#7007)
* Fix the benchmarks * Migrate staking to weightInfo * Fix global benchmarks * re-calculate the submit solution weight. * Fix some refund. * Get rid of all the extra parameters. * Fix staking tests. * new values from the bench machine. * Fix some grumbles * better macro * Some better doc * Move to interpreted wasm * Make it work temporarily * Final fix of default ones. * Fix payout benchmarks * Fix payout stuff * One last fix * use benchmarking machine for numbers * update weight docs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -149,22 +149,9 @@ fn struct_def(
|
||||
)
|
||||
}).collect::<TokenStream2>();
|
||||
|
||||
|
||||
let len_impl = (1..=count).map(|c| {
|
||||
let field_name = field_name_for(c);
|
||||
quote!(
|
||||
all_len = all_len.saturating_add(self.#field_name.len());
|
||||
)
|
||||
}).collect::<TokenStream2>();
|
||||
|
||||
let edge_count_impl = (1..=count).map(|c| {
|
||||
let field_name = field_name_for(c);
|
||||
quote!(
|
||||
all_edges = all_edges.saturating_add(
|
||||
self.#field_name.len().saturating_mul(#c as usize)
|
||||
);
|
||||
)
|
||||
}).collect::<TokenStream2>();
|
||||
let len_impl = len_impl(count);
|
||||
let edge_count_impl = edge_count_impl(count);
|
||||
let unique_targets_impl = unique_targets_impl(count);
|
||||
|
||||
let derives_and_maybe_compact_encoding = if compact_encoding {
|
||||
// custom compact encoding.
|
||||
@@ -209,6 +196,26 @@ fn struct_def(
|
||||
all_edges
|
||||
}
|
||||
|
||||
/// Get the number of unique targets in the whole struct.
|
||||
///
|
||||
/// Once presented with a list of winners, this set and the set of winners must be
|
||||
/// equal.
|
||||
///
|
||||
/// The resulting indices are sorted.
|
||||
pub fn unique_targets(&self) -> Vec<#target_type> {
|
||||
let mut all_targets: Vec<#target_type> = Vec::with_capacity(self.average_edge_count());
|
||||
let mut maybe_insert_target = |t: #target_type| {
|
||||
match all_targets.binary_search(&t) {
|
||||
Ok(_) => (),
|
||||
Err(pos) => all_targets.insert(pos, t)
|
||||
}
|
||||
};
|
||||
|
||||
#unique_targets_impl
|
||||
|
||||
all_targets
|
||||
}
|
||||
|
||||
/// Get the average edge count.
|
||||
pub fn average_edge_count(&self) -> usize {
|
||||
self.edge_count().checked_div(self.len()).unwrap_or(0)
|
||||
@@ -217,6 +224,65 @@ fn struct_def(
|
||||
))
|
||||
}
|
||||
|
||||
fn len_impl(count: usize) -> TokenStream2 {
|
||||
(1..=count).map(|c| {
|
||||
let field_name = field_name_for(c);
|
||||
quote!(
|
||||
all_len = all_len.saturating_add(self.#field_name.len());
|
||||
)
|
||||
}).collect::<TokenStream2>()
|
||||
}
|
||||
|
||||
fn edge_count_impl(count: usize) -> TokenStream2 {
|
||||
(1..=count).map(|c| {
|
||||
let field_name = field_name_for(c);
|
||||
quote!(
|
||||
all_edges = all_edges.saturating_add(
|
||||
self.#field_name.len().saturating_mul(#c as usize)
|
||||
);
|
||||
)
|
||||
}).collect::<TokenStream2>()
|
||||
}
|
||||
|
||||
fn unique_targets_impl(count: usize) -> TokenStream2 {
|
||||
let unique_targets_impl_single = {
|
||||
let field_name = field_name_for(1);
|
||||
quote! {
|
||||
self.#field_name.iter().for_each(|(_, t)| {
|
||||
maybe_insert_target(*t);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
let unique_targets_impl_double = {
|
||||
let field_name = field_name_for(2);
|
||||
quote! {
|
||||
self.#field_name.iter().for_each(|(_, (t1, _), t2)| {
|
||||
maybe_insert_target(*t1);
|
||||
maybe_insert_target(*t2);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
let unique_targets_impl_rest = (3..=count).map(|c| {
|
||||
let field_name = field_name_for(c);
|
||||
quote! {
|
||||
self.#field_name.iter().for_each(|(_, inners, t_last)| {
|
||||
inners.iter().for_each(|(t, _)| {
|
||||
maybe_insert_target(*t);
|
||||
});
|
||||
maybe_insert_target(*t_last);
|
||||
});
|
||||
}
|
||||
}).collect::<TokenStream2>();
|
||||
|
||||
quote! {
|
||||
#unique_targets_impl_single
|
||||
#unique_targets_impl_double
|
||||
#unique_targets_impl_rest
|
||||
}
|
||||
}
|
||||
|
||||
fn imports() -> Result<TokenStream2> {
|
||||
if std::env::var("CARGO_PKG_NAME").unwrap() == "sp-npos-elections" {
|
||||
Ok(quote! {
|
||||
|
||||
Reference in New Issue
Block a user