From 8c6996af3b6705d4c069e9a8eae164f5f5ce4c3c Mon Sep 17 00:00:00 2001 From: Green Baneling Date: Tue, 29 Oct 2024 18:36:45 +0100 Subject: [PATCH] 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,