fuel_core_producer/
ports.rs1use 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 fn latest_height(&self) -> Option<BlockHeight>;
40
41 fn get_block(&self, height: &BlockHeight) -> StorageResult<Cow<CompressedBlock>>;
43
44 fn get_full_block(&self, height: &BlockHeight) -> StorageResult<Block>;
46
47 fn block_header_merkle_root(&self, height: &BlockHeight) -> StorageResult<Bytes32>;
49
50 fn latest_consensus_parameters_version(
52 &self,
53 ) -> StorageResult<ConsensusParametersVersion>;
54
55 fn latest_state_transition_bytecode_version(
57 &self,
58 ) -> StorageResult<StateTransitionBytecodeVersion>;
59}
60
61pub trait TxPool: Send + Sync {
62 type TxSource;
64
65 #[allow(async_fn_in_trait)]
67 async fn get_source(
68 &self,
69 gas_price: u64,
70 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 async fn wait_for_at_least_height(
84 &self,
85 height: &DaBlockHeight,
86 ) -> anyhow::Result<DaBlockHeight>;
87
88 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 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 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}