fuel-core
fuel-core copied to clipboard
feat: Regression based modelling of gas prices
Related issues:
- https://github.com/FuelLabs/fuel-vm/issues/611
- https://github.com/FuelLabs/fuel-core/issues/1522
There are some outstanding issues that I will address presently. But the PR is ready for a first round of reviews. I will do a new VM release with required cost changes and integrate. I will also upgrade the Rust version, as well as other tangential changes, in separate PRs.
The code itself looks good to me. Can you post the results for this so we can compare to old benchmark results?
I am in the process of producing some outputs now, and I will post them here when they are complete. To do this, I am running a subset of the VM benches that will include a number of heavy and light outputs, just to give an idea of the full suite. After that, we can run the full VM suite on a dedicated instance to get the new outputs.
This test may produce some functions that are currently not supported, i.e. logarithmic, exponential, or quadratic. If this happens, these costs will not be supported. Fortunately, this approach allows us to more accurately match a cost to an appropriate model of function, and we can simply provide a regression and resolver if we need to support this in the future.
Given the current PR, and the data provided here, collect
gives us the following:
use super::*;
/// File generated by fuel-core: benches/src/collect/state.rs:197. With the following git hash
pub const GIT: &str = "856f763cc042e78e6aa215e60614827b0e6cb812";
pub fn default_gas_costs() -> GasCostsValues {
GasCostsValues {
add: 1,
addi: 1,
aloc: 1,
and: 1,
andi: 1,
bal: 832,
bhei: 1,
bhsh: 1,
burn: 73630,
cb: 1,
cfei: 1,
cfsi: 1,
croo: 173,
div: 1,
divi: 1,
eck1: 3849,
ecr1: 51685,
ed19: 3783,
eq: 1,
exp: 1,
expi: 1,
flag: 1,
gm: 1,
gt: 1,
gtf: 1,
ji: 1,
jmp: 1,
jne: 1,
jnei: 1,
jnzi: 1,
jmpf: 1,
jmpb: 1,
jnzf: 1,
jnzb: 1,
jnef: 1,
jneb: 1,
lb: 1,
log: 1503,
lt: 1,
lw: 1,
mint: 58278,
mlog: 2,
state_root: DependentCost::HeavyOperation {
base: 0,
gas_per_unit: 186,
},
modi: 1,
mod_op: 1,
movi: 1,
mroo: 4,
mul: 1,
muli: 1,
mldv: 1,
noop: 1,
not: 1,
or: 1,
ori: 1,
poph: 1,
popl: 1,
pshh: 1,
pshl: 1,
move_op: 1,
ret: 1687,
sb: 1,
sll: 1,
slli: 1,
srl: 1,
srli: 1,
srw: 41,
sub: 1,
subi: 1,
sw: 1,
sww: 1253,
time: 1,
tr: 120175,
tro: 72174,
wdcm: 1,
wqcm: 2,
wdop: 2,
wqop: 2,
wdml: 2,
wqml: 3,
wddv: 5,
wqdv: 9,
wdmd: 11,
wqmd: 19,
wdam: 9,
wqam: 11,
wdmm: 14,
wqmm: 14,
xor: 1,
xori: 1,
call: DependentCost::LightOperation {
base: 11852,
units_per_gas: 11,
},
ccp: DependentCost::LightOperation {
base: 137,
units_per_gas: 31,
},
csiz: DependentCost::LightOperation {
base: 150,
units_per_gas: 57,
},
k256: DependentCost::LightOperation {
base: 23,
units_per_gas: 3,
},
ldc: DependentCost::LightOperation {
base: 142,
units_per_gas: 32,
},
logd: DependentCost::LightOperation {
base: 1575,
units_per_gas: 2,
},
mcl: DependentCost::LightOperation {
base: 0,
units_per_gas: 538,
},
mcli: DependentCost::LightOperation {
base: 0,
units_per_gas: 548,
},
mcp: DependentCost::LightOperation {
base: 0,
units_per_gas: 448,
},
mcpi: DependentCost::LightOperation {
base: 2,
units_per_gas: 1824,
},
meq: DependentCost::LightOperation {
base: 1,
units_per_gas: 1104,
},
rvrt: 1742,
s256: DependentCost::LightOperation {
base: 10,
units_per_gas: 3,
},
scwq: DependentCost::HeavyOperation {
base: 1,
gas_per_unit: 0,
},
smo: DependentCost::LightOperation {
base: 71020,
units_per_gas: 2,
},
srwq: DependentCost::LightOperation {
base: 0,
units_per_gas: 1,
},
swwq: DependentCost::HeavyOperation {
base: 1,
gas_per_unit: 0,
},
contract_root: DependentCost::LightOperation {
base: 0,
units_per_gas: 3,
},
retd: DependentCost::LightOperation {
base: 1583,
units_per_gas: 2,
},
}
}
Note that scwq
and swwq
were not included:
Warning the following keys were not set by this bench:
["jmpb", "jmpf", "jneb", "jnef", "jnzb", "jnzf", "mldv", "poph", "popl", "pshh", "pshl", "scwq", "swwq"]
I like the idea of this change, it looks great=)
I want to block the merging of this PR until we have stable results from the
collect
binary that we can use in production.Right now it doesn't return prices for sequential opcodes.
Can you clarify which sequential opcodes are not returned by this version of collect
please? I can investigate that.
Edit: If you're referring to the fact that the above results do not include scwq
and swwq
, it's simply because the benchmark data I used to generate the prices did not include them. They were generated from this data as provided on Slack.
Updated prices:
use super::*;
/// File generated by fuel-core: benches/src/collect/state.rs:197. With the following git hash
pub const GIT: &str = "12c044d226407e230b7653251dd381e15f5f5462";
pub fn default_gas_costs() -> GasCostsValues {
GasCostsValues {
add: 1,
addi: 1,
aloc: 0,
and: 1,
andi: 1,
bal: 40,
bhei: 1,
bhsh: 1,
burn: 27737,
cb: 1,
cfei: 1,
cfsi: 1,
croo: 39,
div: 1,
divi: 1,
eck1: 3106,
ecr1: 42737,
ed19: 2896,
eq: 1,
exp: 1,
expi: 1,
flag: 0,
gm: 1,
gt: 1,
gtf: 1,
ji: 1,
jmp: 1,
jne: 1,
jnei: 1,
jnzi: 1,
jmpf: 1,
jmpb: 1,
jnzf: 1,
jnzb: 1,
jnef: 1,
jneb: 1,
lb: 1,
log: 86,
lt: 1,
lw: 1,
mint: 25514,
mlog: 1,
state_root: DependentCost::HeavyOperation {
base: 0,
gas_per_unit: 161,
},
modi: 1,
mod_op: 1,
movi: 1,
mroo: 3,
mul: 1,
muli: 1,
mldv: 3,
noop: 1,
not: 1,
or: 1,
ori: 1,
poph: 2,
popl: 2,
pshh: 2,
pshl: 2,
move_op: 1,
ret: 126,
sb: 1,
sll: 1,
slli: 1,
srl: 1,
srli: 1,
srw: 223,
sub: 1,
subi: 1,
sw: 1,
sww: 26246,
time: 75,
tr: 38924,
tro: 26755,
wdcm: 1,
wqcm: 2,
wdop: 2,
wqop: 2,
wdml: 2,
wqml: 3,
wddv: 4,
wqdv: 5,
wdmd: 9,
wqmd: 16,
wdam: 8,
wqam: 10,
wdmm: 9,
wqmm: 9,
xor: 1,
xori: 1,
call: DependentCost::LightOperation {
base: 16160,
units_per_gas: 60,
},
ccp: DependentCost::LightOperation {
base: 20,
units_per_gas: 23,
},
csiz: DependentCost::LightOperation {
base: 28,
units_per_gas: 300,
},
k256: DependentCost::LightOperation {
base: 27,
units_per_gas: 4,
},
ldc: DependentCost::LightOperation {
base: 18,
units_per_gas: 73,
},
logd: DependentCost::LightOperation {
base: 124,
units_per_gas: 3,
},
mcl: DependentCost::LightOperation {
base: 0,
units_per_gas: 639,
},
mcli: DependentCost::LightOperation {
base: 0,
units_per_gas: 639,
},
mcp: DependentCost::LightOperation {
base: 1,
units_per_gas: 523,
},
mcpi: DependentCost::HeavyOperation {
base: 2,
gas_per_unit: 0,
},
meq: DependentCost::LightOperation {
base: 1,
units_per_gas: 1349,
},
rvrt: 126,
s256: DependentCost::LightOperation {
base: 20,
units_per_gas: 3,
},
scwq: DependentCost::HeavyOperation {
base: 2093854,
gas_per_unit: 21099,
},
smo: DependentCost::LightOperation {
base: 26672,
units_per_gas: 3,
},
srwq: DependentCost::HeavyOperation {
base: 410,
gas_per_unit: 19,
},
swwq: DependentCost::HeavyOperation {
base: 1503569,
gas_per_unit: 20088,
},
contract_root: DependentCost::LightOperation {
base: 0,
units_per_gas: 3,
},
retd: DependentCost::LightOperation {
base: 145,
units_per_gas: 3,
},
}
}