This commit is contained in:
hinto.janai 2024-10-14 20:48:47 -04:00
parent a10ed59201
commit d7d8b3509e
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
3 changed files with 20 additions and 10 deletions

View file

@ -4,6 +4,7 @@ use std::task::{Context, Poll};
use anyhow::Error; use anyhow::Error;
use cuprate_consensus::BlockChainContextService; use cuprate_consensus::BlockChainContextService;
use cuprate_pruning::PruningSeed;
use futures::future::BoxFuture; use futures::future::BoxFuture;
use monero_serai::block::Block; use monero_serai::block::Block;
use tower::Service; use tower::Service;
@ -70,6 +71,9 @@ pub enum BlockchainManagerResponse {
/// Response to [`BlockchainManagerRequest::PopBlocks`] /// Response to [`BlockchainManagerRequest::PopBlocks`]
PopBlocks { new_height: usize }, PopBlocks { new_height: usize },
/// Response to [`BlockchainManagerRequest::Prune`]
Prune(PruningSeed),
/// Response to [`BlockchainManagerRequest::Pruned`] /// Response to [`BlockchainManagerRequest::Pruned`]
Pruned(bool), Pruned(bool),

View file

@ -5,7 +5,6 @@ use std::{
use anyhow::{anyhow, Error}; use anyhow::{anyhow, Error};
use cuprate_p2p_core::{client::handshaker::builder::DummyAddressBook, ClearNet}; use cuprate_p2p_core::{client::handshaker::builder::DummyAddressBook, ClearNet};
use cuprate_types::HardFork;
use monero_serai::block::Block; use monero_serai::block::Block;
use tower::{Service, ServiceExt}; use tower::{Service, ServiceExt};
@ -44,15 +43,14 @@ use cuprate_rpc_types::{
misc::{BlockHeader, ChainInfo, GetBan, HardforkEntry, HistogramEntry, Status, TxBacklogEntry}, misc::{BlockHeader, ChainInfo, GetBan, HardforkEntry, HistogramEntry, Status, TxBacklogEntry},
CORE_RPC_VERSION, CORE_RPC_VERSION,
}; };
use cuprate_types::HardFork;
use crate::rpc::{ use crate::rpc::{
helper, helper,
request::{address_book, blockchain, blockchain_context, blockchain_manager}, request::{address_book, blockchain, blockchain_context, blockchain_manager, txpool},
CupratedRpcHandler, CupratedRpcHandler,
}; };
use super::request::txpool;
/// Map a [`JsonRpcRequest`] to the function that will lead to a [`JsonRpcResponse`]. /// Map a [`JsonRpcRequest`] to the function that will lead to a [`JsonRpcResponse`].
pub(super) async fn map_request( pub(super) async fn map_request(
state: CupratedRpcHandler, state: CupratedRpcHandler,
@ -719,13 +717,18 @@ async fn get_miner_data(
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3453-L3476> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3453-L3476>
async fn prune_blockchain( async fn prune_blockchain(
state: CupratedRpcHandler, mut state: CupratedRpcHandler,
request: PruneBlockchainRequest, request: PruneBlockchainRequest,
) -> Result<PruneBlockchainResponse, Error> { ) -> Result<PruneBlockchainResponse, Error> {
let pruned = blockchain_manager::pruned(&mut state.blockchain_manager).await?;
let pruning_seed = blockchain_manager::prune(&mut state.blockchain_manager)
.await?
.compress();
Ok(PruneBlockchainResponse { Ok(PruneBlockchainResponse {
base: ResponseBase::OK, base: ResponseBase::OK,
pruned: todo!(), pruned,
pruning_seed: todo!(), pruning_seed,
}) })
} }

View file

@ -5,6 +5,7 @@ use monero_serai::block::Block;
use tower::{Service, ServiceExt}; use tower::{Service, ServiceExt};
use cuprate_helper::cast::{u64_to_usize, usize_to_u64}; use cuprate_helper::cast::{u64_to_usize, usize_to_u64};
use cuprate_pruning::PruningSeed;
use crate::rpc::handler::{ use crate::rpc::handler::{
BlockchainManagerHandle, BlockchainManagerRequest, BlockchainManagerResponse, BlockchainManagerHandle, BlockchainManagerRequest, BlockchainManagerResponse,
@ -30,8 +31,10 @@ pub(crate) async fn pop_blocks(
} }
/// [`BlockchainManagerRequest::Prune`] /// [`BlockchainManagerRequest::Prune`]
pub(crate) async fn prune(blockchain_manager: &mut BlockchainManagerHandle) -> Result<(), Error> { pub(crate) async fn prune(
let BlockchainManagerResponse::Ok = blockchain_manager blockchain_manager: &mut BlockchainManagerHandle,
) -> Result<PruningSeed, Error> {
let BlockchainManagerResponse::Prune(seed) = blockchain_manager
.ready() .ready()
.await? .await?
.call(BlockchainManagerRequest::Prune) .call(BlockchainManagerRequest::Prune)
@ -40,7 +43,7 @@ pub(crate) async fn prune(blockchain_manager: &mut BlockchainManagerHandle) -> R
unreachable!(); unreachable!();
}; };
Ok(()) Ok(seed)
} }
/// [`BlockchainManagerRequest::Pruned`] /// [`BlockchainManagerRequest::Pruned`]