pub trait HostCostModel {
    // Required method
    fn evaluate(&self, input: Option<u64>) -> Result<u64, HostError>;
}
Expand description

We provide a “cost model” object that evaluates a linear expression:

f(x) = a + b * Option

Where a, b are “fixed” parameters at construction time (extracted from an on-chain cost schedule, so technically not totally fixed) and Option is some abstract input variable – say, event counts or object sizes – provided at runtime. If the input cannot be defined, i.e., the cost is constant, input-independent, then pass in None as the input.

The same CostModel type, i.e. CostType (applied to different parameters and variables) is used for calculating memory as well as CPU time.

The various CostTypes are carefully choosen such that 1. their underlying cost characteristics (both cpu and memory) at runtime can be described sufficiently by a linear model and 2. they together encompass the vast majority of available operations done by the env – the host and the VM.

The parameters for a CostModel are calibrated empirically. See this crate’s benchmarks for more details.

Required Methods§

source

fn evaluate(&self, input: Option<u64>) -> Result<u64, HostError>

Implementors§