mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-23 03:59:37 +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.
|
/// TODO: use real type when public.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
#[expect(clippy::large_enum_variant)]
|
||||||
pub enum BlockchainManagerRequest {
|
pub enum BlockchainManagerRequest {
|
||||||
/// Pop blocks off the top of the blockchain.
|
/// Pop blocks off the top of the blockchain.
|
||||||
///
|
///
|
||||||
|
@ -70,6 +71,18 @@ pub enum BlockchainManagerRequest {
|
||||||
/// The address that will receive the coinbase reward.
|
/// The address that will receive the coinbase reward.
|
||||||
wallet_address: String,
|
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.
|
/// TODO: use real type when public.
|
||||||
|
@ -110,6 +123,11 @@ pub enum BlockchainManagerResponse {
|
||||||
/// The new top height. (TODO: is this correct?)
|
/// The new top height. (TODO: is this correct?)
|
||||||
height: usize,
|
height: usize,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// /// Response to [`BlockchainManagerRequest::Spans`].
|
||||||
|
// Spans(Vec<Span<Z::Addr>>),
|
||||||
|
/// Response to [`BlockchainManagerRequest::NextNeededPruningSeed`].
|
||||||
|
NextNeededPruningSeed(PruningSeed),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: use real type when public.
|
/// TODO: use real type when public.
|
||||||
|
|
|
@ -177,53 +177,3 @@ pub(crate) async fn get_bans<Z: NetworkZone>(
|
||||||
|
|
||||||
Ok(bans)
|
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`].
|
//! Functions for [`BlockchainManagerRequest`] & [`BlockchainManagerResponse`].
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
|
use cuprate_p2p_core::NetworkZone;
|
||||||
|
use cuprate_rpc_types::misc::Span;
|
||||||
use monero_serai::block::Block;
|
use monero_serai::block::Block;
|
||||||
use tower::{Service, ServiceExt};
|
use tower::{Service, ServiceExt};
|
||||||
|
|
||||||
|
@ -8,8 +10,9 @@ use cuprate_helper::cast::{u64_to_usize, usize_to_u64};
|
||||||
use cuprate_pruning::PruningSeed;
|
use cuprate_pruning::PruningSeed;
|
||||||
use cuprate_types::{AddAuxPow, AuxPow, HardFork};
|
use cuprate_types::{AddAuxPow, AuxPow, HardFork};
|
||||||
|
|
||||||
use crate::rpc::handler::{
|
use crate::rpc::{
|
||||||
BlockchainManagerHandle, BlockchainManagerRequest, BlockchainManagerResponse,
|
constants::FIELD_NOT_SUPPORTED,
|
||||||
|
handler::{BlockchainManagerHandle, BlockchainManagerRequest, BlockchainManagerResponse},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// [`BlockchainManagerRequest::PopBlocks`]
|
/// [`BlockchainManagerRequest::PopBlocks`]
|
||||||
|
@ -144,27 +147,6 @@ pub(crate) async fn target_height(
|
||||||
Ok(usize_to_u64(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`]
|
/// [`BlockchainManagerRequest::GenerateBlocks`]
|
||||||
pub(crate) async fn generate_blocks(
|
pub(crate) async fn generate_blocks(
|
||||||
blockchain_manager: &mut BlockchainManagerHandle,
|
blockchain_manager: &mut BlockchainManagerHandle,
|
||||||
|
@ -189,3 +171,51 @@ pub(crate) async fn generate_blocks(
|
||||||
|
|
||||||
Ok((blocks, usize_to_u64(height)))
|
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::ConnectionCount
|
||||||
| AddressBookRequest::SetBan(_)
|
| AddressBookRequest::SetBan(_)
|
||||||
| AddressBookRequest::GetBans
|
| AddressBookRequest::GetBans
|
||||||
| AddressBookRequest::ConnectionInfo
|
| AddressBookRequest::ConnectionInfo => {
|
||||||
| AddressBookRequest::NextNeededPruningSeed
|
|
||||||
| AddressBookRequest::Spans => {
|
|
||||||
todo!("finish https://github.com/Cuprate/cuprate/pull/297")
|
todo!("finish https://github.com/Cuprate/cuprate/pull/297")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -112,9 +112,7 @@ impl<N: NetworkZone> Service<AddressBookRequest<N>> for DummyAddressBook {
|
||||||
| AddressBookRequest::ConnectionCount
|
| AddressBookRequest::ConnectionCount
|
||||||
| AddressBookRequest::SetBan(_)
|
| AddressBookRequest::SetBan(_)
|
||||||
| AddressBookRequest::GetBans
|
| AddressBookRequest::GetBans
|
||||||
| AddressBookRequest::ConnectionInfo
|
| AddressBookRequest::ConnectionInfo => {
|
||||||
| AddressBookRequest::NextNeededPruningSeed
|
|
||||||
| AddressBookRequest::Spans => {
|
|
||||||
todo!("finish https://github.com/Cuprate/cuprate/pull/297")
|
todo!("finish https://github.com/Cuprate/cuprate/pull/297")
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -6,7 +6,7 @@ use cuprate_wire::{CoreSyncData, PeerListEntryBase};
|
||||||
use crate::{
|
use crate::{
|
||||||
client::InternalPeerID,
|
client::InternalPeerID,
|
||||||
handles::ConnectionHandle,
|
handles::ConnectionHandle,
|
||||||
types::{BanState, ConnectionInfo, SetBan, Span},
|
types::{BanState, ConnectionInfo, SetBan},
|
||||||
NetZoneAddress, NetworkAddressIncorrectZone, NetworkZone,
|
NetZoneAddress, NetworkAddressIncorrectZone, NetworkZone,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -132,15 +132,6 @@ pub enum AddressBookRequest<Z: NetworkZone> {
|
||||||
|
|
||||||
/// Get the state of all bans.
|
/// Get the state of all bans.
|
||||||
GetBans,
|
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.
|
/// A response from the address book service.
|
||||||
|
@ -178,10 +169,4 @@ pub enum AddressBookResponse<Z: NetworkZone> {
|
||||||
|
|
||||||
/// Response to [`AddressBookRequest::GetBans`].
|
/// Response to [`AddressBookRequest::GetBans`].
|
||||||
GetBans(Vec<BanState<Z::Addr>>),
|
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`.
|
/// 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)]
|
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct Span<A: NetZoneAddress> {
|
pub struct Span<A: NetZoneAddress> {
|
||||||
pub nblocks: u64,
|
pub nblocks: u64,
|
||||||
|
|
Loading…
Reference in a new issue