1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
use async_trait::async_trait;
use fuel_core_storage::{
transactional::StorageTransaction,
Result as StorageResult,
};
use fuel_core_types::{
blockchain::{
block::CompressedBlock,
primitives::{
BlockHeight,
DaBlockHeight,
},
},
fuel_tx::{
Bytes32,
Receipt,
Transaction,
},
services::{
block_producer::Components,
executor::{
Result as ExecutorResult,
UncommittedResult,
},
},
};
use std::borrow::Cow;
pub trait BlockProducerDatabase: Send + Sync {
/// Gets the committed block at the `height`.
fn get_block(&self, height: &BlockHeight) -> StorageResult<Cow<CompressedBlock>>;
/// Gets the block header BMT MMR root at `height`.
fn block_header_merkle_root(&self, height: &BlockHeight) -> StorageResult<Bytes32>;
/// Fetch the current block height.
fn current_block_height(&self) -> StorageResult<BlockHeight>;
}
#[async_trait]
pub trait TxPool: Send + Sync {
/// The source of the transactions used by the executor.
type TxSource;
/// Returns the source of includable transactions.
fn get_source(
&self,
// could be used by the txpool to filter txs based on maturity
block_height: BlockHeight,
) -> Self::TxSource;
}
#[async_trait::async_trait]
pub trait Relayer: Send + Sync {
/// Wait for the relayer to reach at least this height and return the
/// latest height (which is guaranteed to be >= height).
async fn wait_for_at_least(
&self,
height: &DaBlockHeight,
) -> anyhow::Result<DaBlockHeight>;
}
pub trait Executor: Send + Sync {
/// The database used by the executor.
type Database;
/// The source of transaction used by the executor.
type TxSource;
/// Executes the block and returns the result of execution with uncommitted database
/// transaction.
fn execute_without_commit(
&self,
component: Components<Self::TxSource>,
) -> ExecutorResult<UncommittedResult<StorageTransaction<Self::Database>>>;
/// Executes the block without committing it to the database. During execution collects the
/// receipts to return them. The `utxo_validation` field can be used to disable the validation
/// of utxos during execution.
fn dry_run(
&self,
block: Components<Transaction>,
utxo_validation: Option<bool>,
) -> ExecutorResult<Vec<Vec<Receipt>>>;
}