diff --git a/CHANGELOG.md b/CHANGELOG.md index 68c92872cbd..5668ab0ef55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ Description of the upcoming release here. - [#1393](https://github.com/FuelLabs/fuel-core/pull/1393): Increase heartbeat timeout from `2` to `60` seconds, as suggested in [this issue](https://github.com/FuelLabs/fuel-core/issues/1330). - [#1395](https://github.com/FuelLabs/fuel-core/pull/1395): Add DependentCost benchmarks for `k256`, `s256` and `mcpi` instructions. - [#1408](https://github.com/FuelLabs/fuel-core/pull/1408): Update gas benchmarks for storage opcodes to use a pre-populated database to get more accurate worst-case costs. +- [#1454](https://github.com/FuelLabs/fuel-core/pull/1454): Update gas benchmarks for opcodes that append receipts. #### Breaking - [#1491](https://github.com/FuelLabs/fuel-core/pull/1491): Removed unused request and response variants from the Gossipsub implementation, as well as related definitions and tests. Specifically, this removes gossiping of `ConsensusVote` and `NewBlock` events. diff --git a/benches/benches/utils.rs b/benches/benches/utils.rs index f2af0e21f01..fa3dd065ede 100644 --- a/benches/benches/utils.rs +++ b/benches/benches/utils.rs @@ -6,10 +6,16 @@ use fuel_core_types::{ Instruction, RegId, }, + fuel_tx, fuel_types::{ RegisterId, Word, }, + fuel_vm::interpreter::ReceiptsCtx, +}; +use rand::{ + rngs::StdRng, + Rng, }; pub const STATE_SIZE: u64 = 10_000_000; @@ -70,3 +76,24 @@ pub fn set_full_word(r: RegisterId, v: Word) -> Vec { ops.pop().unwrap(); // Remove last shift ops } + +const BENCH_RECEIPTS: usize = (u16::MAX - 1) as usize; + +/// Testing receipt context +#[allow(dead_code)] // Unsure why this is needed, as the code is used +pub fn make_receipts(rng: &mut StdRng) -> ReceiptsCtx { + let mut ctx = ReceiptsCtx::default(); + for _ in 0..BENCH_RECEIPTS { + ctx.push(fuel_tx::Receipt::Log { + id: rng.gen(), + ra: rng.gen(), + rb: rng.gen(), + rc: rng.gen(), + rd: rng.gen(), + pc: rng.gen(), + is: rng.gen(), + }) + .expect("Context should not be full"); + } + ctx +} diff --git a/benches/benches/vm_set/blockchain.rs b/benches/benches/vm_set/blockchain.rs index a72920c5f2c..718cf0cdf19 100644 --- a/benches/benches/vm_set/blockchain.rs +++ b/benches/benches/vm_set/blockchain.rs @@ -3,6 +3,8 @@ use std::{ sync::Arc, }; +use crate::utils::make_receipts; + use super::run_group_ref; use criterion::{ @@ -130,6 +132,8 @@ pub fn run(c: &mut Criterion) { let db = BenchDb::new(&contract).expect("Unable to fill contract storage"); + let receipts_ctx = make_receipts(rng); + run_group_ref( &mut c.benchmark_group("bal"), "bal", @@ -279,7 +283,8 @@ pub fn run(c: &mut Criterion) { .with_db(db.to_vm_database()) .with_contract_code(code) .with_data(data) - .with_prepare_script(prepare_script), + .with_prepare_script(prepare_script) + .with_call_receipts(receipts_ctx.clone()), ); } @@ -427,7 +432,8 @@ pub fn run(c: &mut Criterion) { db.to_vm_database(), op::mint(RegId::ONE, RegId::ZERO), ) - .expect("failed to prepare contract"), + .expect("failed to prepare contract") + .with_call_receipts(receipts_ctx.clone()), ); run_group_ref( @@ -439,7 +445,8 @@ pub fn run(c: &mut Criterion) { op::burn(RegId::ONE, RegId::HP), ) .expect("failed to prepare contract") - .prepend_prepare_script(vec![op::movi(0x10, 32), op::aloc(0x10)]), + .prepend_prepare_script(vec![op::movi(0x10, 32), op::aloc(0x10)]) + .with_call_receipts(receipts_ctx.clone()), ); run_group_ref( @@ -459,7 +466,8 @@ pub fn run(c: &mut Criterion) { db.to_vm_database(), op::tr(0x15, 0x14, 0x15), ) - .expect("failed to prepare contract"); + .expect("failed to prepare contract") + .with_call_receipts(receipts_ctx.clone()); input .prepare_script .extend(vec![op::movi(0x15, 2000), op::movi(0x14, 100)]); @@ -473,7 +481,8 @@ pub fn run(c: &mut Criterion) { db.to_vm_database(), op::tro(RegId::ZERO, 0x15, 0x14, RegId::HP), ) - .expect("failed to prepare contract"); + .expect("failed to prepare contract") + .with_call_receipts(receipts_ctx.clone()); let coin_output = Output::variable(Address::zeroed(), 100, AssetId::zeroed()); input.outputs.push(coin_output); let predicate = op::ret(RegId::ONE).to_bytes().to_vec(); @@ -546,7 +555,8 @@ pub fn run(c: &mut Criterion) { db.to_vm_database(), op::smo(0x15, 0x16, 0x17, 0x18), ) - .expect("failed to prepare contract"); + .expect("failed to prepare contract") + .with_call_receipts(receipts_ctx.clone()); input.post_call.extend(vec![ op::gtf_args(0x15, 0x00, GTFArgs::ScriptData), // Offset 32 + 8 + 8 + 32 diff --git a/benches/benches/vm_set/flow.rs b/benches/benches/vm_set/flow.rs index 9f88e7f9b3a..24bd2258d8b 100644 --- a/benches/benches/vm_set/flow.rs +++ b/benches/benches/vm_set/flow.rs @@ -1,6 +1,9 @@ use super::run_group_ref; -use crate::utils::arb_dependent_cost_values; +use crate::utils::{ + arb_dependent_cost_values, + make_receipts, +}; use criterion::{ Criterion, Throughput, @@ -16,6 +19,7 @@ pub fn run(c: &mut Criterion) { let rng = &mut StdRng::seed_from_u64(2322u64); let linear = arb_dependent_cost_values(); + let receipts_ctx = make_receipts(rng); run_group_ref( &mut c.benchmark_group("jmp"), @@ -47,13 +51,15 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("ret_script"), "ret_script", - VmBench::new(op::ret(RegId::ONE)), + VmBench::new(op::ret(RegId::ONE)).with_call_receipts(receipts_ctx.clone()), ); run_group_ref( &mut c.benchmark_group("ret_contract"), "ret_contract", - VmBench::contract(rng, op::ret(RegId::ONE)).unwrap(), + VmBench::contract(rng, op::ret(RegId::ONE)) + .unwrap() + .with_call_receipts(receipts_ctx.clone()), ); let mut retd_contract = c.benchmark_group("retd_contract"); @@ -64,7 +70,8 @@ pub fn run(c: &mut Criterion) { format!("{i}"), VmBench::contract(rng, op::retd(RegId::ONE, 0x10)) .unwrap() - .with_post_call(vec![op::movi(0x10, *i)]), + .with_post_call(vec![op::movi(0x10, *i)]) + .with_call_receipts(receipts_ctx.clone()), ); } retd_contract.finish(); @@ -77,7 +84,8 @@ pub fn run(c: &mut Criterion) { format!("{i}"), VmBench::contract(rng, op::retd(RegId::ONE, 0x10)) .unwrap() - .with_post_call(vec![op::movi(0x10, *i)]), + .with_post_call(vec![op::movi(0x10, *i)]) + .with_call_receipts(receipts_ctx.clone()), ); } retd_script.finish(); @@ -85,19 +93,22 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("rvrt_script"), "rvrt_script", - VmBench::new(op::rvrt(RegId::ONE)), + VmBench::new(op::rvrt(RegId::ONE)).with_call_receipts(receipts_ctx.clone()), ); run_group_ref( &mut c.benchmark_group("rvrt_contract"), "rvrt_contract", - VmBench::contract(rng, op::ret(RegId::ONE)).unwrap(), + VmBench::contract(rng, op::ret(RegId::ONE)) + .unwrap() + .with_call_receipts(receipts_ctx.clone()), ); run_group_ref( &mut c.benchmark_group("log"), "log", - VmBench::new(op::log(0x10, 0x11, 0x12, 0x13)), + VmBench::new(op::log(0x10, 0x11, 0x12, 0x13)) + .with_call_receipts(receipts_ctx.clone()), ); let mut logd = c.benchmark_group("logd"); @@ -107,7 +118,8 @@ pub fn run(c: &mut Criterion) { &mut logd, format!("{i}"), VmBench::new(op::logd(0x10, 0x11, RegId::ZERO, 0x13)) - .with_prepare_script(vec![op::movi(0x13, *i)]), + .with_prepare_script(vec![op::movi(0x13, *i)]) + .with_call_receipts(receipts_ctx.clone()), ); } logd.finish(); diff --git a/benches/src/lib.rs b/benches/src/lib.rs index e6428ca8175..d59ea2e3562 100644 --- a/benches/src/lib.rs +++ b/benches/src/lib.rs @@ -24,6 +24,7 @@ use fuel_core_types::{ interpreter::{ diff, InterpreterParams, + ReceiptsCtx, }, *, }, @@ -69,10 +70,10 @@ impl From> for ContractCode { } pub struct PrepareCall { - ra: RegId, - rb: RegId, - rc: RegId, - rd: RegId, + pub ra: RegId, + pub rb: RegId, + pub rc: RegId, + pub rd: RegId, } pub struct VmBench { @@ -92,6 +93,7 @@ pub struct VmBench { pub prepare_call: Option, pub dummy_contract: Option, pub contract_code: Option, + pub receipts_ctx: Option, } #[derive(Debug, Clone)] @@ -130,6 +132,7 @@ impl VmBench { prepare_call: None, dummy_contract: None, contract_code: None, + receipts_ctx: None, } } @@ -207,7 +210,6 @@ impl VmBench { self.db.replace(db); self } - pub fn with_params(mut self, params: ConsensusParameters) -> Self { self.params = params; self @@ -277,6 +279,11 @@ impl VmBench { self } + pub fn with_call_receipts(mut self, receipts_ctx: ReceiptsCtx) -> Self { + self.receipts_ctx = Some(receipts_ctx); + self + } + pub fn with_dummy_contract(mut self, dummy_contract: ContractId) -> Self { self.dummy_contract.replace(dummy_contract); self @@ -313,6 +320,7 @@ impl TryFrom for VmBenchPrepared { prepare_call, dummy_contract, contract_code, + receipts_ctx, } = case; let mut db = db.unwrap_or_else(new_db); @@ -417,6 +425,10 @@ impl TryFrom for VmBenchPrepared { let mut vm: Interpreter<_, _> = txtor.into(); + if let Some(receipts_ctx) = receipts_ctx { + *vm.receipts_mut() = receipts_ctx; + } + if let Some(p) = prepare_call { let PrepareCall { ra, rb, rc, rd } = p;