Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b854452
Add possibility to submit a list of changes to rocksdb
AurelienFT Jan 22, 2025
3134fb0
Special case history rocksdb and changelog
AurelienFT Jan 23, 2025
8db1be9
Merge branch 'master' into take_vec_changes_rocksdb
AurelienFT Jan 23, 2025
7b06b0d
Make sure we don't create a transaction if not needed & Clippy
AurelienFT Jan 23, 2025
f8e001f
Change `commit_changes_with_height_update` to work with StorageChanges
AurelienFT Jan 24, 2025
b92cbd8
fix compilation relayer feature
AurelienFT Jan 24, 2025
fb5c157
Merge branch 'master' into take_vec_changes_rocksdb
AurelienFT Jan 24, 2025
81e7c12
Fix changelog
AurelienFT Jan 24, 2025
46c83e4
changelog
AurelienFT Jan 24, 2025
3a67be5
Fix test compilation and clippy
AurelienFT Jan 24, 2025
9171473
fmt
AurelienFT Jan 24, 2025
742a0e3
Merge branch 'master' into take_vec_changes_rocksdb
AurelienFT Jan 27, 2025
1dfaa47
Refactor `iter_store_keys` (#2651)
MitchTurner Jan 29, 2025
d5b5265
Merge branch 'master' into take_vec_changes_rocksdb
AurelienFT Jan 30, 2025
965d208
Merge branch 'master' into take_vec_changes_rocksdb
MitchTurner Jan 31, 2025
ca80eea
Merge branch 'master' into take_vec_changes_rocksdb
AurelienFT Feb 3, 2025
eaf2c57
Merge branch 'master' into take_vec_changes_rocksdb
AurelienFT Feb 3, 2025
f89556c
Merge branch 'master' into take_vec_changes_rocksdb
AurelienFT Feb 11, 2025
fe267c5
Update CHANGELOG.md
AurelienFT Feb 11, 2025
b6eeb6a
Merge branch 'master' into take_vec_changes_rocksdb
AurelienFT Feb 19, 2025
6453efe
Handle conflicts in the case of multiple changes
xgreenx Feb 20, 2025
a2db262
Small things from the final review
xgreenx Feb 20, 2025
b74c791
Merge branch 'master' into take_vec_changes_rocksdb
xgreenx Feb 20, 2025
c70e803
Merge branch 'master' into take_vec_changes_rocksdb
AurelienFT Feb 20, 2025
42cf2b8
Merge branch 'master' into take_vec_changes_rocksdb
AurelienFT Feb 20, 2025
766edce
Merge branch 'master' into take_vec_changes_rocksdb
AurelienFT Feb 22, 2025
e738d0f
Merge branch 'master' into take_vec_changes_rocksdb
AurelienFT Feb 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changes/added/2619.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add possibility to submit list of changes to rocksdb.
9 changes: 8 additions & 1 deletion crates/database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
#![deny(warnings)]
#![deny(unused_variables)]

use fuel_core_storage::Error as StorageError;
use fuel_core_storage::{
transactional::ReferenceBytesKey,
Error as StorageError,
};
use fuel_core_types::services::executor::Error as ExecutorError;

/// The error occurred during work with any of databases.
Expand Down Expand Up @@ -84,6 +87,10 @@ pub enum Error {
#[display(fmt = "Restore error: {}", _0)]
RestoreError(anyhow::Error),

#[display(fmt = "During committing of the changes found conflicting \
modifications at column {column} for the key {key:?}")]
ConflictingChanges { column: u32, key: ReferenceBytesKey },

/// Not related to database error.
#[from]
Other(anyhow::Error),
Expand Down
33 changes: 21 additions & 12 deletions crates/fuel-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use fuel_core_storage::{
ConflictPolicy,
HistoricalView,
Modifiable,
StorageChanges,
StorageTransaction,
},
Error as StorageError,
Expand Down Expand Up @@ -452,23 +453,23 @@ impl Modifiable for Database<Relayer> {

impl Modifiable for GenesisDatabase<OnChain> {
fn commit_changes(&mut self, changes: Changes) -> StorageResult<()> {
self.data.as_ref().commit_changes(None, changes)
self.data.as_ref().commit_changes(None, changes.into())
}
}

impl Modifiable for GenesisDatabase<OffChain> {
fn commit_changes(&mut self, changes: Changes) -> StorageResult<()> {
self.data.as_ref().commit_changes(None, changes)
self.data.as_ref().commit_changes(None, changes.into())
}
}

impl Modifiable for GenesisDatabase<Relayer> {
fn commit_changes(&mut self, changes: Changes) -> StorageResult<()> {
self.data.as_ref().commit_changes(None, changes)
self.data.as_ref().commit_changes(None, changes.into())
}
}

pub fn commit_changes_with_height_update<Description>(
pub fn commit_changes_with_height_update<Description, Changes>(
database: &mut Database<Description>,
changes: Changes,
heights_lookup: impl Fn(
Expand All @@ -480,8 +481,10 @@ where
Description::Height: Debug + PartialOrd + DatabaseHeight,
for<'a> StorageTransaction<&'a &'a mut Database<Description>>:
StorageMutate<MetadataTable<Description>, Error = StorageError>,
Changes: Into<StorageChanges>,
{
// Gets the all new heights from the `changes`
let mut changes = changes.into();
let iterator = ChangesIterator::<Description::Column>::new(&changes);
let new_heights = heights_lookup(&iterator)?;

Expand Down Expand Up @@ -533,14 +536,14 @@ where
}
};

let updated_changes = if let Some(new_height) = new_height {
if let Some(new_height) = new_height {
// We want to update the metadata table to include a new height.
// For that, we are building a new storage transaction around `changes`.
// Modifying this transaction will include all required updates into the `changes`.
// For that, we are building a new storage transaction.
// We get the changes from the database and add to our list of changes.
let mut transaction = StorageTransaction::transaction(
&database,
ConflictPolicy::Overwrite,
changes,
Default::default(),
);
let maybe_current_metadata = transaction
.storage_as_mut::<MetadataTable<Description>>()
Expand All @@ -550,14 +553,20 @@ where
.storage_as_mut::<MetadataTable<Description>>()
.insert(&(), &metadata)?;

transaction.into_changes()
} else {
changes
changes = match changes {
StorageChanges::Changes(c) => {
StorageChanges::ChangesList(vec![c, transaction.into_changes()])
}
StorageChanges::ChangesList(mut list) => {
list.push(transaction.into_changes());
StorageChanges::ChangesList(list)
}
}
};

// Atomically commit the changes to the database, and to the mutex-protected field.
let mut guard = database.stage.height.lock();
database.data.commit_changes(new_height, updated_changes)?;
database.data.commit_changes(new_height, changes)?;

// Update the block height
if let Some(new_height) = new_height {
Expand Down
4 changes: 4 additions & 0 deletions crates/fuel-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3182,6 +3182,7 @@ mod tests {
IteratorOverTable,
},
tables::FuelBlocks,
transactional::StorageChanges,
StorageAsMut,
};
use fuel_core_types::{
Expand Down Expand Up @@ -3325,6 +3326,7 @@ mod tests {
let (result, changes) = producer.produce_without_commit(block.into())?.into();

// Then
let changes = StorageChanges::Changes(changes);
let view = ChangesIterator::<Column>::new(&changes);
assert_eq!(
view.iter_all::<Messages>(None).count() as u64,
Expand Down Expand Up @@ -3934,6 +3936,7 @@ mod tests {
.into();

// Then
let changes = StorageChanges::Changes(changes);
let view = ChangesIterator::<Column>::new(&changes);
assert!(result.skipped_transactions.is_empty());
assert_eq!(view.iter_all::<Messages>(None).count() as u64, 0);
Expand Down Expand Up @@ -3976,6 +3979,7 @@ mod tests {
.into();

// Then
let changes = StorageChanges::Changes(changes);
let view = ChangesIterator::<Column>::new(&changes);
assert!(result.skipped_transactions.is_empty());
assert_eq!(view.iter_all::<Messages>(None).count() as u64, 0);
Expand Down
10 changes: 5 additions & 5 deletions crates/fuel-core/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use fuel_core_storage::{
transactional::{
AtomicView,
ReadTransaction,
StorageChanges,
},
IsNotFound,
StorageAsMut,
Expand Down Expand Up @@ -311,11 +312,10 @@ impl FuelService {
&Consensus::Genesis(initialized_genesis),
)?;

self.shared
.database
.on_chain()
.data
.commit_changes(Some(genesis_block_height), database_tx.into_changes())?;
self.shared.database.on_chain().data.commit_changes(
Some(genesis_block_height),
StorageChanges::Changes(database_tx.into_changes()),
)?;
}

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ mod tests {
},
tables::Coins,
transactional::{
Changes,
StorageChanges,
StorageTransaction,
},
Result as StorageResult,
Expand Down Expand Up @@ -574,7 +574,7 @@ mod tests {
fn commit_changes(
&self,
_: Option<BlockHeight>,
_: Changes,
_: StorageChanges,
) -> StorageResult<()> {
Err(anyhow::anyhow!("I refuse to work!").into())
}
Expand Down
6 changes: 3 additions & 3 deletions crates/fuel-core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use fuel_core_storage::{
IterableStore,
},
kv_store::StorageColumn,
transactional::Changes,
transactional::StorageChanges,
Result as StorageResult,
};
use std::fmt::Debug;
Expand Down Expand Up @@ -57,7 +57,7 @@ pub trait TransactableStorage<Height>: IterableStore + Debug + Send + Sync {
fn commit_changes(
&self,
height: Option<Height>,
changes: Changes,
changes: StorageChanges,
) -> StorageResult<()>;

fn view_at_height(
Expand All @@ -77,7 +77,7 @@ impl<Height, S> TransactableStorage<Height>
where
S: IterableStore + Debug + Send + Sync,
{
fn commit_changes(&self, _: Option<Height>, _: Changes) -> StorageResult<()> {
fn commit_changes(&self, _: Option<Height>, _: StorageChanges) -> StorageResult<()> {
unimplemented!()
}

Expand Down
Loading
Loading