Modify get_transactions to split requests as to not hit the restricted RPC limits

This commit is contained in:
Luke Parker
2023-07-05 22:12:34 -04:00
parent 93fe8a52dd
commit 3c6cc42c23
2 changed files with 39 additions and 25 deletions

View File

@@ -44,18 +44,23 @@ async fn check_block(rpc: Arc<Rpc<HttpRpc>>, block_i: usize) {
txs: Vec<TransactionResponse>,
}
let txs: TransactionsResponse = rpc
.rpc_call(
"get_transactions",
Some(json!({
"txs_hashes": block.txs.iter().map(hex::encode).collect::<Vec<_>>()
})),
)
.await
.expect("couldn't call get_transactions");
assert!(txs.missed_tx.is_empty());
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": 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),