From 72dd40dbe5a72f0c3e05f7581d28b0c2b0b6a559 Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Tue, 15 Oct 2024 17:34:31 +0300 Subject: [PATCH 01/10] Re-add changes to a clean branch from master (too many conflicts) --- crates/fuel-core/src/combined_database.rs | 17 +- crates/fuel-core/src/database.rs | 12 +- crates/fuel-core/src/graphql_api.rs | 2 +- .../src/graphql_api/da_compression.rs | 181 +++++++++++++++++- tests/tests/da_compression.rs | 72 ++++++- 5 files changed, 258 insertions(+), 26 deletions(-) diff --git a/crates/fuel-core/src/combined_database.rs b/crates/fuel-core/src/combined_database.rs index f69649d2605..b7cc0506706 100644 --- a/crates/fuel-core/src/combined_database.rs +++ b/crates/fuel-core/src/combined_database.rs @@ -94,6 +94,19 @@ impl CombinedDatabase { }) } + /// A test-only temporary rocksdb database with given rewind policy. + #[cfg(feature = "rocksdb")] + pub fn from_state_rewind_policy( + state_rewind_policy: StateRewindPolicy, + ) -> DatabaseResult { + Ok(Self { + on_chain: Database::rocksdb_temp(state_rewind_policy)?, + off_chain: Database::rocksdb_temp(state_rewind_policy)?, + relayer: Database::rocksdb_temp(state_rewind_policy)?, + gas_price: Default::default(), + }) + } + pub fn from_config(config: &CombinedDatabaseConfig) -> DatabaseResult { let combined_database = match config.database_type { #[cfg(feature = "rocksdb")] @@ -103,7 +116,9 @@ impl CombinedDatabase { tracing::warn!( "No RocksDB path configured, initializing database with a tmp directory" ); - CombinedDatabase::default() + CombinedDatabase::from_state_rewind_policy( + config.state_rewind_policy, + )? } else { tracing::info!( "Opening database {:?} with cache size \"{}\" and state rewind policy \"{:?}\"", diff --git a/crates/fuel-core/src/database.rs b/crates/fuel-core/src/database.rs index d1d85dfe17e..79da7b7a36e 100644 --- a/crates/fuel-core/src/database.rs +++ b/crates/fuel-core/src/database.rs @@ -249,12 +249,11 @@ where } #[cfg(feature = "rocksdb")] - pub fn rocksdb_temp() -> Self { - let db = RocksDb::>::default_open_temp(None).unwrap(); - let historical_db = - HistoricalRocksDB::new(db, StateRewindPolicy::NoRewind).unwrap(); + pub fn rocksdb_temp(rewind_policy: StateRewindPolicy) -> Result { + let db = RocksDb::>::default_open_temp(None)?; + let historical_db = HistoricalRocksDB::new(db, rewind_policy)?; let data = Arc::new(historical_db); - Self::from_storage(DataSource::new(data, Stage::default())) + Ok(Self::from_storage(DataSource::new(data, Stage::default()))) } } @@ -273,7 +272,8 @@ where } #[cfg(feature = "rocksdb")] { - Self::rocksdb_temp() + Self::rocksdb_temp(StateRewindPolicy::NoRewind) + .expect("Failed to create a temporary database") } } } diff --git a/crates/fuel-core/src/graphql_api.rs b/crates/fuel-core/src/graphql_api.rs index 772bbc815ea..4e469a205d7 100644 --- a/crates/fuel-core/src/graphql_api.rs +++ b/crates/fuel-core/src/graphql_api.rs @@ -9,7 +9,7 @@ use std::{ }; pub mod api_service; -mod da_compression; +pub mod da_compression; pub mod database; pub(crate) mod metrics_extension; pub mod ports; diff --git a/crates/fuel-core/src/graphql_api/da_compression.rs b/crates/fuel-core/src/graphql_api/da_compression.rs index e9d11d1c22e..50f88f6e073 100644 --- a/crates/fuel-core/src/graphql_api/da_compression.rs +++ b/crates/fuel-core/src/graphql_api/da_compression.rs @@ -14,14 +14,21 @@ use fuel_core_compression::{ config::Config, ports::{ EvictorDb, + HistoryLookup, TemporalRegistry, UtxoIdToPointer, }, }; use fuel_core_storage::{ not_found, + tables::{ + Coins, + FuelBlocks, + Messages, + }, StorageAsMut, StorageAsRef, + StorageInspect, }; use fuel_core_types::{ blockchain::block::Block, @@ -49,8 +56,8 @@ where { let compressed = compress( config, - CompressTx { - db_tx, + CompressDbTx { + db_tx: DbTx { db_tx }, block_events, }, block, @@ -65,14 +72,23 @@ where Ok(()) } -struct CompressTx<'a, Tx> { - db_tx: &'a mut Tx, +pub struct DbTx<'a, Tx> { + pub db_tx: &'a mut Tx, +} + +struct CompressDbTx<'a, Tx> { + db_tx: DbTx<'a, Tx>, block_events: &'a [Event], } +pub struct DecompressDbTx<'a, Tx, Onchain> { + pub db_tx: DbTx<'a, Tx>, + pub onchain_db: Onchain, +} + macro_rules! impl_temporal_registry { ($type:ty) => { paste::paste! { - impl<'a, Tx> TemporalRegistry<$type> for CompressTx<'a, Tx> + impl<'a, Tx> TemporalRegistry<$type> for DbTx<'a, Tx> where Tx: OffChainDatabaseTransaction, { @@ -150,7 +166,79 @@ macro_rules! impl_temporal_registry { } } - impl<'a, Tx> EvictorDb<$type> for CompressTx<'a, Tx> + impl<'a, Tx> TemporalRegistry<$type> for CompressDbTx<'a, Tx> + where + Tx: OffChainDatabaseTransaction, + { + fn read_registry( + &self, + key: &fuel_core_types::fuel_compression::RegistryKey, + ) -> anyhow::Result<$type> { + self.db_tx.read_registry(key) + } + + fn read_timestamp( + &self, + key: &fuel_core_types::fuel_compression::RegistryKey, + ) -> anyhow::Result { + <_ as TemporalRegistry<$type>>::read_timestamp(&self.db_tx, key) + } + + fn write_registry( + &mut self, + key: &fuel_core_types::fuel_compression::RegistryKey, + value: &$type, + timestamp: Tai64, + ) -> anyhow::Result<()> { + self.db_tx.write_registry(key, value, timestamp) + } + + fn registry_index_lookup( + &self, + value: &$type, + ) -> anyhow::Result> + { + self.db_tx.registry_index_lookup(value) + } + } + + impl<'a, Tx, Offchain> TemporalRegistry<$type> for DecompressDbTx<'a, Tx, Offchain> + where + Tx: OffChainDatabaseTransaction, + { + fn read_registry( + &self, + key: &fuel_core_types::fuel_compression::RegistryKey, + ) -> anyhow::Result<$type> { + self.db_tx.read_registry(key) + } + + fn read_timestamp( + &self, + key: &fuel_core_types::fuel_compression::RegistryKey, + ) -> anyhow::Result { + <_ as TemporalRegistry<$type>>::read_timestamp(&self.db_tx, key) + } + + fn write_registry( + &mut self, + key: &fuel_core_types::fuel_compression::RegistryKey, + value: &$type, + timestamp: Tai64, + ) -> anyhow::Result<()> { + self.db_tx.write_registry(key, value, timestamp) + } + + fn registry_index_lookup( + &self, + value: &$type, + ) -> anyhow::Result> + { + self.db_tx.registry_index_lookup(value) + } + } + + impl<'a, Tx> EvictorDb<$type> for CompressDbTx<'a, Tx> where Tx: OffChainDatabaseTransaction, { @@ -158,7 +246,7 @@ macro_rules! impl_temporal_registry { &mut self, key: fuel_core_types::fuel_compression::RegistryKey, ) -> anyhow::Result<()> { - self.db_tx + self.db_tx.db_tx .storage_as_mut::() .insert(&MetadataKey::$type, &key)?; Ok(()) @@ -168,7 +256,7 @@ macro_rules! impl_temporal_registry { &self, ) -> anyhow::Result> { Ok(self - .db_tx + .db_tx.db_tx .storage_as_ref::() .get(&MetadataKey::$type)? .map(|v| v.into_owned()) @@ -185,7 +273,7 @@ impl_temporal_registry!(ContractId); impl_temporal_registry!(ScriptCode); impl_temporal_registry!(PredicateCode); -impl<'a, Tx> UtxoIdToPointer for CompressTx<'a, Tx> +impl<'a, Tx> UtxoIdToPointer for CompressDbTx<'a, Tx> where Tx: OffChainDatabaseTransaction, { @@ -210,3 +298,78 @@ where anyhow::bail!("UtxoId not found in the block events"); } } + +impl<'a, Tx, Onchain> HistoryLookup for DecompressDbTx<'a, Tx, Onchain> +where + Tx: OffChainDatabaseTransaction, + Onchain: StorageInspect + + StorageInspect + + StorageInspect, +{ + fn utxo_id( + &self, + c: fuel_core_types::fuel_tx::CompressedUtxoId, + ) -> anyhow::Result { + if c.tx_pointer.block_height() == 0u32.into() { + // This is a genesis coin, which is handled differently. + // See CoinConfigGenerator::generate which generates the genesis coins. + let mut bytes = [0u8; 32]; + let tx_index = c.tx_pointer.tx_index(); + bytes[..std::mem::size_of_val(&tx_index)] + .copy_from_slice(&tx_index.to_be_bytes()); + return Ok(fuel_core_types::fuel_tx::UtxoId::new( + fuel_core_types::fuel_tx::TxId::from(bytes), + 0, + )); + } + + let block_info = self + .onchain_db + .storage_as_ref::() + .get(&c.tx_pointer.block_height())? + .ok_or(not_found!(fuel_core_storage::tables::FuelBlocks))?; + + let tx_id = *block_info + .transactions() + .get(c.tx_pointer.tx_index() as usize) + .ok_or(anyhow::anyhow!( + "Transaction not found in the block: {:?}", + c.tx_pointer + ))?; + + Ok(fuel_core_types::fuel_tx::UtxoId::new(tx_id, c.output_index)) + } + + fn coin( + &self, + utxo_id: fuel_core_types::fuel_tx::UtxoId, + ) -> anyhow::Result { + let coin = self + .onchain_db + .storage_as_ref::() + .get(&dbg!(utxo_id))? + .ok_or(not_found!(fuel_core_storage::tables::Coins))?; + Ok(fuel_core_compression::ports::CoinInfo { + owner: *coin.owner(), + asset_id: *coin.asset_id(), + amount: *coin.amount(), + }) + } + + fn message( + &self, + nonce: fuel_core_types::fuel_types::Nonce, + ) -> anyhow::Result { + let message = self + .onchain_db + .storage_as_ref::() + .get(&nonce)? + .ok_or(not_found!(fuel_core_storage::tables::Messages))?; + Ok(fuel_core_compression::ports::MessageInfo { + sender: *message.sender(), + recipient: *message.recipient(), + amount: message.amount(), + data: message.data().clone(), + }) + } +} diff --git a/tests/tests/da_compression.rs b/tests/tests/da_compression.rs index 43fce2a27e6..09d407de6b4 100644 --- a/tests/tests/da_compression.rs +++ b/tests/tests/da_compression.rs @@ -1,7 +1,13 @@ use core::time::Duration; use fuel_core::{ - combined_database::CombinedDatabase, - fuel_core_graphql_api::worker_service::DaCompressionConfig, + chain_config::TESTNET_WALLET_SECRETS, + fuel_core_graphql_api::{ + da_compression::{ + DbTx, + DecompressDbTx, + }, + worker_service::DaCompressionConfig, + }, p2p_test_helpers::*, service::{ Config, @@ -9,11 +15,19 @@ use fuel_core::{ }, }; use fuel_core_client::client::{ + pagination::PaginationRequest, types::TransactionStatus, FuelClient, }; -use fuel_core_compression::VersionedCompressedBlock; +use fuel_core_compression::{ + decompress::decompress, + VersionedCompressedBlock, +}; use fuel_core_poa::signer::SignMode; +use fuel_core_storage::transactional::{ + HistoricalView, + IntoTransaction, +}; use fuel_core_types::{ fuel_asm::{ op, @@ -21,9 +35,11 @@ use fuel_core_types::{ }, fuel_crypto::SecretKey, fuel_tx::{ + Address, GasCosts, Input, TransactionBuilder, + TxPointer, }, secrecy::Secret, }; @@ -31,30 +47,56 @@ use rand::{ rngs::StdRng, SeedableRng, }; +use std::str::FromStr; #[tokio::test] async fn can_fetch_da_compressed_block_from_graphql() { let mut rng = StdRng::seed_from_u64(10); let poa_secret = SecretKey::random(&mut rng); - let db = CombinedDatabase::default(); let mut config = Config::local_node(); config.consensus_signer = SignMode::Key(Secret::new(poa_secret.into())); + config.utxo_validation = true; let compression_config = fuel_core_compression::Config { temporal_registry_retention: Duration::from_secs(3600), }; config.da_compression = DaCompressionConfig::Enabled(compression_config); - let srv = FuelService::from_combined_database(db.clone(), config) - .await - .unwrap(); + let srv = FuelService::new_node(config).await.unwrap(); let client = FuelClient::from(srv.bound_address); + let wallet_secret = + SecretKey::from_str(TESTNET_WALLET_SECRETS[1]).expect("Expected valid secret"); + let wallet_address = Address::from(*wallet_secret.public_key().hash()); + + let coin = client + .coins( + &wallet_address, + None, + PaginationRequest { + cursor: None, + results: 1, + direction: fuel_core_client::client::pagination::PageDirection::Forward, + }, + ) + .await + .expect("Unable to get coins") + .results + .into_iter() + .next() + .expect("Expected at least one coin"); + let tx = TransactionBuilder::script([op::ret(RegId::ONE)].into_iter().collect(), vec![]) .max_fee_limit(0) .script_gas_limit(1_000_000) .with_gas_costs(GasCosts::free()) - .add_fee_input() + .add_unsigned_coin_input( + wallet_secret, + coin.utxo_id, + coin.amount, + coin.asset_id, + TxPointer::new(coin.block_created.into(), coin.tx_created_idx), + ) .finalize_as_transaction(); let status = client.submit_and_await_commit(&tx).await.unwrap(); @@ -68,7 +110,19 @@ async fn can_fetch_da_compressed_block_from_graphql() { let block = client.da_compressed_block(block_height).await.unwrap(); let block = block.expect("Unable to get compressed block"); - let _: VersionedCompressedBlock = postcard::from_bytes(&block).unwrap(); + let block: VersionedCompressedBlock = postcard::from_bytes(&block).unwrap(); + + let db = &srv.shared.database; + let mut tx_inner = db.off_chain().clone().into_transaction(); + let db_tx = DecompressDbTx { + db_tx: DbTx { + db_tx: &mut tx_inner, + }, + onchain_db: db.on_chain().view_at(&0u32.into()).unwrap(), + }; + let decompressed = decompress(compression_config, db_tx, block).await.unwrap(); + + assert!(decompressed.transactions.len() == 2); } #[tokio::test(flavor = "multi_thread")] From bcf1b6ccdc10ffe679eaccfc65689616cef09efb Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Tue, 15 Oct 2024 17:41:24 +0300 Subject: [PATCH 02/10] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fb76386829..4ea12b9a522 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - [2321](https://github.com/FuelLabs/fuel-core/pull/2321): New metrics for the txpool: "The size of transactions in the txpool" (`txpool_tx_size`), "The time spent by a transaction in the txpool in seconds" (`txpool_tx_time_in_txpool_seconds`), The number of transactions in the txpool (`txpool_number_of_transactions`), "The number of transactions pending verification before entering the txpool" (`txpool_number_of_transactions_pending_verification`), "The number of executable transactions in the txpool" (`txpool_number_of_executable_transactions`), "The time it took to select transactions for inclusion in a block in nanoseconds" (`txpool_select_transaction_time_nanoseconds`), The time it took to insert a transaction in the txpool in milliseconds (`txpool_insert_transaction_time_milliseconds`). +- [2295](https://github.com/FuelLabs/fuel-core/pull/2295): A test case for decompressing DA-compressed blocks. + +### Changed +- [2295](https://github.com/FuelLabs/fuel-core/pull/2295): `CombinedDb::from_config` now respects `state_rewind_policy` with tmp RocksDB. ## [Version 0.40.0] From cf227f57c03a5db80dc18ca25068c880ee6b9cea Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Tue, 15 Oct 2024 17:58:44 +0300 Subject: [PATCH 03/10] Fix benches --- benches/benches/block_target_gas.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/benches/benches/block_target_gas.rs b/benches/benches/block_target_gas.rs index 9574720a3df..fddd14a24c9 100644 --- a/benches/benches/block_target_gas.rs +++ b/benches/benches/block_target_gas.rs @@ -27,6 +27,7 @@ use fuel_core::{ Config, FuelService, }, + state::historical_rocksdb::StateRewindPolicy, }; use fuel_core_benches::{ default_gas_costs::default_gas_costs, @@ -265,7 +266,8 @@ fn service_with_many_contracts( .build() .unwrap(); let _drop = rt.enter(); - let mut database = Database::rocksdb_temp(); + let mut database = Database::rocksdb_temp(StateRewindPolicy::NoRewind) + .expect("Failed to create database"); let mut chain_config = ChainConfig::local_testnet(); From a7324f750a08463fbc83ea5282afd184ecc4f7dc Mon Sep 17 00:00:00 2001 From: Hannes Karppila <2204863+Dentosal@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:11:08 +0300 Subject: [PATCH 04/10] Remove dbg! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: RafaƂ Chabowski <88321181+rafal-ch@users.noreply.github.com> --- crates/fuel-core/src/graphql_api/da_compression.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fuel-core/src/graphql_api/da_compression.rs b/crates/fuel-core/src/graphql_api/da_compression.rs index 50f88f6e073..bc9b978d708 100644 --- a/crates/fuel-core/src/graphql_api/da_compression.rs +++ b/crates/fuel-core/src/graphql_api/da_compression.rs @@ -347,7 +347,7 @@ where let coin = self .onchain_db .storage_as_ref::() - .get(&dbg!(utxo_id))? + .get(utxo_id)? .ok_or(not_found!(fuel_core_storage::tables::Coins))?; Ok(fuel_core_compression::ports::CoinInfo { owner: *coin.owner(), From a4c891e62bdf6d48fe6e851694e4c9bc125990fc Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Thu, 17 Oct 2024 14:05:27 +0300 Subject: [PATCH 05/10] PR review/cleanup --- crates/fuel-core/src/graphql_api/da_compression.rs | 6 +++--- tests/tests/da_compression.rs | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/fuel-core/src/graphql_api/da_compression.rs b/crates/fuel-core/src/graphql_api/da_compression.rs index bc9b978d708..722f63b5080 100644 --- a/crates/fuel-core/src/graphql_api/da_compression.rs +++ b/crates/fuel-core/src/graphql_api/da_compression.rs @@ -325,9 +325,9 @@ where let block_info = self .onchain_db - .storage_as_ref::() + .storage_as_ref::() .get(&c.tx_pointer.block_height())? - .ok_or(not_found!(fuel_core_storage::tables::FuelBlocks))?; + .ok_or(not_found!(FuelBlocks))?; let tx_id = *block_info .transactions() @@ -347,7 +347,7 @@ where let coin = self .onchain_db .storage_as_ref::() - .get(utxo_id)? + .get(&utxo_id)? .ok_or(not_found!(fuel_core_storage::tables::Coins))?; Ok(fuel_core_compression::ports::CoinInfo { owner: *coin.owner(), diff --git a/tests/tests/da_compression.rs b/tests/tests/da_compression.rs index 09d407de6b4..5195f5dc271 100644 --- a/tests/tests/da_compression.rs +++ b/tests/tests/da_compression.rs @@ -108,8 +108,11 @@ async fn can_fetch_da_compressed_block_from_graphql() { } }; - let block = client.da_compressed_block(block_height).await.unwrap(); - let block = block.expect("Unable to get compressed block"); + let block = client + .da_compressed_block(block_height) + .await + .unwrap() + .expect("Unable to get compressed block"); let block: VersionedCompressedBlock = postcard::from_bytes(&block).unwrap(); let db = &srv.shared.database; From 5251318e5e1596e8262c248d762f21a3d4d2c1fc Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Thu, 17 Oct 2024 14:09:03 +0300 Subject: [PATCH 06/10] Move from_state_rewind_policy behind test-helpers --- crates/fuel-core/src/combined_database.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fuel-core/src/combined_database.rs b/crates/fuel-core/src/combined_database.rs index b7cc0506706..d5b6be3937b 100644 --- a/crates/fuel-core/src/combined_database.rs +++ b/crates/fuel-core/src/combined_database.rs @@ -95,7 +95,7 @@ impl CombinedDatabase { } /// A test-only temporary rocksdb database with given rewind policy. - #[cfg(feature = "rocksdb")] + #[cfg(all(any(test, feature = "test-helpers"), feature = "rocksdb"))] pub fn from_state_rewind_policy( state_rewind_policy: StateRewindPolicy, ) -> DatabaseResult { From beaee56e2e3d231f39fdbadfeb5c61022b8f1a7b Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Thu, 17 Oct 2024 14:23:22 +0300 Subject: [PATCH 07/10] Revert 5251318e5e1596e8262c248d762f21a3d4d2c1fc --- crates/fuel-core/src/combined_database.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fuel-core/src/combined_database.rs b/crates/fuel-core/src/combined_database.rs index d5b6be3937b..b7cc0506706 100644 --- a/crates/fuel-core/src/combined_database.rs +++ b/crates/fuel-core/src/combined_database.rs @@ -95,7 +95,7 @@ impl CombinedDatabase { } /// A test-only temporary rocksdb database with given rewind policy. - #[cfg(all(any(test, feature = "test-helpers"), feature = "rocksdb"))] + #[cfg(feature = "rocksdb")] pub fn from_state_rewind_policy( state_rewind_policy: StateRewindPolicy, ) -> DatabaseResult { From 8c6996af3b6705d4c069e9a8eae164f5f5ce4c3c Mon Sep 17 00:00:00 2001 From: Green Baneling Date: Tue, 29 Oct 2024 18:36:45 +0100 Subject: [PATCH 08/10] Extend `fuel-core` for the watchtower (#2372) This PR extends the `fuel-core` too make public some functionality that could be useful to reuse in the watchtower https://github.com/FuelLabs/network-watchtower. ### Before requesting review - [x] I have reviewed the code myself --- crates/compression/src/lib.rs | 10 ++++++++++ crates/compression/src/registry.rs | 2 +- crates/fuel-core/src/database.rs | 2 +- crates/fuel-core/src/state/generic_database.rs | 2 +- crates/storage/src/structured_storage.rs | 2 +- crates/storage/src/transactional.rs | 12 ++++++++---- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/crates/compression/src/lib.rs b/crates/compression/src/lib.rs index bd4b0fdcbba..d41deccefa1 100644 --- a/crates/compression/src/lib.rs +++ b/crates/compression/src/lib.rs @@ -16,6 +16,7 @@ pub use registry::RegistryKeyspace; use fuel_core_types::{ blockchain::header::PartialBlockHeader, fuel_tx::CompressedTransaction, + fuel_types::BlockHeight, }; use registry::RegistrationsPerTable; @@ -42,6 +43,15 @@ impl Default for VersionedCompressedBlock { } } +impl VersionedCompressedBlock { + /// Returns the height of the compressed block. + pub fn height(&self) -> &BlockHeight { + match self { + VersionedCompressedBlock::V0(block) => block.header.height(), + } + } +} + #[cfg(test)] mod tests { use fuel_core_compression as _; diff --git a/crates/compression/src/registry.rs b/crates/compression/src/registry.rs index 0bf1e3a5967..1fd20365d1a 100644 --- a/crates/compression/src/registry.rs +++ b/crates/compression/src/registry.rs @@ -78,7 +78,7 @@ macro_rules! tables { impl RegistrationsPerTable { - pub(crate) fn write_to_registry(&self, registry: &mut R, timestamp: Tai64) -> anyhow::Result<()> + pub fn write_to_registry(&self, registry: &mut R, timestamp: Tai64) -> anyhow::Result<()> where R: TemporalRegistryAll { diff --git a/crates/fuel-core/src/database.rs b/crates/fuel-core/src/database.rs index b50fc4d7fa1..50c286ea85b 100644 --- a/crates/fuel-core/src/database.rs +++ b/crates/fuel-core/src/database.rs @@ -408,7 +408,7 @@ impl Modifiable for GenesisDatabase { } } -fn commit_changes_with_height_update( +pub fn commit_changes_with_height_update( database: &mut Database, changes: Changes, heights_lookup: impl Fn( diff --git a/crates/fuel-core/src/state/generic_database.rs b/crates/fuel-core/src/state/generic_database.rs index 8306df1b1fb..b6f5f2ea464 100644 --- a/crates/fuel-core/src/state/generic_database.rs +++ b/crates/fuel-core/src/state/generic_database.rs @@ -44,7 +44,7 @@ impl GenericDatabase { } pub fn into_inner(self) -> Storage { - self.storage.into_inner() + self.storage.into_storage() } } diff --git a/crates/storage/src/structured_storage.rs b/crates/storage/src/structured_storage.rs index e78e9637484..9a76595bdf8 100644 --- a/crates/storage/src/structured_storage.rs +++ b/crates/storage/src/structured_storage.rs @@ -105,7 +105,7 @@ impl StructuredStorage { } /// Returns the inner storage. - pub fn into_inner(self) -> S { + pub fn into_storage(self) -> S { self.inner } } diff --git a/crates/storage/src/transactional.rs b/crates/storage/src/transactional.rs index 14ec74159ed..34fd040f512 100644 --- a/crates/storage/src/transactional.rs +++ b/crates/storage/src/transactional.rs @@ -112,6 +112,13 @@ impl StorageTransaction { self.inner.changes } + /// Returns the storage and changes to it. + pub fn into_inner(self) -> (S, Changes) { + let storage = self.inner.storage; + let changes = self.inner.changes; + (storage, changes) + } + /// Resets the changes to the storage. pub fn reset_changes(&mut self) { self.inner.changes = Default::default(); @@ -259,10 +266,7 @@ pub trait WriteTransaction { fn write_transaction(&mut self) -> StorageTransaction<&mut Self>; } -impl WriteTransaction for S -where - S: Modifiable, -{ +impl WriteTransaction for S { fn write_transaction(&mut self) -> StorageTransaction<&mut Self> { StorageTransaction::transaction( self, From aca530adcb7eef4e58e5f91a0d38dc27562d44c4 Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Sat, 2 Nov 2024 07:51:35 +0200 Subject: [PATCH 09/10] Address PR comments --- crates/fuel-core/src/combined_database.rs | 6 +++--- tests/tests/da_compression.rs | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/fuel-core/src/combined_database.rs b/crates/fuel-core/src/combined_database.rs index fdacccfb306..c0b6d291af1 100644 --- a/crates/fuel-core/src/combined_database.rs +++ b/crates/fuel-core/src/combined_database.rs @@ -107,13 +107,13 @@ impl CombinedDatabase { /// A test-only temporary rocksdb database with given rewind policy. #[cfg(feature = "rocksdb")] - pub fn from_state_rewind_policy( + pub fn temp_database_with_state_rewind_policy( state_rewind_policy: StateRewindPolicy, ) -> DatabaseResult { Ok(Self { on_chain: Database::rocksdb_temp(state_rewind_policy)?, off_chain: Database::rocksdb_temp(state_rewind_policy)?, - relayer: Database::rocksdb_temp(state_rewind_policy)?, + relayer: Default::default(), gas_price: Default::default(), }) } @@ -127,7 +127,7 @@ impl CombinedDatabase { tracing::warn!( "No RocksDB path configured, initializing database with a tmp directory" ); - CombinedDatabase::from_state_rewind_policy( + CombinedDatabase::temp_database_with_state_rewind_policy( config.state_rewind_policy, )? } else { diff --git a/tests/tests/da_compression.rs b/tests/tests/da_compression.rs index 5195f5dc271..b4f82b39a53 100644 --- a/tests/tests/da_compression.rs +++ b/tests/tests/da_compression.rs @@ -115,6 +115,7 @@ async fn can_fetch_da_compressed_block_from_graphql() { .expect("Unable to get compressed block"); let block: VersionedCompressedBlock = postcard::from_bytes(&block).unwrap(); + // Reuse the existing offchain db to decompress the block let db = &srv.shared.database; let mut tx_inner = db.off_chain().clone().into_transaction(); let db_tx = DecompressDbTx { From 3b1bd257e5bb7efc1406724f587d8990393bb510 Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Sat, 2 Nov 2024 08:09:13 +0200 Subject: [PATCH 10/10] Fix a typo that the spellchecker complains about --- crates/client/assets/debugAdapterProtocol.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/client/assets/debugAdapterProtocol.json b/crates/client/assets/debugAdapterProtocol.json index 44a0c2eed9c..b435aef0f85 100644 --- a/crates/client/assets/debugAdapterProtocol.json +++ b/crates/client/assets/debugAdapterProtocol.json @@ -1440,7 +1440,7 @@ { "$ref": "#/definitions/Request" }, { "type": "object", - "description": "Replaces all existing instruction breakpoints. Typically, instruction breakpoints would be set from a diassembly window. \nTo clear all instruction breakpoints, specify an empty array.\nWhen an instruction breakpoint is hit, a 'stopped' event (with reason 'instruction breakpoint') is generated.\nClients should only call this request if the capability 'supportsInstructionBreakpoints' is true.", + "description": "Replaces all existing instruction breakpoints. Typically, instruction breakpoints would be set from a disassembly window. \nTo clear all instruction breakpoints, specify an empty array.\nWhen an instruction breakpoint is hit, a 'stopped' event (with reason 'instruction breakpoint') is generated.\nClients should only call this request if the capability 'supportsInstructionBreakpoints' is true.", "properties": { "command": { "type": "string",