init block downloader

This commit is contained in:
Boog900 2024-05-23 01:34:08 +01:00
parent 3365af9af7
commit 5a0d4a4e94
No known key found for this signature in database
GPG key ID: 42AB1287CB0041C2
4 changed files with 60 additions and 0 deletions

11
Cargo.lock generated
View file

@ -98,6 +98,16 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "async-buffer"
version = "0.1.0"
dependencies = [
"futures",
"pin-project",
"thiserror",
"tokio",
]
[[package]]
name = "async-lock"
version = "3.3.0"
@ -580,6 +590,7 @@ dependencies = [
name = "cuprate-p2p"
version = "0.1.0"
dependencies = [
"async-buffer",
"bytes",
"cuprate-helper",
"cuprate-test-utils",

View file

@ -12,6 +12,7 @@ monero-p2p = { path = "../monero-p2p", features = ["borsh"] }
monero-address-book = { path = "../address-book" }
monero-pruning = { path = "../../pruning" }
cuprate-helper = { path = "../../helper", features = ["asynch"] }
async-buffer = { path = "../async-buffer" }
monero-serai = { workspace = true, features = ["std"] }

View file

@ -0,0 +1,47 @@
//! # Block Downloader
//!
use std::sync::Arc;
use monero_serai::{block::Block, transaction::Transaction};
use async_buffer::BufferStream;
use monero_p2p::{handles::ConnectionHandle, NetworkZone};
use crate::client_pool::ClientPool;
/// A downloaded batch of blocks.
pub struct BlockBatch {
/// The blocks.
blocks: (Block, Vec<Transaction>),
/// The peer that gave us this block.
peer_handle: ConnectionHandle,
}
/// The block downloader config.
#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq)]
pub struct BlockDownloaderConfig {
/// The size of the buffer between the block downloader and the place which
/// is consuming the downloaded blocks.
buffer_size: usize,
/// The size of the in progress queue at which we stop requesting more blocks.
in_progress_queue_size: usize,
}
/// # Block Downloader
///
/// This function starts the block downloader and returns a [`BufferStream`] that will produce
/// a sequential stream of blocks.
///
/// The block downloader will pick the longest chain and will follow it for as long as possible,
/// the blocks given from the [`BufferStream`] will be in order.
///
/// The block downloader may fail before the whole chain is downloaded. If this is the case you are
/// free to call this function again, so it can start the search again.
pub fn download_blocks<N: NetworkZone, S>(
client_pool: Arc<ClientPool<N>>,
peer_sync_svc: S,
config: BlockDownloaderConfig,
) -> BufferStream<BlockBatch> {
todo!()
}

View file

@ -14,6 +14,7 @@ use tracing::{instrument, Instrument, Span};
use monero_p2p::{CoreSyncSvc, NetworkZone, PeerRequestHandler};
mod block_downloader;
mod broadcast;
mod client_pool;
pub mod config;