From 4986d4d034499dafc19b9dcd72458717b6ecdd5b Mon Sep 17 00:00:00 2001 From: Green Baneling Date: Fri, 7 Jun 2024 00:36:15 +0200 Subject: [PATCH] Use `DependentCost` for `aloc` opcode (#1934) PR upgrades the `fuel-vm` to `0.52.0`. A new VM changes `aloc` opcode to be `DependentCost`. It requires updated benchmarks. The PR also updates default gas costs according to a new Vultr instance we use to do benchmarks. It works faster than the previous one, so all opcodes became cheaper. The `vm_initialziation` became much cheaper and now has reasonable values. The `bloc` opcode became expensive and depended on a number of allocated bytes. ## Checklist - [x] Breaking changes are clearly marked as such in the PR description and changelog ### Before requesting review - [x] I have reviewed the code myself ### After merging, notify other teams - [x] Both SDKs --------- Co-authored-by: Hannes Karppila Co-authored-by: Mitchell Turner --- CHANGELOG.md | 11 +- Cargo.lock | 32 +- Cargo.toml | 2 +- benches/benches-outputs/src/lib.rs | 2 +- benches/benches/utils.rs | 22 +- benches/benches/vm_initialization.rs | 62 +-- benches/benches/vm_set/alu.rs | 34 +- benches/benches/vm_set/blockchain.rs | 25 +- benches/src/bin/collect.rs | 6 +- benches/src/default_gas_costs.rs | 155 +++---- .../chainspec/local-testnet/README.md | 25 +- .../benchmarks_fuel_core_0_26_0.json | 416 ----------------- .../benchmarks_fuel_core_0_28_0.json | 424 ++++++++++++++++++ .../chainspec/local-testnet/chain_config.json | 159 +++---- .../chainspec/local-testnet/state_config.json | 2 +- .../state_transition_bytecode.wasm | Bin 2509382 -> 1953796 bytes ci_checks.sh | 2 +- ..._tests__snapshot_local_testnet_config.snap | 9 +- crates/client/assets/schema.sdl | 1 + crates/client/src/client/schema/chain.rs | 7 +- ..._chain__tests__chain_gql_query_output.snap | 12 +- crates/client/src/client/types/gas_costs.rs | 4 +- crates/fuel-core/src/schema/chain.rs | 8 +- 23 files changed, 726 insertions(+), 694 deletions(-) delete mode 100644 bin/fuel-core/chainspec/local-testnet/benchmarks_fuel_core_0_26_0.json create mode 100644 bin/fuel-core/chainspec/local-testnet/benchmarks_fuel_core_0_28_0.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f3b70be51..f473013ab2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Changed +- [#1934](https://github.com/FuelLabs/fuel-core/pull/1934): Updated benchmark for the `aloc` opcode to be `DependentCost`. Updated `vm_initialization` benchmark to exclude growing of memory(It is handled by VM reuse). - [#1916](https://github.com/FuelLabs/fuel-core/pull/1916): Speed up synchronisation of the blocks for the `fuel-core-sync` service. +- [#1888](https://github.com/FuelLabs/fuel-core/pull/1888): optimization: Reuse VM memory across executions. #### Breaking +- [#1934](https://github.com/FuelLabs/fuel-core/pull/1934): Changed `GasCosts` endpoint to return `DependentCost` for the `aloc` opcode via `alocDependentCost`. +- [#1934](https://github.com/FuelLabs/fuel-core/pull/1934): Updated default gas costs for the local testnet configuration. All opcodes became cheaper. - [#1924](https://github.com/FuelLabs/fuel-core/pull/1924): `dry_run_opt` has new `gas_price: Option` argument +- [#1888](https://github.com/FuelLabs/fuel-core/pull/1888): Upgraded `fuel-vm` to `0.51.0`. See [release](https://github.com/FuelLabs/fuel-vm/releases/tag/v0.51.0) for more information. ### Added - [#1939](https://github.com/FuelLabs/fuel-core/pull/1939): Added API functions to open a RocksDB in different modes. @@ -20,12 +25,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Removed - [#1913](https://github.com/FuelLabs/fuel-core/pull/1913): Removed dead code from the project. -### Changed -- [#1888](https://github.com/FuelLabs/fuel-core/pull/1888): optimization: Reuse VM memory across executions. - -#### Breaking -- [#1888](https://github.com/FuelLabs/fuel-core/pull/1888): Upgraded `fuel-vm` to `0.51.0`. See [release](https://github.com/FuelLabs/fuel-vm/releases/tag/v0.51.0) for more information. - ### Fixed - [#1921](https://github.com/FuelLabs/fuel-core/pull/1921): Fixed unstable `gossipsub_broadcast_tx_with_accept` test. - [#1915](https://github.com/FuelLabs/fuel-core/pull/1915): Fixed reconnection issue in the dev cluster with AWS cluster. diff --git a/Cargo.lock b/Cargo.lock index 1b54c7f866..56cbc2caef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2817,9 +2817,9 @@ dependencies = [ [[package]] name = "fuel-asm" -version = "0.51.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0b13a9708f7c87e47c7bdac1ba53520dbb35d52a1c5bf077202874263c4ded2" +checksum = "9e3effa050e7e838d1eff68ca49f2d97558c4f90d13b2ac439253dfa3267c022" dependencies = [ "bitflags 2.5.0", "fuel-types", @@ -3411,9 +3411,9 @@ dependencies = [ [[package]] name = "fuel-crypto" -version = "0.51.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73c08da09f3436a14c65a8bbac2f30cb91a78546661e98446be44318a457ae40" +checksum = "a60228bcd5439c9bf206cf337d7d02b40efc56140769db52c2c035d43feb832b" dependencies = [ "coins-bip32", "coins-bip39", @@ -3432,9 +3432,9 @@ dependencies = [ [[package]] name = "fuel-derive" -version = "0.51.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23868a33cea329387876f0589276dadf148e320a4f9ea6b2734391420d4d9b12" +checksum = "9f987a055f018d138248d530a0a40354fa173288c3f81db5b3dfb5087562ebdf" dependencies = [ "proc-macro2", "quote", @@ -3444,9 +3444,9 @@ dependencies = [ [[package]] name = "fuel-merkle" -version = "0.51.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82b9932b20011c055287839ae4578787216ab3c78b2b44fca5f6371bb618f3e9" +checksum = "3c82370a37e83c53d0a06ce580ccfc4e36eb4cf2b23e67a142de4491d8a2d624" dependencies = [ "derive_more", "digest 0.10.7", @@ -3459,15 +3459,15 @@ dependencies = [ [[package]] name = "fuel-storage" -version = "0.51.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c786dcf141847a8f7a6a91ce108ee18b82ab4b8163d0de0ae4456cb4271519d" +checksum = "51fc51ee30c4e8b447b4579351128466c507687748d3f1ae9740481d8ef5d5c5" [[package]] name = "fuel-tx" -version = "0.51.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5437facc953b3dda2656f1782150a64c65acfb8bc44baddee4703530025c9bf6" +checksum = "23baeb39cbc093b66adb951a205f1696bf2403c0bb1a667fb98ddedeb299a8cb" dependencies = [ "bitflags 2.5.0", "derivative", @@ -3488,9 +3488,9 @@ dependencies = [ [[package]] name = "fuel-types" -version = "0.51.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00250cf68b66bc0689d24a20e6ebcedb509536e12967cfbeeefe45188e90e01e" +checksum = "960797d6245c3a7a1efc1925216901e644d7e698b81f192f2d2645c3cb7723fb" dependencies = [ "fuel-derive", "hex", @@ -3500,9 +3500,9 @@ dependencies = [ [[package]] name = "fuel-vm" -version = "0.51.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71ce30e132528432fe16af39696f943479a7bbd6a673e6f5659deba1b112ad24" +checksum = "b1efb9a8664859711066c9f786a84ff96e804940713d6e2cfcb3c88904d969fd" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 5f1ceb5cf9..0410d05323 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -81,7 +81,7 @@ fuel-core-wasm-executor = { version = "0.27.0", path = "./crates/services/upgrad fuel-core-xtask = { version = "0.0.0", path = "./xtask" } # Fuel dependencies -fuel-vm-private = { version = "0.51.0", package = "fuel-vm", default-features = false } +fuel-vm-private = { version = "0.52.0", package = "fuel-vm", default-features = false } # Common dependencies anyhow = "1.0" diff --git a/benches/benches-outputs/src/lib.rs b/benches/benches-outputs/src/lib.rs index cff4d42db8..41cad337a3 100644 --- a/benches/benches-outputs/src/lib.rs +++ b/benches/benches-outputs/src/lib.rs @@ -1,5 +1,5 @@ use fuel_core_types::fuel_tx::{ - consensus_parameters::gas::GasCostsValuesV1, + consensus_parameters::gas::GasCostsValuesV2, DependentCost, GasCostsValues, }; diff --git a/benches/benches/utils.rs b/benches/benches/utils.rs index e07a36f012..52b82cee52 100644 --- a/benches/benches/utils.rs +++ b/benches/benches/utils.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + use core::iter::successors; use ethnum::U256; use fuel_core_types::{ @@ -80,7 +82,6 @@ pub fn set_full_word(r: RegisterId, v: Word) -> Vec { const BENCH_RECEIPTS: usize = (u16::MAX - 4) 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 { @@ -97,3 +98,22 @@ pub fn make_receipts(rng: &mut StdRng) -> ReceiptsCtx { } ctx } + +const LAST_VALUE: u64 = 100_000; + +pub fn linear_short() -> Vec { + let mut linear_short = vec![1, 10, 100, 1000, 10_000]; + linear_short.push(LAST_VALUE); + linear_short +} + +pub fn linear() -> Vec { + let mut linear: Vec = vec![1, 10, 100, 1000, 10_000]; + let mut l = successors(Some(LAST_VALUE as f64), |n| Some(n / 1.5)) + .take(5) + .map(|f| f as u64) + .collect::>(); + l.sort_unstable(); + linear.extend(l); + linear +} diff --git a/benches/benches/vm_initialization.rs b/benches/benches/vm_initialization.rs index e758622be8..93644a762d 100644 --- a/benches/benches/vm_initialization.rs +++ b/benches/benches/vm_initialization.rs @@ -3,7 +3,6 @@ use criterion::{ Criterion, Throughput, }; -use fuel_core_storage::InterpreterStorage; use fuel_core_types::{ fuel_asm::{ op, @@ -23,17 +22,8 @@ use fuel_core_types::{ checked_transaction::{ Checked, IntoChecked, - Ready, - }, - constraints::reg_key::{ - Reg, - RegMut, - }, - consts::VM_MAX_RAM, - interpreter::{ - MemoryInstance, - NotSupportedEcal, }, + interpreter::NotSupportedEcal, Interpreter, }, }; @@ -110,8 +100,10 @@ pub fn vm_initialization(c: &mut Criterion) { group.throughput(Throughput::Bytes(tx_size as u64)); group.bench_function(name, |b| { b.iter(|| { - unoptimized_vm_initialization_with_allocating_full_range_of_memory( - &mut vm, &tx, + #[allow(clippy::unit_arg)] + black_box( + vm.init_script(tx.clone()) + .expect("Should be able to execute transaction"), ); }) }); @@ -119,47 +111,3 @@ pub fn vm_initialization(c: &mut Criterion) { group.finish(); } - -#[allow(clippy::unit_arg)] -fn unoptimized_vm_initialization_with_allocating_full_range_of_memory( - vm: &mut Interpreter, - ready_tx: &Ready