Chunk /gettransactions to avoid hitting restricted RPC limit

pull/434/head
tobtoht 2 years ago committed by wowario
parent d0b1c21683
commit aeeb7fb5ca
No known key found for this signature in database
GPG Key ID: 24DCBE762DE9C111

@ -3106,14 +3106,18 @@ void wallet2::update_pool_state(std::vector<std::tuple<cryptonote::transaction,
} }
} }
// get those txes // get_transaction_pool_hashes.bin may return more transactions than we're allowed to request in restricted mode
if (!txids.empty()) const size_t SLICE_SIZE = 100; // RESTRICTED_TRANSACTIONS_COUNT as defined in rpc/core_rpc_server.cpp
for (size_t offset = 0; offset < txids.size(); offset += SLICE_SIZE)
{ {
cryptonote::COMMAND_RPC_GET_TRANSACTIONS::request req; cryptonote::COMMAND_RPC_GET_TRANSACTIONS::request req;
cryptonote::COMMAND_RPC_GET_TRANSACTIONS::response res; cryptonote::COMMAND_RPC_GET_TRANSACTIONS::response res;
for (const auto &p: txids)
req.txs_hashes.push_back(epee::string_tools::pod_to_hex(p.first)); const size_t n_txids = std::min<size_t>(SLICE_SIZE, txids.size() - offset);
MDEBUG("asking for " << txids.size() << " transactions"); for (size_t n = offset; n < (offset + n_txids); ++n) {
req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txids.at(n).first));
}
MDEBUG("asking for " << req.txs_hashes.size() << " transactions");
req.decode_as_json = false; req.decode_as_json = false;
req.prune = true; req.prune = true;
@ -3130,7 +3134,7 @@ void wallet2::update_pool_state(std::vector<std::tuple<cryptonote::transaction,
MDEBUG("Got " << r << " and " << res.status); MDEBUG("Got " << r << " and " << res.status);
if (r && res.status == CORE_RPC_STATUS_OK) if (r && res.status == CORE_RPC_STATUS_OK)
{ {
if (res.txs.size() == txids.size()) if (res.txs.size() == req.txs_hashes.size())
{ {
for (const auto &tx_entry: res.txs) for (const auto &tx_entry: res.txs)
{ {
@ -3166,7 +3170,7 @@ void wallet2::update_pool_state(std::vector<std::tuple<cryptonote::transaction,
} }
else else
{ {
LOG_PRINT_L0("Expected " << txids.size() << " tx(es), got " << res.txs.size()); LOG_PRINT_L0("Expected " << n_txids << " out of " << txids.size() << " tx(es), got " << res.txs.size());
} }
} }
else else

Loading…
Cancel
Save