mirror of
https://github.com/monero-project/monero.git
synced 2025-08-14 04:45:30 -04:00
wallet: select part of the fake outs from recent outputs
25% of the outputs are selected from the last 5 days (if possible), in order to avoid the common case of sending recently received outputs again. 25% and 5 days are subject to review later, since it's just a wallet level change.
This commit is contained in:
parent
34fcfcd7cc
commit
88faec75fe
9 changed files with 92 additions and 32 deletions
|
@ -2657,7 +2657,7 @@ void BlockchainLMDB::get_output_tx_and_index(const uint64_t& amount, const std::
|
|||
LOG_PRINT_L3("db3: " << db3);
|
||||
}
|
||||
|
||||
std::map<uint64_t, uint64_t> BlockchainLMDB::get_output_histogram(const std::vector<uint64_t> &amounts, bool unlocked) const
|
||||
std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>> BlockchainLMDB::get_output_histogram(const std::vector<uint64_t> &amounts, bool unlocked, uint64_t recent_cutoff) const
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
|
@ -2665,7 +2665,7 @@ std::map<uint64_t, uint64_t> BlockchainLMDB::get_output_histogram(const std::vec
|
|||
TXN_PREFIX_RDONLY();
|
||||
RCURSOR(output_amounts);
|
||||
|
||||
std::map<uint64_t, uint64_t> histogram;
|
||||
std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>> histogram;
|
||||
MDB_val k;
|
||||
MDB_val v;
|
||||
|
||||
|
@ -2683,7 +2683,7 @@ std::map<uint64_t, uint64_t> BlockchainLMDB::get_output_histogram(const std::vec
|
|||
mdb_size_t num_elems = 0;
|
||||
mdb_cursor_count(m_cur_output_amounts, &num_elems);
|
||||
uint64_t amount = *(const uint64_t*)k.mv_data;
|
||||
histogram[amount] = num_elems;
|
||||
histogram[amount] = std::make_tuple(num_elems, 0, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -2694,13 +2694,13 @@ std::map<uint64_t, uint64_t> BlockchainLMDB::get_output_histogram(const std::vec
|
|||
int ret = mdb_cursor_get(m_cur_output_amounts, &k, &v, MDB_SET);
|
||||
if (ret == MDB_NOTFOUND)
|
||||
{
|
||||
histogram[amount] = 0;
|
||||
histogram[amount] = std::make_tuple(0, 0, 0);
|
||||
}
|
||||
else if (ret == MDB_SUCCESS)
|
||||
{
|
||||
mdb_size_t num_elems = 0;
|
||||
mdb_cursor_count(m_cur_output_amounts, &num_elems);
|
||||
histogram[amount] = num_elems;
|
||||
histogram[amount] = std::make_tuple(num_elems, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2709,11 +2709,11 @@ std::map<uint64_t, uint64_t> BlockchainLMDB::get_output_histogram(const std::vec
|
|||
}
|
||||
}
|
||||
|
||||
if (unlocked) {
|
||||
if (unlocked || recent_cutoff > 0) {
|
||||
const uint64_t blockchain_height = height();
|
||||
for (auto i: histogram) {
|
||||
uint64_t amount = i.first;
|
||||
uint64_t num_elems = i.second;
|
||||
for (std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>>::iterator i = histogram.begin(); i != histogram.end(); ++i) {
|
||||
uint64_t amount = i->first;
|
||||
uint64_t num_elems = std::get<0>(i->second);
|
||||
while (num_elems > 0) {
|
||||
const tx_out_index toi = get_output_tx_and_index(amount, num_elems - 1);
|
||||
const uint64_t height = get_tx_block_height(toi.first);
|
||||
|
@ -2722,7 +2722,23 @@ std::map<uint64_t, uint64_t> BlockchainLMDB::get_output_histogram(const std::vec
|
|||
--num_elems;
|
||||
}
|
||||
// modifying second does not invalidate the iterator
|
||||
i.second = num_elems;
|
||||
std::get<1>(i->second) = num_elems;
|
||||
|
||||
if (recent_cutoff > 0)
|
||||
{
|
||||
uint64_t recent = 0;
|
||||
while (num_elems > 0) {
|
||||
const tx_out_index toi = get_output_tx_and_index(amount, num_elems - 1);
|
||||
const uint64_t height = get_tx_block_height(toi.first);
|
||||
const uint64_t ts = get_block_timestamp(height);
|
||||
if (ts < recent_cutoff)
|
||||
break;
|
||||
--num_elems;
|
||||
++recent;
|
||||
}
|
||||
// modifying second does not invalidate the iterator
|
||||
std::get<2>(i->second) = recent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue