Skip to content

Commit

Permalink
Extend fuel-core for the watchtower (#2372)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xgreenx authored Oct 29, 2024
1 parent 75ae124 commit 8c6996a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
10 changes: 10 additions & 0 deletions crates/compression/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub use registry::RegistryKeyspace;
use fuel_core_types::{
blockchain::header::PartialBlockHeader,
fuel_tx::CompressedTransaction,
fuel_types::BlockHeight,
};
use registry::RegistrationsPerTable;

Expand All @@ -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 _;
Expand Down
2 changes: 1 addition & 1 deletion crates/compression/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ macro_rules! tables {


impl RegistrationsPerTable {
pub(crate) fn write_to_registry<R>(&self, registry: &mut R, timestamp: Tai64) -> anyhow::Result<()>
pub fn write_to_registry<R>(&self, registry: &mut R, timestamp: Tai64) -> anyhow::Result<()>
where
R: TemporalRegistryAll
{
Expand Down
2 changes: 1 addition & 1 deletion crates/fuel-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl Modifiable for GenesisDatabase<Relayer> {
}
}

fn commit_changes_with_height_update<Description>(
pub fn commit_changes_with_height_update<Description>(
database: &mut Database<Description>,
changes: Changes,
heights_lookup: impl Fn(
Expand Down
2 changes: 1 addition & 1 deletion crates/fuel-core/src/state/generic_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<Storage> GenericDatabase<Storage> {
}

pub fn into_inner(self) -> Storage {
self.storage.into_inner()
self.storage.into_storage()
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/storage/src/structured_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<S> StructuredStorage<S> {
}

/// Returns the inner storage.
pub fn into_inner(self) -> S {
pub fn into_storage(self) -> S {
self.inner
}
}
Expand Down
12 changes: 8 additions & 4 deletions crates/storage/src/transactional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ impl<S> StorageTransaction<S> {
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();
Expand Down Expand Up @@ -259,10 +266,7 @@ pub trait WriteTransaction {
fn write_transaction(&mut self) -> StorageTransaction<&mut Self>;
}

impl<S> WriteTransaction for S
where
S: Modifiable,
{
impl<S> WriteTransaction for S {
fn write_transaction(&mut self) -> StorageTransaction<&mut Self> {
StorageTransaction::transaction(
self,
Expand Down

0 comments on commit 8c6996a

Please sign in to comment.