mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-23 12:09:57 +00:00
blockchain manager msg types
This commit is contained in:
parent
a1b3bdabef
commit
cf3095446e
6 changed files with 212 additions and 117 deletions
|
@ -3,13 +3,11 @@
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use futures::{channel::oneshot::channel, future::BoxFuture};
|
use futures::future::BoxFuture;
|
||||||
use serde::{Deserialize, Serialize};
|
use monero_serai::block::Block;
|
||||||
use tower::Service;
|
use tower::Service;
|
||||||
|
|
||||||
use cuprate_blockchain::service::{BlockchainReadHandle, BlockchainWriteHandle};
|
use cuprate_blockchain::service::{BlockchainReadHandle, BlockchainWriteHandle};
|
||||||
use cuprate_helper::asynch::InfallibleOneshotReceiver;
|
|
||||||
use cuprate_json_rpc::Id;
|
|
||||||
use cuprate_rpc_interface::RpcHandler;
|
use cuprate_rpc_interface::RpcHandler;
|
||||||
use cuprate_rpc_types::{
|
use cuprate_rpc_types::{
|
||||||
bin::{BinRequest, BinResponse},
|
bin::{BinRequest, BinResponse},
|
||||||
|
@ -20,6 +18,82 @@ use cuprate_txpool::service::{TxpoolReadHandle, TxpoolWriteHandle};
|
||||||
|
|
||||||
use crate::rpc::{bin, json, other};
|
use crate::rpc::{bin, json, other};
|
||||||
|
|
||||||
|
/// TODO: use real type when public.
|
||||||
|
#[derive(Clone)]
|
||||||
|
#[expect(clippy::large_enum_variant)]
|
||||||
|
pub enum BlockchainManagerRequest {
|
||||||
|
/// Input is the amount of blocks to pop.
|
||||||
|
PopBlocks { amount: usize },
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
Prune,
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
Pruned,
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
RelayBlock(Block),
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
Syncing,
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
Synced,
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
Target,
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
TargetHeight,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO: use real type when public.
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum BlockchainManagerResponse {
|
||||||
|
/// TODO
|
||||||
|
///
|
||||||
|
/// Response to:
|
||||||
|
/// - [`BlockchainManagerRequest::Prune`]
|
||||||
|
/// - [`BlockchainManagerRequest::RelayBlock`]
|
||||||
|
Ok,
|
||||||
|
|
||||||
|
/// Response to [`BlockchainManagerRequest::PopBlocks`]
|
||||||
|
///
|
||||||
|
/// TODO
|
||||||
|
PopBlocks { new_height: usize },
|
||||||
|
|
||||||
|
/// Response to [`BlockchainManagerRequest::Pruned`]
|
||||||
|
///
|
||||||
|
/// TODO
|
||||||
|
Pruned(bool),
|
||||||
|
|
||||||
|
/// Response to [`BlockchainManagerRequest::Syncing`]
|
||||||
|
///
|
||||||
|
/// TODO
|
||||||
|
Syncing(bool),
|
||||||
|
|
||||||
|
/// Response to [`BlockchainManagerRequest::Synced`]
|
||||||
|
///
|
||||||
|
/// TODO
|
||||||
|
Synced(bool),
|
||||||
|
|
||||||
|
/// Response to [`BlockchainManagerRequest::Target`]
|
||||||
|
///
|
||||||
|
/// TODO
|
||||||
|
Target { height: usize },
|
||||||
|
|
||||||
|
/// Response to [`BlockchainManagerRequest::TargetHeight`]
|
||||||
|
///
|
||||||
|
/// TODO
|
||||||
|
TargetHeight { height: usize },
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO: use real type when public.
|
||||||
|
pub type BlockchainManagerHandle = cuprate_database_service::DatabaseReadService<
|
||||||
|
BlockchainManagerRequest,
|
||||||
|
BlockchainManagerResponse,
|
||||||
|
>;
|
||||||
|
|
||||||
/// TODO
|
/// TODO
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CupratedRpcHandler {
|
pub struct CupratedRpcHandler {
|
||||||
|
@ -43,6 +117,9 @@ pub struct CupratedRpcHandlerState {
|
||||||
/// Write handle to the blockchain database.
|
/// Write handle to the blockchain database.
|
||||||
pub blockchain_write: BlockchainWriteHandle,
|
pub blockchain_write: BlockchainWriteHandle,
|
||||||
|
|
||||||
|
/// Handle to the blockchain manager.
|
||||||
|
pub blockchain_manager: BlockchainManagerHandle,
|
||||||
|
|
||||||
/// Read handle to the transaction pool database.
|
/// Read handle to the transaction pool database.
|
||||||
pub txpool_read: TxpoolReadHandle,
|
pub txpool_read: TxpoolReadHandle,
|
||||||
|
|
||||||
|
|
|
@ -1,31 +1,15 @@
|
||||||
//! Functions for TODO: doc enum message.
|
//! Functions for TODO: doc enum message.
|
||||||
|
|
||||||
use std::{
|
use std::convert::Infallible;
|
||||||
collections::{HashMap, HashSet},
|
|
||||||
convert::Infallible,
|
|
||||||
sync::Arc,
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::Error;
|
||||||
use futures::StreamExt;
|
use tower::ServiceExt;
|
||||||
use monero_serai::block::Block;
|
|
||||||
use tower::{Service, ServiceExt};
|
|
||||||
|
|
||||||
use cuprate_helper::{
|
use cuprate_helper::cast::usize_to_u64;
|
||||||
cast::{u64_to_usize, usize_to_u64},
|
|
||||||
map::split_u128_into_low_high_bits,
|
|
||||||
};
|
|
||||||
use cuprate_p2p_core::{
|
use cuprate_p2p_core::{
|
||||||
client::handshaker::builder::DummyAddressBook,
|
|
||||||
services::{AddressBookRequest, AddressBookResponse},
|
services::{AddressBookRequest, AddressBookResponse},
|
||||||
AddressBook, ClearNet, NetworkZone,
|
AddressBook, NetworkZone,
|
||||||
};
|
};
|
||||||
use cuprate_types::{
|
|
||||||
blockchain::{BlockchainReadRequest, BlockchainWriteRequest},
|
|
||||||
Chain, ExtendedBlockHeader, HardFork, OutputOnChain, VerifiedBlockInformation,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::rpc::{CupratedRpcHandler, CupratedRpcHandlerState};
|
|
||||||
|
|
||||||
/// [`AddressBookRequest::PeerlistSize`]
|
/// [`AddressBookRequest::PeerlistSize`]
|
||||||
pub(super) async fn peerlist_size<Z: NetworkZone>(
|
pub(super) async fn peerlist_size<Z: NetworkZone>(
|
||||||
|
|
|
@ -3,26 +3,18 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
ops::Range,
|
ops::Range,
|
||||||
sync::Arc,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::Error;
|
||||||
use cuprate_blockchain::service::BlockchainReadHandle;
|
use cuprate_blockchain::service::BlockchainReadHandle;
|
||||||
use futures::StreamExt;
|
|
||||||
use monero_serai::block::Block;
|
|
||||||
use tower::{Service, ServiceExt};
|
use tower::{Service, ServiceExt};
|
||||||
|
|
||||||
use cuprate_helper::{
|
use cuprate_helper::cast::{u64_to_usize, usize_to_u64};
|
||||||
cast::{u64_to_usize, usize_to_u64},
|
|
||||||
map::split_u128_into_low_high_bits,
|
|
||||||
};
|
|
||||||
use cuprate_types::{
|
use cuprate_types::{
|
||||||
blockchain::{BlockchainReadRequest, BlockchainResponse, BlockchainWriteRequest},
|
blockchain::{BlockchainReadRequest, BlockchainResponse},
|
||||||
Chain, ExtendedBlockHeader, HardFork, OutputOnChain, VerifiedBlockInformation,
|
Chain, ExtendedBlockHeader, OutputOnChain,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::rpc::CupratedRpcHandlerState;
|
|
||||||
|
|
||||||
/// [`BlockchainReadRequest::BlockExtendedHeader`].
|
/// [`BlockchainReadRequest::BlockExtendedHeader`].
|
||||||
pub(super) async fn block_extended_header(
|
pub(super) async fn block_extended_header(
|
||||||
mut blockchain_read: BlockchainReadHandle,
|
mut blockchain_read: BlockchainReadHandle,
|
||||||
|
|
|
@ -1,32 +1,15 @@
|
||||||
//! Functions for [`BlockChainContextRequest`] and [`BlockChainContextResponse`].
|
//! Functions for [`BlockChainContextRequest`] and [`BlockChainContextResponse`].
|
||||||
|
|
||||||
use std::{
|
use std::convert::Infallible;
|
||||||
collections::{HashMap, HashSet},
|
|
||||||
convert::Infallible,
|
|
||||||
ops::Range,
|
|
||||||
sync::Arc,
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::Error;
|
||||||
use futures::StreamExt;
|
|
||||||
use monero_serai::block::Block;
|
|
||||||
use randomx_rs::RandomXVM;
|
|
||||||
use tower::{Service, ServiceExt};
|
use tower::{Service, ServiceExt};
|
||||||
|
|
||||||
use cuprate_consensus::context::{
|
use cuprate_consensus::context::{
|
||||||
BlockChainContext, BlockChainContextRequest, BlockChainContextResponse,
|
BlockChainContext, BlockChainContextRequest, BlockChainContextResponse,
|
||||||
BlockChainContextService,
|
BlockChainContextService,
|
||||||
};
|
};
|
||||||
use cuprate_helper::{
|
use cuprate_types::HardFork;
|
||||||
cast::{u64_to_usize, usize_to_u64},
|
|
||||||
map::split_u128_into_low_high_bits,
|
|
||||||
};
|
|
||||||
use cuprate_types::{
|
|
||||||
blockchain::{BlockchainReadRequest, BlockchainResponse, BlockchainWriteRequest},
|
|
||||||
Chain, ExtendedBlockHeader, HardFork, OutputOnChain, VerifiedBlockInformation,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::rpc::CupratedRpcHandlerState;
|
|
||||||
|
|
||||||
/// [`BlockChainContextRequest::Context`].
|
/// [`BlockChainContextRequest::Context`].
|
||||||
pub(super) async fn context(
|
pub(super) async fn context(
|
||||||
|
|
|
@ -1,63 +1,139 @@
|
||||||
//! Functions for TODO: doc enum message.
|
//! Functions for TODO: doc enum message.
|
||||||
|
|
||||||
use std::{
|
use anyhow::Error;
|
||||||
collections::{HashMap, HashSet},
|
|
||||||
sync::Arc,
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
|
||||||
use futures::StreamExt;
|
|
||||||
use monero_serai::block::Block;
|
use monero_serai::block::Block;
|
||||||
use tower::{Service, ServiceExt};
|
use tower::{Service, ServiceExt};
|
||||||
|
|
||||||
use cuprate_consensus::BlockchainResponse;
|
use cuprate_helper::cast::{u64_to_usize, usize_to_u64};
|
||||||
use cuprate_helper::{
|
|
||||||
cast::{u64_to_usize, usize_to_u64},
|
use crate::rpc::handler::{
|
||||||
map::split_u128_into_low_high_bits,
|
BlockchainManagerHandle, BlockchainManagerRequest, BlockchainManagerResponse,
|
||||||
};
|
|
||||||
use cuprate_types::{
|
|
||||||
blockchain::{BlockchainReadRequest, BlockchainWriteRequest},
|
|
||||||
Chain, ExtendedBlockHeader, HardFork, OutputOnChain, VerifiedBlockInformation,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::rpc::{CupratedRpcHandler, CupratedRpcHandlerState};
|
/// [`BlockchainManagerResponse::PopBlocks`]
|
||||||
|
pub(super) async fn pop_blocks(
|
||||||
|
blockchain_manager: &mut BlockchainManagerHandle,
|
||||||
|
amount: u64,
|
||||||
|
) -> Result<u64, Error> {
|
||||||
|
let BlockchainManagerResponse::PopBlocks { new_height } = blockchain_manager
|
||||||
|
.ready()
|
||||||
|
.await?
|
||||||
|
.call(BlockchainManagerRequest::PopBlocks {
|
||||||
|
amount: u64_to_usize(amount),
|
||||||
|
})
|
||||||
|
.await?
|
||||||
|
else {
|
||||||
|
unreachable!();
|
||||||
|
};
|
||||||
|
|
||||||
/// TODO: doc enum message
|
Ok(usize_to_u64(new_height))
|
||||||
pub(super) async fn pop_blocks() -> Result<(u64, [u8; 32]), Error> {
|
|
||||||
Ok(todo!())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: doc enum message
|
/// [`BlockchainManagerResponse::Prune`]
|
||||||
pub(super) async fn prune() -> Result<(), Error> {
|
pub(super) async fn prune(blockchain_manager: &mut BlockchainManagerHandle) -> Result<(), Error> {
|
||||||
Ok(todo!())
|
let BlockchainManagerResponse::Ok = blockchain_manager
|
||||||
|
.ready()
|
||||||
|
.await?
|
||||||
|
.call(BlockchainManagerRequest::Prune)
|
||||||
|
.await?
|
||||||
|
else {
|
||||||
|
unreachable!();
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: doc enum message
|
/// [`BlockchainManagerResponse::Pruned`]
|
||||||
pub(super) async fn pruned() -> Result<bool, Error> {
|
pub(super) async fn pruned(
|
||||||
Ok(todo!())
|
blockchain_manager: &mut BlockchainManagerHandle,
|
||||||
|
) -> Result<bool, Error> {
|
||||||
|
let BlockchainManagerResponse::Pruned(pruned) = blockchain_manager
|
||||||
|
.ready()
|
||||||
|
.await?
|
||||||
|
.call(BlockchainManagerRequest::Pruned)
|
||||||
|
.await?
|
||||||
|
else {
|
||||||
|
unreachable!();
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(pruned)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: doc enum message
|
/// [`BlockchainManagerResponse::RelayBlock`]
|
||||||
pub(super) async fn relay_block() -> Result<bool, Error> {
|
pub(super) async fn relay_block(
|
||||||
Ok(todo!())
|
blockchain_manager: &mut BlockchainManagerHandle,
|
||||||
|
block: Block,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let BlockchainManagerResponse::Ok = blockchain_manager
|
||||||
|
.ready()
|
||||||
|
.await?
|
||||||
|
.call(BlockchainManagerRequest::RelayBlock(block))
|
||||||
|
.await?
|
||||||
|
else {
|
||||||
|
unreachable!();
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: doc enum message
|
/// [`BlockchainManagerResponse::Syncing`]
|
||||||
pub(super) async fn syncing() -> Result<bool, Error> {
|
pub(super) async fn syncing(
|
||||||
Ok(todo!())
|
blockchain_manager: &mut BlockchainManagerHandle,
|
||||||
|
) -> Result<bool, Error> {
|
||||||
|
let BlockchainManagerResponse::Syncing(syncing) = blockchain_manager
|
||||||
|
.ready()
|
||||||
|
.await?
|
||||||
|
.call(BlockchainManagerRequest::Syncing)
|
||||||
|
.await?
|
||||||
|
else {
|
||||||
|
unreachable!();
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(syncing)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: doc enum message
|
/// [`BlockchainManagerResponse::Synced`]
|
||||||
pub(super) async fn synced() -> Result<bool, Error> {
|
pub(super) async fn synced(
|
||||||
Ok(todo!())
|
blockchain_manager: &mut BlockchainManagerHandle,
|
||||||
|
) -> Result<bool, Error> {
|
||||||
|
let BlockchainManagerResponse::Synced(syncing) = blockchain_manager
|
||||||
|
.ready()
|
||||||
|
.await?
|
||||||
|
.call(BlockchainManagerRequest::Synced)
|
||||||
|
.await?
|
||||||
|
else {
|
||||||
|
unreachable!();
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(syncing)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: doc enum message
|
/// [`BlockchainManagerResponse::Target`]
|
||||||
pub(super) async fn target() -> Result<bool, Error> {
|
pub(super) async fn target(blockchain_manager: &mut BlockchainManagerHandle) -> Result<u64, Error> {
|
||||||
Ok(todo!())
|
let BlockchainManagerResponse::Target { height } = blockchain_manager
|
||||||
|
.ready()
|
||||||
|
.await?
|
||||||
|
.call(BlockchainManagerRequest::Target)
|
||||||
|
.await?
|
||||||
|
else {
|
||||||
|
unreachable!();
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(usize_to_u64(height))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: doc enum message
|
/// [`BlockchainManagerResponse::TargetHeight`]
|
||||||
pub(super) async fn target_height() -> Result<bool, Error> {
|
pub(super) async fn target_height(
|
||||||
Ok(todo!())
|
blockchain_manager: &mut BlockchainManagerHandle,
|
||||||
|
) -> Result<u64, Error> {
|
||||||
|
let BlockchainManagerResponse::TargetHeight { height } = blockchain_manager
|
||||||
|
.ready()
|
||||||
|
.await?
|
||||||
|
.call(BlockchainManagerRequest::TargetHeight)
|
||||||
|
.await?
|
||||||
|
else {
|
||||||
|
unreachable!();
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(usize_to_u64(height))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,15 @@
|
||||||
//! Functions for TODO: doc enum message.
|
//! Functions for TODO: doc enum message.
|
||||||
|
|
||||||
use std::{
|
use std::convert::Infallible;
|
||||||
collections::{HashMap, HashSet},
|
|
||||||
convert::Infallible,
|
|
||||||
sync::Arc,
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::Error;
|
||||||
use cuprate_database_service::DatabaseReadService;
|
|
||||||
use futures::StreamExt;
|
|
||||||
use monero_serai::block::Block;
|
|
||||||
use tower::{Service, ServiceExt};
|
use tower::{Service, ServiceExt};
|
||||||
|
|
||||||
use cuprate_consensus::BlockchainResponse;
|
use cuprate_helper::cast::usize_to_u64;
|
||||||
use cuprate_helper::{
|
|
||||||
cast::{u64_to_usize, usize_to_u64},
|
|
||||||
map::split_u128_into_low_high_bits,
|
|
||||||
};
|
|
||||||
use cuprate_txpool::service::{
|
use cuprate_txpool::service::{
|
||||||
interface::{TxpoolReadRequest, TxpoolReadResponse},
|
interface::{TxpoolReadRequest, TxpoolReadResponse},
|
||||||
TxpoolReadHandle,
|
TxpoolReadHandle,
|
||||||
};
|
};
|
||||||
use cuprate_types::{
|
|
||||||
blockchain::{BlockchainReadRequest, BlockchainWriteRequest},
|
|
||||||
Chain, ExtendedBlockHeader, HardFork, OutputOnChain, VerifiedBlockInformation,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::rpc::{CupratedRpcHandler, CupratedRpcHandlerState};
|
|
||||||
|
|
||||||
/// [`TxpoolReadRequest::Backlog`]
|
/// [`TxpoolReadRequest::Backlog`]
|
||||||
pub(super) async fn backlog(txpool_read: &mut TxpoolReadHandle) -> Result<Vec<Infallible>, Error> {
|
pub(super) async fn backlog(txpool_read: &mut TxpoolReadHandle) -> Result<Vec<Infallible>, Error> {
|
||||||
|
|
Loading…
Reference in a new issue