mirror of
https://github.com/serai-dex/serai.git
synced 2025-01-18 16:55:16 +00:00
Modify get_transactions to split requests as to not hit the restricted RPC limits
This commit is contained in:
parent
93fe8a52dd
commit
3c6cc42c23
2 changed files with 39 additions and 25 deletions
|
@ -44,18 +44,23 @@ async fn check_block(rpc: Arc<Rpc<HttpRpc>>, block_i: usize) {
|
|||
txs: Vec<TransactionResponse>,
|
||||
}
|
||||
|
||||
let mut hashes_hex = block.txs.iter().map(hex::encode).collect::<Vec<_>>();
|
||||
let mut all_txs = vec![];
|
||||
while !hashes_hex.is_empty() {
|
||||
let txs: TransactionsResponse = rpc
|
||||
.rpc_call(
|
||||
"get_transactions",
|
||||
Some(json!({
|
||||
"txs_hashes": block.txs.iter().map(hex::encode).collect::<Vec<_>>()
|
||||
"txs_hashes": hashes_hex.drain(.. hashes_hex.len().min(100)).collect::<Vec<_>>(),
|
||||
})),
|
||||
)
|
||||
.await
|
||||
.expect("couldn't call get_transactions");
|
||||
assert!(txs.missed_tx.is_empty());
|
||||
all_txs.extend(txs.txs);
|
||||
}
|
||||
|
||||
for (tx_hash, tx_res) in block.txs.into_iter().zip(txs.txs.into_iter()) {
|
||||
for (tx_hash, tx_res) in block.txs.into_iter().zip(all_txs.into_iter()) {
|
||||
assert_eq!(
|
||||
tx_res.tx_hash,
|
||||
hex::encode(tx_hash),
|
||||
|
|
|
@ -198,11 +198,18 @@ impl<R: RpcConnection> Rpc<R> {
|
|||
return Ok(vec![]);
|
||||
}
|
||||
|
||||
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
|
||||
.rpc_call(
|
||||
"get_transactions",
|
||||
Some(json!({
|
||||
"txs_hashes": hashes.iter().map(hex::encode).collect::<Vec<_>>()
|
||||
"txs_hashes": hashes_hex.drain(.. this_count).collect::<Vec<_>>(),
|
||||
})),
|
||||
)
|
||||
.await?;
|
||||
|
@ -213,8 +220,10 @@ impl<R: RpcConnection> Rpc<R> {
|
|||
))?;
|
||||
}
|
||||
|
||||
txs
|
||||
.txs
|
||||
all_txs.extend(txs.txs);
|
||||
}
|
||||
|
||||
all_txs
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, res)| {
|
||||
|
|
Loading…
Reference in a new issue