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