Compare commits

...

4 commits

Author SHA1 Message Date
hinto.janai
805f475083
/get_transaction_pool_stats 2024-12-13 20:21:11 -05:00
hinto.janai
c5abf9bb98
/get_transaction_pool 2024-12-13 20:14:16 -05:00
hinto.janai
c924f24765
/peerlist 2024-12-13 19:50:19 -05:00
hinto.janai
b3314d4981
/send_raw_transaction, /save_bc, response_base 2024-12-13 19:30:25 -05:00
16 changed files with 432 additions and 198 deletions

View file

@ -110,7 +110,7 @@ async fn get_blocks(
} }
Ok(GetBlocksResponse { Ok(GetBlocksResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
blocks: todo!(), blocks: todo!(),
start_height: todo!(), start_height: todo!(),
current_height: todo!(), current_height: todo!(),
@ -136,7 +136,7 @@ async fn get_blocks_by_height(
.collect::<Result<Vec<BlockCompleteEntry>, Error>>()?; .collect::<Result<Vec<BlockCompleteEntry>, Error>>()?;
Ok(GetBlocksByHeightResponse { Ok(GetBlocksByHeightResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
blocks, blocks,
}) })
} }
@ -178,7 +178,7 @@ async fn get_hashes(
let m_blocks_ids = bytes.split_off(index); let m_blocks_ids = bytes.split_off(index);
Ok(GetHashesResponse { Ok(GetHashesResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
m_blocks_ids, m_blocks_ids,
start_height, start_height,
current_height, current_height,
@ -191,7 +191,7 @@ async fn get_output_indexes(
request: GetOutputIndexesRequest, request: GetOutputIndexesRequest,
) -> Result<GetOutputIndexesResponse, Error> { ) -> Result<GetOutputIndexesResponse, Error> {
Ok(GetOutputIndexesResponse { Ok(GetOutputIndexesResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
..todo!() ..todo!()
}) })
} }
@ -202,7 +202,7 @@ async fn get_outs(
request: GetOutsRequest, request: GetOutsRequest,
) -> Result<GetOutsResponse, Error> { ) -> Result<GetOutsResponse, Error> {
Ok(GetOutsResponse { Ok(GetOutsResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
..todo!() ..todo!()
}) })
} }
@ -213,7 +213,7 @@ async fn get_transaction_pool_hashes(
request: GetTransactionPoolHashesRequest, request: GetTransactionPoolHashesRequest,
) -> Result<GetTransactionPoolHashesResponse, Error> { ) -> Result<GetTransactionPoolHashesResponse, Error> {
Ok(GetTransactionPoolHashesResponse { Ok(GetTransactionPoolHashesResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
..todo!() ..todo!()
}) })
} }
@ -224,7 +224,7 @@ async fn get_output_distribution(
request: GetOutputDistributionRequest, request: GetOutputDistributionRequest,
) -> Result<GetOutputDistributionResponse, Error> { ) -> Result<GetOutputDistributionResponse, Error> {
Ok(GetOutputDistributionResponse { Ok(GetOutputDistributionResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
..todo!() ..todo!()
}) })
} }

View file

