Skip to content

Commit

Permalink
Update benches that are affected by receipts (#1454)
Browse files Browse the repository at this point in the history
Closes #1414. Also does some
upgrades for latest `fuel-vm` version. Targets
FuelLabs/fuel-vm#625 currently, needs new
`fuel-vm` release after that is merged.


This also mostly reverts #1457
which was not working correctly, especially with regards to `call`
instruction.

---------

Co-authored-by: xgreenx <xgreenx9999@gmail.com>
  • Loading branch information
Dentosal and xgreenx authored Nov 20, 2023
1 parent 72bb2df commit 1c46249
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 27 additions & 0 deletions benches/benches/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,3 +76,24 @@ pub fn set_full_word(r: RegisterId, v: Word) -> Vec<Instruction> {
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
}
22 changes: 16 additions & 6 deletions benches/benches/vm_set/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::{
sync::Arc,
};

use crate::utils::make_receipts;

use super::run_group_ref;

use criterion::{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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()),
);
}

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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)]);
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
30 changes: 21 additions & 9 deletions benches/benches/vm_set/flow.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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"),
Expand Down Expand Up @@ -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");
Expand All @@ -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();
Expand All @@ -77,27 +84,31 @@ 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();

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");
Expand All @@ -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();
Expand Down
22 changes: 17 additions & 5 deletions benches/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use fuel_core_types::{
interpreter::{
diff,
InterpreterParams,
ReceiptsCtx,
},
*,
},
Expand Down Expand Up @@ -69,10 +70,10 @@ impl From<Vec<u8>> 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 {
Expand All @@ -92,6 +93,7 @@ pub struct VmBench {
pub prepare_call: Option<PrepareCall>,
pub dummy_contract: Option<ContractId>,
pub contract_code: Option<ContractCode>,
pub receipts_ctx: Option<ReceiptsCtx>,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -130,6 +132,7 @@ impl VmBench {
prepare_call: None,
dummy_contract: None,
contract_code: None,
receipts_ctx: None,
}
}

Expand Down Expand Up @@ -207,7 +210,6 @@ impl VmBench {
self.db.replace(db);
self
}

pub fn with_params(mut self, params: ConsensusParameters) -> Self {
self.params = params;
self
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -313,6 +320,7 @@ impl TryFrom<VmBench> for VmBenchPrepared {
prepare_call,
dummy_contract,
contract_code,
receipts_ctx,
} = case;

let mut db = db.unwrap_or_else(new_db);
Expand Down Expand Up @@ -417,6 +425,10 @@ impl TryFrom<VmBench> 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;

Expand Down

0 comments on commit 1c46249

Please sign in to comment.