/get_transaction_pool_stats

This commit is contained in:
hinto.janai 2024-12-13 20:21:11 -05:00
parent c5abf9bb98
commit 805f475083
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
4 changed files with 42 additions and 3 deletions

View file

@ -517,9 +517,13 @@ async fn get_transaction_pool_stats(
mut state: CupratedRpcHandler,
_: GetTransactionPoolStatsRequest,
) -> Result<GetTransactionPoolStatsResponse, Error> {
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,
})
}

View file

@ -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<TxpoolStats, Error> {
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,

View file

@ -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<TxInfo>,
spent_key_images: Vec<SpentKeyImageInfo>,
},
/// Response to [`TxpoolReadRequest::PoolStats`].
PoolStats(TxpoolStats),
}
//---------------------------------------------------------------------------------------------------- TxpoolWriteRequest

View file

@ -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!()))
}