Merge pull request #634

7fc6fa3 wallet: forbid dust altogether in output selection where appropriate (moneromooo-monero)
5e1a739 blockchain: log number of outputs available for a new tx (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2016-01-31 15:21:45 +02:00
commit 569316aea3
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
3 changed files with 15 additions and 5 deletions

View file

@ -2043,6 +2043,7 @@ bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t* pmax_used_bloc
{ {
const txin_to_key& in_to_key = boost::get<txin_to_key>(txin); const txin_to_key& in_to_key = boost::get<txin_to_key>(txin);
uint64_t n_outputs = m_db->get_num_outputs(in_to_key.amount); uint64_t n_outputs = m_db->get_num_outputs(in_to_key.amount);
LOG_PRINT_L2("output size " << print_money(in_to_key.amount) << ": " << n_outputs << " available");
// n_outputs includes the output we're considering // n_outputs includes the output we're considering
if (n_outputs <= 2) if (n_outputs <= 2)
++n_unmixable; ++n_unmixable;

View file

@ -1587,7 +1587,7 @@ namespace
// returns: // returns:
// direct return: amount of money found // direct return: amount of money found
// modified reference: selected_transfers, a list of iterators/indices of input sources // modified reference: selected_transfers, a list of iterators/indices of input sources
uint64_t wallet2::select_transfers(uint64_t needed_money, bool add_dust, uint64_t dust, std::list<transfer_container::iterator>& selected_transfers) uint64_t wallet2::select_transfers(uint64_t needed_money, bool add_dust, uint64_t dust, bool hf2_rules, std::list<transfer_container::iterator>& selected_transfers)
{ {
std::vector<size_t> unused_transfers_indices; std::vector<size_t> unused_transfers_indices;
std::vector<size_t> unused_dust_indices; std::vector<size_t> unused_dust_indices;
@ -1602,7 +1602,15 @@ uint64_t wallet2::select_transfers(uint64_t needed_money, bool add_dust, uint64_
if (dust < td.amount() && is_valid_decomposed_amount(td.amount())) if (dust < td.amount() && is_valid_decomposed_amount(td.amount()))
unused_transfers_indices.push_back(i); unused_transfers_indices.push_back(i);
else else
unused_dust_indices.push_back(i); {
// for hf2 rules, we disregard dust, which will be spendable only
// via sweep_dust. If we're asked to add dust, though, we still
// consider them, as this will be a mixin 0 tx (and thus we may
// end up with a tx with one mixable output and N dusty ones).
// This should be made better at some point...
if (!hf2_rules || add_dust)
unused_dust_indices.push_back(i);
}
} }
} }

View file

@ -363,7 +363,7 @@ namespace tools
void pull_blocks(uint64_t start_height, uint64_t& blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::list<cryptonote::block_complete_entry> &blocks); void pull_blocks(uint64_t start_height, uint64_t& blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::list<cryptonote::block_complete_entry> &blocks);
void pull_next_blocks(uint64_t start_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history, const std::list<cryptonote::block_complete_entry> &prev_blocks, std::list<cryptonote::block_complete_entry> &blocks, bool &error); void pull_next_blocks(uint64_t start_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history, const std::list<cryptonote::block_complete_entry> &prev_blocks, std::list<cryptonote::block_complete_entry> &blocks, bool &error);
void process_blocks(uint64_t start_height, const std::list<cryptonote::block_complete_entry> &blocks, uint64_t& blocks_added); void process_blocks(uint64_t start_height, const std::list<cryptonote::block_complete_entry> &blocks, uint64_t& blocks_added);
uint64_t select_transfers(uint64_t needed_money, bool add_dust, uint64_t dust, std::list<transfer_container::iterator>& selected_transfers); uint64_t select_transfers(uint64_t needed_money, bool add_dust, uint64_t dust, bool hf2_rules, std::list<transfer_container::iterator>& selected_transfers);
bool prepare_file_names(const std::string& file_path); bool prepare_file_names(const std::string& file_path);
void process_unconfirmed(const cryptonote::transaction& tx, uint64_t height); void process_unconfirmed(const cryptonote::transaction& tx, uint64_t height);
void process_outgoing(const cryptonote::transaction& tx, uint64_t height, uint64_t spent, uint64_t received); void process_outgoing(const cryptonote::transaction& tx, uint64_t height, uint64_t spent, uint64_t received);
@ -564,8 +564,9 @@ namespace tools
// randomly select inputs for transaction // randomly select inputs for transaction
// throw if requested send amount is greater than amount available to send // throw if requested send amount is greater than amount available to send
std::list<transfer_container::iterator> selected_transfers; std::list<transfer_container::iterator> selected_transfers;
const bool add_dust = (0 == fake_outputs_count) && !use_fork_rules(2); // first fork has version 2 bool hf2_rules = use_fork_rules(2); // first fork has version 2
uint64_t found_money = select_transfers(needed_money, add_dust, dust_policy.dust_threshold, selected_transfers); const bool add_dust = (0 == fake_outputs_count) && hf2_rules;
uint64_t found_money = select_transfers(needed_money, add_dust, dust_policy.dust_threshold, hf2_rules, selected_transfers);
THROW_WALLET_EXCEPTION_IF(found_money < needed_money, error::not_enough_money, found_money, needed_money - fee, fee); THROW_WALLET_EXCEPTION_IF(found_money < needed_money, error::not_enough_money, found_money, needed_money - fee, fee);
typedef COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry out_entry; typedef COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry out_entry;