diff options
author | Riccardo Spagni <ric@spagni.net> | 2016-09-15 15:23:49 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2016-09-15 15:23:49 +0200 |
commit | 7c899ec33a0bc7c10b759f062648dbc3c2644023 (patch) | |
tree | 992d19b08a5465a27854ba295414275d730dddf6 /src/wallet/wallet2.cpp | |
parent | Merge pull request #1072 (diff) | |
parent | Decrease minimum fee from 0.01/kB to 0.002/kB (diff) | |
download | monero-7c899ec33a0bc7c10b759f062648dbc3c2644023.tar.xz |
Merge pull request #1074
cd01bae Decrease minimum fee from 0.01/kB to 0.002/kB (moneromooo-monero)
Diffstat (limited to 'src/wallet/wallet2.cpp')
-rw-r--r-- | src/wallet/wallet2.cpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 01892dc49..75d532432 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -98,16 +98,16 @@ void do_prepare_file_names(const std::string& file_path, std::string& keys_file, } } -uint64_t calculate_fee(size_t bytes, uint64_t fee_multiplier) +uint64_t calculate_fee(uint64_t fee_per_kb, size_t bytes, uint64_t fee_multiplier) { THROW_WALLET_EXCEPTION_IF(fee_multiplier <= 0 || fee_multiplier > 3, tools::error::invalid_fee_multiplier); uint64_t kB = (bytes + 1023) / 1024; - return kB * FEE_PER_KB * fee_multiplier; + return kB * fee_per_kb * fee_multiplier; } -uint64_t calculate_fee(const cryptonote::blobdata &blob, uint64_t fee_multiplier) +uint64_t calculate_fee(uint64_t fee_per_kb, const cryptonote::blobdata &blob, uint64_t fee_multiplier) { - return calculate_fee(blob.size(), fee_multiplier); + return calculate_fee(fee_per_kb, blob.size(), fee_multiplier); } } //namespace @@ -2556,6 +2556,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions(std::vector<crypto { const std::vector<size_t> unused_transfers_indices = select_available_outputs_from_histogram(fake_outs_count + 1, true, true, trusted_daemon); + const uint64_t fee_per_kb = use_fork_rules(3, -720 * 14) ? FEE_PER_KB : FEE_PER_KB_OLD; fee_multiplier = sanitize_fee_multiplier(fee_multiplier); // failsafe split attempt counter @@ -2588,7 +2589,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions(std::vector<crypto { transfer(dst_vector, fake_outs_count, unused_transfers_indices, unlock_time, needed_fee, extra, tx, ptx, trusted_daemon); auto txBlob = t_serializable_object_to_blob(ptx.tx); - needed_fee = calculate_fee(txBlob, fee_multiplier); + needed_fee = calculate_fee(fee_per_kb, txBlob, fee_multiplier); } while (ptx.fee < needed_fee); ptx_vector.push_back(ptx); @@ -3225,6 +3226,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp uint64_t upper_transaction_size_limit = get_upper_tranaction_size_limit(); const bool use_rct = use_fork_rules(4, 0); + const uint64_t fee_per_kb = use_fork_rules(3, -720 * 14) ? FEE_PER_KB : FEE_PER_KB_OLD; fee_multiplier = sanitize_fee_multiplier(fee_multiplier); // throw if attempting a transaction with no destinations @@ -3278,7 +3280,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp { // this is used to build a tx that's 1 or 2 inputs, and 2 outputs, which // will get us a known fee. - uint64_t estimated_fee = calculate_fee(estimate_rct_tx_size(2, fake_outs_count + 1, 2), fee_multiplier); + uint64_t estimated_fee = calculate_fee(fee_per_kb, estimate_rct_tx_size(2, fake_outs_count + 1, 2), fee_multiplier); prefered_inputs = pick_prefered_rct_inputs(needed_money + estimated_fee); if (!prefered_inputs.empty()) { @@ -3372,7 +3374,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, unlock_time, needed_fee, extra, detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), test_tx, test_ptx); auto txBlob = t_serializable_object_to_blob(test_ptx.tx); - needed_fee = calculate_fee(txBlob, fee_multiplier); + needed_fee = calculate_fee(fee_per_kb, txBlob, fee_multiplier); available_for_fee = test_ptx.fee + test_ptx.change_dts.amount + (!test_ptx.dust_added_to_fee ? test_ptx.dust : 0); LOG_PRINT_L2("Made a " << txBlob.size() << " kB tx, with " << print_money(available_for_fee) << " available for fee (" << print_money(needed_fee) << " needed)"); @@ -3476,6 +3478,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_all(const cryptono uint64_t upper_transaction_size_limit = get_upper_tranaction_size_limit(); const bool use_rct = use_fork_rules(4, 0); + const uint64_t fee_per_kb = use_fork_rules(3, -720 * 14) ? FEE_PER_KB : FEE_PER_KB_OLD; fee_multiplier = sanitize_fee_multiplier(fee_multiplier); // gather all our dust and non dust outputs @@ -3506,7 +3509,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_all(const cryptono // get a random unspent output and use it to pay next chunk. We try to alternate // dust and non dust to ensure we never get with only dust, from which we might // get a tx that can't pay for itself - size_t idx = unused_transfers_indices.empty() ? pop_best_value(unused_dust_indices, tx.selected_transfers) : unused_dust_indices.empty() ? pop_best_value(unused_transfers_indices, tx.selected_transfers) : ((tx.selected_transfers.size() & 1) || accumulated_outputs > FEE_PER_KB * fee_multiplier * (upper_transaction_size_limit + 1023) / 1024) ? pop_best_value(unused_dust_indices, tx.selected_transfers) : pop_best_value(unused_transfers_indices, tx.selected_transfers); + size_t idx = unused_transfers_indices.empty() ? pop_best_value(unused_dust_indices, tx.selected_transfers) : unused_dust_indices.empty() ? pop_best_value(unused_transfers_indices, tx.selected_transfers) : ((tx.selected_transfers.size() & 1) || accumulated_outputs > fee_per_kb * fee_multiplier * (upper_transaction_size_limit + 1023) / 1024) ? pop_best_value(unused_dust_indices, tx.selected_transfers) : pop_best_value(unused_transfers_indices, tx.selected_transfers); const transfer_details &td = m_transfers[idx]; LOG_PRINT_L2("Picking output " << idx << ", amount " << print_money(td.amount())); @@ -3543,7 +3546,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_all(const cryptono transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, unlock_time, needed_fee, extra, detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), test_tx, test_ptx); auto txBlob = t_serializable_object_to_blob(test_ptx.tx); - needed_fee = calculate_fee(txBlob, fee_multiplier); + needed_fee = calculate_fee(fee_per_kb, txBlob, fee_multiplier); available_for_fee = test_ptx.fee + test_ptx.dests[0].amount + test_ptx.change_dts.amount; LOG_PRINT_L2("Made a " << txBlob.size() << " kB tx, with " << print_money(available_for_fee) << " available for fee (" << print_money(needed_fee) << " needed)"); @@ -3560,7 +3563,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_all(const cryptono transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, unlock_time, needed_fee, extra, detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), test_tx, test_ptx); txBlob = t_serializable_object_to_blob(test_ptx.tx); - needed_fee = calculate_fee(txBlob, fee_multiplier); + needed_fee = calculate_fee(fee_per_kb, txBlob, fee_multiplier); LOG_PRINT_L2("Made an attempt at a final " << ((txBlob.size() + 1023)/1024) << " kB tx, with " << print_money(test_ptx.fee) << " fee and " << print_money(test_ptx.change_dts.amount) << " change"); } while (needed_fee > test_ptx.fee); @@ -3745,7 +3748,7 @@ void wallet2::get_hard_fork_info(uint8_t version, uint64_t &earliest_height) earliest_height = resp_t.result.earliest_height; } //---------------------------------------------------------------------------------------------------- -bool wallet2::use_fork_rules(uint8_t version, uint64_t early_blocks) +bool wallet2::use_fork_rules(uint8_t version, int64_t early_blocks) { cryptonote::COMMAND_RPC_GET_HEIGHT::request req = AUTO_VAL_INIT(req); cryptonote::COMMAND_RPC_GET_HEIGHT::response res = AUTO_VAL_INIT(res); @@ -3890,6 +3893,8 @@ std::vector<wallet2::pending_tx> wallet2::create_unmixable_sweep_transactions(bo const bool hf1_rules = use_fork_rules(2, 10); // first hard fork has version 2 tx_dust_policy dust_policy(hf1_rules ? 0 : ::config::DEFAULT_DUST_THRESHOLD); + const uint64_t fee_per_kb = use_fork_rules(3, -720 * 14) ? FEE_PER_KB : FEE_PER_KB_OLD; + // may throw std::vector<size_t> unmixable_outputs = select_available_unmixable_outputs(trusted_daemon); size_t num_dust_outputs = unmixable_outputs.size(); @@ -3923,13 +3928,13 @@ std::vector<wallet2::pending_tx> wallet2::create_unmixable_sweep_transactions(bo { transfer_from(unmixable_outputs, num_outputs_per_tx, (uint64_t)0 /* unlock_time */, 0, detail::digit_split_strategy, dust_policy, extra, tx, ptx); auto txBlob = t_serializable_object_to_blob(ptx.tx); - needed_fee = calculate_fee(txBlob, 1); + needed_fee = calculate_fee(fee_per_kb, txBlob, 1); // reroll the tx with the actual amount minus the fee // if there's not enough for the fee, it'll throw transfer_from(unmixable_outputs, num_outputs_per_tx, (uint64_t)0 /* unlock_time */, needed_fee, detail::digit_split_strategy, dust_policy, extra, tx, ptx); txBlob = t_serializable_object_to_blob(ptx.tx); - needed_fee = calculate_fee(txBlob, 1); + needed_fee = calculate_fee(fee_per_kb, txBlob, 1); } while (ptx.fee < needed_fee); ptx_vector.push_back(ptx); |