Merge pull request #10015

8f98dac wallet: deprecate wallet2::find_and_save_rings() (jeffro256)
This commit is contained in:
tobtoht 2025-08-01 11:52:22 +00:00
commit 35efc7e340
No known key found for this signature in database
GPG key ID: E45B10DD027D2472
4 changed files with 6 additions and 80 deletions

View file

@ -2231,15 +2231,7 @@ bool simple_wallet::blackballed(const std::vector<std::string> &args)
bool simple_wallet::save_known_rings(const std::vector<std::string> &args) bool simple_wallet::save_known_rings(const std::vector<std::string> &args)
{ {
try fail_msg_writer() << tr("save_known_rings is deprecated");
{
LOCK_IDLE_SCOPE();
m_wallet->find_and_save_rings();
}
catch (const std::exception &e)
{
fail_msg_writer() << tr("Failed to save known rings: ") << e.what();
}
return true; return true;
} }

View file

@ -2479,7 +2479,6 @@ void WalletImpl::doRefresh()
if (m_history->count() == 0) { if (m_history->count() == 0) {
m_history->refresh(); m_history->refresh();
} }
m_wallet->find_and_save_rings(false);
} else { } else {
LOG_PRINT_L3(__FUNCTION__ << ": skipping refresh - daemon is not synced"); LOG_PRINT_L3(__FUNCTION__ << ": skipping refresh - daemon is not synced");
} }

View file

@ -1250,7 +1250,7 @@ wallet2::wallet2(network_type nettype, uint64_t kdf_rounds, bool unattended, std
m_original_keys_available(false), m_original_keys_available(false),
m_message_store(http_client_factory->create()), m_message_store(http_client_factory->create()),
m_key_device_type(hw::device::device_type::SOFTWARE), m_key_device_type(hw::device::device_type::SOFTWARE),
m_ring_history_saved(false), m_ring_history_saved(true),
m_ringdb(), m_ringdb(),
m_last_block_reward(0), m_last_block_reward(0),
m_unattended(unattended), m_unattended(unattended),
@ -6520,15 +6520,6 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass
if (get_num_subaddress_accounts() == 0) if (get_num_subaddress_accounts() == 0)
add_subaddress_account(tr("Primary account")); add_subaddress_account(tr("Primary account"));
try
{
find_and_save_rings(false);
}
catch (const std::exception &e)
{
MERROR("Failed to save rings, will try again next time");
}
try try
{ {
if (use_fs) if (use_fs)
@ -8918,67 +8909,11 @@ bool wallet2::unset_ring(const crypto::hash &txid)
bool wallet2::find_and_save_rings(bool force) bool wallet2::find_and_save_rings(bool force)
{ {
if (!force && m_ring_history_saved) if (force)
return true; {
if (!m_ringdb) MWARNING("wallet2::find_and_save_rings() is deprecated");
return false; return false;
COMMAND_RPC_GET_TRANSACTIONS::request req = AUTO_VAL_INIT(req);
COMMAND_RPC_GET_TRANSACTIONS::response res = AUTO_VAL_INIT(res);
MDEBUG("Finding and saving rings...");
// get payments we made
std::vector<crypto::hash> txs_hashes;
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>());
for (const std::pair<crypto::hash,wallet2::confirmed_transfer_details> &entry: payments)
{
const crypto::hash &txid = entry.first;
txs_hashes.push_back(txid);
} }
MDEBUG("Found " << std::to_string(txs_hashes.size()) << " transactions");
// get those transactions from the daemon
auto it = txs_hashes.begin();
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.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]));
{
const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex};
uint64_t pre_call_credits = m_rpc_payment_state.credits;
req.client = get_client_signature();
bool r = epee::net_utils::invoke_http_json("/gettransactions", req, res, *m_http_client, rpc_timeout);
THROW_ON_RPC_RESPONSE_ERROR_GENERIC(r, {}, res, "/gettransactions");
THROW_WALLET_EXCEPTION_IF(res.txs.size() != req.txs_hashes.size(), error::wallet_internal_error,
"daemon returned wrong response for gettransactions, wrong txs count = " +
std::to_string(res.txs.size()) + ", expected " + std::to_string(req.txs_hashes.size()));
check_rpc_cost("/gettransactions", res.credits, pre_call_credits, res.txs.size() * COST_PER_TX);
}
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");
for (size_t i = 0; i < res.txs.size(); ++i, ++it)
{
const auto &tx_info = res.txs[i];
cryptonote::transaction tx;
crypto::hash tx_hash;
THROW_WALLET_EXCEPTION_IF(!get_pruned_tx(tx_info, tx, tx_hash), error::wallet_internal_error,
"Failed to get transaction from daemon");
THROW_WALLET_EXCEPTION_IF(!(tx_hash == *it), error::wallet_internal_error, "Wrong txid received");
THROW_WALLET_EXCEPTION_IF(!add_rings(get_ringdb_key(), tx), error::wallet_internal_error, "Failed to save ring");
}
}
MINFO("Found and saved rings for " << txs_hashes.size() << " transactions");
m_ring_history_saved = true; m_ring_history_saved = true;
return true; return true;
} }

View file

@ -1767,7 +1767,7 @@ private:
bool set_rings(const std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> &rings, bool relative); bool set_rings(const std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> &rings, bool relative);
bool unset_ring(const std::vector<crypto::key_image> &key_images); bool unset_ring(const std::vector<crypto::key_image> &key_images);
bool unset_ring(const crypto::hash &txid); bool unset_ring(const crypto::hash &txid);
bool find_and_save_rings(bool force = true); [[deprecated]] bool find_and_save_rings(bool force = true);
bool blackball_output(const std::pair<uint64_t, uint64_t> &output); bool blackball_output(const std::pair<uint64_t, uint64_t> &output);
bool set_blackballed_outputs(const std::vector<std::pair<uint64_t, uint64_t>> &outputs, bool add = false); bool set_blackballed_outputs(const std::vector<std::pair<uint64_t, uint64_t>> &outputs, bool add = false);