Skip to content

Commit

Permalink
Refactor fuel-core to use version of StorageRead::read with offset (F…
Browse files Browse the repository at this point in the history
…ull update to 0.59.1) (#2438)

## Linked Issues/PRs
<!-- List of related issues/PRs -->

Related to FuelLabs/fuel-vm#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 FuelLabs/fuel-vm#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 <[email protected]>
Co-authored-by: AurelienFT <[email protected]>
Co-authored-by: AurelienFT <[email protected]>
Co-authored-by: green <[email protected]>
  • Loading branch information
5 people authored Dec 23, 2024
1 parent 4bf049d commit d6e4bb9
Show file tree
Hide file tree
Showing 39 changed files with 364 additions and 109 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
128 changes: 89 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 0 additions & 3 deletions benches/benches/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) => {
Expand All @@ -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
})
});
Expand Down
11 changes: 9 additions & 2 deletions benches/src/default_gas_costs.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 3 additions & 7 deletions benches/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ impl TryFrom<VmBench> 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);
Expand Down Expand Up @@ -531,9 +530,7 @@ impl TryFrom<VmBench> 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) => {
Expand All @@ -546,12 +543,11 @@ impl TryFrom<VmBench> 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::InitialVmState> = 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,
Expand Down
Loading

0 comments on commit d6e4bb9

Please sign in to comment.