From 805f475083c3561c71e406581dbcee30eea1837b Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Fri, 13 Dec 2024 20:21:11 -0500 Subject: [PATCH] `/get_transaction_pool_stats` --- binaries/cuprated/src/rpc/other.rs | 6 +++++- binaries/cuprated/src/rpc/request/txpool.rs | 23 ++++++++++++++++++++- storage/txpool/src/service/interface.rs | 8 ++++++- storage/txpool/src/service/read.rs | 8 +++++++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/binaries/cuprated/src/rpc/other.rs b/binaries/cuprated/src/rpc/other.rs index b6b97d7..7cbbd34 100644 --- a/binaries/cuprated/src/rpc/other.rs +++ b/binaries/cuprated/src/rpc/other.rs @@ -517,9 +517,13 @@ async fn get_transaction_pool_stats( mut state: CupratedRpcHandler, _: GetTransactionPoolStatsRequest, ) -> Result { + let include_sensitive_txs = !state.is_restricted(); + + let pool_stats = txpool::pool_stats(&mut state.txpool_read, include_sensitive_txs).await?; + Ok(GetTransactionPoolStatsResponse { base: helper::access_response_base(false), - ..todo!() + pool_stats, }) } diff --git a/binaries/cuprated/src/rpc/request/txpool.rs b/binaries/cuprated/src/rpc/request/txpool.rs index ded73a7..007660b 100644 --- a/binaries/cuprated/src/rpc/request/txpool.rs +++ b/binaries/cuprated/src/rpc/request/txpool.rs @@ -16,7 +16,7 @@ use cuprate_txpool::{ TxEntry, }; use cuprate_types::{ - rpc::{PoolInfo, PoolInfoFull, PoolInfoIncremental, PoolTxInfo}, + rpc::{PoolInfo, PoolInfoFull, PoolInfoIncremental, PoolTxInfo, TxpoolStats}, TxInPool, TxRelayChecks, }; @@ -157,6 +157,27 @@ pub(crate) async fn pool( Ok((txs, spent_key_images)) } +/// TODO +pub(crate) async fn pool_stats( + txpool_read: &mut TxpoolReadHandle, + include_sensitive_txs: bool, +) -> Result { + let TxpoolReadResponse::PoolStats(txpool_stats) = txpool_read + .ready() + .await + .map_err(|e| anyhow!(e))? + .call(TxpoolReadRequest::PoolStats { + include_sensitive_txs, + }) + .await + .map_err(|e| anyhow!(e))? + else { + unreachable!(); + }; + + Ok(txpool_stats) +} + /// TODO pub(crate) async fn flush( txpool_manager: &mut Infallible, diff --git a/storage/txpool/src/service/interface.rs b/storage/txpool/src/service/interface.rs index 047fd71..578e6a5 100644 --- a/storage/txpool/src/service/interface.rs +++ b/storage/txpool/src/service/interface.rs @@ -8,7 +8,7 @@ use std::{ }; use cuprate_types::{ - rpc::{PoolInfo, SpentKeyImageInfo, TxInfo}, + rpc::{PoolInfo, SpentKeyImageInfo, TxInfo, TxpoolStats}, TransactionVerificationData, TxInPool, }; @@ -70,6 +70,9 @@ pub enum TxpoolReadRequest { /// TODO Pool { include_sensitive_txs: bool }, + + /// TODO + PoolStats { include_sensitive_txs: bool }, } //---------------------------------------------------------------------------------------------------- TxpoolReadResponse @@ -124,6 +127,9 @@ pub enum TxpoolReadResponse { txs: Vec, spent_key_images: Vec, }, + + /// Response to [`TxpoolReadRequest::PoolStats`]. + PoolStats(TxpoolStats), } //---------------------------------------------------------------------------------------------------- TxpoolWriteRequest diff --git a/storage/txpool/src/service/read.rs b/storage/txpool/src/service/read.rs index 8d393c9..844165f 100644 --- a/storage/txpool/src/service/read.rs +++ b/storage/txpool/src/service/read.rs @@ -92,6 +92,9 @@ fn map_request( TxpoolReadRequest::Pool { include_sensitive_txs, } => pool(env, include_sensitive_txs), + TxpoolReadRequest::PoolStats { + include_sensitive_txs, + } => pool_stats(env, include_sensitive_txs), } } @@ -260,3 +263,8 @@ fn pool(env: &ConcreteEnv, include_sensitive_txs: bool) -> ReadResponseResult { spent_key_images: todo!(), }) } + +/// [`TxpoolReadRequest::PoolStats`]. +fn pool_stats(env: &ConcreteEnv, include_sensitive_txs: bool) -> ReadResponseResult { + Ok(TxpoolReadResponse::PoolStats(todo!())) +}