/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, account_public_address: String,
extra_nonce: Vec<u8>, extra_nonce: Vec<u8>,
}, },
/// TODO
Stop,
} }
/// TODO: use real type when public. /// 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> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1537-L1582>
async fn get_peer_list( async fn get_peer_list(
state: CupratedRpcHandler, mut state: CupratedRpcHandler,
request: GetPeerListRequest, request: GetPeerListRequest,
) -> Result<GetPeerListResponse, Error> { ) -> Result<GetPeerListResponse, Error> {
let (white_list, gray_list) = address_book::peerlist::<ClearNet>(&mut DummyAddressBook).await?; 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> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1663-L1687>
async fn get_transaction_pool( async fn get_transaction_pool(
state: CupratedRpcHandler, mut state: CupratedRpcHandler,
request: GetTransactionPoolRequest, _: GetTransactionPoolRequest,
) -> Result<GetTransactionPoolResponse, Error> { ) -> 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 { Ok(GetTransactionPoolResponse {
base: helper::access_response_base(false), 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> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1741-L1756>
async fn get_transaction_pool_stats( async fn get_transaction_pool_stats(
state: CupratedRpcHandler, mut state: CupratedRpcHandler,
request: GetTransactionPoolStatsRequest, _: GetTransactionPoolStatsRequest,
) -> Result<GetTransactionPoolStatsResponse, Error> { ) -> Result<GetTransactionPoolStatsResponse, Error> {
Ok(GetTransactionPoolStatsResponse { Ok(GetTransactionPoolStatsResponse {
base: helper::access_response_base(false), 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> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1780-L1788>
async fn stop_daemon( async fn stop_daemon(
state: CupratedRpcHandler, mut state: CupratedRpcHandler,
request: StopDaemonRequest, _: StopDaemonRequest,
) -> Result<StopDaemonResponse, Error> { ) -> Result<StopDaemonResponse, Error> {
todo!(); blockchain_manager::stop(&mut state.blockchain_manager).await?;
Ok(StopDaemonResponse { status: Status::Ok }) Ok(StopDaemonResponse { status: Status::Ok })
} }
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3066-L3077> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3066-L3077>
async fn get_limit( async fn get_limit(
state: CupratedRpcHandler, mut state: CupratedRpcHandler,
request: GetLimitRequest, _: GetLimitRequest,
) -> Result<GetLimitResponse, Error> { ) -> Result<GetLimitResponse, Error> {
Ok(GetLimitResponse { Ok(GetLimitResponse {
base: helper::response_base(false), 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> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3079-L3117>
async fn set_limit( async fn set_limit(
state: CupratedRpcHandler, mut state: CupratedRpcHandler,
request: SetLimitRequest, request: SetLimitRequest,
) -> Result<SetLimitResponse, Error> { ) -> Result<SetLimitResponse, Error> {
Ok(SetLimitResponse { 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> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3119-L3127>
async fn out_peers( async fn out_peers(
state: CupratedRpcHandler, mut state: CupratedRpcHandler,
request: OutPeersRequest, request: OutPeersRequest,
) -> Result<OutPeersResponse, Error> { ) -> Result<OutPeersResponse, Error> {
Ok(OutPeersResponse { 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> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3129-L3137>
async fn in_peers( async fn in_peers(
state: CupratedRpcHandler, mut state: CupratedRpcHandler,
request: InPeersRequest, request: InPeersRequest,
) -> Result<InPeersResponse, Error> { ) -> Result<InPeersResponse, Error> {
Ok(InPeersResponse { 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> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L584-L599>
async fn get_net_stats( async fn get_net_stats(
state: CupratedRpcHandler, mut state: CupratedRpcHandler,
request: GetNetStatsRequest, _: GetNetStatsRequest,
) -> Result<GetNetStatsResponse, Error> { ) -> Result<GetNetStatsResponse, Error> {
Ok(GetNetStatsResponse { Ok(GetNetStatsResponse {
base: helper::response_base(false), 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> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1713-L1739>
async fn get_transaction_pool_hashes( async fn get_transaction_pool_hashes(
state: CupratedRpcHandler, mut state: CupratedRpcHandler,
request: GetTransactionPoolHashesRequest, _: GetTransactionPoolHashesRequest,
) -> Result<GetTransactionPoolHashesResponse, Error> { ) -> Result<GetTransactionPoolHashesResponse, Error> {
Ok(GetTransactionPoolHashesResponse { Ok(GetTransactionPoolHashesResponse {
base: helper::response_base(false), 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> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L193-L225>
async fn get_public_nodes( async fn get_public_nodes(
state: CupratedRpcHandler, mut state: CupratedRpcHandler,
request: GetPublicNodesRequest, request: GetPublicNodesRequest,
) -> Result<GetPublicNodesResponse, Error> { ) -> Result<GetPublicNodesResponse, Error> {
Ok(GetPublicNodesResponse { 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> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1758-L1778>
async fn set_bootstrap_daemon( async fn set_bootstrap_daemon(
@ -709,6 +682,24 @@ async fn update(
todo!(); 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> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1413-L1462>
async fn start_mining( async fn start_mining(
state: CupratedRpcHandler, state: CupratedRpcHandler,
@ -732,3 +723,11 @@ async fn mining_status(
) -> Result<MiningStatusResponse, Error> { ) -> Result<MiningStatusResponse, Error> {
unreachable!(); 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(()) 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 tower::{Service, ServiceExt};
use cuprate_helper::cast::usize_to_u64; use cuprate_helper::cast::usize_to_u64;
use cuprate_rpc_types::misc::{SpentKeyImageInfo, TxInfo};
use cuprate_txpool::{ use cuprate_txpool::{
service::{ service::{
interface::{TxpoolReadRequest, TxpoolReadResponse}, interface::{TxpoolReadRequest, TxpoolReadResponse},
@ -129,6 +130,33 @@ pub(crate) async fn key_images_spent(
Ok(status) 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 /// TODO
pub(crate) async fn flush( pub(crate) async fn flush(
txpool_manager: &mut Infallible, txpool_manager: &mut Infallible,

View file

@ -13,7 +13,7 @@ use cuprate_p2p_core::{
types::{ConnectionId, ConnectionInfo, SetBan, Span}, types::{ConnectionId, ConnectionInfo, SetBan, Span},
NetZoneAddress, 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 { impl From<BlockHeader> for crate::misc::BlockHeader {
fn from(x: BlockHeader) -> Self { 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, sync::Arc,
}; };
use cuprate_types::{rpc::PoolInfo, TransactionVerificationData, TxInPool}; use cuprate_types::{
rpc::{PoolInfo, SpentKeyImageInfo, TxInfo},
TransactionVerificationData, TxInPool,
};
use crate::{ use crate::{
tx::TxEntry, tx::TxEntry,
@ -64,6 +67,9 @@ pub enum TxpoolReadRequest {
key_images: Vec<[u8; 32]>, key_images: Vec<[u8; 32]>,
include_sensitive_txs: bool, include_sensitive_txs: bool,
}, },
/// TODO
Pool { include_sensitive_txs: bool },
} }
//---------------------------------------------------------------------------------------------------- TxpoolReadResponse //---------------------------------------------------------------------------------------------------- TxpoolReadResponse
@ -112,6 +118,12 @@ pub enum TxpoolReadResponse {
/// Response to [`TxpoolReadRequest::KeyImagesSpent`]. /// Response to [`TxpoolReadRequest::KeyImagesSpent`].
KeyImagesSpent(Vec<bool>), KeyImagesSpent(Vec<bool>),
/// Response to [`TxpoolReadRequest::Pool`].
Pool {
txs: Vec<TxInfo>,
spent_key_images: Vec<SpentKeyImageInfo>,
},
} }
//---------------------------------------------------------------------------------------------------- TxpoolWriteRequest //---------------------------------------------------------------------------------------------------- TxpoolWriteRequest

View file

@ -89,6 +89,9 @@ fn map_request(
key_images, key_images,
include_sensitive_txs, include_sensitive_txs,
} => key_images_spent(env, 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 { ) -> ReadResponseResult {
Ok(TxpoolReadResponse::KeyImagesSpent(todo!())) 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 1558..=1567
)] )]
SpentKeyImageInfo { SpentKeyImageInfo {
id_hash: String, id_hash: [u8; 32],
txs_hashes: Vec<String>, txs_hashes: Vec<[u8; 32]>,
} }
#[doc = monero_definition_link!( #[doc = monero_definition_link!(