Skip to content

Commit

Permalink
Making relayer independent from the executor (FuelLabs#1625)
Browse files Browse the repository at this point in the history
It is preparation for the
FuelLabs#1568.

The changes make relayer storage independent from the executor storage.
Before, the relayer and executor shared write ownership to the
`Messages` table. The relayer was inserting new messages, and the
executor was removing them.

With this change, only the executor modifies the `Messages`
table(inserts and removes messages). The relayer has its own new
`History` table, that stores all events from the DA layer per each
height.

This change also makes the insertion of upcoming events from DA as part
of the state transition, allowing in the future handle [force
transaction
inclusion](FuelLabs#1626).

The change:
- Adds blanket implementation for the `VmStorageRequirements` since the
executor requires access to the `FuelBlocks` table, and we can inherit
this implementation.
- Adds new tests for the executor that verifies fetching data from the
relayer.
- Introduces a new general `Event` type for messages and forced
transactions (in the future).
  • Loading branch information
xgreenx authored Jan 30, 2024
1 parent 3fdd33d commit 3c55250
Show file tree
Hide file tree
Showing 25 changed files with 822 additions and 335 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Description of the upcoming release here.
### Changed

- [#1633](https://github.com/FuelLabs/fuel-core/pull/1633): Notify services about importing of the genesis block.
- [#1625](https://github.com/FuelLabs/fuel-core/pull/1625): Making relayer independent from the executor and preparation for the force transaction inclusion.
- [#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
Expand Down
32 changes: 2 additions & 30 deletions crates/fuel-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,8 @@ use fuel_core_storage::{
Result as StorageResult,
};
use fuel_core_types::{
blockchain::primitives::{
BlockId,
DaBlockHeight,
},
fuel_types::{
BlockHeight,
Bytes32,
ContractId,
},
tai64::Tai64,
blockchain::primitives::DaBlockHeight,
fuel_types::BlockHeight,
};
use std::{
fmt::{
Expand Down Expand Up @@ -395,26 +387,6 @@ impl ChainConfigDb for Database {
}
}

impl fuel_core_storage::vm_storage::VmStorageRequirements for Database {
type Error = StorageError;

fn block_time(&self, height: &BlockHeight) -> StorageResult<Tai64> {
self.block_time(height)
}

fn get_block_id(&self, height: &BlockHeight) -> StorageResult<Option<BlockId>> {
self.get_block_id(height)
}

fn init_contract_state<S: Iterator<Item = (Bytes32, Bytes32)>>(
&mut self,
contract_id: &ContractId,
slots: S,
) -> StorageResult<()> {
self.init_contract_state(contract_id, slots)
}
}

impl AtomicView for Database {
type View = Database;

Expand Down
15 changes: 0 additions & 15 deletions crates/fuel-core/src/database/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use fuel_core_types::{
entities::message::MerkleProof,
fuel_merkle::binary::MerkleTree,
fuel_types::BlockHeight,
tai64::Tai64,
};
use itertools::Itertools;
use std::borrow::{
Expand Down Expand Up @@ -182,20 +181,6 @@ impl Database {
self.latest_compressed_block()
}

pub fn block_time(&self, height: &BlockHeight) -> StorageResult<Tai64> {
let block = self
.storage::<FuelBlocks>()
.get(height)?
.ok_or(not_found!(FuelBlocks))?;
Ok(block.header().time().to_owned())
}

pub fn get_block_id(&self, height: &BlockHeight) -> StorageResult<Option<BlockId>> {
self.storage::<FuelBlocks>()
.get(height)
.map(|v| v.map(|v| v.id()))
}

pub fn get_block_height(&self, id: &BlockId) -> StorageResult<Option<BlockHeight>> {
self.storage::<FuelBlockSecondaryKeyBlockHeights>()
.get(id)
Expand Down
39 changes: 38 additions & 1 deletion crates/fuel-core/src/database/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use fuel_core_storage::{
Result as StorageResult,
StorageAsMut,
StorageAsRef,
StorageBatchMutate,
StorageInspect,
StorageMutate,
StorageRead,
Expand Down Expand Up @@ -91,7 +92,10 @@ use_structured_implementation!(
FuelBlockMerkleMetadata
);
#[cfg(feature = "relayer")]
use_structured_implementation!(fuel_core_relayer::ports::RelayerMetadata);
use_structured_implementation!(
fuel_core_relayer::storage::RelayerMetadata,
fuel_core_relayer::storage::EventsHistory
);

impl<M> StorageInspect<M> for Database
where
Expand Down Expand Up @@ -165,3 +169,36 @@ where
self.data.storage::<M>().read_alloc(key)
}
}

impl<M> StorageBatchMutate<M> for Database
where
M: Mappable,
StructuredStorage<DataSource>:
StorageBatchMutate<M, Error = StorageError> + UseStructuredImplementation<M>,
{
fn init_storage<'a, Iter>(&mut self, set: Iter) -> StorageResult<()>
where
Iter: 'a + Iterator<Item = (&'a M::Key, &'a M::Value)>,
M::Key: 'a,
M::Value: 'a,
{
StorageBatchMutate::init_storage(&mut self.data, set)
}

fn insert_batch<'a, Iter>(&mut self, set: Iter) -> StorageResult<()>
where
Iter: 'a + Iterator<Item = (&'a M::Key, &'a M::Value)>,
M::Key: 'a,
M::Value: 'a,
{
StorageBatchMutate::insert_batch(&mut self.data, set)
}

fn remove_batch<'a, Iter>(&mut self, set: Iter) -> StorageResult<()>
where
Iter: 'a + Iterator<Item = &'a M::Key>,
M::Key: 'a,
{
StorageBatchMutate::remove_batch(&mut self.data, set)
}
}
Loading

0 comments on commit 3c55250

Please sign in to comment.