[contracts] Adapt storage reading host functions to Weights V2 (#12976)

* update RuntimeCosts to Weights V2, update tests

* improve docs

* clearer naming and docs to compat_weight helper

* Apply suggestions from code review

Co-authored-by: Alexander Theißen <alex.theissen@me.com>

* save before master merge

* HostFnWeights to Weight

* added to_weight! macro

* Apply suggestions from code review

Co-authored-by: Alexander Theißen <alex.theissen@me.com>

* RuntimeCosts::ChainExtension to weight_v2

* chain extension to weight v2

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
This commit is contained in:
Sasha Gryaznov
2023-01-18 12:36:09 +02:00
committed by GitHub
parent 338d75d0a3
commit 05b846d63b
9 changed files with 189 additions and 154 deletions
@@ -122,23 +122,23 @@ fn iterate_fields(data: &syn::DataStruct, fmt: impl Fn(&Ident) -> TokenStream2)
fn format_weight(field: &Ident) -> TokenStream2 {
quote_spanned! { field.span() =>
&if self.#field > 1_000_000_000 {
&if self.#field.ref_time() > 1_000_000_000 {
format!(
"{:.1?} ms",
Fixed::saturating_from_rational(self.#field, 1_000_000_000).to_float()
Fixed::saturating_from_rational(self.#field.ref_time(), 1_000_000_000).to_float()
)
} else if self.#field > 1_000_000 {
} else if self.#field.ref_time() > 1_000_000 {
format!(
"{:.1?} µs",
Fixed::saturating_from_rational(self.#field, 1_000_000).to_float()
Fixed::saturating_from_rational(self.#field.ref_time(), 1_000_000).to_float()
)
} else if self.#field > 1_000 {
} else if self.#field.ref_time() > 1_000 {
format!(
"{:.1?} ns",
Fixed::saturating_from_rational(self.#field, 1_000).to_float()
Fixed::saturating_from_rational(self.#field.ref_time(), 1_000).to_float()
)
} else {
format!("{} ps", self.#field)
format!("{} ps", self.#field.ref_time())
}
}
}