Function fp_evm::weight_per_gas

source ·
pub fn weight_per_gas(
    block_gas_limit: u64,
    txn_ratio: Perbill,
    weight_millis_per_block: u64
) -> u64
Expand description

WeightPerGas is an approximate ratio of the amount of Weight per Gas. u64 works for approximations because Weight is a very small unit compared to gas.

GAS_PER_MILLIS * WEIGHT_MILLIS_PER_BLOCK * TXN_RATIO ~= BLOCK_GAS_LIMIT WEIGHT_PER_GAS = WEIGHT_REF_TIME_PER_MILLIS / GAS_PER_MILLIS = WEIGHT_REF_TIME_PER_MILLIS / (BLOCK_GAS_LIMIT / TXN_RATIO / WEIGHT_MILLIS_PER_BLOCK) = TXN_RATIO * (WEIGHT_REF_TIME_PER_MILLIS * WEIGHT_MILLIS_PER_BLOCK) / BLOCK_GAS_LIMIT

For example, given the 2000ms Weight, from which 75% only are used for transactions, the total EVM execution gas limit is GAS_PER_MILLIS * 2000 * 75% = BLOCK_GAS_LIMIT.