fuel_core_txpool/
ports.rs1use std::sync::Arc;
2
3use fuel_core_services::stream::BoxStream;
4use fuel_core_storage::{
5 PredicateStorageRequirements,
6 Result as StorageResult,
7};
8use fuel_core_types::{
9 blockchain::header::ConsensusParametersVersion,
10 entities::{
11 coins::coin::CompressedCoin,
12 relayer::message::Message,
13 },
14 fuel_tx::{
15 BlobId,
16 Bytes32,
17 ConsensusParameters,
18 ContractId,
19 Transaction,
20 TxId,
21 UtxoId,
22 },
23 fuel_types::Nonce,
24 services::{
25 block_importer::SharedImportResult,
26 p2p::{
27 GossipsubMessageAcceptance,
28 GossipsubMessageInfo,
29 NetworkData,
30 PeerId,
31 },
32 transaction_status::{
33 PreConfirmationStatus,
34 TransactionStatus,
35 },
36 },
37};
38use tokio::sync::broadcast;
39
40use crate::GasPrice;
41
42pub use fuel_core_storage::transactional::AtomicView;
43use fuel_core_types::services::transaction_status::statuses;
44
45pub trait TxStatusManager: Send + Sync + 'static {
46 fn status_update(&self, tx_id: TxId, tx_status: TransactionStatus);
47
48 fn preconfirmations_update_listener(
49 &self,
50 ) -> broadcast::Receiver<(TxId, PreConfirmationStatus)>;
51
52 fn squeezed_out_txs(&self, statuses: Vec<(TxId, statuses::SqueezedOut)>);
53}
54
55pub trait BlockImporter {
56 fn block_events(&self) -> BoxStream<SharedImportResult>;
58}
59
60pub trait ChainStateInfoProvider: Send + Sync + 'static {
62 fn latest_consensus_parameters(
64 &self,
65 ) -> (ConsensusParametersVersion, Arc<ConsensusParameters>);
66}
67
68pub trait TxPoolPersistentStorage:
69 Clone + PredicateStorageRequirements + Send + Sync + 'static
70{
71 fn contains_tx(&self, tx_id: &TxId) -> StorageResult<bool>;
73
74 fn utxo(&self, utxo_id: &UtxoId) -> StorageResult<Option<CompressedCoin>>;
76
77 fn contract_exist(&self, contract_id: &ContractId) -> StorageResult<bool>;
79
80 fn blob_exist(&self, blob_id: &BlobId) -> StorageResult<bool>;
82
83 fn message(&self, message_id: &Nonce) -> StorageResult<Option<Message>>;
85}
86
87pub trait GasPriceProvider: Send + Sync + 'static {
89 fn next_gas_price(&self) -> GasPrice;
91}
92
93#[derive(Debug, Clone, Copy, PartialEq)]
94pub enum WasmValidityError {
95 NotEnabled,
97 NotFound,
99 NotValid,
101}
102
103pub trait WasmChecker: Send + Sync + 'static {
104 fn validate_uploaded_wasm(
105 &self,
106 wasm_root: &Bytes32,
107 ) -> Result<(), WasmValidityError>;
108}
109
110pub trait P2PSubscriptions {
111 type GossipedTransaction: NetworkData<Transaction>;
112
113 fn subscribe_new_peers(&self) -> BoxStream<PeerId>;
116
117 fn gossiped_transaction_events(&self) -> BoxStream<Self::GossipedTransaction>;
119}
120
121pub trait NotifyP2P {
122 fn broadcast_transaction(&self, transaction: Arc<Transaction>) -> anyhow::Result<()>;
124
125 fn notify_gossip_transaction_validity(
127 &self,
128 message_info: GossipsubMessageInfo,
129 validity: GossipsubMessageAcceptance,
130 ) -> anyhow::Result<()>;
131}
132
133#[async_trait::async_trait]
134pub trait P2PRequests: NotifyP2P + Send + Sync + 'static {
135 async fn request_tx_ids(&self, peer_id: PeerId) -> anyhow::Result<Vec<TxId>>;
137
138 async fn request_txs(
140 &self,
141 peer_id: PeerId,
142 tx_ids: Vec<TxId>,
143 ) -> anyhow::Result<Vec<Option<Transaction>>>;
144}