Skip to content

Commit

Permalink
Implemented tracking of the height during committing of the changes.
Browse files Browse the repository at this point in the history
The `Database` is responsible for its updating and tracking.
  • Loading branch information
xgreenx committed Feb 23, 2024
1 parent 5b9bd78 commit 7b1141a
Show file tree
Hide file tree
Showing 22 changed files with 861 additions and 187 deletions.
2 changes: 1 addition & 1 deletion benches/benches/block_target_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ fn service_with_many_contracts(
.build()
.unwrap();
let _drop = rt.enter();
let mut database = Database::rocksdb();
let mut database = Database::rocksdb_temp();
let mut config = Config::local_node();
config
.chain_conf
Expand Down
33 changes: 27 additions & 6 deletions crates/database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ pub enum Error {
/// Error occurred during serialization or deserialization of the entity.
#[display(fmt = "error performing serialization or deserialization")]
Codec,
/// Chain can be initialized once.
#[display(fmt = "Failed to initialize chain")]
ChainAlreadyInitialized,
/// Chain should be initialized before usage.
#[display(fmt = "Chain is not yet initialized")]
ChainUninitialized,
/// The version of database or data is invalid (possibly not migrated).
#[display(
fmt = "Invalid database version, expected {expected:#x}, found {found:#x}"
Expand All @@ -37,6 +31,33 @@ pub enum Error {
/// the database version expected by this build of fuel-core
expected: u32,
},
/// Multiple heights found in the commit to teh database.
#[display(fmt = "Multiple heights found in the commit {heights:?}")]
MultipleHeightsInCommit {
/// List of heights found in the commit.
heights: Vec<u64>,
},
/// Failed to advance the height.
#[display(fmt = "Failed to advance the height")]
FailedToAdvanceHeight,
/// The new and old heights are not linked.
#[display(
fmt = "New and old heights are not linked: prev_height: {prev_height:#x}, new_height: {new_height:#x}"
)]
HeightsAreNotLinked {
/// The old height.
prev_height: u64,
/// The new height.
new_height: u64,
},
/// The new height is not found, but the old height is set.
#[display(
fmt = "The new height is not found, but the old height is set: prev_height: {prev_height:#x}"
)]
NewHeightIsNotSet {
/// The old height known by the database.
prev_height: u64,
},

/// Not related to database error.
#[from]
Expand Down
16 changes: 4 additions & 12 deletions crates/fuel-core/src/combined_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ use crate::database::{
Database,
};
use fuel_core_storage::Result as StorageResult;
use fuel_core_types::{
blockchain::primitives::DaBlockHeight,
fuel_types::BlockHeight,
};

/// A database that combines the on-chain, off-chain and relayer databases into one entity.
#[derive(Default, Clone)]
Expand Down Expand Up @@ -57,14 +53,10 @@ impl CombinedDatabase {
)
}

pub fn init(
&mut self,
block_height: &BlockHeight,
da_block_height: &DaBlockHeight,
) -> StorageResult<()> {
self.on_chain.init(block_height)?;
self.off_chain.init(block_height)?;
self.relayer.init(da_block_height)?;
pub fn check_version(&self) -> StorageResult<()> {
self.on_chain.check_version()?;
self.off_chain.check_version()?;
self.relayer.check_version()?;
Ok(())
}

Expand Down
Loading

0 comments on commit 7b1141a

Please sign in to comment.