/get_transaction_pool

This commit is contained in:
hinto.janai 2024-12-13 20:14:16 -05:00
parent c924f24765
commit c5abf9bb98
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
8 changed files with 133 additions and 57 deletions

View file

@ -95,6 +95,9 @@ pub enum BlockchainManagerRequest {
account_public_address: String,
extra_nonce: Vec<u8>,
},
/// TODO
Stop,
}
/// TODO: use real type when public.

View file

@ -483,7 +483,7 @@ async fn save_bc(mut state: CupratedRpcHandler, _: SaveBcRequest) -> Result<Save
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1537-L1582>
async fn get_peer_list(
state: CupratedRpcHandler,
mut state: CupratedRpcHandler,
request: GetPeerListRequest,
) -> Result<GetPeerListResponse, Error> {
let (white_list, gray_list) = address_book::peerlist::<ClearNet>(&mut DummyAddressBook).await?;
@ -495,54 +495,27 @@ async fn get_peer_list(
})
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1626-L1639>
async fn set_log_hash_rate(
state: CupratedRpcHandler,
request: SetLogHashRateRequest,
) -> Result<SetLogHashRateResponse, Error> {
unreachable!();
Ok(SetLogHashRateResponse {
base: helper::response_base(false),
})
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1641-L1652>
async fn set_log_level(
state: CupratedRpcHandler,
request: SetLogLevelRequest,
) -> Result<SetLogLevelResponse, Error> {
todo!();
Ok(SetLogLevelResponse {
base: helper::response_base(false),
})
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1654-L1661>
async fn set_log_categories(
state: CupratedRpcHandler,
request: SetLogCategoriesRequest,
) -> Result<SetLogCategoriesResponse, Error> {
Ok(SetLogCategoriesResponse {
base: helper::response_base(false),
..todo!()
})
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1663-L1687>
async fn get_transaction_pool(
state: CupratedRpcHandler,
request: GetTransactionPoolRequest,
mut state: CupratedRpcHandler,
_: GetTransactionPoolRequest,
) -> Result<GetTransactionPoolResponse, Error> {
let include_sensitive_txs = !state.is_restricted();
let (transactions, spent_key_images) =
txpool::pool(&mut state.txpool_read, include_sensitive_txs).await?;
Ok(GetTransactionPoolResponse {
base: helper::access_response_base(false),
..todo!()
transactions,
spent_key_images,
})
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1741-L1756>
async fn get_transaction_pool_stats(
state: CupratedRpcHandler,
request: GetTransactionPoolStatsRequest,
mut state: CupratedRpcHandler,
_: GetTransactionPoolStatsRequest,
) -> Result<GetTransactionPoolStatsResponse, Error> {
Ok(GetTransactionPoolStatsResponse {
base: helper::access_response_base(false),
@ -552,17 +525,17 @@ async fn get_transaction_pool_stats(
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1780-L1788>
async fn stop_daemon(
state: CupratedRpcHandler,
request: StopDaemonRequest,
mut state: CupratedRpcHandler,
_: StopDaemonRequest,
) -> Result<StopDaemonResponse, Error> {
todo!();
blockchain_manager::stop(&mut state.blockchain_manager).await?;
Ok(StopDaemonResponse { status: Status::Ok })
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3066-L3077>
async fn get_limit(
state: CupratedRpcHandler,
request: GetLimitRequest,
mut state: CupratedRpcHandler,
_: GetLimitRequest,
) -> Result<GetLimitResponse, Error> {
Ok(GetLimitResponse {
base: helper::response_base(false),
@ -572,7 +545,7 @@ async fn get_limit(
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3079-L3117>
async fn set_limit(
state: CupratedRpcHandler,
mut state: CupratedRpcHandler,
request: SetLimitRequest,
) -> Result<SetLimitResponse, Error> {
Ok(SetLimitResponse {
@ -583,7 +556,7 @@ async fn set_limit(
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3119-L3127>
async fn out_peers(
state: CupratedRpcHandler,
mut state: CupratedRpcHandler,
request: OutPeersRequest,
) -> Result<OutPeersResponse, Error> {
Ok(OutPeersResponse {
@ -594,7 +567,7 @@ async fn out_peers(
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3129-L3137>
async fn in_peers(
state: CupratedRpcHandler,
mut state: CupratedRpcHandler,
request: InPeersRequest,
) -> Result<InPeersResponse, Error> {
Ok(InPeersResponse {
@ -605,8 +578,8 @@ async fn in_peers(
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L584-L599>
async fn get_net_stats(
state: CupratedRpcHandler,
request: GetNetStatsRequest,
mut state: CupratedRpcHandler,
_: GetNetStatsRequest,
) -> Result<GetNetStatsResponse, Error> {
Ok(GetNetStatsResponse {
base: helper::response_base(false),
@ -671,8 +644,8 @@ async fn pop_blocks(
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1713-L1739>
async fn get_transaction_pool_hashes(
state: CupratedRpcHandler,
request: GetTransactionPoolHashesRequest,
mut state: CupratedRpcHandler,
_: GetTransactionPoolHashesRequest,
) -> Result<GetTransactionPoolHashesResponse, Error> {
Ok(GetTransactionPoolHashesResponse {
base: helper::response_base(false),
@ -682,7 +655,7 @@ async fn get_transaction_pool_hashes(
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L193-L225>
async fn get_public_nodes(
state: CupratedRpcHandler,
mut state: CupratedRpcHandler,
request: GetPublicNodesRequest,
) -> Result<GetPublicNodesResponse, Error> {
Ok(GetPublicNodesResponse {
@ -691,7 +664,7 @@ async fn get_public_nodes(
})
}
//---------------------------------------------------------------------------------------------------- Unsupported RPC calls
//---------------------------------------------------------------------------------------------------- Unsupported RPC calls (for now)
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1758-L1778>
async fn set_bootstrap_daemon(
@ -709,6 +682,24 @@ async fn update(
todo!();
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1641-L1652>
async fn set_log_level(
state: CupratedRpcHandler,
request: SetLogLevelRequest,
) -> Result<SetLogLevelResponse, Error> {
todo!()
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1654-L1661>
async fn set_log_categories(
state: CupratedRpcHandler,
request: SetLogCategoriesRequest,
) -> Result<SetLogCategoriesResponse, Error> {
todo!()
}
//---------------------------------------------------------------------------------------------------- Unsupported RPC calls (forever)
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1413-L1462>
async fn start_mining(
state: CupratedRpcHandler,
@ -732,3 +723,11 @@ async fn mining_status(
) -> Result<MiningStatusResponse, Error> {
unreachable!();
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1626-L1639>
async fn set_log_hash_rate(
state: CupratedRpcHandler,
request: SetLogHashRateRequest,
) -> Result<SetLogHashRateResponse, Error> {
unreachable!();
}

View file

@ -256,3 +256,17 @@ pub(crate) async fn sync(blockchain_manager: &mut BlockchainManagerHandle) -> Re
Ok(())
}
/// [`BlockchainManagerRequest::Stop`]
pub(crate) async fn stop(blockchain_manager: &mut BlockchainManagerHandle) -> Result<(), Error> {
let BlockchainManagerResponse::Ok = blockchain_manager
.ready()
.await?
.call(BlockchainManagerRequest::Stop)
.await?
else {
unreachable!();
};
Ok(())
}

View file

@ -7,6 +7,7 @@ use monero_serai::transaction::Transaction;
use tower::{Service, ServiceExt};
use cuprate_helper::cast::usize_to_u64;
use cuprate_rpc_types::misc::{SpentKeyImageInfo, TxInfo};
use cuprate_txpool::{
service::{
interface::{TxpoolReadRequest, TxpoolReadResponse},
@ -129,6 +130,33 @@ pub(crate) async fn key_images_spent(
Ok(status)
}
/// TODO
pub(crate) async fn pool(
txpool_read: &mut TxpoolReadHandle,
include_sensitive_txs: bool,
) -> Result<(Vec<TxInfo>, Vec<SpentKeyImageInfo>), Error> {
let TxpoolReadResponse::Pool {
txs,
spent_key_images,
} = txpool_read
.ready()
.await
.map_err(|e| anyhow!(e))?
.call(TxpoolReadRequest::Pool {
include_sensitive_txs,
})
.await
.map_err(|e| anyhow!(e))?
else {
unreachable!();
};
let txs = txs.into_iter().map(Into::into).collect();
let spent_key_images = spent_key_images.into_iter().map(Into::into).collect();
Ok((txs, spent_key_images))
}
/// TODO
pub(crate) async fn flush(
txpool_manager: &mut Infallible,

View file

@ -13,7 +13,7 @@ use cuprate_p2p_core::{
types::{ConnectionId, ConnectionInfo, SetBan, Span},
NetZoneAddress,
};
use cuprate_types::rpc::{BlockHeader, ChainInfo, HistogramEntry, TxInfo};
use cuprate_types::rpc::{BlockHeader, ChainInfo, HistogramEntry, SpentKeyImageInfo, TxInfo};
impl From<BlockHeader> for crate::misc::BlockHeader {
fn from(x: BlockHeader) -> Self {
@ -184,3 +184,12 @@ impl From<TxInfo> for crate::misc::TxInfo {
}
}
}
impl From<SpentKeyImageInfo> for crate::misc::SpentKeyImageInfo {
fn from(x: SpentKeyImageInfo) -> Self {
Self {
id_hash: Hex(x.id_hash),
txs_hashes: x.txs_hashes.into_iter().map(Hex).collect(),
}
}
}

View file

@ -7,7 +7,10 @@ use std::{
sync::Arc,
};
use cuprate_types::{rpc::PoolInfo, TransactionVerificationData, TxInPool};
use cuprate_types::{
rpc::{PoolInfo, SpentKeyImageInfo, TxInfo},
TransactionVerificationData, TxInPool,
};
use crate::{
tx::TxEntry,
@ -64,6 +67,9 @@ pub enum TxpoolReadRequest {
key_images: Vec<[u8; 32]>,
include_sensitive_txs: bool,
},
/// TODO
Pool { include_sensitive_txs: bool },
}
//---------------------------------------------------------------------------------------------------- TxpoolReadResponse
@ -112,6 +118,12 @@ pub enum TxpoolReadResponse {
/// Response to [`TxpoolReadRequest::KeyImagesSpent`].
KeyImagesSpent(Vec<bool>),
/// Response to [`TxpoolReadRequest::Pool`].
Pool {
txs: Vec<TxInfo>,
spent_key_images: Vec<SpentKeyImageInfo>,
},
}
//---------------------------------------------------------------------------------------------------- TxpoolWriteRequest

View file

@ -89,6 +89,9 @@ fn map_request(
key_images,
include_sensitive_txs,
} => key_images_spent(env, key_images, include_sensitive_txs),
TxpoolReadRequest::Pool {
include_sensitive_txs,
} => pool(env, include_sensitive_txs),
}
}
@ -249,3 +252,11 @@ fn key_images_spent(
) -> ReadResponseResult {
Ok(TxpoolReadResponse::KeyImagesSpent(todo!()))
}
/// [`TxpoolReadRequest::Pool`].
fn pool(env: &ConcreteEnv, include_sensitive_txs: bool) -> ReadResponseResult {
Ok(TxpoolReadResponse::Pool {
txs: todo!(),
spent_key_images: todo!(),
})
}

View file

@ -383,8 +383,8 @@ define_struct_and_impl_epee! {
1558..=1567
)]
SpentKeyImageInfo {
id_hash: String,
txs_hashes: Vec<String>,
id_hash: [u8; 32],
txs_hashes: Vec<[u8; 32]>,
}
#[doc = monero_definition_link!(