Skip to content

Commit 8f98dac

Browse files
jeffro256j-berman
andcommitted
wallet: deprecate wallet2::find_and_save_rings()
Rings for outgoing transactions are stored within the scanning code since the last hardfork, so this code is largely unneccessary now. Co-authored-by: j-berman <justinberman@protonmail.com>
1 parent ec870e5 commit 8f98dac

File tree

4 files changed

+6
-80
lines changed

4 files changed

+6
-80
lines changed

src/simplewallet/simplewallet.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,15 +2231,7 @@ bool simple_wallet::blackballed(const std::vector<std::string> &args)
22312231

22322232
bool simple_wallet::save_known_rings(const std::vector<std::string> &args)
22332233
{
2234-
try
2235-
{
2236-
LOCK_IDLE_SCOPE();
2237-
m_wallet->find_and_save_rings();
2238-
}
2239-
catch (const std::exception &e)
2240-
{
2241-
fail_msg_writer() << tr("Failed to save known rings: ") << e.what();
2242-
}
2234+
fail_msg_writer() << tr("save_known_rings is deprecated");
22432235
return true;
22442236
}
22452237

src/wallet/api/wallet.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2479,7 +2479,6 @@ void WalletImpl::doRefresh()
24792479
if (m_history->count() == 0) {
24802480
m_history->refresh();
24812481
}
2482-
m_wallet->find_and_save_rings(false);
24832482
} else {
24842483
LOG_PRINT_L3(__FUNCTION__ << ": skipping refresh - daemon is not synced");
24852484
}

src/wallet/wallet2.cpp

Lines changed: 4 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ wallet2::wallet2(network_type nettype, uint64_t kdf_rounds, bool unattended, std
12501250
m_original_keys_available(false),
12511251
m_message_store(http_client_factory->create()),
12521252
m_key_device_type(hw::device::device_type::SOFTWARE),
1253-
m_ring_history_saved(false),
1253+
m_ring_history_saved(true),
12541254
m_ringdb(),
12551255
m_last_block_reward(0),
12561256
m_unattended(unattended),
@@ -6520,15 +6520,6 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass
65206520
if (get_num_subaddress_accounts() == 0)
65216521
add_subaddress_account(tr("Primary account"));
65226522

6523-
try
6524-
{
6525-
find_and_save_rings(false);
6526-
}
6527-
catch (const std::exception &e)
6528-
{
6529-
MERROR("Failed to save rings, will try again next time");
6530-
}
6531-
65326523
try
65336524
{
65346525
if (use_fs)
@@ -8918,67 +8909,11 @@ bool wallet2::unset_ring(const crypto::hash &txid)
89188909

89198910
bool wallet2::find_and_save_rings(bool force)
89208911
{
8921-
if (!force && m_ring_history_saved)
8922-
return true;
8923-
if (!m_ringdb)
8924-
return false;
8925-
8926-
COMMAND_RPC_GET_TRANSACTIONS::request req = AUTO_VAL_INIT(req);
8927-
COMMAND_RPC_GET_TRANSACTIONS::response res = AUTO_VAL_INIT(res);
8928-
8929-
MDEBUG("Finding and saving rings...");
8930-
8931-
// get payments we made
8932-
std::vector<crypto::hash> txs_hashes;
8933-
std::list<std::pair<crypto::hash,wallet2::confirmed_transfer_details>> payments;
8934-
get_payments_out(payments, 0, std::numeric_limits<uint64_t>::max(), boost::none, std::set<uint32_t>());
8935-
for (const std::pair<crypto::hash,wallet2::confirmed_transfer_details> &entry: payments)
8936-
{
8937-
const crypto::hash &txid = entry.first;
8938-
txs_hashes.push_back(txid);
8939-
}
8940-
8941-
MDEBUG("Found " << std::to_string(txs_hashes.size()) << " transactions");
8942-
8943-
// get those transactions from the daemon
8944-
auto it = txs_hashes.begin();
8945-
static const size_t SLICE_SIZE = 200;
8946-
for (size_t slice = 0; slice < txs_hashes.size(); slice += SLICE_SIZE)
8912+
if (force)
89478913
{
8948-
req.decode_as_json = false;
8949-
req.prune = true;
8950-
req.txs_hashes.clear();
8951-
size_t ntxes = slice + SLICE_SIZE > txs_hashes.size() ? txs_hashes.size() - slice : SLICE_SIZE;
8952-
for (size_t s = slice; s < slice + ntxes; ++s)
8953-
req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txs_hashes[s]));
8954-
8955-
{
8956-
const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex};
8957-
uint64_t pre_call_credits = m_rpc_payment_state.credits;
8958-
req.client = get_client_signature();
8959-
bool r = epee::net_utils::invoke_http_json("/gettransactions", req, res, *m_http_client, rpc_timeout);
8960-
THROW_ON_RPC_RESPONSE_ERROR_GENERIC(r, {}, res, "/gettransactions");
8961-
THROW_WALLET_EXCEPTION_IF(res.txs.size() != req.txs_hashes.size(), error::wallet_internal_error,
8962-
"daemon returned wrong response for gettransactions, wrong txs count = " +
8963-
std::to_string(res.txs.size()) + ", expected " + std::to_string(req.txs_hashes.size()));
8964-
check_rpc_cost("/gettransactions", res.credits, pre_call_credits, res.txs.size() * COST_PER_TX);
8965-
}
8966-
8967-
MDEBUG("Scanning " << res.txs.size() << " transactions");
8968-
THROW_WALLET_EXCEPTION_IF(slice + res.txs.size() > txs_hashes.size(), error::wallet_internal_error, "Unexpected tx array size");
8969-
for (size_t i = 0; i < res.txs.size(); ++i, ++it)
8970-
{
8971-
const auto &tx_info = res.txs[i];
8972-
cryptonote::transaction tx;
8973-
crypto::hash tx_hash;
8974-
THROW_WALLET_EXCEPTION_IF(!get_pruned_tx(tx_info, tx, tx_hash), error::wallet_internal_error,
8975-
"Failed to get transaction from daemon");
8976-
THROW_WALLET_EXCEPTION_IF(!(tx_hash == *it), error::wallet_internal_error, "Wrong txid received");
8977-
THROW_WALLET_EXCEPTION_IF(!add_rings(get_ringdb_key(), tx), error::wallet_internal_error, "Failed to save ring");
8978-
}
8914+
MWARNING("wallet2::find_and_save_rings() is deprecated");
8915+
return false;
89798916
}
8980-
8981-
MINFO("Found and saved rings for " << txs_hashes.size() << " transactions");
89828917
m_ring_history_saved = true;
89838918
return true;
89848919
}

src/wallet/wallet2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ namespace tools
17671767
bool set_rings(const std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> &rings, bool relative);
17681768
bool unset_ring(const std::vector<crypto::key_image> &key_images);
17691769
bool unset_ring(const crypto::hash &txid);
1770-
bool find_and_save_rings(bool force = true);
1770+
[[deprecated]] bool find_and_save_rings(bool force = true);
17711771

17721772
bool blackball_output(const std::pair<uint64_t, uint64_t> &output);
17731773
bool set_blackballed_outputs(const std::vector<std::pair<uint64_t, uint64_t>> &outputs, bool add = false);

0 commit comments

Comments
 (0)