Respect maximum amount of outs per request
Some checks failed
coins/ Tests / test-coins (push) Has been cancelled
Coordinator Tests / build (push) Has been cancelled
Full Stack Tests / build (push) Has been cancelled
Lint / clippy (macos-13) (push) Has been cancelled
Lint / clippy (macos-14) (push) Has been cancelled
Lint / clippy (ubuntu-latest) (push) Has been cancelled
Lint / clippy (windows-latest) (push) Has been cancelled
Lint / deny (push) Has been cancelled
Lint / fmt (push) Has been cancelled
Lint / machete (push) Has been cancelled
Monero Tests / unit-tests (push) Has been cancelled
Tests / test-infra (push) Has been cancelled
Tests / test-substrate (push) Has been cancelled
Tests / test-serai-client (push) Has been cancelled
Monero Tests / integration-tests (v0.17.3.2) (push) Has been cancelled
Monero Tests / integration-tests (v0.18.2.0) (push) Has been cancelled
no-std build / build (push) Has been cancelled
Processor Tests / build (push) Has been cancelled
Reproducible Runtime / build (push) Has been cancelled

This commit is contained in:
Luke Parker 2024-07-14 20:28:10 -04:00
parent 0cb24dde02
commit 8e7e61adbd
No known key found for this signature in database

View file

@ -33,10 +33,15 @@ use monero_serai::{
use monero_address::Address; use monero_address::Address;
// Number of blocks the fee estimate will be valid for // Number of blocks the fee estimate will be valid for
// https://github.com/monero-project/monero/blob/94e67bf96bbc010241f29ada6abc89f49a81759c/ // https://github.com/monero-project/monero/blob/94e67bf96bbc010241f29ada6abc89f49a81759c
// src/wallet/wallet2.cpp#L121 // /src/wallet/wallet2.cpp#L121
const GRACE_BLOCKS_FOR_FEE_ESTIMATE: u64 = 10; 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. /// An error from the RPC.
#[derive(Clone, PartialEq, Eq, Debug)] #[derive(Clone, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "std", derive(thiserror::Error))] #[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 hashes_hex = hashes.iter().map(hex::encode).collect::<Vec<_>>();
let mut all_txs = Vec::with_capacity(hashes.len()); let mut all_txs = Vec::with_capacity(hashes.len());
while !hashes_hex.is_empty() { 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 this_count = TXS_PER_REQUEST.min(hashes_hex.len());
let txs: TransactionsResponse = self 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 hashes_hex = hashes.iter().map(hex::encode).collect::<Vec<_>>();
let mut all_txs = Vec::with_capacity(hashes.len()); let mut all_txs = Vec::with_capacity(hashes.len());
while !hashes_hex.is_empty() { 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 this_count = TXS_PER_REQUEST.min(hashes_hex.len());
let txs: TransactionsResponse = self let txs: TransactionsResponse = self
@ -993,7 +992,13 @@ impl<R: Rpc> DecoyRpc for R {
outs: Vec<OutputResponse>, 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( .rpc_call(
"get_outs", "get_outs",
Some(json!({ Some(json!({
@ -1006,12 +1011,12 @@ impl<R: Rpc> DecoyRpc for R {
) )
.await?; .await?;
if res.status != "OK" { if rpc_res.status != "OK" {
Err(RpcError::InvalidNode("bad response to get_outs".to_string()))?; Err(RpcError::InvalidNode("bad response to get_outs".to_string()))?;
} }
Ok( res.extend(
res rpc_res
.outs .outs
.into_iter() .into_iter()
.map(|output| { .map(|output| {
@ -1028,7 +1033,10 @@ impl<R: Rpc> DecoyRpc for R {
}) })
}) })
.collect::<Result<Vec<_>, RpcError>>()?, .collect::<Result<Vec<_>, RpcError>>()?,
) );
}
Ok(res)
} }
async fn get_unlocked_outputs( async fn get_unlocked_outputs(