doc updates

This commit is contained in:
Boog900 2024-11-18 16:04:00 +00:00
parent efa092572a
commit 49db43180f
No known key found for this signature in database
GPG key ID: 42AB1287CB0041C2
4 changed files with 45 additions and 31 deletions

View file

@ -1,15 +1,17 @@
//! P2P //! P2P
//! //!
//! Will handle initiating the P2P and contains a protocol request handler. //! Will handle initiating the P2P and contains a protocol request handler.
use crate::txpool::IncomingTxHandler; use futures::{FutureExt, TryFutureExt};
use tokio::sync::oneshot;
use tower::ServiceExt;
use cuprate_blockchain::service::BlockchainReadHandle; use cuprate_blockchain::service::BlockchainReadHandle;
use cuprate_consensus::BlockChainContextService; use cuprate_consensus::BlockChainContextService;
use cuprate_p2p::{NetworkInterface, P2PConfig}; use cuprate_p2p::{NetworkInterface, P2PConfig};
use cuprate_p2p_core::ClearNet; use cuprate_p2p_core::ClearNet;
use cuprate_txpool::service::TxpoolReadHandle; use cuprate_txpool::service::TxpoolReadHandle;
use futures::{FutureExt, TryFutureExt};
use tokio::sync::oneshot; use crate::txpool::IncomingTxHandler;
use tower::ServiceExt;
mod core_sync_service; mod core_sync_service;
mod network_address; mod network_address;
@ -17,6 +19,10 @@ pub mod request_handler;
pub use network_address::CrossNetworkInternalPeerId; pub use network_address::CrossNetworkInternalPeerId;
/// Starts the P2P clearnet network, returning a [`NetworkInterface`] to interact with it.
///
/// A [`oneshot::Sender`] is also returned to provide the [`IncomingTxHandler`], until this is provided network
/// handshakes can not be completed.
pub async fn start_clearnet_p2p( pub async fn start_clearnet_p2p(
blockchain_read_handle: BlockchainReadHandle, blockchain_read_handle: BlockchainReadHandle,
blockchain_context_service: BlockChainContextService, blockchain_context_service: BlockChainContextService,

View file

@ -1,13 +1,16 @@
use bytes::Bytes;
use futures::future::Shared;
use futures::{future::BoxFuture, FutureExt};
use monero_serai::{block::Block, transaction::Transaction};
use std::hash::Hash;
use std::{ use std::{
collections::HashSet, collections::HashSet,
future::{ready, Ready}, future::{ready, Ready},
hash::Hash,
task::{Context, Poll}, task::{Context, Poll},
}; };
use bytes::Bytes;
use futures::{
future::{BoxFuture, Shared},
FutureExt,
};
use monero_serai::{block::Block, transaction::Transaction};
use tokio::sync::{broadcast, oneshot, watch}; use tokio::sync::{broadcast, oneshot, watch};
use tokio_stream::wrappers::WatchStream; use tokio_stream::wrappers::WatchStream;
use tower::{Service, ServiceExt}; use tower::{Service, ServiceExt};
@ -28,9 +31,9 @@ use cuprate_helper::{
use cuprate_p2p::constants::{ use cuprate_p2p::constants::{
MAX_BLOCKS_IDS_IN_CHAIN_ENTRY, MAX_BLOCK_BATCH_LEN, MAX_TRANSACTION_BLOB_SIZE, MEDIUM_BAN, MAX_BLOCKS_IDS_IN_CHAIN_ENTRY, MAX_BLOCK_BATCH_LEN, MAX_TRANSACTION_BLOB_SIZE, MEDIUM_BAN,
}; };
use cuprate_p2p_core::client::InternalPeerID;
use cuprate_p2p_core::{ use cuprate_p2p_core::{
client::PeerInformation, NetZoneAddress, NetworkZone, ProtocolRequest, ProtocolResponse, client::{InternalPeerID, PeerInformation},
NetZoneAddress, NetworkZone, ProtocolRequest, ProtocolResponse,
}; };
use cuprate_txpool::service::TxpoolReadHandle; use cuprate_txpool::service::TxpoolReadHandle;
use cuprate_types::{ use cuprate_types::{
@ -42,30 +45,32 @@ use cuprate_wire::protocol::{
GetObjectsResponse, NewFluffyBlock, NewTransactions, GetObjectsResponse, NewFluffyBlock, NewTransactions,
}; };
use crate::blockchain::interface::{self as blockchain_interface, IncomingBlockError}; use crate::{
use crate::constants::PANIC_CRITICAL_SERVICE_ERROR; blockchain::interface::{self as blockchain_interface, IncomingBlockError},
use crate::p2p::CrossNetworkInternalPeerId; constants::PANIC_CRITICAL_SERVICE_ERROR,
use crate::txpool::{IncomingTxHandler, IncomingTxs}; p2p::CrossNetworkInternalPeerId,
txpool::{IncomingTxError, IncomingTxHandler, IncomingTxs},
};
/// The P2P protocol request handler [`MakeService`](tower::MakeService). /// The P2P protocol request handler [`MakeService`](tower::MakeService).
#[derive(Clone)] #[derive(Clone)]
pub struct P2pProtocolRequestHandlerMaker { pub struct P2pProtocolRequestHandlerMaker {
/// The [`BlockchainReadHandle`]
pub blockchain_read_handle: BlockchainReadHandle, pub blockchain_read_handle: BlockchainReadHandle,
pub blockchain_context_service: BlockChainContextService, pub blockchain_context_service: BlockChainContextService,
/// The [`TxpoolReadHandle`].
pub txpool_read_handle: TxpoolReadHandle, pub txpool_read_handle: TxpoolReadHandle,
/// The [`IncomingTxHandler`], wrapped in an [`Option`] as there is a cyclic reference between [`P2pProtocolRequestHandlerMaker`]
/// and the [`IncomingTxHandler`].
pub incoming_tx_handler: Option<IncomingTxHandler>, pub incoming_tx_handler: Option<IncomingTxHandler>,
/// A [`Future`](std::future::Future) that produces the [`IncomingTxHandler`].
pub incoming_tx_handler_fut: Shared<oneshot::Receiver<IncomingTxHandler>>, pub incoming_tx_handler_fut: Shared<oneshot::Receiver<IncomingTxHandler>>,
} }
impl<A: NetZoneAddress> Service<PeerInformation<A>> for P2pProtocolRequestHandlerMaker impl<A: NetZoneAddress> Service<PeerInformation<A>> for P2pProtocolRequestHandlerMaker
where where
A: NetZoneAddress,
InternalPeerID<A>: Into<CrossNetworkInternalPeerId>, InternalPeerID<A>: Into<CrossNetworkInternalPeerId>,
{ {
type Response = P2pProtocolRequestHandler<A>; type Response = P2pProtocolRequestHandler<A>;
@ -109,13 +114,12 @@ where
/// The P2P protocol request handler. /// The P2P protocol request handler.
#[derive(Clone)] #[derive(Clone)]
pub struct P2pProtocolRequestHandler<N: NetZoneAddress> { pub struct P2pProtocolRequestHandler<N: NetZoneAddress> {
/// The [`PeerInformation`] for this peer.
peer_information: PeerInformation<N>, peer_information: PeerInformation<N>,
/// The [`BlockchainReadHandle`].
blockchain_read_handle: BlockchainReadHandle, blockchain_read_handle: BlockchainReadHandle,
blockchain_context_service: BlockChainContextService, blockchain_context_service: BlockChainContextService,
/// The [`TxpoolReadHandle`].
txpool_read_handle: TxpoolReadHandle, txpool_read_handle: TxpoolReadHandle,
incoming_tx_handler: IncomingTxHandler, incoming_tx_handler: IncomingTxHandler,
@ -123,7 +127,6 @@ pub struct P2pProtocolRequestHandler<N: NetZoneAddress> {
impl<A: NetZoneAddress> Service<ProtocolRequest> for P2pProtocolRequestHandler<A> impl<A: NetZoneAddress> Service<ProtocolRequest> for P2pProtocolRequestHandler<A>
where where
A: NetZoneAddress,
InternalPeerID<A>: Into<CrossNetworkInternalPeerId>, InternalPeerID<A>: Into<CrossNetworkInternalPeerId>,
{ {
type Response = ProtocolResponse; type Response = ProtocolResponse;
@ -163,7 +166,7 @@ where
self.incoming_tx_handler.clone(), self.incoming_tx_handler.clone(),
) )
.boxed(), .boxed(),
ProtocolRequest::GetTxPoolCompliment(_) => ready(Ok(ProtocolResponse::NA)).boxed(), // TODO: tx-pool ProtocolRequest::GetTxPoolCompliment(_) => ready(Ok(ProtocolResponse::NA)).boxed(), // TODO: should we support this?
} }
} }
} }
@ -303,6 +306,7 @@ async fn new_fluffy_block<A: NetZoneAddress>(
mut blockchain_read_handle: BlockchainReadHandle, mut blockchain_read_handle: BlockchainReadHandle,
mut txpool_read_handle: TxpoolReadHandle, mut txpool_read_handle: TxpoolReadHandle,
) -> anyhow::Result<ProtocolResponse> { ) -> anyhow::Result<ProtocolResponse> {
// TODO: check context service here and ignore the block?
let current_blockchain_height = request.current_blockchain_height; let current_blockchain_height = request.current_blockchain_height;
peer_information peer_information
@ -324,7 +328,6 @@ async fn new_fluffy_block<A: NetZoneAddress>(
.into_iter() .into_iter()
.map(|tx_blob| { .map(|tx_blob| {
if tx_blob.len() > MAX_TRANSACTION_BLOB_SIZE { if tx_blob.len() > MAX_TRANSACTION_BLOB_SIZE {
peer_information.handle.ban_peer(MEDIUM_BAN);
anyhow::bail!("Peer sent a transaction over the size limit."); anyhow::bail!("Peer sent a transaction over the size limit.");
} }

View file

@ -13,9 +13,9 @@ use monero_serai::block::Block;
use crate::{ use crate::{
types::{ types::{
Chain, ExtendedBlockHeader, MissingTxsInBlock, OutputOnChain, VerifiedBlockInformation, Chain, ExtendedBlockHeader, MissingTxsInBlock, OutputOnChain, VerifiedBlockInformation,
}, ChainInfo, },
AltBlockInformation, BlockCompleteEntry, ChainId, CoinbaseTxSum, OutputHistogramEntry, AltBlockInformation, BlockCompleteEntry, ChainId, ChainInfo, CoinbaseTxSum,
OutputHistogramInput, OutputHistogramEntry, OutputHistogramInput,
}; };
//---------------------------------------------------------------------------------------------------- ReadRequest //---------------------------------------------------------------------------------------------------- ReadRequest
@ -132,7 +132,9 @@ pub enum BlockchainReadRequest {
AltBlocksInChain(ChainId), AltBlocksInChain(ChainId),
/// Get a [`Block`] by its height. /// Get a [`Block`] by its height.
Block { height: usize }, Block {
height: usize,
},
/// Get a [`Block`] by its hash. /// Get a [`Block`] by its hash.
BlockByHash([u8; 32]), BlockByHash([u8; 32]),
@ -152,7 +154,10 @@ pub enum BlockchainReadRequest {
/// `N` last blocks starting at particular height. /// `N` last blocks starting at particular height.
/// ///
/// TODO: document fields after impl. /// TODO: document fields after impl.
CoinbaseTxSum { height: usize, count: u64 }, CoinbaseTxSum {
height: usize,
count: u64,
},
/// Get information on all alternative chains. /// Get information on all alternative chains.
AltChains, AltChains,

View file

@ -26,8 +26,8 @@ pub use transaction_verification_data::{
pub use types::{ pub use types::{
AddAuxPow, AltBlockInformation, AuxPow, Chain, ChainId, ChainInfo, CoinbaseTxSum, AddAuxPow, AltBlockInformation, AuxPow, Chain, ChainId, ChainInfo, CoinbaseTxSum,
ExtendedBlockHeader, FeeEstimate, HardForkInfo, MinerData, MinerDataTxBacklogEntry, ExtendedBlockHeader, FeeEstimate, HardForkInfo, MinerData, MinerDataTxBacklogEntry,
OutputHistogramEntry, OutputHistogramInput, OutputOnChain, VerifiedBlockInformation, MissingTxsInBlock, OutputHistogramEntry, OutputHistogramInput, OutputOnChain,
VerifiedTransactionInformation, VerifiedBlockInformation, VerifiedTransactionInformation,
}; };
//---------------------------------------------------------------------------------------------------- Feature-gated //---------------------------------------------------------------------------------------------------- Feature-gated