wallet2: request transactions in slices when scanning for known rings
This avoid massive memory consumption for huge wallets
This commit is contained in:
parent
2897c269de
commit
58f6607382
|
@ -5615,19 +5615,30 @@ bool wallet2::find_and_save_rings(bool force)
|
||||||
MDEBUG("Finding and saving rings...");
|
MDEBUG("Finding and saving rings...");
|
||||||
|
|
||||||
// get payments we made
|
// get payments we made
|
||||||
|
std::vector<crypto::hash> txs_hashes;
|
||||||
std::list<std::pair<crypto::hash,wallet2::confirmed_transfer_details>> payments;
|
std::list<std::pair<crypto::hash,wallet2::confirmed_transfer_details>> payments;
|
||||||
get_payments_out(payments, 0, std::numeric_limits<uint64_t>::max(), boost::none, std::set<uint32_t>());
|
get_payments_out(payments, 0, std::numeric_limits<uint64_t>::max(), boost::none, std::set<uint32_t>());
|
||||||
for (const std::pair<crypto::hash,wallet2::confirmed_transfer_details> &entry: payments)
|
for (const std::pair<crypto::hash,wallet2::confirmed_transfer_details> &entry: payments)
|
||||||
{
|
{
|
||||||
const crypto::hash &txid = entry.first;
|
const crypto::hash &txid = entry.first;
|
||||||
req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid));
|
txs_hashes.push_back(txid);
|
||||||
}
|
}
|
||||||
|
|
||||||
MDEBUG("Found " << std::to_string(req.txs_hashes.size()) << " transactions");
|
MDEBUG("Found " << std::to_string(txs_hashes.size()) << " transactions");
|
||||||
|
|
||||||
|
crypto::chacha_key key;
|
||||||
|
generate_chacha_key_from_secret_keys(key);
|
||||||
|
|
||||||
// get those transactions from the daemon
|
// get those transactions from the daemon
|
||||||
|
static const size_t SLICE_SIZE = 200;
|
||||||
|
for (size_t slice = 0; slice < txs_hashes.size(); slice += SLICE_SIZE)
|
||||||
|
{
|
||||||
req.decode_as_json = false;
|
req.decode_as_json = false;
|
||||||
req.prune = true;
|
req.prune = true;
|
||||||
|
req.txs_hashes.clear();
|
||||||
|
size_t ntxes = slice + SLICE_SIZE > txs_hashes.size() ? txs_hashes.size() - slice : SLICE_SIZE;
|
||||||
|
for (size_t s = slice; s < slice + ntxes; ++s)
|
||||||
|
req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txs_hashes[s]));
|
||||||
bool r;
|
bool r;
|
||||||
{
|
{
|
||||||
const boost::lock_guard<boost::mutex> lock{m_daemon_rpc_mutex};
|
const boost::lock_guard<boost::mutex> lock{m_daemon_rpc_mutex};
|
||||||
|
@ -5641,14 +5652,12 @@ bool wallet2::find_and_save_rings(bool force)
|
||||||
std::to_string(res.txs.size()) + ", expected " + std::to_string(req.txs_hashes.size()));
|
std::to_string(res.txs.size()) + ", expected " + std::to_string(req.txs_hashes.size()));
|
||||||
|
|
||||||
MDEBUG("Scanning " << res.txs.size() << " transactions");
|
MDEBUG("Scanning " << res.txs.size() << " transactions");
|
||||||
|
THROW_WALLET_EXCEPTION_IF(slice + res.txs.size() > txs_hashes.size(), error::wallet_internal_error, "Unexpected tx array size");
|
||||||
crypto::chacha_key key;
|
|
||||||
generate_chacha_key_from_secret_keys(key);
|
|
||||||
|
|
||||||
auto it = req.txs_hashes.begin();
|
auto it = req.txs_hashes.begin();
|
||||||
for (size_t i = 0; i < res.txs.size(); ++i, ++it)
|
for (size_t i = 0; i < res.txs.size(); ++i, ++it)
|
||||||
{
|
{
|
||||||
const auto &tx_info = res.txs[i];
|
const auto &tx_info = res.txs[i];
|
||||||
|
THROW_WALLET_EXCEPTION_IF(tx_info.tx_hash != epee::string_tools::pod_to_hex(txs_hashes[slice + i]), error::wallet_internal_error, "Wrong txid received");
|
||||||
THROW_WALLET_EXCEPTION_IF(tx_info.tx_hash != *it, error::wallet_internal_error, "Wrong txid received");
|
THROW_WALLET_EXCEPTION_IF(tx_info.tx_hash != *it, error::wallet_internal_error, "Wrong txid received");
|
||||||
cryptonote::blobdata bd;
|
cryptonote::blobdata bd;
|
||||||
THROW_WALLET_EXCEPTION_IF(!epee::string_tools::parse_hexstr_to_binbuff(tx_info.as_hex, bd), error::wallet_internal_error, "failed to parse tx from hexstr");
|
THROW_WALLET_EXCEPTION_IF(!epee::string_tools::parse_hexstr_to_binbuff(tx_info.as_hex, bd), error::wallet_internal_error, "failed to parse tx from hexstr");
|
||||||
|
@ -5658,8 +5667,9 @@ bool wallet2::find_and_save_rings(bool force)
|
||||||
THROW_WALLET_EXCEPTION_IF(epee::string_tools::pod_to_hex(tx_hash) != tx_info.tx_hash, error::wallet_internal_error, "txid mismatch");
|
THROW_WALLET_EXCEPTION_IF(epee::string_tools::pod_to_hex(tx_hash) != tx_info.tx_hash, error::wallet_internal_error, "txid mismatch");
|
||||||
THROW_WALLET_EXCEPTION_IF(!add_rings(key, tx), error::wallet_internal_error, "Failed to save ring");
|
THROW_WALLET_EXCEPTION_IF(!add_rings(key, tx), error::wallet_internal_error, "Failed to save ring");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MINFO("Found and saved rings for " << res.txs.size() << " transactions");
|
MINFO("Found and saved rings for " << txs_hashes.size() << " transactions");
|
||||||
m_ring_history_saved = true;
|
m_ring_history_saved = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue