1use fuel_core_services::stream::BoxStream;
4use fuel_core_types::{
5 blockchain::{
6 primitives::DaBlockHeight,
7 SealedBlock,
8 SealedBlockHeader,
9 },
10 fuel_types::BlockHeight,
11 services::p2p::{
12 PeerId,
13 SourcePeer,
14 Transactions,
15 },
16};
17use std::ops::Range;
18
19#[derive(Clone, Copy, Debug, PartialEq, Eq)]
21pub enum PeerReportReason {
22 SuccessfulBlockImport,
25
26 MissingBlockHeaders,
29 BadBlockHeader,
31 MissingTransactions,
33 InvalidTransactions,
35}
36
37#[async_trait::async_trait]
38#[cfg_attr(any(test, feature = "benchmarking"), mockall::automock)]
39pub trait PeerToPeerPort {
41 fn height_stream(&self) -> BoxStream<BlockHeight>;
43
44 async fn get_sealed_block_headers(
46 &self,
47 block_height_range: Range<u32>,
48 ) -> anyhow::Result<SourcePeer<Option<Vec<SealedBlockHeader>>>>;
49
50 async fn get_transactions(
52 &self,
53 block_ids: Range<u32>,
54 ) -> anyhow::Result<SourcePeer<Option<Vec<Transactions>>>>;
55
56 async fn get_transactions_from_peer(
59 &self,
60 block_ids: SourcePeer<Range<u32>>,
61 ) -> anyhow::Result<Option<Vec<Transactions>>>;
62
63 fn report_peer(&self, peer: PeerId, report: PeerReportReason) -> anyhow::Result<()>;
65}
66
67#[cfg_attr(any(test, feature = "benchmarking"), mockall::automock)]
68pub trait ConsensusPort {
70 fn check_sealed_header(&self, header: &SealedBlockHeader) -> anyhow::Result<bool>;
72 fn await_da_height(
74 &self,
75 da_height: &DaBlockHeight,
76 ) -> impl core::future::Future<Output = anyhow::Result<()>> + Send;
77}
78
79#[cfg_attr(any(test, feature = "benchmarking"), mockall::automock)]
80pub trait BlockImporterPort {
82 fn committed_height_stream(&self) -> BoxStream<BlockHeight>;
84
85 fn execute_and_commit(
88 &self,
89 block: SealedBlock,
90 ) -> impl core::future::Future<Output = anyhow::Result<()>> + Send;
91}