Skip to content

Commit

Permalink
Use AtomicView in all services (#1612)
Browse files Browse the repository at this point in the history
Related to #1589 and
preparation for #1583.

All services that use the database for read-only purposes use
`AtomicView` now instead of direct access to the database.

- Removed `Relayer` from the `Verifier` because if it is not used for
now, plus it may not be needed because of the shared sequencer and its
consensus rules.
- Added verification of the transactions root hash into `Verifier`.
- Removed requesting of the one block from p2p, it is possible to use
range request for that purposes.
- Removed not used `get_sealed_header` and `get_sealed_block` method.
- Added the `latest_height` method to `AtomicView` because the database
always knows its latest height.
- Added customisation of the `Height` used by the `AtomicView`. In the
case of the relayer, we want to use `DaBlockHeight` as a primary key to
create a snapshot, while in the case of the Fuel's databases, we want to
use `BockHeight` as a primary key.
- Renamed `Executor` into `ExecutionInstance` and changed it to be a
one-time usable instance. It consumes the `self` to perform the
execution of the block. The instance has a view of the database and
execution options.
  • Loading branch information
xgreenx authored Jan 27, 2024
1 parent 2eaa6d4 commit a05ce48
Show file tree
Hide file tree
Showing 41 changed files with 641 additions and 629 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
- command: check
args: --all-targets
- command: doc
args: --all-features --workspace
args: --all-features --workspace --no-deps
- command: make
args: check --locked
- command: test
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Description of the upcoming release here.

### Changed

- [#1613](https://github.com/FuelLabs/fuel-core/pull/1613): Add api endpoint to retrieve a message by its nonce
- [#1613](https://github.com/FuelLabs/fuel-core/pull/1613): Add api endpoint to retrieve a message by its nonce.
- [#1612](https://github.com/FuelLabs/fuel-core/pull/1612): Use `AtomicView` in all services for consistent results.
- [#1597](https://github.com/FuelLabs/fuel-core/pull/1597): Unify namespacing for `libp2p` modules
- [#1591](https://github.com/FuelLabs/fuel-core/pull/1591): Simplify libp2p dependencies and not depend on all sub modules directly.
- [#1590](https://github.com/FuelLabs/fuel-core/pull/1590): Use `AtomicView` in the `TxPool` to read the state of the database during insertion of the transactions.
Expand Down
2 changes: 1 addition & 1 deletion 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 bin/fuel-core/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use fuel_core::{
config::Trigger,
Config,
DbType,
RelayerVerifierConfig,
RelayerConsensusConfig,
ServiceTrait,
VMConfig,
},
Expand Down Expand Up @@ -289,7 +289,7 @@ impl Command {
None
};

let verifier = RelayerVerifierConfig {
let verifier = RelayerConsensusConfig {
max_da_lag: max_da_lag.into(),
max_wait_time: max_wait_time.into(),
};
Expand Down Expand Up @@ -334,7 +334,7 @@ impl Command {
sync: sync_args.into(),
consensus_key,
name,
verifier,
relayer_consensus_config: verifier,
min_connected_reserved_peers,
time_until_synced: time_until_synced.into(),
query_log_threshold_time: query_log_threshold_time.into(),
Expand Down
2 changes: 1 addition & 1 deletion ci_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cargo +nightly fmt --all -- --check &&
cargo sort -w --check &&
source .github/workflows/scripts/verify_openssl.sh &&
cargo clippy --all-targets --all-features &&
cargo doc --all-features --workspace &&
cargo doc --all-features --workspace --no-deps &&
cargo make check --locked &&
cargo make check --all-features --locked &&
cargo check -p fuel-core-types --target wasm32-unknown-unknown --no-default-features &&
Expand Down
66 changes: 65 additions & 1 deletion crates/fuel-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use fuel_core_storage::{
TableWithBlueprint,
},
transactional::{
AtomicView,
StorageTransaction,
Transactional,
},
Expand All @@ -38,7 +39,10 @@ use fuel_core_storage::{
Result as StorageResult,
};
use fuel_core_types::{
blockchain::primitives::BlockId,
blockchain::primitives::{
BlockId,
DaBlockHeight,
},
fuel_types::{
BlockHeight,
Bytes32,
Expand Down Expand Up @@ -411,6 +415,66 @@ impl fuel_core_storage::vm_storage::VmStorageRequirements for Database {
}
}

impl AtomicView for Database {
type View = Database;

type Height = BlockHeight;

fn latest_height(&self) -> BlockHeight {
// TODO: The database should track the latest height inside of the database object
// instead of fetching it from the `FuelBlocks` table. As a temporary solution,
// fetch it from the table for now.
self.latest_height().unwrap_or_default()
}

fn view_at(&self, _: &BlockHeight) -> StorageResult<Self::View> {
// TODO: Unimplemented until of the https://github.com/FuelLabs/fuel-core/issues/451
Ok(self.latest_view())
}

fn latest_view(&self) -> Self::View {
// TODO: https://github.com/FuelLabs/fuel-core/issues/1581
self.clone()
}
}

pub struct RelayerReadDatabase(Database);

impl RelayerReadDatabase {
pub fn new(database: Database) -> Self {
Self(database)
}
}

impl AtomicView for RelayerReadDatabase {
type View = Database;
type Height = DaBlockHeight;

fn latest_height(&self) -> Self::Height {
#[cfg(feature = "relayer")]
{
use fuel_core_relayer::ports::RelayerDb;
// TODO: The database should track the latest da height inside of the database object
// instead of fetching it from the `RelayerMetadata` table. As a temporary solution,
// fetch it from the table for now.
// https://github.com/FuelLabs/fuel-core/issues/1589
self.0.get_finalized_da_height().unwrap_or_default()
}
#[cfg(not(feature = "relayer"))]
{
DaBlockHeight(0)
}
}

fn view_at(&self, _: &Self::Height) -> StorageResult<Self::View> {
Ok(self.latest_view())
}

fn latest_view(&self) -> Self::View {
self.0.clone()
}
}

#[cfg(feature = "rocksdb")]
pub fn convert_to_rocksdb_direction(
direction: fuel_core_storage::iter::IterDirection,
Expand Down
Loading

0 comments on commit a05ce48

Please sign in to comment.