diff --git a/binaries/cuprated/src/rpc/handler.rs b/binaries/cuprated/src/rpc/handler.rs index bb19bbd..1f73403 100644 --- a/binaries/cuprated/src/rpc/handler.rs +++ b/binaries/cuprated/src/rpc/handler.rs @@ -23,6 +23,7 @@ use crate::rpc::{bin, json, other}; /// TODO: use real type when public. #[derive(Clone)] +#[expect(clippy::large_enum_variant)] pub enum BlockchainManagerRequest { /// Pop blocks off the top of the blockchain. /// @@ -70,6 +71,18 @@ pub enum BlockchainManagerRequest { /// The address that will receive the coinbase reward. wallet_address: String, }, + + // // TODO: the below requests actually belong to the block downloader/syncer: + // // + // /// Get [`Span`] data. + // /// + // /// This is data that describes an active downloading process, + // /// if we are fully synced, this will return an empty [`Vec`]. + // Spans, + + // + /// Get the next [`PruningSeed`] needed for a pruned sync. + NextNeededPruningSeed, } /// TODO: use real type when public. @@ -110,6 +123,11 @@ pub enum BlockchainManagerResponse { /// The new top height. (TODO: is this correct?) height: usize, }, + + // /// Response to [`BlockchainManagerRequest::Spans`]. + // Spans(Vec>), + /// Response to [`BlockchainManagerRequest::NextNeededPruningSeed`]. + NextNeededPruningSeed(PruningSeed), } /// TODO: use real type when public. diff --git a/binaries/cuprated/src/rpc/request/address_book.rs b/binaries/cuprated/src/rpc/request/address_book.rs index 966a2de..771acb2 100644 --- a/binaries/cuprated/src/rpc/request/address_book.rs +++ b/binaries/cuprated/src/rpc/request/address_book.rs @@ -177,53 +177,3 @@ pub(crate) async fn get_bans( Ok(bans) } - -/// [`AddressBookRequest::Spans`] -pub(crate) async fn spans( - address_book: &mut impl AddressBook, -) -> Result, Error> { - let AddressBookResponse::Spans(vec) = address_book - .ready() - .await - .map_err(|e| anyhow!(e))? - .call(AddressBookRequest::Spans) - .await - .map_err(|e| anyhow!(e))? - else { - unreachable!(); - }; - - // FIXME: impl this map somewhere instead of inline. - let vec = vec - .into_iter() - .map(|span| Span { - connection_id: String::from(FIELD_NOT_SUPPORTED), - nblocks: span.nblocks, - rate: span.rate, - remote_address: span.remote_address.to_string(), - size: span.size, - speed: span.speed, - start_block_height: span.start_block_height, - }) - .collect(); - - Ok(vec) -} - -/// [`AddressBookRequest::NextNeededPruningSeed`] -pub(crate) async fn next_needed_pruning_seed( - address_book: &mut impl AddressBook, -) -> Result { - let AddressBookResponse::NextNeededPruningSeed(seed) = address_book - .ready() - .await - .map_err(|e| anyhow!(e))? - .call(AddressBookRequest::NextNeededPruningSeed) - .await - .map_err(|e| anyhow!(e))? - else { - unreachable!(); - }; - - Ok(seed) -} diff --git a/binaries/cuprated/src/rpc/request/blockchain_manager.rs b/binaries/cuprated/src/rpc/request/blockchain_manager.rs index 4ed0347..9522266 100644 --- a/binaries/cuprated/src/rpc/request/blockchain_manager.rs +++ b/binaries/cuprated/src/rpc/request/blockchain_manager.rs @@ -1,6 +1,8 @@ //! Functions for [`BlockchainManagerRequest`] & [`BlockchainManagerResponse`]. use anyhow::Error; +use cuprate_p2p_core::NetworkZone; +use cuprate_rpc_types::misc::Span; use monero_serai::block::Block; use tower::{Service, ServiceExt}; @@ -8,8 +10,9 @@ use cuprate_helper::cast::{u64_to_usize, usize_to_u64}; use cuprate_pruning::PruningSeed; use cuprate_types::{AddAuxPow, AuxPow, HardFork}; -use crate::rpc::handler::{ - BlockchainManagerHandle, BlockchainManagerRequest, BlockchainManagerResponse, +use crate::rpc::{ + constants::FIELD_NOT_SUPPORTED, + handler::{BlockchainManagerHandle, BlockchainManagerRequest, BlockchainManagerResponse}, }; /// [`BlockchainManagerRequest::PopBlocks`] @@ -144,27 +147,6 @@ pub(crate) async fn target_height( Ok(usize_to_u64(height)) } -/// [`BlockchainManagerRequest::AddAuxPow`] -pub(crate) async fn add_aux_pow( - blockchain_manager: &mut BlockchainManagerHandle, - block_template: Block, - aux_pow: Vec, -) -> Result { - let BlockchainManagerResponse::AddAuxPow(response) = blockchain_manager - .ready() - .await? - .call(BlockchainManagerRequest::AddAuxPow { - block_template, - aux_pow, - }) - .await? - else { - unreachable!(); - }; - - Ok(response) -} - /// [`BlockchainManagerRequest::GenerateBlocks`] pub(crate) async fn generate_blocks( blockchain_manager: &mut BlockchainManagerHandle, @@ -189,3 +171,51 @@ pub(crate) async fn generate_blocks( Ok((blocks, usize_to_u64(height))) } + +// [`BlockchainManagerRequest::Spans`] +pub(crate) async fn spans( + blockchain_manager: &mut BlockchainManagerHandle, +) -> Result, Error> { + // let BlockchainManagerResponse::Spans(vec) = blockchain_manager + // .ready() + // .await? + // .call(BlockchainManagerRequest::Spans) + // .await? + // else { + // unreachable!(); + // }; + + let vec: Vec> = todo!(); + + // FIXME: impl this map somewhere instead of inline. + let vec = vec + .into_iter() + .map(|span| Span { + connection_id: String::from(FIELD_NOT_SUPPORTED), + nblocks: span.nblocks, + rate: span.rate, + remote_address: span.remote_address.to_string(), + size: span.size, + speed: span.speed, + start_block_height: span.start_block_height, + }) + .collect(); + + Ok(vec) +} + +/// [`BlockchainManagerRequest::NextNeededPruningSeed`] +pub(crate) async fn next_needed_pruning_seed( + blockchain_manager: &mut BlockchainManagerHandle, +) -> Result { + let BlockchainManagerResponse::NextNeededPruningSeed(seed) = blockchain_manager + .ready() + .await? + .call(BlockchainManagerRequest::NextNeededPruningSeed) + .await? + else { + unreachable!(); + }; + + Ok(seed) +} diff --git a/p2p/address-book/src/book.rs b/p2p/address-book/src/book.rs index bc7109b..3e5269f 100644 --- a/p2p/address-book/src/book.rs +++ b/p2p/address-book/src/book.rs @@ -424,9 +424,7 @@ impl Service> for AddressBook { | AddressBookRequest::ConnectionCount | AddressBookRequest::SetBan(_) | AddressBookRequest::GetBans - | AddressBookRequest::ConnectionInfo - | AddressBookRequest::NextNeededPruningSeed - | AddressBookRequest::Spans => { + | AddressBookRequest::ConnectionInfo => { todo!("finish https://github.com/Cuprate/cuprate/pull/297") } }; diff --git a/p2p/p2p-core/src/client/handshaker/builder/dummy.rs b/p2p/p2p-core/src/client/handshaker/builder/dummy.rs index 4c039bb..48b3daf 100644 --- a/p2p/p2p-core/src/client/handshaker/builder/dummy.rs +++ b/p2p/p2p-core/src/client/handshaker/builder/dummy.rs @@ -112,9 +112,7 @@ impl Service> for DummyAddressBook { | AddressBookRequest::ConnectionCount | AddressBookRequest::SetBan(_) | AddressBookRequest::GetBans - | AddressBookRequest::ConnectionInfo - | AddressBookRequest::NextNeededPruningSeed - | AddressBookRequest::Spans => { + | AddressBookRequest::ConnectionInfo => { todo!("finish https://github.com/Cuprate/cuprate/pull/297") } })) diff --git a/p2p/p2p-core/src/services.rs b/p2p/p2p-core/src/services.rs index 481f024..6d1089c 100644 --- a/p2p/p2p-core/src/services.rs +++ b/p2p/p2p-core/src/services.rs @@ -6,7 +6,7 @@ use cuprate_wire::{CoreSyncData, PeerListEntryBase}; use crate::{ client::InternalPeerID, handles::ConnectionHandle, - types::{BanState, ConnectionInfo, SetBan, Span}, + types::{BanState, ConnectionInfo, SetBan}, NetZoneAddress, NetworkAddressIncorrectZone, NetworkZone, }; @@ -132,15 +132,6 @@ pub enum AddressBookRequest { /// Get the state of all bans. GetBans, - - /// Get [`Span`] data. - /// - /// This is data that describes an active downloading process, - /// if we are fully synced, this will return an empty [`Vec`]. - Spans, - - /// Get the next [`PruningSeed`] needed for a pruned sync. - NextNeededPruningSeed, } /// A response from the address book service. @@ -178,10 +169,4 @@ pub enum AddressBookResponse { /// Response to [`AddressBookRequest::GetBans`]. GetBans(Vec>), - - /// Response to [`AddressBookRequest::Spans`]. - Spans(Vec>), - - /// Response to [`AddressBookRequest::NextNeededPruningSeed`]. - NextNeededPruningSeed(PruningSeed), } diff --git a/p2p/p2p-core/src/types.rs b/p2p/p2p-core/src/types.rs index 3553422..083a703 100644 --- a/p2p/p2p-core/src/types.rs +++ b/p2p/p2p-core/src/types.rs @@ -181,7 +181,8 @@ pub struct ConnectionInfo { /// Used in RPC's `sync_info`. /// -/// Data within [`crate::services::AddressBookResponse::Spans`]. +// TODO: fix docs after +// Data within [`crate::services::AddressBookResponse::Spans`]. #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Span { pub nblocks: u64,