use fuel_core_services::stream::BoxStream;
use fuel_core_types::{
blockchain::{
primitives::DaBlockHeight,
SealedBlock,
SealedBlockHeader,
},
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,
}
#[cfg_attr(any(test, feature = "benchmarking"), mockall::automock)]
#[async_trait::async_trait]
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: 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)]
#[async_trait::async_trait]
pub trait ConsensusPort {
fn check_sealed_header(&self, header: &SealedBlockHeader) -> anyhow::Result<bool>;
async fn await_da_height(&self, da_height: &DaBlockHeight) -> anyhow::Result<()>;
}
#[cfg_attr(any(test, feature = "benchmarking"), mockall::automock)]
#[async_trait::async_trait]
pub trait BlockImporterPort {
fn committed_height_stream(&self) -> BoxStream<BlockHeight>;
async fn execute_and_commit(&self, block: SealedBlock) -> anyhow::Result<()>;
}