mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-22 19:49:33 +00:00
move Spans
and NextNeededPruningSeed
This commit is contained in:
parent
9482753304
commit
58a91c4e65
7 changed files with 76 additions and 96 deletions
|
@ -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:
|
||||
// // <https://github.com/Cuprate/cuprate/pull/320#discussion_r1811089758>
|
||||
// /// 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<Span<Z::Addr>>),
|
||||
/// Response to [`BlockchainManagerRequest::NextNeededPruningSeed`].
|
||||
NextNeededPruningSeed(PruningSeed),
|
||||
}
|
||||
|
||||
/// TODO: use real type when public.
|
||||
|
|
|
@ -177,53 +177,3 @@ pub(crate) async fn get_bans<Z: NetworkZone>(
|
|||
|
||||
Ok(bans)
|
||||
}
|
||||
|
||||
/// [`AddressBookRequest::Spans`]
|
||||
pub(crate) async fn spans<Z: NetworkZone>(
|
||||
address_book: &mut impl AddressBook<Z>,
|
||||
) -> Result<Vec<Span>, 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<Z: NetworkZone>(
|
||||
address_book: &mut impl AddressBook<Z>,
|
||||
) -> Result<PruningSeed, Error> {
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -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<AuxPow>,
|
||||
) -> Result<AddAuxPow, Error> {
|
||||
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<Z: NetworkZone>(
|
||||
blockchain_manager: &mut BlockchainManagerHandle,
|
||||
) -> Result<Vec<Span>, Error> {
|
||||
// let BlockchainManagerResponse::Spans(vec) = blockchain_manager
|
||||
// .ready()
|
||||
// .await?
|
||||
// .call(BlockchainManagerRequest::Spans)
|
||||
// .await?
|
||||
// else {
|
||||
// unreachable!();
|
||||
// };
|
||||
|
||||
let vec: Vec<cuprate_p2p_core::types::Span<Z::Addr>> = 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<PruningSeed, Error> {
|
||||
let BlockchainManagerResponse::NextNeededPruningSeed(seed) = blockchain_manager
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockchainManagerRequest::NextNeededPruningSeed)
|
||||
.await?
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
Ok(seed)
|
||||
}
|
||||
|
|
|
@ -424,9 +424,7 @@ impl<Z: BorshNetworkZone> Service<AddressBookRequest<Z>> for AddressBook<Z> {
|
|||
| AddressBookRequest::ConnectionCount
|
||||
| AddressBookRequest::SetBan(_)
|
||||
| AddressBookRequest::GetBans
|
||||
| AddressBookRequest::ConnectionInfo
|
||||
| AddressBookRequest::NextNeededPruningSeed
|
||||
| AddressBookRequest::Spans => {
|
||||
| AddressBookRequest::ConnectionInfo => {
|
||||
todo!("finish https://github.com/Cuprate/cuprate/pull/297")
|
||||
}
|
||||
};
|
||||
|
|
|
@ -112,9 +112,7 @@ impl<N: NetworkZone> Service<AddressBookRequest<N>> 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")
|
||||
}
|
||||
}))
|
||||
|
|
|
@ -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<Z: NetworkZone> {
|
|||
|
||||
/// 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<Z: NetworkZone> {
|
|||
|
||||
/// Response to [`AddressBookRequest::GetBans`].
|
||||
GetBans(Vec<BanState<Z::Addr>>),
|
||||
|
||||
/// Response to [`AddressBookRequest::Spans`].
|
||||
Spans(Vec<Span<Z::Addr>>),
|
||||
|
||||
/// Response to [`AddressBookRequest::NextNeededPruningSeed`].
|
||||
NextNeededPruningSeed(PruningSeed),
|
||||
}
|
||||
|
|
|
@ -181,7 +181,8 @@ pub struct ConnectionInfo<A: NetZoneAddress> {
|
|||
|
||||
/// Used in RPC's `sync_info`.
|
||||
///
|
||||
/// Data within [`crate::services::AddressBookResponse::Spans`].
|
||||
// TODO: fix docs after <https://github.com/Cuprate/cuprate/pull/320#discussion_r1811089758>
|
||||
// Data within [`crate::services::AddressBookResponse::Spans`].
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct Span<A: NetZoneAddress> {
|
||||
pub nblocks: u64,
|
||||
|
|
Loading…
Reference in a new issue