fuel_core_producer/
ports.rs

1use fuel_core_storage::{
2    transactional::Changes,
3    Result as StorageResult,
4};
5use fuel_core_types::{
6    blockchain::{
7        block::CompressedBlock,
8        header::{
9            ConsensusParametersVersion,
10            StateTransitionBytecodeVersion,
11        },
12        primitives::DaBlockHeight,
13    },
14    fuel_tx::{
15        Bytes32,
16        Transaction,
17    },
18    fuel_types::BlockHeight,
19    services::{
20        block_producer::Components,
21        executor::{
22            Result as ExecutorResult,
23            TransactionExecutionStatus,
24            UncommittedResult,
25        },
26    },
27};
28use std::borrow::Cow;
29
30pub trait BlockProducerDatabase: Send + Sync {
31    /// Returns the latest block height.
32    fn latest_height(&self) -> Option<BlockHeight>;
33
34    /// Gets the committed block at the `height`.
35    fn get_block(&self, height: &BlockHeight) -> StorageResult<Cow<CompressedBlock>>;
36
37    /// Gets the block header BMT MMR root at `height`.
38    fn block_header_merkle_root(&self, height: &BlockHeight) -> StorageResult<Bytes32>;
39
40    /// Returns the latest consensus parameters version.
41    fn latest_consensus_parameters_version(
42        &self,
43    ) -> StorageResult<ConsensusParametersVersion>;
44
45    /// Returns the latest state transition bytecode version.
46    fn latest_state_transition_bytecode_version(
47        &self,
48    ) -> StorageResult<StateTransitionBytecodeVersion>;
49}
50
51pub trait TxPool: Send + Sync {
52    /// The source of the transactions used by the executor.
53    type TxSource;
54
55    /// Returns the source of includable transactions.
56    #[allow(async_fn_in_trait)]
57    async fn get_source(
58        &self,
59        gas_price: u64,
60        // could be used by the txpool to filter txs based on maturity
61        block_height: BlockHeight,
62    ) -> anyhow::Result<Self::TxSource>;
63}
64
65pub struct RelayerBlockInfo {
66    pub gas_cost: u64,
67    pub tx_count: u64,
68}
69
70#[async_trait::async_trait]
71pub trait Relayer: Send + Sync {
72    /// Wait for the relayer to reach at least this height and return the latest height.
73    async fn wait_for_at_least_height(
74        &self,
75        height: &DaBlockHeight,
76    ) -> anyhow::Result<DaBlockHeight>;
77
78    /// Get the total Forced Transaction gas cost for the block at the given height.
79    async fn get_cost_and_transactions_number_for_block(
80        &self,
81        height: &DaBlockHeight,
82    ) -> anyhow::Result<RelayerBlockInfo>;
83}
84
85pub trait BlockProducer<TxSource>: Send + Sync {
86    /// Executes the block and returns the result of execution with uncommitted database
87    /// transaction.
88    fn produce_without_commit(
89        &self,
90        component: Components<TxSource>,
91    ) -> ExecutorResult<UncommittedResult<Changes>>;
92}
93
94pub trait DryRunner: Send + Sync {
95    /// Executes the block without committing it to the database. During execution collects the
96    /// receipts to return them. The `utxo_validation` field can be used to disable the validation
97    /// of utxos during execution.
98    fn dry_run(
99        &self,
100        block: Components<Vec<Transaction>>,
101        utxo_validation: Option<bool>,
102    ) -> ExecutorResult<Vec<TransactionExecutionStatus>>;
103}