Respect maximum amount of outs per request

This commit is contained in:
Luke Parker
2024-07-14 20:28:10 -04:00
parent 0cb24dde02
commit 8e7e61adbd

View File

@@ -33,10 +33,15 @@ use monero_serai::{
use monero_address::Address;
// Number of blocks the fee estimate will be valid for
// https://github.com/monero-project/monero/blob/94e67bf96bbc010241f29ada6abc89f49a81759c/
// src/wallet/wallet2.cpp#L121
// https://github.com/monero-project/monero/blob/94e67bf96bbc010241f29ada6abc89f49a81759c
// /src/wallet/wallet2.cpp#L121
const GRACE_BLOCKS_FOR_FEE_ESTIMATE: u64 = 10;
// Monero errors if more than 100 is requested unless using a non-restricted RPC
// https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454
// /src/rpc/core_rpc_server.cpp#L75
const TXS_PER_REQUEST: usize = 100;
/// An error from the RPC.
#[derive(Clone, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
@@ -335,8 +340,6 @@ pub trait Rpc: Sync + Clone + Debug {
let mut hashes_hex = hashes.iter().map(hex::encode).collect::<Vec<_>>();
let mut all_txs = Vec::with_capacity(hashes.len());
while !hashes_hex.is_empty() {
// Monero errors if more than 100 is requested unless using a non-restricted RPC
const TXS_PER_REQUEST: usize = 100;
let this_count = TXS_PER_REQUEST.min(hashes_hex.len());
let txs: TransactionsResponse = self
@@ -404,10 +407,6 @@ pub trait Rpc: Sync + Clone + Debug {
let mut hashes_hex = hashes.iter().map(hex::encode).collect::<Vec<_>>();
let mut all_txs = Vec::with_capacity(hashes.len());
while !hashes_hex.is_empty() {
// Monero errors if more than 100 is requested unless using a non-restricted RPC
// TODO: Cite
// TODO: Deduplicate with above
const TXS_PER_REQUEST: usize = 100;
let this_count = TXS_PER_REQUEST.min(hashes_hex.len());
let txs: TransactionsResponse = self
@@ -993,7 +992,13 @@ impl<R: Rpc> DecoyRpc for R {
outs: Vec<OutputResponse>,
}
let res: OutsResponse = self
// https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454
// /src/rpc/core_rpc_server.cpp#L67
const MAX_OUTS: usize = 5000;
let mut res = Vec::with_capacity(indexes.len());
for indexes in indexes.chunks(MAX_OUTS) {
let rpc_res: OutsResponse = self
.rpc_call(
"get_outs",
Some(json!({
@@ -1006,12 +1011,12 @@ impl<R: Rpc> DecoyRpc for R {
)
.await?;
if res.status != "OK" {
if rpc_res.status != "OK" {
Err(RpcError::InvalidNode("bad response to get_outs".to_string()))?;
}
Ok(
res
res.extend(
rpc_res
.outs
.into_iter()
.map(|output| {
@@ -1028,7 +1033,10 @@ impl<R: Rpc> DecoyRpc for R {
})
})
.collect::<Result<Vec<_>, RpcError>>()?,
)
);
}
Ok(res)
}
async fn get_unlocked_outputs(