From d7d8b3509e1ca94b19062a9407f4ab24d4422e0e Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Mon, 14 Oct 2024 20:48:47 -0400 Subject: [PATCH] prune --- binaries/cuprated/src/rpc/handler.rs | 4 ++++ binaries/cuprated/src/rpc/json.rs | 17 ++++++++++------- .../src/rpc/request/blockchain_manager.rs | 9 ++++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/binaries/cuprated/src/rpc/handler.rs b/binaries/cuprated/src/rpc/handler.rs index 2019beb4..a9bbba6c 100644 --- a/binaries/cuprated/src/rpc/handler.rs +++ b/binaries/cuprated/src/rpc/handler.rs @@ -4,6 +4,7 @@ use std::task::{Context, Poll}; use anyhow::Error; use cuprate_consensus::BlockChainContextService; +use cuprate_pruning::PruningSeed; use futures::future::BoxFuture; use monero_serai::block::Block; use tower::Service; @@ -70,6 +71,9 @@ pub enum BlockchainManagerResponse { /// Response to [`BlockchainManagerRequest::PopBlocks`] PopBlocks { new_height: usize }, + /// Response to [`BlockchainManagerRequest::Prune`] + Prune(PruningSeed), + /// Response to [`BlockchainManagerRequest::Pruned`] Pruned(bool), diff --git a/binaries/cuprated/src/rpc/json.rs b/binaries/cuprated/src/rpc/json.rs index e9cd80c3..65bc64e7 100644 --- a/binaries/cuprated/src/rpc/json.rs +++ b/binaries/cuprated/src/rpc/json.rs @@ -5,7 +5,6 @@ use std::{ use anyhow::{anyhow, Error}; use cuprate_p2p_core::{client::handshaker::builder::DummyAddressBook, ClearNet}; -use cuprate_types::HardFork; use monero_serai::block::Block; use tower::{Service, ServiceExt}; @@ -44,15 +43,14 @@ use cuprate_rpc_types::{ misc::{BlockHeader, ChainInfo, GetBan, HardforkEntry, HistogramEntry, Status, TxBacklogEntry}, CORE_RPC_VERSION, }; +use cuprate_types::HardFork; use crate::rpc::{ helper, - request::{address_book, blockchain, blockchain_context, blockchain_manager}, + request::{address_book, blockchain, blockchain_context, blockchain_manager, txpool}, CupratedRpcHandler, }; -use super::request::txpool; - /// Map a [`JsonRpcRequest`] to the function that will lead to a [`JsonRpcResponse`]. pub(super) async fn map_request( state: CupratedRpcHandler, @@ -719,13 +717,18 @@ async fn get_miner_data( /// async fn prune_blockchain( - state: CupratedRpcHandler, + mut state: CupratedRpcHandler, request: PruneBlockchainRequest, ) -> Result { + let pruned = blockchain_manager::pruned(&mut state.blockchain_manager).await?; + let pruning_seed = blockchain_manager::prune(&mut state.blockchain_manager) + .await? + .compress(); + Ok(PruneBlockchainResponse { base: ResponseBase::OK, - pruned: todo!(), - pruning_seed: todo!(), + pruned, + pruning_seed, }) } diff --git a/binaries/cuprated/src/rpc/request/blockchain_manager.rs b/binaries/cuprated/src/rpc/request/blockchain_manager.rs index 569c7e14..96547ba5 100644 --- a/binaries/cuprated/src/rpc/request/blockchain_manager.rs +++ b/binaries/cuprated/src/rpc/request/blockchain_manager.rs @@ -5,6 +5,7 @@ use monero_serai::block::Block; use tower::{Service, ServiceExt}; use cuprate_helper::cast::{u64_to_usize, usize_to_u64}; +use cuprate_pruning::PruningSeed; use crate::rpc::handler::{ BlockchainManagerHandle, BlockchainManagerRequest, BlockchainManagerResponse, @@ -30,8 +31,10 @@ pub(crate) async fn pop_blocks( } /// [`BlockchainManagerRequest::Prune`] -pub(crate) async fn prune(blockchain_manager: &mut BlockchainManagerHandle) -> Result<(), Error> { - let BlockchainManagerResponse::Ok = blockchain_manager +pub(crate) async fn prune( + blockchain_manager: &mut BlockchainManagerHandle, +) -> Result { + let BlockchainManagerResponse::Prune(seed) = blockchain_manager .ready() .await? .call(BlockchainManagerRequest::Prune) @@ -40,7 +43,7 @@ pub(crate) async fn prune(blockchain_manager: &mut BlockchainManagerHandle) -> R unreachable!(); }; - Ok(()) + Ok(seed) } /// [`BlockchainManagerRequest::Pruned`]