[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
@@ -253,7 +253,7 @@ pub enum RuntimeCosts {
/// Weight of calling `seal_ecdsa_recover`.
EcdsaRecovery,
/// Weight charged by a chain extension through `seal_call_chain_extension`.
ChainExtension(u64),
ChainExtension(Weight),
/// Weight charged for calling into the runtime.
CallRuntime(Weight),
/// Weight of calling `seal_set_code_hash`
@@ -272,7 +272,7 @@ impl RuntimeCosts {
fn token<T: Config>(&self, s: &HostFnWeights<T>) -> RuntimeToken {
use self::RuntimeCosts::*;
let weight = match *self {
MeteringBlock(amount) => s.gas.saturating_add(amount),
MeteringBlock(amount) => s.gas.saturating_add(Weight::from_ref_time(amount)),
CopyFromContract(len) => s.return_per_byte.saturating_mul(len.into()),
CopyToContract(len) => s.input_per_byte.saturating_mul(len.into()),
Caller => s.caller,
@@ -335,8 +335,8 @@ impl RuntimeCosts {
.hash_blake2_128
.saturating_add(s.hash_blake2_128_per_byte.saturating_mul(len.into())),
EcdsaRecovery => s.ecdsa_recover,
ChainExtension(amount) => amount,
CallRuntime(weight) => weight.ref_time(),
ChainExtension(weight) => weight,
CallRuntime(weight) => weight,
SetCodeHash => s.set_code_hash,
EcdsaToEthAddress => s.ecdsa_to_eth_address,
ReentrantCount => s.reentrance_count,
@@ -346,7 +346,7 @@ impl RuntimeCosts {
RuntimeToken {
#[cfg(test)]
_created_from: *self,
weight: Weight::from_ref_time(weight),
weight,
}
}
}