From d6e4bb9e336d1f0dbc554f0eaaa67d4afd5adacf Mon Sep 17 00:00:00 2001 From: Andrea Cerone <22031682+acerone85@users.noreply.github.com> Date: Mon, 23 Dec 2024 19:41:25 +0100 Subject: [PATCH] Refactor fuel-core to use version of StorageRead::read with offset (Full update to 0.59.1) (#2438) ## Linked Issues/PRs Related to https://github.com/FuelLabs/fuel-vm/issues/681 ## Description In order to load contracts from a given offset efficiently, we have changed the interface of `StorageRead::read` to accept a n offset in input (see https://github.com/FuelLabs/fuel-vm/pull/863). This PR refactors the fuel-core repo to make use of the new StorageRead trait. ## Checklist - [ ] Breaking changes are clearly marked as such in the PR description and changelog - [ ] New behavior is reflected in tests - [ ] [The specification](https://github.com/FuelLabs/fuel-specs/) matches the implemented behavior (link update PR if changes are needed) ### Before requesting review - [ ] I have reviewed the code myself - [ ] I have created follow-up issues caused by this PR and linked them here ### After merging, notify other teams [Add or remove entries as needed] - [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/) - [ ] [Sway compiler](https://github.com/FuelLabs/sway/) - [ ] [Platform documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+) (for out-of-organization contributors, the person merging the PR will do this) - [ ] Someone else? --------- Co-authored-by: AurelienFT Co-authored-by: AurelienFT Co-authored-by: AurelienFT <32803821+AurelienFT@users.noreply.github.com> Co-authored-by: green --- CHANGELOG.md | 3 + Cargo.lock | 128 ++++++++++++------ Cargo.toml | 2 +- benches/benches/vm.rs | 3 - benches/src/default_gas_costs.rs | 11 +- benches/src/lib.rs | 10 +- .../test_data/large_state/chain_config.json | 7 + .../chainspec/local-testnet/chain_config.json | 9 +- ...s__snapshot_configurable_block_height.snap | 7 + ..._tests__snapshot_local_testnet_config.snap | 9 +- ...s__snapshot_configurable_block_height.snap | 7 + ...ests__snapshot_contract_with_balances.snap | 7 + ...__tests__snapshot_contract_with_state.snap | 7 + ...ts__snapshot_contract_with_tx_pointer.snap | 7 + ...tests__snapshot_contract_with_utxo_id.snap | 7 + ..._tests__snapshot_local_testnet_config.snap | 7 + ...ig__tests__snapshot_simple_coin_state.snap | 7 + ...nfig__tests__snapshot_simple_contract.snap | 7 + ..._tests__snapshot_simple_message_state.snap | 7 + crates/client/assets/schema.sdl | 2 + crates/client/src/client/schema/chain.rs | 6 +- ..._chain__tests__chain_gql_query_output.snap | 13 ++ crates/fuel-core/src/graphql_api/database.rs | 9 +- crates/fuel-core/src/schema/chain.rs | 11 +- crates/fuel-core/src/schema/dap.rs | 21 ++- crates/fuel-core/src/state/data_source.rs | 3 +- .../fuel-core/src/state/generic_database.rs | 12 +- .../fuel-core/src/state/historical_rocksdb.rs | 4 +- .../src/state/iterable_key_value_view.rs | 3 +- crates/fuel-core/src/state/key_value_view.rs | 3 +- crates/fuel-core/src/state/rocks_db.rs | 23 +++- crates/services/executor/src/executor.rs | 7 +- crates/services/txpool_v2/src/tests/mocks.rs | 21 ++- crates/storage/src/kv_store.rs | 30 ++-- crates/storage/src/structured_storage.rs | 12 +- crates/storage/src/transactional.rs | 3 +- crates/storage/src/vm_storage.rs | 9 +- crates/types/Cargo.toml | 6 +- tests/tests/poa.rs | 23 ++-- 39 files changed, 364 insertions(+), 109 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3445c6d3a53..49594c1e5a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,11 +45,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [2468](https://github.com/FuelLabs/fuel-core/pull/2468): Abstract unrecorded blocks concept for V1 algorithm, create new storage impl. Introduce `TransactionableStorage` trait to allow atomic changes to the storage. - [2295](https://github.com/FuelLabs/fuel-core/pull/2295): `CombinedDb::from_config` now respects `state_rewind_policy` with tmp RocksDB. - [2378](https://github.com/FuelLabs/fuel-core/pull/2378): Use cached hash of the topic instead of calculating it on each publishing gossip message. +- [2438](https://github.com/FuelLabs/fuel-core/pull/2438): Refactored service to use new implementation of `StorageRead::read` that takes an offset in input. - [2429](https://github.com/FuelLabs/fuel-core/pull/2429): Introduce custom enum for representing result of running service tasks - [2377](https://github.com/FuelLabs/fuel-core/pull/2377): Add more errors that can be returned as responses when using protocol `/fuel/req_res/0.0.2`. The errors supported are `ProtocolV1EmptyResponse` (status code `0`) for converting empty responses sent via protocol `/fuel/req_res/0.0.1`, `RequestedRangeTooLarge`(status code `1`) if the client requests a range of objects such as sealed block headers or transactions too large, `Timeout` (status code `2`) if the remote peer takes too long to fulfill a request, or `SyncProcessorOutOfCapacity` if the remote peer is fulfilling too many requests concurrently. - [2233](https://github.com/FuelLabs/fuel-core/pull/2233): Introduce a new column `modification_history_v2` for storing the modification history in the historical rocksDB. Keys in this column are stored in big endian order. Changed the behaviour of the historical rocksDB to write changes for new block heights to the new column, and to perform lookup of values from the `modification_history_v2` table first, and then from the `modification_history` table, performing a migration upon access if necessary. #### Breaking +- [2438](https://github.com/FuelLabs/fuel-core/pull/2438): The `fuel-core-client` can only work with new version of the `fuel-core`. The `0.40` and all older versions are not supported. +- [2438](https://github.com/FuelLabs/fuel-core/pull/2438): Updated `fuel-vm` to `0.59.1` release. Check [release notes](https://github.com/FuelLabs/fuel-vm/releases/tag/v0.59.0) for more details. - [2389](https://github.com/FuelLabs/fuel-core/pull/2258): Updated the `messageProof` GraphQL schema to return a non-nullable `MessageProof`. - [2154](https://github.com/FuelLabs/fuel-core/pull/2154): Transaction graphql endpoints use `TransactionType` instead of `fuel_tx::Transaction`. - [2446](https://github.com/FuelLabs/fuel-core/pull/2446): Use graphiql instead of graphql-playground due to known vulnerability and stale development. diff --git a/Cargo.lock b/Cargo.lock index 0bc9f38389d..f785bfaae99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2292,6 +2292,7 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.90", + "unicode-xid", ] [[package]] @@ -2488,6 +2489,18 @@ dependencies = [ "zeroize", ] +[[package]] +name = "educe" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7bc049e1bd8cdeb31b68bbd586a9464ecf9f3944af3958a7a9d0f8b9799417" +dependencies = [ + "enum-ordinalize", + "proc-macro2", + "quote", + "syn 2.0.90", +] + [[package]] name = "either" version = "1.13.0" @@ -2599,6 +2612,26 @@ dependencies = [ "syn 2.0.90", ] +[[package]] +name = "enum-ordinalize" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea0dcfa4e54eeb516fe454635a95753ddd39acda650ce703031c6973e315dd5" +dependencies = [ + "enum-ordinalize-derive", +] + +[[package]] +name = "enum-ordinalize-derive" +version = "4.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -3130,24 +3163,24 @@ dependencies = [ [[package]] name = "fuel-asm" -version = "0.58.2" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f325971bf9047ec70004f80a989e03456316bc19cbef3ff3a39a38b192ab56e" +checksum = "885617a606218680114122f4e1107ed5c9424e42dec05de84843e4a3a99e2cd7" dependencies = [ "bitflags 2.6.0", - "fuel-types 0.58.2", + "fuel-types 0.59.1", "serde", "strum 0.24.1", ] [[package]] name = "fuel-compression" -version = "0.58.2" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24e42841f56f76ed759b3f516e5188d5c42de47015bee951651660c13b6dfa6c" +checksum = "6269052edeef79b4fe02ee1bb518e926098dd0ef81d88e3a617b218c05cef233" dependencies = [ - "fuel-derive 0.58.2", - "fuel-types 0.58.2", + "fuel-derive 0.59.1", + "fuel-types 0.59.1", "serde", ] @@ -3658,7 +3691,7 @@ dependencies = [ "enum-iterator", "fuel-core-storage", "fuel-core-types 0.40.0", - "fuel-vm 0.58.2", + "fuel-vm 0.59.1", "impl-tools", "itertools 0.12.1", "mockall", @@ -3800,7 +3833,7 @@ dependencies = [ "bs58", "derivative", "derive_more 0.99.18", - "fuel-vm 0.58.2", + "fuel-vm 0.59.1", "rand", "secrecy", "serde", @@ -3857,15 +3890,15 @@ dependencies = [ [[package]] name = "fuel-crypto" -version = "0.58.2" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e318850ca64890ff123a99b6b866954ef49da94ab9bc6827cf6ee045568585" +checksum = "8e5643d6c281369825854bbc96d5d1648fe49ddcc3443961c633270f65e6c4b6" dependencies = [ "coins-bip32", "coins-bip39", "ecdsa", "ed25519-dalek", - "fuel-types 0.58.2", + "fuel-types 0.59.1", "k256", "lazy_static", "p256", @@ -3890,9 +3923,9 @@ dependencies = [ [[package]] name = "fuel-derive" -version = "0.58.2" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab0bc46a3552964bae5169e79b383761a54bd115ea66951a1a7a229edcefa55a" +checksum = "8703ee10001e6a52ad9a0d8411ca5a92098de978ccfbdddd0ba185f3a7405b4c" dependencies = [ "proc-macro2", "quote", @@ -3928,13 +3961,13 @@ dependencies = [ [[package]] name = "fuel-merkle" -version = "0.58.2" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c79eca6a452311c70978a5df796c0f99f27e474b69719e0db4c1d82e68800d07" +checksum = "7446f9cc1885ede3af88cf567931f96fd1feda3146e9052c09b1b260fbd56173" dependencies = [ "derive_more 0.99.18", "digest 0.10.7", - "fuel-storage 0.58.2", + "fuel-storage 0.59.1", "hashbrown 0.13.2", "hex", "serde", @@ -3949,9 +3982,9 @@ checksum = "4c1b711f28553ddc5f3546711bd220e144ce4c1af7d9e9a1f70b2f20d9f5b791" [[package]] name = "fuel-storage" -version = "0.58.2" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d0c46b5d76b3e11197bd31e036cd8b1cb46c4d822cacc48836638080c6d2b76" +checksum = "01f810b544f0930fc68e1311ea078fad9af6912d5215a9ae9febda67206e34e5" [[package]] name = "fuel-tx" @@ -3977,18 +4010,18 @@ dependencies = [ [[package]] name = "fuel-tx" -version = "0.58.2" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6723bb8710ba2b70516ac94d34459593225870c937670fb3afaf82e0354667ac" +checksum = "806498d953bc989995425f1bb7c17890f5538a3664c6ec3b5d8a77c63d617421" dependencies = [ "bitflags 2.6.0", - "derivative", - "derive_more 0.99.18", - "fuel-asm 0.58.2", + "derive_more 1.0.0", + "educe", + "fuel-asm 0.59.1", "fuel-compression", - "fuel-crypto 0.58.2", - "fuel-merkle 0.58.2", - "fuel-types 0.58.2", + "fuel-crypto 0.59.1", + "fuel-merkle 0.59.1", + "fuel-types 0.59.1", "hashbrown 0.14.5", "itertools 0.10.5", "postcard", @@ -4011,11 +4044,11 @@ dependencies = [ [[package]] name = "fuel-types" -version = "0.58.2" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "982265415a99b5bd6277bc24194a233bb2e18764df11c937b3dbb11a02c9e545" +checksum = "d0d46d41db59c131195e6d842cc1e50f0b8adeadf2a840519e8b57b78e57a0bf" dependencies = [ - "fuel-derive 0.58.2", + "fuel-derive 0.59.1", "hex", "rand", "serde", @@ -4054,24 +4087,24 @@ dependencies = [ [[package]] name = "fuel-vm" -version = "0.58.2" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54b5362d7d072c72eec20581f67fc5400090c356a7f3ae77c79880b3b177b667" +checksum = "9bcf74f636cc01a1ab035458628f925945bb4df9da653058c6ab2b26fa25f087" dependencies = [ "anyhow", "async-trait", "backtrace", "bitflags 2.6.0", - "derivative", "derive_more 0.99.18", + "educe", "ethnum", - "fuel-asm 0.58.2", + "fuel-asm 0.59.1", "fuel-compression", - "fuel-crypto 0.58.2", - "fuel-merkle 0.58.2", - "fuel-storage 0.58.2", - "fuel-tx 0.58.2", - "fuel-types 0.58.2", + "fuel-crypto 0.59.1", + "fuel-merkle 0.59.1", + "fuel-storage 0.59.1", + "fuel-tx 0.59.1", + "fuel-types 0.59.1", "hashbrown 0.14.5", "itertools 0.10.5", "libm", @@ -4084,6 +4117,7 @@ dependencies = [ "sha3", "static_assertions", "strum 0.24.1", + "substrate-bn", "tai64", ] @@ -5404,6 +5438,9 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin 0.9.8", +] [[package]] name = "lazycell" @@ -8972,6 +9009,19 @@ dependencies = [ "syn 2.0.90", ] +[[package]] +name = "substrate-bn" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b5bbfa79abbae15dd642ea8176a21a635ff3c00059961d1ea27ad04e5b441c" +dependencies = [ + "byteorder", + "crunchy", + "lazy_static", + "rand", + "rustc-hex", +] + [[package]] name = "subtle" version = "2.6.1" diff --git a/Cargo.toml b/Cargo.toml index 0a711e83ad3..8931ac5437f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,7 +87,7 @@ fuel-core-xtask = { version = "0.0.0", path = "./xtask" } fuel-gas-price-algorithm = { version = "0.40.0", path = "crates/fuel-gas-price-algorithm" } # Fuel dependencies -fuel-vm-private = { version = "0.58.2", package = "fuel-vm", default-features = false } +fuel-vm-private = { version = "0.59.1", package = "fuel-vm", default-features = false } # Common dependencies anyhow = "1.0" diff --git a/benches/benches/vm.rs b/benches/benches/vm.rs index f895290bff8..e629ccbf654 100644 --- a/benches/benches/vm.rs +++ b/benches/benches/vm.rs @@ -41,7 +41,6 @@ where let clock = quanta::Clock::new(); let original_db = vm.as_mut().database_mut().clone(); - let original_memory = vm.memory().clone(); // During block production/validation for each state, which may affect the state of the database, // we create a new storage transaction. The code here simulates the same behavior to have // the same nesting level and the same performance. @@ -53,7 +52,6 @@ where let mut total = core::time::Duration::ZERO; for _ in 0..iters { - vm.memory_mut().clone_from(&original_memory); let start = black_box(clock.raw()); match instruction { Instruction::CALL(call) => { @@ -72,7 +70,6 @@ where vm.as_mut().database_mut().reset_changes(); } *vm.as_mut().database_mut() = original_db; - *vm.memory_mut() = original_memory; total }) }); diff --git a/benches/src/default_gas_costs.rs b/benches/src/default_gas_costs.rs index ed10c1c3333..dc09359b7ad 100644 --- a/benches/src/default_gas_costs.rs +++ b/benches/src/default_gas_costs.rs @@ -1,7 +1,7 @@ use super::*; -use fuel_core_types::fuel_tx::consensus_parameters::gas::GasCostsValuesV4; +use fuel_core_types::fuel_tx::consensus_parameters::gas::GasCostsValuesV5; pub fn default_gas_costs() -> GasCostsValues { - GasCostsValuesV4 { + GasCostsValuesV5 { add: 2, addi: 2, and: 2, @@ -90,6 +90,13 @@ pub fn default_gas_costs() -> GasCostsValues { wqmm: 6, xor: 2, xori: 2, + // TODO: Change to correct values + ecop: 2, + // TODO: Change to correct values + epar: DependentCost::HeavyOperation { + base: 2, + gas_per_unit: 2, + }, aloc: DependentCost::LightOperation { base: 2, units_per_gas: 35, diff --git a/benches/src/lib.rs b/benches/src/lib.rs index c84fb4e6418..3bed0a964de 100644 --- a/benches/src/lib.rs +++ b/benches/src/lib.rs @@ -398,7 +398,6 @@ impl TryFrom for VmBenchPrepared { let prepare_script = prepare_script .into_iter() .chain(iter::once(op::ret(RegId::ONE))) - .chain(iter::once(instruction)) .collect(); let mut tx = TransactionBuilder::script(prepare_script, data); @@ -531,9 +530,7 @@ impl TryFrom for VmBenchPrepared { } } - let start_vm = vm.clone(); - let original_db = vm.as_mut().database_mut().clone(); - let original_memory = vm.memory().clone(); + let vm_before_first_instruction = vm.clone(); let mut vm = vm.add_recording(); match instruction { Instruction::CALL(call) => { @@ -546,12 +543,11 @@ impl TryFrom for VmBenchPrepared { } let storage_diff = vm.storage_diff(); let mut vm = vm.remove_recording(); - let mut diff = start_vm.diff(&vm); + let mut diff = vm.rollback_to(&vm_before_first_instruction); diff += storage_diff; let diff: diff::Diff = diff.into(); vm.reset_vm_state(&diff); - *vm.as_mut().database_mut() = original_db; - *vm.memory_mut() = original_memory; + assert_eq!(vm_before_first_instruction, vm); Ok(Self { vm, diff --git a/bin/e2e-test-client/src/tests/test_data/large_state/chain_config.json b/bin/e2e-test-client/src/tests/test_data/large_state/chain_config.json index 7748984b6b1..66747c21118 100644 --- a/bin/e2e-test-client/src/tests/test_data/large_state/chain_config.json +++ b/bin/e2e-test-client/src/tests/test_data/large_state/chain_config.json @@ -129,6 +129,7 @@ "wqmm": 11, "xor": 2, "xori": 2, + "ecop": 2, "call": { "LightOperation": { "base": 21687, @@ -237,6 +238,12 @@ "gas_per_unit": 26613 } }, + "epar": { + "HeavyOperation": { + "base": 2, + "gas_per_unit": 2 + } + }, "contract_root": { "LightOperation": { "base": 45, diff --git a/bin/fuel-core/chainspec/local-testnet/chain_config.json b/bin/fuel-core/chainspec/local-testnet/chain_config.json index 2977f4b4b08..43b15e86195 100644 --- a/bin/fuel-core/chainspec/local-testnet/chain_config.json +++ b/bin/fuel-core/chainspec/local-testnet/chain_config.json @@ -40,7 +40,7 @@ }, "chain_id": 0, "gas_costs": { - "V4": { + "V5": { "add": 2, "addi": 2, "and": 2, @@ -126,6 +126,7 @@ "wqmm": 6, "xor": 2, "xori": 2, + "ecop": 2, "aloc": { "LightOperation": { "base": 2, @@ -270,6 +271,12 @@ "gas_per_unit": 5776 } }, + "epar": { + "HeavyOperation": { + "base": 2, + "gas_per_unit": 2 + } + }, "contract_root": { "LightOperation": { "base": 24, diff --git a/crates/chain-config/src/config/snapshots/fuel_core_chain_config__config__chain__tests__snapshot_configurable_block_height.snap b/crates/chain-config/src/config/snapshots/fuel_core_chain_config__config__chain__tests__snapshot_configurable_block_height.snap index ec4e7c71b41..cb4cc418132 100644 --- a/crates/chain-config/src/config/snapshots/fuel_core_chain_config__config__chain__tests__snapshot_configurable_block_height.snap +++ b/crates/chain-config/src/config/snapshots/fuel_core_chain_config__config__chain__tests__snapshot_configurable_block_height.snap @@ -123,6 +123,7 @@ expression: json "wqmm": 3, "xor": 1, "xori": 1, + "ecop": 1, "call": { "LightOperation": { "base": 144, @@ -225,6 +226,12 @@ expression: json "units_per_gas": 5 } }, + "epar": { + "HeavyOperation": { + "base": 100, + "gas_per_unit": 1 + } + }, "contract_root": { "LightOperation": { "base": 75, diff --git a/crates/chain-config/src/config/snapshots/fuel_core_chain_config__config__chain__tests__snapshot_local_testnet_config.snap b/crates/chain-config/src/config/snapshots/fuel_core_chain_config__config__chain__tests__snapshot_local_testnet_config.snap index c3123c6bb38..473a293c2f7 100644 --- a/crates/chain-config/src/config/snapshots/fuel_core_chain_config__config__chain__tests__snapshot_local_testnet_config.snap +++ b/crates/chain-config/src/config/snapshots/fuel_core_chain_config__config__chain__tests__snapshot_local_testnet_config.snap @@ -44,7 +44,7 @@ expression: json }, "chain_id": 0, "gas_costs": { - "V4": { + "V5": { "add": 1, "addi": 1, "and": 1, @@ -130,6 +130,7 @@ expression: json "wqmm": 3, "xor": 1, "xori": 1, + "ecop": 3500, "aloc": { "LightOperation": { "base": 2, @@ -274,6 +275,12 @@ expression: json "units_per_gas": 5 } }, + "epar": { + "HeavyOperation": { + "base": 69000, + "gas_per_unit": 52000 + } + }, "contract_root": { "LightOperation": { "base": 75, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_configurable_block_height.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_configurable_block_height.snap index f03cb0053c4..d3cd9c62f3c 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_configurable_block_height.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_configurable_block_height.snap @@ -122,6 +122,7 @@ expression: json "wqmm": 3, "xor": 1, "xori": 1, + "ecop": 1, "call": { "LightOperation": { "base": 144, @@ -230,6 +231,12 @@ expression: json "units_per_gas": 5 } }, + "epar": { + "HeavyOperation": { + "base": 100, + "gas_per_unit": 1 + } + }, "contract_root": { "LightOperation": { "base": 75, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_balances.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_balances.snap index 24b18202318..201905633ca 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_balances.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_balances.snap @@ -136,6 +136,7 @@ expression: json "wqmm": 3, "xor": 1, "xori": 1, + "ecop": 1, "call": { "LightOperation": { "base": 144, @@ -244,6 +245,12 @@ expression: json "units_per_gas": 5 } }, + "epar": { + "HeavyOperation": { + "base": 100, + "gas_per_unit": 1 + } + }, "contract_root": { "LightOperation": { "base": 75, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_state.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_state.snap index 00a0bac4d9f..c454ad90979 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_state.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_state.snap @@ -136,6 +136,7 @@ expression: json "wqmm": 3, "xor": 1, "xori": 1, + "ecop": 1, "call": { "LightOperation": { "base": 144, @@ -244,6 +245,12 @@ expression: json "units_per_gas": 5 } }, + "epar": { + "HeavyOperation": { + "base": 100, + "gas_per_unit": 1 + } + }, "contract_root": { "LightOperation": { "base": 75, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_tx_pointer.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_tx_pointer.snap index 6b1d97d832b..8497696b415 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_tx_pointer.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_tx_pointer.snap @@ -132,6 +132,7 @@ expression: json "wqmm": 3, "xor": 1, "xori": 1, + "ecop": 1, "call": { "LightOperation": { "base": 144, @@ -240,6 +241,12 @@ expression: json "units_per_gas": 5 } }, + "epar": { + "HeavyOperation": { + "base": 100, + "gas_per_unit": 1 + } + }, "contract_root": { "LightOperation": { "base": 75, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_utxo_id.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_utxo_id.snap index 00868dc0c0e..877e41f9f83 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_utxo_id.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_utxo_id.snap @@ -132,6 +132,7 @@ expression: json "wqmm": 3, "xor": 1, "xori": 1, + "ecop": 1, "call": { "LightOperation": { "base": 144, @@ -240,6 +241,12 @@ expression: json "units_per_gas": 5 } }, + "epar": { + "HeavyOperation": { + "base": 100, + "gas_per_unit": 1 + } + }, "contract_root": { "LightOperation": { "base": 75, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_local_testnet_config.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_local_testnet_config.snap index 404cf2275d6..93a8b9d2628 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_local_testnet_config.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_local_testnet_config.snap @@ -122,6 +122,7 @@ expression: json "wqmm": 3, "xor": 1, "xori": 1, + "ecop": 1, "call": { "LightOperation": { "base": 144, @@ -230,6 +231,12 @@ expression: json "units_per_gas": 5 } }, + "epar": { + "HeavyOperation": { + "base": 100, + "gas_per_unit": 1 + } + }, "contract_root": { "LightOperation": { "base": 75, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_coin_state.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_coin_state.snap index 735fa9517d3..c68e1b694db 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_coin_state.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_coin_state.snap @@ -135,6 +135,7 @@ expression: json "wqmm": 3, "xor": 1, "xori": 1, + "ecop": 1, "call": { "LightOperation": { "base": 144, @@ -243,6 +244,12 @@ expression: json "units_per_gas": 5 } }, + "epar": { + "HeavyOperation": { + "base": 100, + "gas_per_unit": 1 + } + }, "contract_root": { "LightOperation": { "base": 75, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_contract.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_contract.snap index ba531bfbb32..c4d54dddb49 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_contract.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_contract.snap @@ -130,6 +130,7 @@ expression: json "wqmm": 3, "xor": 1, "xori": 1, + "ecop": 1, "call": { "LightOperation": { "base": 144, @@ -238,6 +239,12 @@ expression: json "units_per_gas": 5 } }, + "epar": { + "HeavyOperation": { + "base": 100, + "gas_per_unit": 1 + } + }, "contract_root": { "LightOperation": { "base": 75, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_message_state.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_message_state.snap index b5d981ce718..ea9d4ae8a21 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_message_state.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_message_state.snap @@ -134,6 +134,7 @@ expression: json "wqmm": 3, "xor": 1, "xori": 1, + "ecop": 1, "call": { "LightOperation": { "base": 144, @@ -242,6 +243,12 @@ expression: json "units_per_gas": 5 } }, + "epar": { + "HeavyOperation": { + "base": 100, + "gas_per_unit": 1 + } + }, "contract_root": { "LightOperation": { "base": 75, diff --git a/crates/client/assets/schema.sdl b/crates/client/assets/schema.sdl index 1c291a567fd..ca280ebc97e 100644 --- a/crates/client/assets/schema.sdl +++ b/crates/client/assets/schema.sdl @@ -443,6 +443,7 @@ type GasCosts { wqmm: U64! xor: U64! xori: U64! + ecop: U64 alocDependentCost: DependentCost! bldd: DependentCost bsiz: DependentCost @@ -467,6 +468,7 @@ type GasCosts { smo: DependentCost! srwq: DependentCost! swwq: DependentCost! + epar: DependentCost contractRoot: DependentCost! stateRoot: DependentCost! vmInitialization: DependentCost! diff --git a/crates/client/src/client/schema/chain.rs b/crates/client/src/client/schema/chain.rs index 31129c74491..c0efa92a27c 100644 --- a/crates/client/src/client/schema/chain.rs +++ b/crates/client/src/client/schema/chain.rs @@ -303,6 +303,7 @@ pub struct GasCosts { pub wqmm: U64, pub xor: U64, pub xori: U64, + pub ecop: Option, pub aloc_dependent_cost: DependentCost, pub bsiz: Option, @@ -328,6 +329,7 @@ pub struct GasCosts { pub smo: DependentCost, pub srwq: DependentCost, pub swwq: DependentCost, + pub epar: Option, // Non-opcodes prices pub contract_root: DependentCost, @@ -350,7 +352,7 @@ impl TryFrom for fuel_core_types::fuel_tx::GasCosts { fn try_from(value: GasCosts) -> Result { match value.version { GasCostsVersion::V1 => Ok(fuel_core_types::fuel_tx::GasCosts::new( - fuel_core_types::fuel_tx::consensus_parameters::gas::GasCostsValuesV4 { + fuel_core_types::fuel_tx::consensus_parameters::gas::GasCostsValuesV5 { add: value.add.into(), addi: value.addi.into(), and: value.and.into(), @@ -436,6 +438,7 @@ impl TryFrom for fuel_core_types::fuel_tx::GasCosts { wqmm: value.wqmm.into(), xor: value.xor.into(), xori: value.xori.into(), + ecop: value.ecop.map(Into::into).unwrap_or(0), aloc: value.aloc_dependent_cost.into(), bsiz: value.bsiz.map(Into::into).unwrap_or(fuel_core_types::fuel_tx::consensus_parameters::DependentCost::free()), @@ -461,6 +464,7 @@ impl TryFrom for fuel_core_types::fuel_tx::GasCosts { smo: value.smo.into(), srwq: value.srwq.into(), swwq: value.swwq.into(), + epar: value.epar.map(Into::into).unwrap_or(fuel_core_types::fuel_tx::consensus_parameters::DependentCost::free()), contract_root: value.contract_root.into(), state_root: value.state_root.into(), vm_initialization: value.vm_initialization.into(), diff --git a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap index 4b97aca83d3..5312de603d1 100644 --- a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap +++ b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap @@ -1,6 +1,7 @@ --- source: crates/client/src/client/schema/chain.rs expression: operation.query +snapshot_kind: text --- query ChainQuery { chain { @@ -165,6 +166,7 @@ query ChainQuery { wqmm xor xori + ecop alocDependentCost { __typename ... on LightOperation { @@ -429,6 +431,17 @@ query ChainQuery { gasPerUnit } } + epar { + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } + } contractRoot { __typename ... on LightOperation { diff --git a/crates/fuel-core/src/graphql_api/database.rs b/crates/fuel-core/src/graphql_api/database.rs index 6feaaabc5dc..36f02562ca6 100644 --- a/crates/fuel-core/src/graphql_api/database.rs +++ b/crates/fuel-core/src/graphql_api/database.rs @@ -261,8 +261,13 @@ impl StorageSize for ReadView { } impl StorageRead for ReadView { - fn read(&self, key: &BlobId, buf: &mut [u8]) -> Result, Self::Error> { - StorageRead::::read(self.on_chain.as_ref(), key, buf) + fn read( + &self, + key: &BlobId, + offset: usize, + buf: &mut [u8], + ) -> Result, Self::Error> { + StorageRead::::read(self.on_chain.as_ref(), key, offset, buf) } fn read_alloc(&self, key: &BlobId) -> Result>, Self::Error> { diff --git a/crates/fuel-core/src/schema/chain.rs b/crates/fuel-core/src/schema/chain.rs index 9acdbb01940..830f281c69f 100644 --- a/crates/fuel-core/src/schema/chain.rs +++ b/crates/fuel-core/src/schema/chain.rs @@ -280,7 +280,8 @@ impl GasCosts { GasCostsValues::V1(_) | GasCostsValues::V2(_) | GasCostsValues::V3(_) - | GasCostsValues::V4(_) => GasCostsVersion::V1, + | GasCostsValues::V4(_) + | GasCostsValues::V5(_) => GasCostsVersion::V1, } } @@ -636,6 +637,10 @@ impl GasCosts { self.0.xori().into() } + async fn ecop(&self) -> Option { + self.0.ecop().ok().map(Into::into) + } + async fn aloc_dependent_cost(&self) -> DependentCost { self.0.aloc().into() } @@ -732,6 +737,10 @@ impl GasCosts { self.0.swwq().into() } + async fn epar(&self) -> Option { + self.0.epar().ok().map(Into::into) + } + // Non-opcode prices async fn contract_root(&self) -> DependentCost { diff --git a/crates/fuel-core/src/schema/dap.rs b/crates/fuel-core/src/schema/dap.rs index 7e920f3ead2..808591fa0c3 100644 --- a/crates/fuel-core/src/schema/dap.rs +++ b/crates/fuel-core/src/schema/dap.rs @@ -132,7 +132,12 @@ impl ConcreteStorage { let fee_params = params.fee_params(); let ready_tx = checked_tx - .into_ready(GAS_PRICE, gas_costs, fee_params) + .into_ready( + GAS_PRICE, + gas_costs, + fee_params, + Some(vm_database.block_height()?), + ) .map_err(|e| { anyhow!("Failed to apply dynamic values to checked tx: {:?}", e) })?; @@ -176,7 +181,12 @@ impl ConcreteStorage { let fee_params = params.fee_params(); let ready_tx = checked_tx - .into_ready(GAS_PRICE, gas_costs, fee_params) + .into_ready( + GAS_PRICE, + gas_costs, + fee_params, + Some(vm_database.block_height()?), + ) .map_err(|e| { anyhow!("Failed to apply dynamic values to checked tx: {:?}", e) })?; @@ -456,7 +466,12 @@ impl DapMutation { match checked_tx { CheckedTransaction::Script(script) => { let ready_tx = script - .into_ready(GAS_PRICE, gas_costs, fee_params) + .into_ready( + GAS_PRICE, + gas_costs, + fee_params, + Some(vm.as_ref().block_height()?), + ) .map_err(|e| { anyhow!("Failed to apply dynamic values to checked tx: {:?}", e) })?; diff --git a/crates/fuel-core/src/state/data_source.rs b/crates/fuel-core/src/state/data_source.rs index cf107d0e1b9..f30f3ee8268 100644 --- a/crates/fuel-core/src/state/data_source.rs +++ b/crates/fuel-core/src/state/data_source.rs @@ -67,9 +67,10 @@ where &self, key: &[u8], column: Self::Column, + offset: usize, buf: &mut [u8], ) -> StorageResult> { - self.data.read(key, column, buf) + self.data.read(key, column, offset, buf) } } diff --git a/crates/fuel-core/src/state/generic_database.rs b/crates/fuel-core/src/state/generic_database.rs index b6f5f2ea464..5a31591268f 100644 --- a/crates/fuel-core/src/state/generic_database.rs +++ b/crates/fuel-core/src/state/generic_database.rs @@ -79,8 +79,13 @@ where M: Mappable, StructuredStorage: StorageRead, { - fn read(&self, key: &M::Key, buf: &mut [u8]) -> Result, Self::Error> { - self.storage.storage::().read(key, buf) + fn read( + &self, + key: &M::Key, + offset: usize, + buf: &mut [u8], + ) -> Result, Self::Error> { + self.storage.storage::().read(key, offset, buf) } fn read_alloc(&self, key: &M::Key) -> Result>, Self::Error> { @@ -124,9 +129,10 @@ where &self, key: &[u8], column: Self::Column, + offset: usize, buf: &mut [u8], ) -> StorageResult> { - KeyValueInspect::read(&self.storage, key, column, buf) + KeyValueInspect::read(&self.storage, key, column, offset, buf) } } diff --git a/crates/fuel-core/src/state/historical_rocksdb.rs b/crates/fuel-core/src/state/historical_rocksdb.rs index a0bd39b2801..059fb35f12b 100644 --- a/crates/fuel-core/src/state/historical_rocksdb.rs +++ b/crates/fuel-core/src/state/historical_rocksdb.rs @@ -534,9 +534,11 @@ where &self, key: &[u8], column: Self::Column, + offset: usize, buf: &mut [u8], ) -> StorageResult> { - self.db.read(key, Column::OriginalColumn(column), buf) + self.db + .read(key, Column::OriginalColumn(column), offset, buf) } } diff --git a/crates/fuel-core/src/state/iterable_key_value_view.rs b/crates/fuel-core/src/state/iterable_key_value_view.rs index 40ab3483ede..1d8fd02cbbb 100644 --- a/crates/fuel-core/src/state/iterable_key_value_view.rs +++ b/crates/fuel-core/src/state/iterable_key_value_view.rs @@ -67,9 +67,10 @@ where &self, key: &[u8], column: Self::Column, + offset: usize, buf: &mut [u8], ) -> StorageResult> { - self.0.read(key, column, buf) + self.0.read(key, column, offset, buf) } } diff --git a/crates/fuel-core/src/state/key_value_view.rs b/crates/fuel-core/src/state/key_value_view.rs index 9e70037fc21..e507e83329a 100644 --- a/crates/fuel-core/src/state/key_value_view.rs +++ b/crates/fuel-core/src/state/key_value_view.rs @@ -54,8 +54,9 @@ where &self, key: &[u8], column: Self::Column, + offset: usize, buf: &mut [u8], ) -> StorageResult> { - self.0.read(key, column, buf) + self.0.read(key, column, offset, buf) } } diff --git a/crates/fuel-core/src/state/rocks_db.rs b/crates/fuel-core/src/state/rocks_db.rs index e69c6289bed..3df5c7127e5 100644 --- a/crates/fuel-core/src/state/rocks_db.rs +++ b/crates/fuel-core/src/state/rocks_db.rs @@ -28,6 +28,7 @@ use fuel_core_storage::{ WriteOperation, }, transactional::Changes, + Error as StorageError, Result as StorageResult, }; use itertools::Itertools; @@ -758,7 +759,8 @@ where &self, key: &[u8], column: Self::Column, - mut buf: &mut [u8], + offset: usize, + buf: &mut [u8], ) -> StorageResult> { self.metrics.read_meter.inc(); let column_metrics = self.metrics.columns_read_statistic.get(&column.id()); @@ -769,10 +771,21 @@ where .get_pinned_cf_opt(&self.cf(column), key, &self.read_options) .map_err(|e| DatabaseError::Other(e.into()))? .map(|value| { - let read = value.len(); - std::io::Write::write_all(&mut buf, value.as_ref()) - .map_err(|e| DatabaseError::Other(anyhow::anyhow!(e)))?; - StorageResult::Ok(read) + let bytes_len = value.len(); + let start = offset; + let end = offset.saturating_add(buf.len()); + + if end > bytes_len { + return Err(StorageError::Other(anyhow::anyhow!( + "Offset `{offset}` is out of bounds `{bytes_len}` \ + for key `{:?}` and column `{column:?}`", + key + ))); + } + + let starting_from_offset = &value[start..end]; + buf[..].copy_from_slice(starting_from_offset); + Ok(buf.len()) }) .transpose()?; diff --git a/crates/services/executor/src/executor.rs b/crates/services/executor/src/executor.rs index bc690c52d3d..1277b143d9c 100644 --- a/crates/services/executor/src/executor.rs +++ b/crates/services/executor/src/executor.rs @@ -1626,7 +1626,12 @@ where .iter() .map(|input| input.predicate_gas_used()) .collect(); - let ready_tx = checked_tx.into_ready(gas_price, gas_costs, fee_params)?; + let ready_tx = checked_tx.into_ready( + gas_price, + gas_costs, + fee_params, + Some(*header.height()), + )?; let mut vm = Interpreter::with_storage( memory, diff --git a/crates/services/txpool_v2/src/tests/mocks.rs b/crates/services/txpool_v2/src/tests/mocks.rs index 1dca65bc9d3..eed1bf5f84f 100644 --- a/crates/services/txpool_v2/src/tests/mocks.rs +++ b/crates/services/txpool_v2/src/tests/mocks.rs @@ -126,16 +126,27 @@ impl StorageRead for MockDb { fn read( &self, key: &::Key, + offset: usize, buf: &mut [u8], ) -> Result, Self::Error> { let table = self.data.lock().unwrap(); let bytes = table.blobs.get(key); - let len = bytes.map(|bytes| { - buf.copy_from_slice(bytes.0.as_slice()); - bytes.0.len() - }); - Ok(len) + bytes + .map(|bytes| { + let bytes_len = bytes.as_ref().len(); + let start = offset; + let end = offset.saturating_add(buf.len()); + + if end > bytes_len { + return Err(()); + } + + let starting_from_offset = &bytes.as_ref()[start..end]; + buf[..].copy_from_slice(starting_from_offset); + Ok(buf.len()) + }) + .transpose() } fn read_alloc( diff --git a/crates/storage/src/kv_store.rs b/crates/storage/src/kv_store.rs index 3e7c1359114..a7029db8d20 100644 --- a/crates/storage/src/kv_store.rs +++ b/crates/storage/src/kv_store.rs @@ -1,9 +1,6 @@ //! The module provides plain abstract definition of the key-value store. -use crate::{ - Error as StorageError, - Result as StorageResult, -}; +use crate::Result as StorageResult; #[cfg(feature = "alloc")] use alloc::{ @@ -67,18 +64,26 @@ pub trait KeyValueInspect { &self, key: &[u8], column: Self::Column, + offset: usize, buf: &mut [u8], ) -> StorageResult> { self.get(key, column)? .map(|value| { - let read = value.len(); - if read != buf.len() { - return Err(StorageError::Other(anyhow::anyhow!( - "Buffer size is not equal to the value size" - ))); + let bytes_len = value.as_ref().len(); + let start = offset; + let end = offset.saturating_add(buf.len()); + + if end > bytes_len { + return Err(anyhow::anyhow!( + "Offset `{offset}` is out of bounds `{bytes_len}` for key `{:?}`", + key + ) + .into()); } - buf.copy_from_slice(value.as_ref()); - Ok(read) + + let starting_from_offset = &value.as_ref()[start..end]; + buf[..].copy_from_slice(starting_from_offset); + Ok(buf.len()) }) .transpose() } @@ -111,9 +116,10 @@ where &self, key: &[u8], column: Self::Column, + offset: usize, buf: &mut [u8], ) -> StorageResult> { - self.deref().read(key, column, buf) + self.deref().read(key, column, offset, buf) } } diff --git a/crates/storage/src/structured_storage.rs b/crates/storage/src/structured_storage.rs index 122792cbf8f..4e1239c5982 100644 --- a/crates/storage/src/structured_storage.rs +++ b/crates/storage/src/structured_storage.rs @@ -147,9 +147,10 @@ where &self, key: &[u8], column: Self::Column, + offset: usize, buf: &mut [u8], ) -> StorageResult> { - self.inner.read(key, column, buf) + self.inner.read(key, column, offset, buf) } } @@ -358,6 +359,7 @@ where fn read( &self, key: &::Key, + offset: usize, buf: &mut [u8], ) -> Result, Self::Error> { let key_encoder = @@ -365,8 +367,12 @@ where key, ); let key_bytes = key_encoder.as_bytes(); - self.inner - .read(key_bytes.as_ref(), ::column(), buf) + self.inner.read( + key_bytes.as_ref(), + ::column(), + offset, + buf, + ) } fn read_alloc( diff --git a/crates/storage/src/transactional.rs b/crates/storage/src/transactional.rs index 4494393ad33..e5e568dd3ea 100644 --- a/crates/storage/src/transactional.rs +++ b/crates/storage/src/transactional.rs @@ -392,6 +392,7 @@ where &self, key: &[u8], column: Self::Column, + offset: usize, buf: &mut [u8], ) -> StorageResult> { if let Some(operation) = self.get_from_changes(key, column) { @@ -409,7 +410,7 @@ where WriteOperation::Remove => Ok(None), } } else { - self.storage.read(key, column, buf) + self.storage.read(key, column, offset, buf) } } } diff --git a/crates/storage/src/vm_storage.rs b/crates/storage/src/vm_storage.rs index 870bf01d1c6..e70b42d6591 100644 --- a/crates/storage/src/vm_storage.rs +++ b/crates/storage/src/vm_storage.rs @@ -190,8 +190,13 @@ impl StorageRead for VmStorage where D: StorageRead, { - fn read(&self, key: &M::Key, buf: &mut [u8]) -> Result, Self::Error> { - StorageRead::::read(&self.database, key, buf) + fn read( + &self, + key: &M::Key, + offset: usize, + buf: &mut [u8], + ) -> Result, Self::Error> { + StorageRead::::read(&self.database, key, offset, buf) } fn read_alloc( diff --git a/crates/types/Cargo.toml b/crates/types/Cargo.toml index 897869db7c1..246952eef4f 100644 --- a/crates/types/Cargo.toml +++ b/crates/types/Cargo.toml @@ -19,7 +19,9 @@ version = { workspace = true } [dependencies] anyhow = { workspace = true } bs58 = { version = "0.5", optional = true } -derivative = { version = "2" } +derivative = { version = "2", default-features = false, optional = true, features = [ + "use_core", +] } derive_more = { version = "0.99" } fuel-vm-private = { workspace = true, default-features = false, features = [ "alloc", @@ -33,7 +35,7 @@ zeroize = "1.5" [features] default = ["std"] -alloc = ["fuel-vm-private/alloc"] +alloc = ["fuel-vm-private/alloc", "derivative"] serde = ["dep:serde", "fuel-vm-private/serde"] da-compression = ["fuel-vm-private/da-compression"] std = ["alloc", "fuel-vm-private/std", "bs58"] diff --git a/tests/tests/poa.rs b/tests/tests/poa.rs index d043d9b4ef9..b360d0d89fa 100644 --- a/tests/tests/poa.rs +++ b/tests/tests/poa.rs @@ -183,7 +183,7 @@ mod p2p { // after the first_producer stops, second_producer should start producing blocks #[tokio::test(flavor = "multi_thread")] async fn test_poa_multiple_producers() { - const SYNC_TIMEOUT: u64 = 30; + const SYNC_TIMEOUT: u64 = 5; const TIME_UNTIL_SYNCED: u64 = SYNC_TIMEOUT + 10; let mut rng = StdRng::seed_from_u64(2222); @@ -201,7 +201,9 @@ mod p2p { let make_node_config = |name: &str| { let mut config = make_config(name.to_string(), config.clone()); config.debug = true; - config.block_production = Trigger::Never; + config.block_production = Trigger::Interval { + block_time: Duration::from_secs(1), + }; config.consensus_signer = SignMode::Key(Secret::new(secret.into())); config.p2p.as_mut().unwrap().bootstrap_nodes = bootstrap.listeners(); config.p2p.as_mut().unwrap().reserved_nodes = bootstrap.listeners(); @@ -216,7 +218,7 @@ mod p2p { let first_producer = make_node(first_producer_config, vec![]).await; - // The first producer should produce 3 blocks. + // The first producer should produce 1 block manually after `SYNC_TIMEOUT` seconds. first_producer .node .shared @@ -224,14 +226,15 @@ mod p2p { .manually_produce_blocks( None, Mode::Blocks { - number_of_blocks: 3, + number_of_blocks: 1, }, ) .await - .expect("The first should produce 3 blocks"); + .expect("The first should produce 1 block manually"); - // Start the second producer after 3 blocks. - // The second producer should synchronize 3 blocks produced by the first producer. + // After 1 manual block start the second producer. + // The first producer should produce 2 more blocks. + // The second producer should synchronize 3(1 manual and 2 produced) blocks. let second_producer = make_node(second_producer_config, vec![]).await; tokio::time::timeout( Duration::from_secs(SYNC_TIMEOUT), @@ -258,11 +261,11 @@ mod p2p { .manually_produce_blocks( None, Mode::Blocks { - number_of_blocks: 2, + number_of_blocks: 1, }, ) .await - .expect("The second should produce 2 blocks"); + .expect("The second should produce 1 blocks"); assert!(start_time.elapsed() >= Duration::from_secs(TIME_UNTIL_SYNCED)); // Restart fresh first producer. @@ -270,7 +273,7 @@ mod p2p { let first_producer = make_node(make_node_config("First Producer reborn"), vec![]).await; tokio::time::timeout( - Duration::from_secs(SYNC_TIMEOUT), + Duration::from_secs(TIME_UNTIL_SYNCED), first_producer.wait_for_blocks(5, false /* is_local */), ) .await