use fuel_core_services::stream::BoxStream;
use fuel_core_storage::{
transactional::Changes,
Result as StorageResult,
};
use fuel_core_types::{
blockchain::{
header::BlockHeader,
primitives::DaBlockHeight,
},
fuel_tx::{
Transaction,
TxId,
},
fuel_types::{
BlockHeight,
Bytes32,
},
services::{
block_importer::{
BlockImportInfo,
UncommittedResult as UncommittedImportResult,
},
executor::{
Error as ExecutorError,
UncommittedResult as UncommittedExecutionResult,
},
txpool::ArcPoolTx,
},
tai64::Tai64,
};
#[cfg_attr(test, mockall::automock)]
pub trait TransactionPool: Send + Sync {
fn pending_number(&self) -> usize;
fn total_consumable_gas(&self) -> u64;
fn remove_txs(&self, tx_ids: Vec<(TxId, ExecutorError)>) -> Vec<ArcPoolTx>;
fn transaction_status_events(&self) -> BoxStream<TxId>;
}
pub enum TransactionsSource {
TxPool,
SpecificTransactions(Vec<Transaction>),
}
#[cfg_attr(test, mockall::automock)]
#[async_trait::async_trait]
pub trait BlockProducer: Send + Sync {
async fn produce_and_execute_block(
&self,
height: BlockHeight,
block_time: Tai64,
source: TransactionsSource,
) -> anyhow::Result<UncommittedExecutionResult<Changes>>;
}
#[cfg_attr(test, mockall::automock)]
#[async_trait::async_trait]
pub trait BlockImporter: Send + Sync {
async fn commit_result(
&self,
result: UncommittedImportResult<Changes>,
) -> anyhow::Result<()>;
fn block_stream(&self) -> BoxStream<BlockImportInfo>;
}
#[cfg_attr(test, mockall::automock)]
pub trait Database {
fn block_header(&self, height: &BlockHeight) -> StorageResult<BlockHeader>;
fn block_header_merkle_root(&self, height: &BlockHeight) -> StorageResult<Bytes32>;
}
#[cfg_attr(test, mockall::automock)]
#[async_trait::async_trait]
pub trait RelayerPort {
async fn await_until_if_in_range(
&self,
da_height: &DaBlockHeight,
max_da_lag: &DaBlockHeight,
) -> anyhow::Result<()>;
}
#[cfg_attr(test, mockall::automock)]
pub trait P2pPort: Send + Sync + 'static {
fn reserved_peers_count(&self) -> BoxStream<usize>;
}
#[async_trait::async_trait]
#[cfg_attr(test, mockall::automock)]
pub trait SyncPort: Send + Sync {
async fn sync_with_peers(&mut self) -> anyhow::Result<()>;
}