Skip to content

Commit

Permalink
Moved implementation of all tables into database/storage folder.
Browse files Browse the repository at this point in the history
Refactored all tables to implement new storage traits(Also refactored all tests).

Replaced all `<Self as Storage<K, V>>::method` with `self.storage::<Table>().method`.
The same for `MerkleRootStorage`. Also refactored all tests.

Instead of constants for columns, use the `Column` enum to manage tables columns(Use `Column`
everywhere instead of `ColumnId`). In the future, we can use more advanced naming for fields,
instead of "column-{i}" because now we have names of enum=)

In some places, removed unnecessary usage of `Vec<u8>`(in `put`, `insert` etc methods).
Removed usage of `Clone` and `Copy` for some `value` in the same methods.

Prepared the code for the next refactoring:
- to simplify the implementation of storage-related traits
- to use only read/write traits in the places where it is really required
- performance improvements to work with types more optimal
  • Loading branch information
xgreenx committed Aug 25, 2022
1 parent cfc3878 commit b336c22
Show file tree
Hide file tree
Showing 56 changed files with 2,298 additions and 1,884 deletions.
75 changes: 67 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions fuel-core-interfaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ chrono = { version = "0.4" }
derive_more = { version = "0.99" }
fuel-asm = "0.8"
fuel-crypto = { version = "0.6", default-features = false, features = [ "random" ] }
fuel-merkle = { version = "0.3" }
fuel-storage = "0.2"
fuel-merkle = { git = "https://github.com/FuelLabs/fuel-merkle", branch = "feature/split-storage-trait" }
fuel-storage = { git = "https://github.com/FuelLabs/fuel-storage", branch = "feature/split-storage-trait" }
fuel-tx = { version = "0.18", default-features = false }
fuel-types = { version = "0.5", default-features = false }
fuel-vm = { version = "0.15", default-features = false }
fuel-vm = { git = "https://github.com/FuelLabs/fuel-vm", branch = "feature/split-storage-trait" }
futures = "0.3"
lazy_static = "1.4"
parking_lot = "0.12"
Expand Down
64 changes: 64 additions & 0 deletions fuel-core-interfaces/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,71 @@
use crate::{
model::{Coin, ConsensusId, DaBlockHeight, Message, ValidatorId, ValidatorStake},
relayer::StakingDiff,
};
use fuel_storage::Mappable;
use fuel_tx::{Transaction, UtxoId};
use fuel_types::{Address, Bytes32, MessageId};
use fuel_vm::prelude::InterpreterError;
use std::io::ErrorKind;
use thiserror::Error;

pub use fuel_vm::storage::{ContractsAssets, ContractsInfo, ContractsRawCode, ContractsState};

/// The storage table of coins UTXOs.
pub struct Coins;

impl Mappable for Coins {
type Key = UtxoId;
type SetValue = Coin;
type GetValue = Self::SetValue;
}

/// The storage table of bridget from Ethereum messages.
pub struct Messages;

impl Mappable for Messages {
type Key = MessageId;
type SetValue = Message;
type GetValue = Self::SetValue;
}

/// The storage table of confirmed transactions.
pub struct Transactions;

impl Mappable for Transactions {
type Key = Bytes32;
type SetValue = Transaction;
type GetValue = Self::SetValue;
}

/// The storage table of delegate's indexes used by relayer.
/// Delegate index maps delegate `Address` with list of da block where delegation happened.
pub struct DelegatesIndexes;

impl Mappable for DelegatesIndexes {
type Key = Address;
type SetValue = [DaBlockHeight];
type GetValue = Vec<DaBlockHeight>;
}

/// The storage table of relayer validators set.
pub struct ValidatorsSet;

impl Mappable for ValidatorsSet {
type Key = ValidatorId;
type SetValue = (ValidatorStake, Option<ConsensusId>);
type GetValue = Self::SetValue;
}

/// The storage table of relayer stacking diffs.
pub struct StackingDiffs;

impl Mappable for StackingDiffs {
type Key = DaBlockHeight;
type SetValue = StakingDiff;
type GetValue = Self::SetValue;
}

#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
Expand Down
2 changes: 2 additions & 0 deletions fuel-core-interfaces/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub mod relayer;
pub mod signer;
pub mod sync;
pub mod txpool;
#[cfg(any(test, feature = "test-helpers"))]
pub mod utils;

pub mod common {
#[doc(no_inline)]
Expand Down
Loading

0 comments on commit b336c22

Please sign in to comment.