@ -41,6 +41,9 @@ pub enum BlockchainManagerRequest {
Box<Block>, Box<Block>,
), ),
/// TODO
Sync,
/// Is the blockchain in the middle of syncing? /// Is the blockchain in the middle of syncing?
/// ///
/// This returning `false` does not necessarily /// This returning `false` does not necessarily
@ -92,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.
@ -102,6 +108,7 @@ pub enum BlockchainManagerResponse {
/// Response to: /// Response to:
/// - [`BlockchainManagerRequest::Prune`] /// - [`BlockchainManagerRequest::Prune`]
/// - [`BlockchainManagerRequest::RelayBlock`] /// - [`BlockchainManagerRequest::RelayBlock`]
/// - [`BlockchainManagerRequest::Sync`]
Ok, Ok,
/// Response to [`BlockchainManagerRequest::PopBlocks`] /// Response to [`BlockchainManagerRequest::PopBlocks`]

View file

@ -11,7 +11,10 @@ use cuprate_helper::{
cast::{u64_to_usize, usize_to_u64}, cast::{u64_to_usize, usize_to_u64},
map::split_u128_into_low_high_bits, map::split_u128_into_low_high_bits,
}; };
use cuprate_rpc_types::misc::BlockHeader; use cuprate_rpc_types::{
base::{AccessResponseBase, ResponseBase},
misc::BlockHeader,
};
use cuprate_types::HardFork; use cuprate_types::HardFork;
use crate::{ use crate::{
@ -166,3 +169,21 @@ pub(super) async fn top_height(state: &mut CupratedRpcHandler) -> Result<(u64, [
let height = chain_height.saturating_sub(1); let height = chain_height.saturating_sub(1);
Ok((height, hash)) Ok((height, hash))
} }
/// TODO
pub const fn response_base(is_bootstrap: bool) -> ResponseBase {
if is_bootstrap {
ResponseBase::OK_UNTRUSTED
} else {
ResponseBase::OK
}
}
/// TODO
pub const fn access_response_base(is_bootstrap: bool) -> AccessResponseBase {
if is_bootstrap {
AccessResponseBase::OK_UNTRUSTED
} else {
AccessResponseBase::OK
}
}

View file

@ -193,7 +193,7 @@ async fn get_block_template(
let wide_difficulty = (difficulty, difficulty_top64).hex_prefix(); let wide_difficulty = (difficulty, difficulty_top64).hex_prefix();
Ok(GetBlockTemplateResponse { Ok(GetBlockTemplateResponse {
base: ResponseBase::OK, base: helper::response_base(false),
blockhashing_blob, blockhashing_blob,
blocktemplate_blob, blocktemplate_blob,
difficulty_top64, difficulty_top64,
@ -215,7 +215,7 @@ async fn get_block_count(
_: GetBlockCountRequest, _: GetBlockCountRequest,
) -> Result<GetBlockCountResponse, Error> { ) -> Result<GetBlockCountResponse, Error> {
Ok(GetBlockCountResponse { Ok(GetBlockCountResponse {
base: ResponseBase::OK, base: helper::response_base(false),
count: helper::top_height(&mut state).await?.0, count: helper::top_height(&mut state).await?.0,
}) })
} }
@ -253,7 +253,7 @@ async fn submit_block(
blockchain_manager::relay_block(&mut state.blockchain_manager, Box::new(block)).await?; blockchain_manager::relay_block(&mut state.blockchain_manager, Box::new(block)).await?;
Ok(SubmitBlockResponse { Ok(SubmitBlockResponse {
base: ResponseBase::OK, base: helper::response_base(false),
block_id, block_id,
}) })
} }
@ -288,7 +288,7 @@ async fn generate_blocks(
let blocks = blocks.into_iter().map(Hex).collect(); let blocks = blocks.into_iter().map(Hex).collect();
Ok(GenerateBlocksResponse { Ok(GenerateBlocksResponse {
base: ResponseBase::OK, base: helper::response_base(false),
blocks, blocks,
height, height,
}) })
@ -303,7 +303,7 @@ async fn get_last_block_header(
let block_header = helper::block_header(&mut state, height, request.fill_pow_hash).await?; let block_header = helper::block_header(&mut state, height, request.fill_pow_hash).await?;
Ok(GetLastBlockHeaderResponse { Ok(GetLastBlockHeaderResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
block_header, block_header,
}) })
} }
@ -338,7 +338,7 @@ async fn get_block_header_by_hash(
} }
Ok(GetBlockHeaderByHashResponse { Ok(GetBlockHeaderByHashResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
block_header, block_header,
block_headers, block_headers,
}) })
@ -354,7 +354,7 @@ async fn get_block_header_by_height(
helper::block_header(&mut state, request.height, request.fill_pow_hash).await?; helper::block_header(&mut state, request.height, request.fill_pow_hash).await?;
Ok(GetBlockHeaderByHeightResponse { Ok(GetBlockHeaderByHeightResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
block_header, block_header,
}) })
} }
@ -409,7 +409,7 @@ async fn get_block_headers_range(
} }
Ok(GetBlockHeadersRangeResponse { Ok(GetBlockHeadersRangeResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
headers, headers,
}) })
} }
@ -442,7 +442,7 @@ async fn get_block(
}; };
Ok(GetBlockResponse { Ok(GetBlockResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
blob, blob,
json, json,
miner_tx_hash, miner_tx_hash,
@ -459,7 +459,7 @@ async fn get_connections(
let connections = address_book::connection_info::<ClearNet>(&mut DummyAddressBook).await?; let connections = address_book::connection_info::<ClearNet>(&mut DummyAddressBook).await?;
Ok(GetConnectionsResponse { Ok(GetConnectionsResponse {
base: ResponseBase::OK, base: helper::response_base(false),
connections, connections,
}) })
} }
@ -557,7 +557,7 @@ async fn get_info(
let wide_difficulty = format!("{:#x}", c.next_difficulty); let wide_difficulty = format!("{:#x}", c.next_difficulty);
Ok(GetInfoResponse { Ok(GetInfoResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
adjusted_time, adjusted_time,
alt_blocks_count, alt_blocks_count,
block_size_limit, block_size_limit,
@ -617,7 +617,7 @@ async fn hard_fork_info(
let info = blockchain_context::hard_fork_info(&mut state.blockchain_context, hard_fork).await?; let info = blockchain_context::hard_fork_info(&mut state.blockchain_context, hard_fork).await?;
Ok(HardForkInfoResponse { Ok(HardForkInfoResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
earliest_height: info.earliest_height, earliest_height: info.earliest_height,
enabled: info.enabled, enabled: info.enabled,
state: info.state, state: info.state,
@ -654,7 +654,7 @@ async fn set_bans(
} }
Ok(SetBansResponse { Ok(SetBansResponse {
base: ResponseBase::OK, base: helper::response_base(false),
}) })
} }
@ -694,7 +694,7 @@ async fn get_bans(state: CupratedRpcHandler, _: GetBansRequest) -> Result<GetBan
.collect(); .collect();
Ok(GetBansResponse { Ok(GetBansResponse {
base: ResponseBase::OK, base: helper::response_base(false),
bans, bans,
}) })
} }
@ -777,7 +777,7 @@ async fn get_output_histogram(
.collect(); .collect();
Ok(GetOutputHistogramResponse { Ok(GetOutputHistogramResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
histogram, histogram,
}) })
} }
@ -800,7 +800,7 @@ async fn get_coinbase_tx_sum(
let wide_fee_amount = format!("{emission_amount:#x}"); let wide_fee_amount = format!("{emission_amount:#x}");
Ok(GetCoinbaseTxSumResponse { Ok(GetCoinbaseTxSumResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
emission_amount, emission_amount,
emission_amount_top64, emission_amount_top64,
fee_amount, fee_amount,
@ -835,7 +835,7 @@ async fn get_version(
} }
Ok(GetVersionResponse { Ok(GetVersionResponse {
base: ResponseBase::OK, base: helper::response_base(false),
version: CORE_RPC_VERSION, version: CORE_RPC_VERSION,
release: RELEASE, release: RELEASE,
current_height, current_height,
@ -854,7 +854,7 @@ async fn get_fee_estimate(
.await?; .await?;
Ok(GetFeeEstimateResponse { Ok(GetFeeEstimateResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
fee: estimate.fee, fee: estimate.fee,
fees: estimate.fees, fees: estimate.fees,
quantization_mask: estimate.quantization_mask, quantization_mask: estimate.quantization_mask,
@ -873,7 +873,7 @@ async fn get_alternate_chains(
.collect(); .collect();
Ok(GetAlternateChainsResponse { Ok(GetAlternateChainsResponse {
base: ResponseBase::OK, base: helper::response_base(false),
chains, chains,
}) })
} }
@ -925,7 +925,7 @@ async fn sync_info(
let overview = String::from(FIELD_NOT_SUPPORTED); let overview = String::from(FIELD_NOT_SUPPORTED);
Ok(SyncInfoResponse { Ok(SyncInfoResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
height, height,
next_needed_pruning_seed, next_needed_pruning_seed,
overview, overview,
@ -951,7 +951,7 @@ async fn get_transaction_pool_backlog(
.collect(); .collect();
Ok(GetTransactionPoolBacklogResponse { Ok(GetTransactionPoolBacklogResponse {
base: ResponseBase::OK, base: helper::response_base(false),
backlog, backlog,
}) })
} }
@ -984,7 +984,7 @@ async fn get_output_distribution(
}).collect::<Result<Vec<Distribution>, _>>()?; }).collect::<Result<Vec<Distribution>, _>>()?;
Ok(GetOutputDistributionResponse { Ok(GetOutputDistributionResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
distributions, distributions,
}) })
} }
@ -1015,7 +1015,7 @@ async fn get_miner_data(
.collect(); .collect();
Ok(GetMinerDataResponse { Ok(GetMinerDataResponse {
base: ResponseBase::OK, base: helper::response_base(false),
major_version, major_version,
height, height,
prev_id, prev_id,
@ -1038,7 +1038,7 @@ async fn prune_blockchain(
.compress(); .compress();
Ok(PruneBlockchainResponse { Ok(PruneBlockchainResponse {
base: ResponseBase::OK, base: helper::response_base(false),
pruned, pruned,
pruning_seed, pruning_seed,
}) })
@ -1090,7 +1090,7 @@ async fn flush_cache(
// TODO: cuprated doesn't need this call; decide behavior. // TODO: cuprated doesn't need this call; decide behavior.
Ok(FlushCacheResponse { Ok(FlushCacheResponse {
base: ResponseBase::OK, base: helper::response_base(false),
}) })
} }
@ -1288,7 +1288,7 @@ fn add_aux_pow_inner(
let aux_pow = aux_pow.into_vec(); let aux_pow = aux_pow.into_vec();
Ok(AddAuxPowResponse { Ok(AddAuxPowResponse {
base: ResponseBase::OK, base: helper::response_base(false),
blocktemplate_blob, blocktemplate_blob,
blockhashing_blob, blockhashing_blob,
merkle_root, merkle_root,
@ -1306,7 +1306,7 @@ async fn get_tx_ids_loose(
return Err(anyhow!("Not implemented")); return Err(anyhow!("Not implemented"));
Ok(GetTxIdsLooseResponse { Ok(GetTxIdsLooseResponse {
base: ResponseBase::OK, base: helper::response_base(false),
txids: todo!(), txids: todo!(),
}) })
} }

View file

@ -1,6 +1,9 @@
//! RPC request handler functions (other JSON endpoints). //! RPC request handler functions (other JSON endpoints).
use std::collections::{BTreeSet, HashMap, HashSet}; use std::{
borrow::Cow,
collections::{BTreeSet, HashMap, HashSet},
};
use anyhow::{anyhow, Error}; use anyhow::{anyhow, Error};
@ -10,6 +13,7 @@ use cuprate_constants::rpc::{
}; };
use cuprate_helper::cast::usize_to_u64; use cuprate_helper::cast::usize_to_u64;
use cuprate_hex::Hex; use cuprate_hex::Hex;
use cuprate_p2p_core::{client::handshaker::builder::DummyAddressBook, ClearNet};
use cuprate_rpc_interface::RpcHandler; use cuprate_rpc_interface::RpcHandler;
use cuprate_rpc_types::{ use cuprate_rpc_types::{
base::{AccessResponseBase, ResponseBase}, base::{AccessResponseBase, ResponseBase},
@ -47,6 +51,8 @@ use crate::{
}, },
}; };
use super::request::address_book;
/// Map a [`OtherRequest`] to the function that will lead to a [`OtherResponse`]. /// Map a [`OtherRequest`] to the function that will lead to a [`OtherResponse`].
pub(super) async fn map_request( pub(super) async fn map_request(
state: CupratedRpcHandler, state: CupratedRpcHandler,
@ -69,9 +75,6 @@ pub(super) async fn map_request(
Req::GetPeerList(r) => Resp::GetPeerList(get_peer_list(state, r).await?), Req::GetPeerList(r) => Resp::GetPeerList(get_peer_list(state, r).await?),
Req::SetLogLevel(r) => Resp::SetLogLevel(set_log_level(state, r).await?), Req::SetLogLevel(r) => Resp::SetLogLevel(set_log_level(state, r).await?),
Req::SetLogCategories(r) => Resp::SetLogCategories(set_log_categories(state, r).await?), Req::SetLogCategories(r) => Resp::SetLogCategories(set_log_categories(state, r).await?),
Req::SetBootstrapDaemon(r) => {
Resp::SetBootstrapDaemon(set_bootstrap_daemon(state, r).await?)
}
Req::GetTransactionPool(r) => { Req::GetTransactionPool(r) => {
Resp::GetTransactionPool(get_transaction_pool(state, r).await?) Resp::GetTransactionPool(get_transaction_pool(state, r).await?)
} }
@ -92,7 +95,8 @@ pub(super) async fn map_request(
Req::GetPublicNodes(r) => Resp::GetPublicNodes(get_public_nodes(state, r).await?), Req::GetPublicNodes(r) => Resp::GetPublicNodes(get_public_nodes(state, r).await?),
// Unsupported requests. // Unsupported requests.
Req::Update(_) Req::SetBootstrapDaemon(_)
| Req::Update(_)
| Req::StartMining(_) | Req::StartMining(_)
| Req::StopMining(_) | Req::StopMining(_)
| Req::MiningStatus(_) | Req::MiningStatus(_)
@ -103,13 +107,13 @@ pub(super) async fn map_request(
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L486-L499> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L486-L499>
async fn get_height( async fn get_height(
mut state: CupratedRpcHandler, mut state: CupratedRpcHandler,
request: GetHeightRequest, _: GetHeightRequest,
) -> Result<GetHeightResponse, Error> { ) -> Result<GetHeightResponse, Error> {
let (height, hash) = helper::top_height(&mut state).await?; let (height, hash) = helper::top_height(&mut state).await?;
let hash = Hex(hash); let hash = Hex(hash);
Ok(GetHeightResponse { Ok(GetHeightResponse {
base: ResponseBase::OK, base: helper::response_base(false),
height, height,
hash, hash,
}) })
@ -254,7 +258,7 @@ async fn get_transactions(
}; };
Ok(GetTransactionsResponse { Ok(GetTransactionsResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
txs_as_hex, txs_as_hex,
txs_as_json, txs_as_json,
missed_tx, missed_tx,
@ -265,7 +269,7 @@ async fn get_transactions(
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L790-L815> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L790-L815>
async fn get_alt_blocks_hashes( async fn get_alt_blocks_hashes(
mut state: CupratedRpcHandler, mut state: CupratedRpcHandler,
request: GetAltBlocksHashesRequest, _: GetAltBlocksHashesRequest,
) -> Result<GetAltBlocksHashesResponse, Error> { ) -> Result<GetAltBlocksHashesResponse, Error> {
let blks_hashes = blockchain::alt_chains(&mut state.blockchain_read) let blks_hashes = blockchain::alt_chains(&mut state.blockchain_read)
.await? .await?
@ -274,7 +278,7 @@ async fn get_alt_blocks_hashes(
.collect(); .collect();
Ok(GetAltBlocksHashesResponse { Ok(GetAltBlocksHashesResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
blks_hashes, blks_hashes,
}) })
} }
@ -321,7 +325,7 @@ async fn is_key_image_spent(
}); });
Ok(IsKeyImageSpentResponse { Ok(IsKeyImageSpentResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
spent_status, spent_status,
}) })
} }
@ -332,7 +336,7 @@ async fn send_raw_transaction(
request: SendRawTransactionRequest, request: SendRawTransactionRequest,
) -> Result<SendRawTransactionResponse, Error> { ) -> Result<SendRawTransactionResponse, Error> {
let mut resp = SendRawTransactionResponse { let mut resp = SendRawTransactionResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
double_spend: false, double_spend: false,
fee_too_low: false, fee_too_low: false,
invalid_input: false, invalid_input: false,
@ -354,20 +358,20 @@ async fn send_raw_transaction(
}; };
if request.do_sanity_checks { if request.do_sanity_checks {
// FIXME: these checks could be defined elsewhere. /// FIXME: these checks could be defined elsewhere.
// ///
// <https://github.com/monero-project/monero/blob/893916ad091a92e765ce3241b94e706ad012b62a/src/cryptonote_core/tx_sanity_check.cpp#L42> /// <https://github.com/monero-project/monero/blob/893916ad091a92e765ce3241b94e706ad012b62a/src/cryptonote_core/tx_sanity_check.cpp#L42>
fn tx_sanity_check(tx: &Transaction, rct_outs_available: u64) -> Result<(), &'static str> { fn tx_sanity_check(tx: &Transaction, rct_outs_available: u64) -> Result<(), String> {
let Some(input) = tx.prefix().inputs.get(0) else { let Some(input) = tx.prefix().inputs.first() else {
return Err("No inputs"); return Err("No inputs".to_string());
}; };
let mut rct_indices = BTreeSet::new(); let mut rct_indices = vec![];
let n_indices: usize = 0; let mut n_indices: usize = 0;
for input in tx.prefix().inputs { for input in &tx.prefix().inputs {
match input { match input {
Input::Gen(_) => return Err("Transaction is coinbase"), Input::Gen(_) => return Err("Transaction is coinbase".to_string()),
Input::ToKey { Input::ToKey {
amount, amount,
key_offsets, key_offsets,
@ -377,8 +381,19 @@ async fn send_raw_transaction(
continue; continue;
}; };
/// <https://github.com/monero-project/monero/blob/893916ad091a92e765ce3241b94e706ad012b62a/src/cryptonote_basic/cryptonote_format_utils.cpp#L1526>
fn relative_output_offsets_to_absolute(mut offsets: Vec<u64>) -> Vec<u64> {
assert!(!offsets.is_empty());
for i in 1..offsets.len() {
offsets[i] += offsets[i - 1];
}
offsets
}
n_indices += key_offsets.len(); n_indices += key_offsets.len();
let absolute = todo!(); let absolute = relative_output_offsets_to_absolute(key_offsets.clone());
rct_indices.extend(absolute); rct_indices.extend(absolute);
} }
} }
@ -394,13 +409,12 @@ async fn send_raw_transaction(
let rct_indices_len = rct_indices.len(); let rct_indices_len = rct_indices.len();
if rct_indices_len < n_indices * 8 / 10 { if rct_indices_len < n_indices * 8 / 10 {
return Err("amount of unique indices is too low (amount of rct indices is {rct_indices_len} out of total {n_indices} indices."); return Err(format!("amount of unique indices is too low (amount of rct indices is {rct_indices_len} out of total {n_indices} indices."));
} }
let offsets = Vec::with_capacity(rct_indices_len); let median = cuprate_helper::num::median(rct_indices);
let median = todo!();
if median < rct_outs_available * 6 / 10 { if median < rct_outs_available * 6 / 10 {
return Err("median offset index is too low (median is {median} out of total {rct_outs_available} offsets). Transactions should contain a higher fraction of recent outputs."); return Err(format!("median offset index is too low (median is {median} out of total {rct_outs_available} offsets). Transactions should contain a higher fraction of recent outputs."));
} }
Ok(()) Ok(())
@ -458,46 +472,10 @@ async fn send_raw_transaction(
Ok(resp) Ok(resp)
} }
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1413-L1462>
async fn start_mining(
state: CupratedRpcHandler,
request: StartMiningRequest,
) -> Result<StartMiningResponse, Error> {
unreachable!();
Ok(StartMiningResponse {
base: ResponseBase::OK,
})
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1464-L1482>
async fn stop_mining(
state: CupratedRpcHandler,
request: StopMiningRequest,
) -> Result<StopMiningResponse, Error> {
unreachable!();
Ok(StopMiningResponse {
base: ResponseBase::OK,
})
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1484-L1523>
async fn mining_status(
state: CupratedRpcHandler,
request: MiningStatusRequest,
) -> Result<MiningStatusResponse, Error> {
unreachable!();
Ok(MiningStatusResponse {
base: ResponseBase::OK,
..todo!()
})
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1525-L1535> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1525-L1535>
async fn save_bc( async fn save_bc(mut state: CupratedRpcHandler, _: SaveBcRequest) -> Result<SaveBcResponse, Error> {
state: CupratedRpcHandler, blockchain_manager::sync(&mut state.blockchain_manager).await?;
request: SaveBcRequest,
) -> Result<SaveBcResponse, Error> {
todo!();
Ok(SaveBcResponse { Ok(SaveBcResponse {
base: ResponseBase::OK, base: ResponseBase::OK,
}) })
@ -505,139 +483,110 @@ async fn save_bc(
/// <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?;
Ok(GetPeerListResponse { Ok(GetPeerListResponse {
base: ResponseBase::OK, base: helper::response_base(false),
..todo!() white_list,
gray_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: ResponseBase::OK,
})
}
/// <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: ResponseBase::OK,
})
}
/// <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: ResponseBase::OK,
..todo!()
})
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1758-L1778>
async fn set_bootstrap_daemon(
state: CupratedRpcHandler,
request: SetBootstrapDaemonRequest,
) -> Result<SetBootstrapDaemonResponse, Error> {
todo!();
Ok(SetBootstrapDaemonResponse { status: Status::Ok })
}
/// <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: AccessResponseBase::OK, 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> {
let include_sensitive_txs = !state.is_restricted();
let pool_stats = txpool::pool_stats(&mut state.txpool_read, include_sensitive_txs).await?;
Ok(GetTransactionPoolStatsResponse { Ok(GetTransactionPoolStatsResponse {
base: AccessResponseBase::OK, base: helper::access_response_base(false),
..todo!() 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: ResponseBase::OK, base: helper::response_base(false),
..todo!() ..todo!()
}) })
} }
/// <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 {
base: ResponseBase::OK, base: helper::response_base(false),
..todo!() ..todo!()
}) })
} }
/// <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 {
base: ResponseBase::OK, base: helper::response_base(false),
..todo!() ..todo!()
}) })
} }
/// <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 {
base: ResponseBase::OK, base: helper::response_base(false),
..todo!() ..todo!()
}) })
} }
/// <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: ResponseBase::OK, base: helper::response_base(false),
..todo!() ..todo!()
}) })
} }
@ -678,22 +627,11 @@ async fn get_outs(
// TODO: check txpool // TODO: check txpool
Ok(GetOutsResponse { Ok(GetOutsResponse {
base: ResponseBase::OK, base: helper::response_base(false),
outs, outs,
}) })
} }
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3139-L3240>
async fn update(
state: CupratedRpcHandler,
request: UpdateRequest,
) -> Result<UpdateResponse, Error> {
Ok(UpdateResponse {
base: ResponseBase::OK,
..todo!()
})
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3242-L3252> /// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3242-L3252>
async fn pop_blocks( async fn pop_blocks(
mut state: CupratedRpcHandler, mut state: CupratedRpcHandler,
@ -703,29 +641,97 @@ async fn pop_blocks(
blockchain_manager::pop_blocks(&mut state.blockchain_manager, request.nblocks).await?; blockchain_manager::pop_blocks(&mut state.blockchain_manager, request.nblocks).await?;
Ok(PopBlocksResponse { Ok(PopBlocksResponse {
base: ResponseBase::OK, base: helper::response_base(false),
height, height,
}) })
} }
/// <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: ResponseBase::OK, base: helper::response_base(false),
..todo!() ..todo!()
}) })
} }
/// <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 {
base: ResponseBase::OK, base: helper::response_base(false),
..todo!() ..todo!()
}) })
} }
//---------------------------------------------------------------------------------------------------- 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(
state: CupratedRpcHandler,
request: SetBootstrapDaemonRequest,
) -> Result<SetBootstrapDaemonResponse, Error> {
todo!();
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L3139-L3240>
async fn update(
state: CupratedRpcHandler,
request: UpdateRequest,
) -> Result<UpdateResponse, Error> {
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,
request: StartMiningRequest,
) -> Result<StartMiningResponse, Error> {
unreachable!()
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1464-L1482>
async fn stop_mining(
state: CupratedRpcHandler,
request: StopMiningRequest,
) -> Result<StopMiningResponse, Error> {
unreachable!();
}
/// <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.cpp#L1484-L1523>
async fn mining_status(
state: CupratedRpcHandler,
request: MiningStatusRequest,
) -> 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

@ -1,11 +1,14 @@
//! Functions to send [`AddressBookRequest`]s. //! Functions to send [`AddressBookRequest`]s.
use std::net::SocketAddrV4;
use anyhow::{anyhow, Error}; use anyhow::{anyhow, Error};
use cuprate_types::rpc::Peer;
use tower::ServiceExt; use tower::ServiceExt;
use cuprate_helper::cast::usize_to_u64; use cuprate_helper::{cast::usize_to_u64, map::u32_from_ipv4};
use cuprate_p2p_core::{ use cuprate_p2p_core::{
services::{AddressBookRequest, AddressBookResponse}, services::{AddressBookRequest, AddressBookResponse, ZoneSpecificPeerListEntryBase},
types::{BanState, ConnectionId}, types::{BanState, ConnectionId},
AddressBook, NetworkZone, AddressBook, NetworkZone,
}; };
@ -161,3 +164,62 @@ pub(crate) async fn get_bans<Z: NetworkZone>(
Ok(bans) Ok(bans)
} }
/// [`AddressBookRequest::Peerlist`]
pub(crate) async fn peerlist<Z: NetworkZone>(
address_book: &mut impl AddressBook<Z>,
) -> Result<(Vec<Peer>, Vec<Peer>), Error> {
let AddressBookResponse::Peerlist(peerlist) = address_book
.ready()
.await
.map_err(|e| anyhow!(e))?
.call(AddressBookRequest::Peerlist)
.await
.map_err(|e| anyhow!(e))?
else {
unreachable!();
};
fn map<Z: NetworkZone>(peers: Vec<ZoneSpecificPeerListEntryBase<Z::Addr>>) -> Vec<Peer> {
peers
.into_iter()
.map(|peer| {
let ZoneSpecificPeerListEntryBase {
adr,
id,
last_seen,
pruning_seed,
rpc_port,
rpc_credits_per_hash,
} = peer;
let host = adr.to_string();
let (ip, port) = if let Ok(socket_addr) = host.parse::<SocketAddrV4>() {
(u32_from_ipv4(*socket_addr.ip()), socket_addr.port())
} else {
(0, 0)
};
let last_seen = last_seen.try_into().unwrap_or(0);
let pruning_seed = pruning_seed.compress();
Peer {
id,
host,
ip,
port,
rpc_port,
rpc_credits_per_hash,
last_seen,
pruning_seed,
}
})
.collect()
}
let white = map::<Z>(peerlist.white);
let grey = map::<Z>(peerlist.grey);
Ok((white, grey))
}

View file

@ -242,3 +242,31 @@ pub(crate) async fn create_block_template(
Ok(block_template) Ok(block_template)
} }
/// [`BlockchainManagerRequest::Sync`]
pub(crate) async fn sync(blockchain_manager: &mut BlockchainManagerHandle) -> Result<(), Error> {
let BlockchainManagerResponse::Ok = blockchain_manager
.ready()
.await?
.call(BlockchainManagerRequest::Sync)
.await?
else {
unreachable!();
};
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},
@ -15,7 +16,7 @@ use cuprate_txpool::{
TxEntry, TxEntry,
}; };
use cuprate_types::{ use cuprate_types::{
rpc::{PoolInfo, PoolInfoFull, PoolInfoIncremental, PoolTxInfo}, rpc::{PoolInfo, PoolInfoFull, PoolInfoIncremental, PoolTxInfo, TxpoolStats},
TxInPool, TxRelayChecks, TxInPool, TxRelayChecks,
}; };
@ -129,6 +130,54 @@ 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
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 /// TODO
pub(crate) async fn flush( pub(crate) async fn flush(
txpool_manager: &mut Infallible, txpool_manager: &mut Infallible,

View file

@ -420,7 +420,8 @@ impl<Z: BorshNetworkZone> Service<AddressBookRequest<Z>> for AddressBook<Z> {
AddressBookRequest::GetBan(addr) => Ok(AddressBookResponse::GetBan { AddressBookRequest::GetBan(addr) => Ok(AddressBookResponse::GetBan {
unban_instant: self.peer_unban_instant(&addr).map(Instant::into_std), unban_instant: self.peer_unban_instant(&addr).map(Instant::into_std),
}), }),
AddressBookRequest::PeerlistSize AddressBookRequest::Peerlist
| AddressBookRequest::PeerlistSize
| AddressBookRequest::ConnectionCount | AddressBookRequest::ConnectionCount
| AddressBookRequest::SetBan(_) | AddressBookRequest::SetBan(_)
| AddressBookRequest::GetBans | AddressBookRequest::GetBans

View file

@ -108,7 +108,8 @@ impl<N: NetworkZone> Service<AddressBookRequest<N>> for DummyAddressBook {
AddressBookRequest::GetBan(_) => AddressBookResponse::GetBan { AddressBookRequest::GetBan(_) => AddressBookResponse::GetBan {
unban_instant: None, unban_instant: None,
}, },
AddressBookRequest::PeerlistSize AddressBookRequest::Peerlist
| AddressBookRequest::PeerlistSize
| AddressBookRequest::ConnectionCount | AddressBookRequest::ConnectionCount
| AddressBookRequest::SetBan(_) | AddressBookRequest::SetBan(_)
| AddressBookRequest::GetBans | AddressBookRequest::GetBans

View file

@ -6,7 +6,7 @@ use cuprate_wire::{CoreSyncData, PeerListEntryBase};
use crate::{ use crate::{
client::InternalPeerID, client::InternalPeerID,
handles::ConnectionHandle, handles::ConnectionHandle,
types::{BanState, ConnectionInfo, SetBan}, types::{BanState, ConnectionInfo, Peerlist, SetBan},
NetZoneAddress, NetworkAddressIncorrectZone, NetworkZone, NetZoneAddress, NetworkAddressIncorrectZone, NetworkZone,
}; };
@ -115,6 +115,9 @@ pub enum AddressBookRequest<Z: NetworkZone> {
/// Gets the specified number of white peers, or less if we don't have enough. /// Gets the specified number of white peers, or less if we don't have enough.
GetWhitePeers(usize), GetWhitePeers(usize),
/// Get info on all peers, white & grey.
Peerlist,
/// Get the amount of white & grey peers. /// Get the amount of white & grey peers.
PeerlistSize, PeerlistSize,
@ -152,6 +155,9 @@ pub enum AddressBookResponse<Z: NetworkZone> {
/// Response to [`AddressBookRequest::GetWhitePeers`]. /// Response to [`AddressBookRequest::GetWhitePeers`].
Peers(Vec<ZoneSpecificPeerListEntryBase<Z::Addr>>), Peers(Vec<ZoneSpecificPeerListEntryBase<Z::Addr>>),
/// Response to [`AddressBookRequest::Peerlist`].
Peerlist(Peerlist<Z::Addr>),
/// Response to [`AddressBookRequest::PeerlistSize`]. /// Response to [`AddressBookRequest::PeerlistSize`].
PeerlistSize { white: usize, grey: usize }, PeerlistSize { white: usize, grey: usize },

View file

@ -5,7 +5,7 @@ use std::time::{Duration, Instant};
use cuprate_pruning::PruningSeed; use cuprate_pruning::PruningSeed;
use cuprate_types::{AddressType, ConnectionState}; use cuprate_types::{AddressType, ConnectionState};
use crate::NetZoneAddress; use crate::{NetZoneAddress, ZoneSpecificPeerListEntryBase};
/// Data within [`crate::services::AddressBookRequest::SetBan`]. /// Data within [`crate::services::AddressBookRequest::SetBan`].
pub struct SetBan<A: NetZoneAddress> { pub struct SetBan<A: NetZoneAddress> {
@ -94,3 +94,10 @@ pub struct Span<A: NetZoneAddress> {
pub speed: u32, pub speed: u32,
pub start_block_height: u64, pub start_block_height: u64,
} }
/// Used in RPC's `/get_peer_list`.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Peerlist<A: NetZoneAddress> {
pub white: Vec<ZoneSpecificPeerListEntryBase<A>>,
pub grey: Vec<ZoneSpecificPeerListEntryBase<A>>,
}

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, TxpoolStats},
TransactionVerificationData, TxInPool,
};
use crate::{ use crate::{
tx::TxEntry, tx::TxEntry,
@ -64,6 +67,12 @@ 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 },
/// TODO
PoolStats { include_sensitive_txs: bool },
} }
//---------------------------------------------------------------------------------------------------- TxpoolReadResponse //---------------------------------------------------------------------------------------------------- TxpoolReadResponse
@ -112,6 +121,15 @@ 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>,
},
/// Response to [`TxpoolReadRequest::PoolStats`].
PoolStats(TxpoolStats),
} }
//---------------------------------------------------------------------------------------------------- TxpoolWriteRequest //---------------------------------------------------------------------------------------------------- TxpoolWriteRequest

View file

@ -89,6 +89,12 @@ 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),
TxpoolReadRequest::PoolStats {
include_sensitive_txs,
} => pool_stats(env, include_sensitive_txs),
} }
} }
@ -249,3 +255,16 @@ 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!(),
})
}
/// [`TxpoolReadRequest::PoolStats`].
fn pool_stats(env: &ConcreteEnv, include_sensitive_txs: bool) -> ReadResponseResult {
Ok(TxpoolReadResponse::PoolStats(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!(