mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-27 01:42:27 +00:00
wallet: fix corner case of no recent outputs available
Also clarify related logs
This commit is contained in:
parent
38727f7d2f
commit
63772e4048
1 changed files with 9 additions and 6 deletions
|
@ -2972,9 +2972,9 @@ void wallet2::get_outs(std::vector<std::vector<entry>> &outs, const std::list<si
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG_PRINT_L1("" << num_outs << " outputs of size " << print_money(amount));
|
LOG_PRINT_L1("" << num_outs << " unlocked outputs of size " << print_money(amount));
|
||||||
THROW_WALLET_EXCEPTION_IF(num_outs == 0, error::wallet_internal_error,
|
THROW_WALLET_EXCEPTION_IF(num_outs == 0, error::wallet_internal_error,
|
||||||
"histogram reports no outputs for " + boost::lexical_cast<std::string>(amount) + ", not even ours");
|
"histogram reports no unlocked outputs for " + boost::lexical_cast<std::string>(amount) + ", not even ours");
|
||||||
THROW_WALLET_EXCEPTION_IF(num_recent_outs > num_outs, error::wallet_internal_error,
|
THROW_WALLET_EXCEPTION_IF(num_recent_outs > num_outs, error::wallet_internal_error,
|
||||||
"histogram reports more recent outs than outs for " + boost::lexical_cast<std::string>(amount));
|
"histogram reports more recent outs than outs for " + boost::lexical_cast<std::string>(amount));
|
||||||
|
|
||||||
|
@ -2984,7 +2984,7 @@ void wallet2::get_outs(std::vector<std::vector<entry>> &outs, const std::list<si
|
||||||
recent_outputs_count = 1; // ensure we have at least one, if possible
|
recent_outputs_count = 1; // ensure we have at least one, if possible
|
||||||
if (recent_outputs_count > num_recent_outs)
|
if (recent_outputs_count > num_recent_outs)
|
||||||
recent_outputs_count = num_recent_outs;
|
recent_outputs_count = num_recent_outs;
|
||||||
if (td.m_global_output_index >= num_outs - num_recent_outs)
|
if (td.m_global_output_index >= num_outs - num_recent_outs && recent_outputs_count > 0)
|
||||||
--recent_outputs_count; // if the real out is recent, pick one less recent fake out
|
--recent_outputs_count; // if the real out is recent, pick one less recent fake out
|
||||||
LOG_PRINT_L1("Using " << recent_outputs_count << " recent outputs");
|
LOG_PRINT_L1("Using " << recent_outputs_count << " recent outputs");
|
||||||
|
|
||||||
|
@ -3023,6 +3023,9 @@ void wallet2::get_outs(std::vector<std::vector<entry>> &outs, const std::list<si
|
||||||
uint64_t r = crypto::rand<uint64_t>() % ((uint64_t)1 << 53);
|
uint64_t r = crypto::rand<uint64_t>() % ((uint64_t)1 << 53);
|
||||||
double frac = std::sqrt((double)r / ((uint64_t)1 << 53));
|
double frac = std::sqrt((double)r / ((uint64_t)1 << 53));
|
||||||
i = (uint64_t)(frac*num_recent_outs) + num_outs - num_recent_outs;
|
i = (uint64_t)(frac*num_recent_outs) + num_outs - num_recent_outs;
|
||||||
|
// just in case rounding up to 1 occurs after calc
|
||||||
|
if (i == num_outs)
|
||||||
|
--i;
|
||||||
LOG_PRINT_L2("picking " << i << " as recent");
|
LOG_PRINT_L2("picking " << i << " as recent");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -3031,11 +3034,11 @@ void wallet2::get_outs(std::vector<std::vector<entry>> &outs, const std::list<si
|
||||||
uint64_t r = crypto::rand<uint64_t>() % ((uint64_t)1 << 53);
|
uint64_t r = crypto::rand<uint64_t>() % ((uint64_t)1 << 53);
|
||||||
double frac = std::sqrt((double)r / ((uint64_t)1 << 53));
|
double frac = std::sqrt((double)r / ((uint64_t)1 << 53));
|
||||||
i = (uint64_t)(frac*num_outs);
|
i = (uint64_t)(frac*num_outs);
|
||||||
|
// just in case rounding up to 1 occurs after calc
|
||||||
|
if (i == num_outs)
|
||||||
|
--i;
|
||||||
LOG_PRINT_L2("picking " << i << " as triangular");
|
LOG_PRINT_L2("picking " << i << " as triangular");
|
||||||
}
|
}
|
||||||
// just in case rounding up to 1 occurs after calc
|
|
||||||
if (i == num_outs)
|
|
||||||
--i;
|
|
||||||
|
|
||||||
if (seen_indices.count(i))
|
if (seen_indices.count(i))
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue