Skip to content

Commit

Permalink
Merge branch 'dento/regenesis-migrate-FuelBlockIdsToHeights' into fea…
Browse files Browse the repository at this point in the history
…ture/benchmarks-0.25.2

# Conflicts:
#	benches/benches/vm_set/blockchain.rs
#	benches/src/lib.rs
  • Loading branch information
xgreenx committed Apr 29, 2024
2 parents 7fcd31d + 97d681c commit 2136866
Show file tree
Hide file tree
Showing 21 changed files with 314 additions and 153 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- [#1856](https://github.com/FuelLabs/fuel-core/pull/1856): Replaced instances of `Union` with `Enum` for GraphQL definitions of `ConsensusParametersVersion` and related types. This is needed because `Union` does not support multiple `Version`s inside discriminants or empty variants.

### Added

- [#1860](https://github.com/FuelLabs/fuel-core/pull/1860): Regenesis now preserves `FuelBlockIdsToHeights` off-chain table.

### Changed

- [#1832](https://github.com/FuelLabs/fuel-core/pull/1832): Snapshot generation can be cancelled. Progress is also reported.
Expand Down
1 change: 1 addition & 0 deletions benches/benches/block_target_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use fuel_core::{
database::{
balances::BalancesInitializer,
state::StateInitializer,
Database,
},
service::{
config::Trigger,
Expand Down
3 changes: 2 additions & 1 deletion benches/benches/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::sync::Arc;

use crate::vm_initialization::vm_initialization;
use contract::*;
use fuel_core::database::GenesisDatabase;
use fuel_core_benches::*;
use fuel_core_storage::transactional::IntoTransaction;
use fuel_core_types::fuel_asm::Instruction;
Expand Down Expand Up @@ -47,7 +48,7 @@ where
let relayer_database_tx = block_database_tx.into_transaction();
let thread_database_tx = relayer_database_tx.into_transaction();
let tx_database_tx = thread_database_tx.into_transaction();
let database = Database::new(Arc::new(tx_database_tx));
let database = GenesisDatabase::new(Arc::new(tx_database_tx));
*vm.as_mut().database_mut() = database.into_transaction();

let mut total = core::time::Duration::ZERO;
Expand Down
7 changes: 4 additions & 3 deletions benches/benches/vm_set/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use fuel_core::{
balances::BalancesInitializer,
database_description::on_chain::OnChain,
state::StateInitializer,
GenesisDatabase,
},
service::Config,
state::rocks_db::{
Expand Down Expand Up @@ -63,7 +64,7 @@ use rand::{
};

pub struct BenchDb {
db: Database,
db: GenesisDatabase,
/// Used for RAII cleanup. Contents of this directory are deleted on drop.
_tmp_dir: ShallowTempDir,
}
Expand All @@ -79,7 +80,7 @@ impl BenchDb {

let state_size = crate::utils::get_state_size();

let mut database = Database::new(db).into_transaction();
let mut database = GenesisDatabase::new(db).into_transaction();
database.init_contract_state(
contract_id,
(0..state_size).map(|_| {
Expand Down Expand Up @@ -125,7 +126,7 @@ impl BenchDb {
}

/// Creates a `VmDatabase` instance.
fn to_vm_database(&self) -> VmStorage<StorageTransaction<Database>> {
fn to_vm_database(&self) -> VmStorage<StorageTransaction<GenesisDatabase>> {
let consensus = ConsensusHeader {
prev_root: Default::default(),
height: 1.into(),
Expand Down
13 changes: 6 additions & 7 deletions benches/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod default_gas_costs;
pub mod import;

pub use fuel_core::database::Database;
pub use fuel_core_storage::vm_storage::VmStorage;
use fuel_core_types::{
fuel_asm::{
Expand Down Expand Up @@ -30,7 +29,7 @@ use fuel_core_types::{
*,
},
};

use fuel_core::database::GenesisDatabase;
use fuel_core_storage::transactional::{
IntoTransaction,
StorageTransaction,
Expand All @@ -43,7 +42,7 @@ use std::{

const LARGE_GAS_LIMIT: u64 = u64::MAX - 1001;

fn new_db() -> VmStorage<StorageTransaction<Database>> {
fn new_db() -> VmStorage<StorageTransaction<GenesisDatabase>> {
// when rocksdb is enabled, this creates a new db instance with a temporary path
VmStorage::default()
}
Expand Down Expand Up @@ -96,7 +95,7 @@ pub struct VmBench {
pub inputs: Vec<Input>,
pub outputs: Vec<Output>,
pub witnesses: Vec<Witness>,
pub db: Option<VmStorage<StorageTransaction<Database>>>,
pub db: Option<VmStorage<StorageTransaction<GenesisDatabase>>>,
pub instruction: Instruction,
pub prepare_call: Option<PrepareCall>,
pub dummy_contract: Option<ContractId>,
Expand All @@ -107,7 +106,7 @@ pub struct VmBench {

#[derive(Debug, Clone)]
pub struct VmBenchPrepared {
pub vm: Interpreter<VmStorage<StorageTransaction<Database>>, Script>,
pub vm: Interpreter<VmStorage<StorageTransaction<GenesisDatabase>>, Script>,
pub instruction: Instruction,
pub diff: diff::Diff<diff::InitialVmState>,
}
Expand Down Expand Up @@ -155,7 +154,7 @@ impl VmBench {

pub fn contract_using_db<R>(
rng: &mut R,
mut db: VmStorage<StorageTransaction<Database>>,
mut db: VmStorage<StorageTransaction<GenesisDatabase>>,
instruction: Instruction,
) -> anyhow::Result<Self>
where
Expand Down Expand Up @@ -214,7 +213,7 @@ impl VmBench {
.with_prepare_call(prepare_call))
}

pub fn with_db(mut self, db: VmStorage<StorageTransaction<Database>>) -> Self {
pub fn with_db(mut self, db: VmStorage<StorageTransaction<GenesisDatabase>>) -> Self {
self.db.replace(db);
self
}
Expand Down
33 changes: 33 additions & 0 deletions crates/fuel-core/src/combined_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
relayer::Relayer,
},
Database,
GenesisDatabase,
Result as DatabaseResult,
},
service::DbType,
Expand Down Expand Up @@ -178,4 +179,36 @@ impl CombinedDatabase {

Ok(state_config)
}

/// Converts the combined database into a genesis combined database.
pub fn into_genesis(self) -> CombinedGenesisDatabase {
CombinedGenesisDatabase {
on_chain: self.on_chain.into_genesis(),
off_chain: self.off_chain.into_genesis(),
relayer: self.relayer.into_genesis(),
}
}
}

/// A genesis database that combines the on-chain, off-chain and relayer
/// genesis databases into one entity.
#[derive(Default, Clone)]
pub struct CombinedGenesisDatabase {
on_chain: GenesisDatabase<OnChain>,
off_chain: GenesisDatabase<OffChain>,
relayer: GenesisDatabase<Relayer>,
}

impl CombinedGenesisDatabase {
pub fn on_chain(&self) -> &GenesisDatabase<OnChain> {
&self.on_chain
}

pub fn off_chain(&self) -> &GenesisDatabase<OffChain> {
&self.off_chain
}

pub fn relayer(&self) -> &GenesisDatabase<Relayer> {
&self.relayer
}
}
Loading

0 comments on commit 2136866

Please sign in to comment.