mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-22 19:49:33 +00:00
Compare commits
4 commits
d4b30333bb
...
805f475083
Author | SHA1 | Date | |
---|---|---|---|
|
805f475083 | ||
|
c5abf9bb98 | ||
|
c924f24765 | ||
|
b3314d4981 |
16 changed files with 432 additions and 198 deletions
|
@ -110,7 +110,7 @@ async fn get_blocks(
|
|||
}
|
||||
|
||||
Ok(GetBlocksResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
blocks: todo!(),
|
||||
start_height: todo!(),
|
||||
current_height: todo!(),
|
||||
|
@ -136,7 +136,7 @@ async fn get_blocks_by_height(
|
|||
.collect::<Result<Vec<BlockCompleteEntry>, Error>>()?;
|
||||
|
||||
Ok(GetBlocksByHeightResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
blocks,
|
||||
})
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ async fn get_hashes(
|
|||
let m_blocks_ids = bytes.split_off(index);
|
||||
|
||||
Ok(GetHashesResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
m_blocks_ids,
|
||||
start_height,
|
||||
current_height,
|
||||
|
@ -191,7 +191,7 @@ async fn get_output_indexes(
|
|||
request: GetOutputIndexesRequest,
|
||||
) -> Result<GetOutputIndexesResponse, Error> {
|
||||
Ok(GetOutputIndexesResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
..todo!()
|
||||
})
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ async fn get_outs(
|
|||
request: GetOutsRequest,
|
||||
) -> Result<GetOutsResponse, Error> {
|
||||
Ok(GetOutsResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
..todo!()
|
||||
})
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ async fn get_transaction_pool_hashes(
|
|||
request: GetTransactionPoolHashesRequest,
|
||||
) -> Result<GetTransactionPoolHashesResponse, Error> {
|
||||
Ok(GetTransactionPoolHashesResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
..todo!()
|
||||
})
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ async fn get_output_distribution(
|
|||
request: GetOutputDistributionRequest,
|
||||
) -> Result<GetOutputDistributionResponse, Error> {
|
||||
Ok(GetOutputDistributionResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
..todo!()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -41,6 +41,9 @@ pub enum BlockchainManagerRequest {
|
|||
Box<Block>,
|
||||
),
|
||||
|
||||
/// TODO
|
||||
Sync,
|
||||
|
||||
/// Is the blockchain in the middle of syncing?
|
||||
///
|
||||
/// This returning `false` does not necessarily
|
||||
|
@ -92,6 +95,9 @@ pub enum BlockchainManagerRequest {
|
|||
account_public_address: String,
|
||||
extra_nonce: Vec<u8>,
|
||||
},
|
||||
|
||||
/// TODO
|
||||
Stop,
|
||||
}
|
||||
|
||||
/// TODO: use real type when public.
|
||||
|
@ -102,6 +108,7 @@ pub enum BlockchainManagerResponse {
|
|||
/// Response to:
|
||||
/// - [`BlockchainManagerRequest::Prune`]
|
||||
/// - [`BlockchainManagerRequest::RelayBlock`]
|
||||
/// - [`BlockchainManagerRequest::Sync`]
|
||||
Ok,
|
||||
|
||||
/// Response to [`BlockchainManagerRequest::PopBlocks`]
|
||||
|
|
|
@ -11,7 +11,10 @@ use cuprate_helper::{
|
|||
cast::{u64_to_usize, usize_to_u64},
|
||||
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 crate::{
|
||||
|
@ -166,3 +169,21 @@ pub(super) async fn top_height(state: &mut CupratedRpcHandler) -> Result<(u64, [
|
|||
let height = chain_height.saturating_sub(1);
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -193,7 +193,7 @@ async fn get_block_template(
|
|||
let wide_difficulty = (difficulty, difficulty_top64).hex_prefix();
|
||||
|
||||
Ok(GetBlockTemplateResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
blockhashing_blob,
|
||||
blocktemplate_blob,
|
||||
difficulty_top64,
|
||||
|
@ -215,7 +215,7 @@ async fn get_block_count(
|
|||
_: GetBlockCountRequest,
|
||||
) -> Result<GetBlockCountResponse, Error> {
|
||||
Ok(GetBlockCountResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
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?;
|
||||
|
||||
Ok(SubmitBlockResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
block_id,
|
||||
})
|
||||
}
|
||||
|
@ -288,7 +288,7 @@ async fn generate_blocks(
|
|||
let blocks = blocks.into_iter().map(Hex).collect();
|
||||
|
||||
Ok(GenerateBlocksResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
blocks,
|
||||
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?;
|
||||
|
||||
Ok(GetLastBlockHeaderResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
block_header,
|
||||
})
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ async fn get_block_header_by_hash(
|
|||
}
|
||||
|
||||
Ok(GetBlockHeaderByHashResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
block_header,
|
||||
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?;
|
||||
|
||||
Ok(GetBlockHeaderByHeightResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
block_header,
|
||||
})
|
||||
}
|
||||
|
@ -409,7 +409,7 @@ async fn get_block_headers_range(
|
|||
}
|
||||
|
||||
Ok(GetBlockHeadersRangeResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
headers,
|
||||
})
|
||||
}
|
||||
|
@ -442,7 +442,7 @@ async fn get_block(
|
|||
};
|
||||
|
||||
Ok(GetBlockResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
blob,
|
||||
json,
|
||||
miner_tx_hash,
|
||||
|
@ -459,7 +459,7 @@ async fn get_connections(
|
|||
let connections = address_book::connection_info::<ClearNet>(&mut DummyAddressBook).await?;
|
||||
|
||||
Ok(GetConnectionsResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
connections,
|
||||
})
|
||||
}
|
||||
|
@ -557,7 +557,7 @@ async fn get_info(
|
|||
let wide_difficulty = format!("{:#x}", c.next_difficulty);
|
||||
|
||||
Ok(GetInfoResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
adjusted_time,
|
||||
alt_blocks_count,
|
||||
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?;
|
||||
|
||||
Ok(HardForkInfoResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
earliest_height: info.earliest_height,
|
||||
enabled: info.enabled,
|
||||
state: info.state,
|
||||
|
@ -654,7 +654,7 @@ async fn set_bans(
|
|||
}
|
||||
|
||||
Ok(SetBansResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -694,7 +694,7 @@ async fn get_bans(state: CupratedRpcHandler, _: GetBansRequest) -> Result<GetBan
|
|||
.collect();
|
||||
|
||||
Ok(GetBansResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
bans,
|
||||
})
|
||||
}
|
||||
|
@ -777,7 +777,7 @@ async fn get_output_histogram(
|
|||
.collect();
|
||||
|
||||
Ok(GetOutputHistogramResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
histogram,
|
||||
})
|
||||
}
|
||||
|
@ -800,7 +800,7 @@ async fn get_coinbase_tx_sum(
|
|||
let wide_fee_amount = format!("{emission_amount:#x}");
|
||||
|
||||
Ok(GetCoinbaseTxSumResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
emission_amount,
|
||||
emission_amount_top64,
|
||||
fee_amount,
|
||||
|
@ -835,7 +835,7 @@ async fn get_version(
|
|||
}
|
||||
|
||||
Ok(GetVersionResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
version: CORE_RPC_VERSION,
|
||||
release: RELEASE,
|
||||
current_height,
|
||||
|
@ -854,7 +854,7 @@ async fn get_fee_estimate(
|
|||
.await?;
|
||||
|
||||
Ok(GetFeeEstimateResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
fee: estimate.fee,
|
||||
fees: estimate.fees,
|
||||
quantization_mask: estimate.quantization_mask,
|
||||
|
@ -873,7 +873,7 @@ async fn get_alternate_chains(
|
|||
.collect();
|
||||
|
||||
Ok(GetAlternateChainsResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
chains,
|
||||
})
|
||||
}
|
||||
|
@ -925,7 +925,7 @@ async fn sync_info(
|
|||
let overview = String::from(FIELD_NOT_SUPPORTED);
|
||||
|
||||
Ok(SyncInfoResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
height,
|
||||
next_needed_pruning_seed,
|
||||
overview,
|
||||
|
@ -951,7 +951,7 @@ async fn get_transaction_pool_backlog(
|
|||
.collect();
|
||||
|
||||
Ok(GetTransactionPoolBacklogResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
backlog,
|
||||
})
|
||||
}
|
||||
|
@ -984,7 +984,7 @@ async fn get_output_distribution(
|
|||
}).collect::<Result<Vec<Distribution>, _>>()?;
|
||||
|
||||
Ok(GetOutputDistributionResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
distributions,
|
||||
})
|
||||
}
|
||||
|
@ -1015,7 +1015,7 @@ async fn get_miner_data(
|
|||
.collect();
|
||||
|
||||
Ok(GetMinerDataResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
major_version,
|
||||
height,
|
||||
prev_id,
|
||||
|
@ -1038,7 +1038,7 @@ async fn prune_blockchain(
|
|||
.compress();
|
||||
|
||||
Ok(PruneBlockchainResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
pruned,
|
||||
pruning_seed,
|
||||
})
|
||||
|
@ -1090,7 +1090,7 @@ async fn flush_cache(
|
|||
// TODO: cuprated doesn't need this call; decide behavior.
|
||||
|
||||
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();
|
||||
|
||||
Ok(AddAuxPowResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
blocktemplate_blob,
|
||||
blockhashing_blob,
|
||||
merkle_root,
|
||||
|
@ -1306,7 +1306,7 @@ async fn get_tx_ids_loose(
|
|||
return Err(anyhow!("Not implemented"));
|
||||
|
||||
Ok(GetTxIdsLooseResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
txids: todo!(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
//! 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};
|
||||
|
||||
|
@ -10,6 +13,7 @@ use cuprate_constants::rpc::{
|
|||
};
|
||||
use cuprate_helper::cast::usize_to_u64;
|
||||
use cuprate_hex::Hex;
|
||||
use cuprate_p2p_core::{client::handshaker::builder::DummyAddressBook, ClearNet};
|
||||
use cuprate_rpc_interface::RpcHandler;
|
||||
use cuprate_rpc_types::{
|
||||
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`].
|
||||
pub(super) async fn map_request(
|
||||
state: CupratedRpcHandler,
|
||||
|
@ -69,9 +75,6 @@ pub(super) async fn map_request(
|
|||
Req::GetPeerList(r) => Resp::GetPeerList(get_peer_list(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::SetBootstrapDaemon(r) => {
|
||||
Resp::SetBootstrapDaemon(set_bootstrap_daemon(state, r).await?)
|
||||
}
|
||||
Req::GetTransactionPool(r) => {
|
||||
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?),
|
||||
|
||||
// Unsupported requests.
|
||||
Req::Update(_)
|
||||
Req::SetBootstrapDaemon(_)
|
||||
| Req::Update(_)
|
||||
| Req::StartMining(_)
|
||||
| Req::StopMining(_)
|
||||
| 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>
|
||||
async fn get_height(
|
||||
mut state: CupratedRpcHandler,
|
||||
request: GetHeightRequest,
|
||||
_: GetHeightRequest,
|
||||
) -> Result<GetHeightResponse, Error> {
|
||||
let (height, hash) = helper::top_height(&mut state).await?;
|
||||
let hash = Hex(hash);
|
||||
|
||||
Ok(GetHeightResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
height,
|
||||
hash,
|
||||
})
|
||||
|
@ -254,7 +258,7 @@ async fn get_transactions(
|
|||
};
|
||||
|
||||
Ok(GetTransactionsResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
txs_as_hex,
|
||||
txs_as_json,
|
||||
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>
|
||||
async fn get_alt_blocks_hashes(
|
||||
mut state: CupratedRpcHandler,
|
||||
request: GetAltBlocksHashesRequest,
|
||||
_: GetAltBlocksHashesRequest,
|
||||
) -> Result<GetAltBlocksHashesResponse, Error> {
|
||||
let blks_hashes = blockchain::alt_chains(&mut state.blockchain_read)
|
||||
.await?
|
||||
|
@ -274,7 +278,7 @@ async fn get_alt_blocks_hashes(
|
|||
.collect();
|
||||
|
||||
Ok(GetAltBlocksHashesResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
blks_hashes,
|
||||
})
|
||||
}
|
||||
|
@ -321,7 +325,7 @@ async fn is_key_image_spent(
|
|||
});
|
||||
|
||||
Ok(IsKeyImageSpentResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
spent_status,
|
||||
})
|
||||
}
|
||||
|
@ -332,7 +336,7 @@ async fn send_raw_transaction(
|
|||
request: SendRawTransactionRequest,
|
||||
) -> Result<SendRawTransactionResponse, Error> {
|
||||
let mut resp = SendRawTransactionResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
base: helper::access_response_base(false),
|
||||
double_spend: false,
|
||||
fee_too_low: false,
|
||||
invalid_input: false,
|
||||
|
@ -354,20 +358,20 @@ async fn send_raw_transaction(
|
|||
};
|
||||
|
||||
if request.do_sanity_checks {
|
||||
// FIXME: these checks could be defined elsewhere.
|
||||
//
|
||||
// <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> {
|
||||
let Some(input) = tx.prefix().inputs.get(0) else {
|
||||
return Err("No inputs");
|
||||
/// FIXME: these checks could be defined elsewhere.
|
||||
///
|
||||
/// <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<(), String> {
|
||||
let Some(input) = tx.prefix().inputs.first() else {
|
||||
return Err("No inputs".to_string());
|
||||
};
|
||||
|
||||
let mut rct_indices = BTreeSet::new();
|
||||
let n_indices: usize = 0;
|
||||
let mut rct_indices = vec![];
|
||||
let mut n_indices: usize = 0;
|
||||
|
||||
for input in tx.prefix().inputs {
|
||||
for input in &tx.prefix().inputs {
|
||||
match input {
|
||||
Input::Gen(_) => return Err("Transaction is coinbase"),
|
||||
Input::Gen(_) => return Err("Transaction is coinbase".to_string()),
|
||||
Input::ToKey {
|
||||
amount,
|
||||
key_offsets,
|
||||
|
@ -377,8 +381,19 @@ async fn send_raw_transaction(
|
|||
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();
|
||||
let absolute = todo!();
|
||||
let absolute = relative_output_offsets_to_absolute(key_offsets.clone());
|
||||
rct_indices.extend(absolute);
|
||||
}
|
||||
}
|
||||
|
@ -394,13 +409,12 @@ async fn send_raw_transaction(
|
|||
|
||||
let rct_indices_len = rct_indices.len();
|
||||
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 = todo!();
|
||||
let median = cuprate_helper::num::median(rct_indices);
|
||||
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(())
|
||||
|
@ -458,46 +472,10 @@ async fn send_raw_transaction(
|
|||
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>
|
||||
async fn save_bc(
|
||||
state: CupratedRpcHandler,
|
||||
request: SaveBcRequest,
|
||||
) -> Result<SaveBcResponse, Error> {
|
||||
todo!();
|
||||
async fn save_bc(mut state: CupratedRpcHandler, _: SaveBcRequest) -> Result<SaveBcResponse, Error> {
|
||||
blockchain_manager::sync(&mut state.blockchain_manager).await?;
|
||||
|
||||
Ok(SaveBcResponse {
|
||||
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>
|
||||
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?;
|
||||
|
||||
Ok(GetPeerListResponse {
|
||||
base: ResponseBase::OK,
|
||||
..todo!()
|
||||
base: helper::response_base(false),
|
||||
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>
|
||||
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: AccessResponseBase::OK,
|
||||
..todo!()
|
||||
base: helper::access_response_base(false),
|
||||
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> {
|
||||
let include_sensitive_txs = !state.is_restricted();
|
||||
|
||||
let pool_stats = txpool::pool_stats(&mut state.txpool_read, include_sensitive_txs).await?;
|
||||
|
||||
Ok(GetTransactionPoolStatsResponse {
|
||||
base: AccessResponseBase::OK,
|
||||
..todo!()
|
||||
base: helper::access_response_base(false),
|
||||
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: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
..todo!()
|
||||
})
|
||||
}
|
||||
|
||||
/// <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 {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
..todo!()
|
||||
})
|
||||
}
|
||||
|
||||
/// <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 {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
..todo!()
|
||||
})
|
||||
}
|
||||
|
||||
/// <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 {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
..todo!()
|
||||
})
|
||||
}
|
||||
|
||||
/// <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: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
..todo!()
|
||||
})
|
||||
}
|
||||
|
@ -678,22 +627,11 @@ async fn get_outs(
|
|||
// TODO: check txpool
|
||||
|
||||
Ok(GetOutsResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
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>
|
||||
async fn pop_blocks(
|
||||
mut state: CupratedRpcHandler,
|
||||
|
@ -703,29 +641,97 @@ async fn pop_blocks(
|
|||
blockchain_manager::pop_blocks(&mut state.blockchain_manager, request.nblocks).await?;
|
||||
|
||||
Ok(PopBlocksResponse {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
height,
|
||||
})
|
||||
}
|
||||
|
||||
/// <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: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
..todo!()
|
||||
})
|
||||
}
|
||||
|
||||
/// <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 {
|
||||
base: ResponseBase::OK,
|
||||
base: helper::response_base(false),
|
||||
..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!();
|
||||
}
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
//! Functions to send [`AddressBookRequest`]s.
|
||||
|
||||
use std::net::SocketAddrV4;
|
||||
|
||||
use anyhow::{anyhow, Error};
|
||||
use cuprate_types::rpc::Peer;
|
||||
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::{
|
||||
services::{AddressBookRequest, AddressBookResponse},
|
||||
services::{AddressBookRequest, AddressBookResponse, ZoneSpecificPeerListEntryBase},
|
||||
types::{BanState, ConnectionId},
|
||||
AddressBook, NetworkZone,
|
||||
};
|
||||
|
@ -161,3 +164,62 @@ pub(crate) async fn get_bans<Z: NetworkZone>(
|
|||
|
||||
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))
|
||||
}
|
||||
|
|
|
@ -242,3 +242,31 @@ pub(crate) async fn create_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(())
|
||||
}
|
||||
|
|
|
@ -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},
|
||||
|
@ -15,7 +16,7 @@ use cuprate_txpool::{
|
|||
TxEntry,
|
||||
};
|
||||
use cuprate_types::{
|
||||
rpc::{PoolInfo, PoolInfoFull, PoolInfoIncremental, PoolTxInfo},
|
||||
rpc::{PoolInfo, PoolInfoFull, PoolInfoIncremental, PoolTxInfo, TxpoolStats},
|
||||
TxInPool, TxRelayChecks,
|
||||
};
|
||||
|
||||
|
@ -129,6 +130,54 @@ 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 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,
|
||||
|
|
|
@ -420,7 +420,8 @@ impl<Z: BorshNetworkZone> Service<AddressBookRequest<Z>> for AddressBook<Z> {
|
|||
AddressBookRequest::GetBan(addr) => Ok(AddressBookResponse::GetBan {
|
||||
unban_instant: self.peer_unban_instant(&addr).map(Instant::into_std),
|
||||
}),
|
||||
AddressBookRequest::PeerlistSize
|
||||
AddressBookRequest::Peerlist
|
||||
| AddressBookRequest::PeerlistSize
|
||||
| AddressBookRequest::ConnectionCount
|
||||
| AddressBookRequest::SetBan(_)
|
||||
| AddressBookRequest::GetBans
|
||||
|
|
|
@ -108,7 +108,8 @@ impl<N: NetworkZone> Service<AddressBookRequest<N>> for DummyAddressBook {
|
|||
AddressBookRequest::GetBan(_) => AddressBookResponse::GetBan {
|
||||
unban_instant: None,
|
||||
},
|
||||
AddressBookRequest::PeerlistSize
|
||||
AddressBookRequest::Peerlist
|
||||
| AddressBookRequest::PeerlistSize
|
||||
| AddressBookRequest::ConnectionCount
|
||||
| AddressBookRequest::SetBan(_)
|
||||
| AddressBookRequest::GetBans
|
||||
|
|
|
@ -6,7 +6,7 @@ use cuprate_wire::{CoreSyncData, PeerListEntryBase};
|
|||
use crate::{
|
||||
client::InternalPeerID,
|
||||
handles::ConnectionHandle,
|
||||
types::{BanState, ConnectionInfo, SetBan},
|
||||
types::{BanState, ConnectionInfo, Peerlist, SetBan},
|
||||
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.
|
||||
GetWhitePeers(usize),
|
||||
|
||||
/// Get info on all peers, white & grey.
|
||||
Peerlist,
|
||||
|
||||
/// Get the amount of white & grey peers.
|
||||
PeerlistSize,
|
||||
|
||||
|
@ -152,6 +155,9 @@ pub enum AddressBookResponse<Z: NetworkZone> {
|
|||
/// Response to [`AddressBookRequest::GetWhitePeers`].
|
||||
Peers(Vec<ZoneSpecificPeerListEntryBase<Z::Addr>>),
|
||||
|
||||
/// Response to [`AddressBookRequest::Peerlist`].
|
||||
Peerlist(Peerlist<Z::Addr>),
|
||||
|
||||
/// Response to [`AddressBookRequest::PeerlistSize`].
|
||||
PeerlistSize { white: usize, grey: usize },
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::time::{Duration, Instant};
|
|||
use cuprate_pruning::PruningSeed;
|
||||
use cuprate_types::{AddressType, ConnectionState};
|
||||
|
||||
use crate::NetZoneAddress;
|
||||
use crate::{NetZoneAddress, ZoneSpecificPeerListEntryBase};
|
||||
|
||||
/// Data within [`crate::services::AddressBookRequest::SetBan`].
|
||||
pub struct SetBan<A: NetZoneAddress> {
|
||||
|
@ -94,3 +94,10 @@ pub struct Span<A: NetZoneAddress> {
|
|||
pub speed: u32,
|
||||
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>>,
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,10 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
|
||||
use cuprate_types::{rpc::PoolInfo, TransactionVerificationData, TxInPool};
|
||||
use cuprate_types::{
|
||||
rpc::{PoolInfo, SpentKeyImageInfo, TxInfo, TxpoolStats},
|
||||
TransactionVerificationData, TxInPool,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
tx::TxEntry,
|
||||
|
@ -64,6 +67,12 @@ pub enum TxpoolReadRequest {
|
|||
key_images: Vec<[u8; 32]>,
|
||||
include_sensitive_txs: bool,
|
||||
},
|
||||
|
||||
/// TODO
|
||||
Pool { include_sensitive_txs: bool },
|
||||
|
||||
/// TODO
|
||||
PoolStats { include_sensitive_txs: bool },
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- TxpoolReadResponse
|
||||
|
@ -112,6 +121,15 @@ pub enum TxpoolReadResponse {
|
|||
|
||||
/// Response to [`TxpoolReadRequest::KeyImagesSpent`].
|
||||
KeyImagesSpent(Vec<bool>),
|
||||
|
||||
/// Response to [`TxpoolReadRequest::Pool`].
|
||||
Pool {
|
||||
txs: Vec<TxInfo>,
|
||||
spent_key_images: Vec<SpentKeyImageInfo>,
|
||||
},
|
||||
|
||||
/// Response to [`TxpoolReadRequest::PoolStats`].
|
||||
PoolStats(TxpoolStats),
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- TxpoolWriteRequest
|
||||
|
|
|
@ -89,6 +89,12 @@ 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),
|
||||
TxpoolReadRequest::PoolStats {
|
||||
include_sensitive_txs,
|
||||
} => pool_stats(env, include_sensitive_txs),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -249,3 +255,16 @@ 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!(),
|
||||
})
|
||||
}
|
||||
|
||||
/// [`TxpoolReadRequest::PoolStats`].
|
||||
fn pool_stats(env: &ConcreteEnv, include_sensitive_txs: bool) -> ReadResponseResult {
|
||||
Ok(TxpoolReadResponse::PoolStats(todo!()))
|
||||
}
|
||||
|
|
|
@ -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!(
|
||||
|
|
Loading…
Reference in a new issue