use fuel_core_services::stream::BoxStream;
use fuel_core_types::{
blockchain::{
SealedBlock,
SealedBlockHeader,
primitives::DaBlockHeight,
},
fuel_types::BlockHeight,
services::p2p::{
PeerId,
SourcePeer,
Transactions,
},
};
use std::ops::Range;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PeerReportReason {
SuccessfulBlockImport,
MissingBlockHeaders,
BadBlockHeader,
MissingTransactions,
InvalidTransactions,
}
#[async_trait::async_trait]
#[cfg_attr(any(test, feature = "benchmarking"), mockall::automock)]
pub trait PeerToPeerPort {
fn height_stream(&self) -> BoxStream<BlockHeight>;
async fn get_sealed_block_headers(
&self,
block_height_range: Range<u32>,
) -> anyhow::Result<SourcePeer<Option<Vec<SealedBlockHeader>>>>;
async fn get_transactions(
&self,
block_ids: Range<u32>,
) -> anyhow::Result<SourcePeer<Option<Vec<Transactions>>>>;
async fn get_transactions_from_peer(
&self,
block_ids: SourcePeer<Range<u32>>,
) -> anyhow::Result<Option<Vec<Transactions>>>;
fn report_peer(&self, peer: PeerId, report: PeerReportReason) -> anyhow::Result<()>;
}
#[cfg_attr(any(test, feature = "benchmarking"), mockall::automock)]
pub trait ConsensusPort {
fn check_sealed_header(&self, header: &SealedBlockHeader) -> anyhow::Result<bool>;
fn await_da_height(
&self,
da_height: &DaBlockHeight,
) -> impl core::future::Future<Output = anyhow::Result<()>> + Send;
}
#[cfg_attr(any(test, feature = "benchmarking"), mockall::automock)]
pub trait BlockImporterPort {
fn committed_height_stream(&self) -> BoxStream<BlockHeight>;
fn execute_and_commit(
&self,
block: SealedBlock,
) -> impl core::future::Future<Output = anyhow::Result<()>> + Send;
}