Skip to content

Commit

Permalink
Merge pull request #238 from graft-project/feature/rta_fixed_fee
Browse files Browse the repository at this point in the history
RTA fixed fee support
  • Loading branch information
mbg033 authored Mar 9, 2019
2 parents af5fe0e + e433564 commit 8d78cbb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/cryptonote_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
#define DYNAMIC_FEE_PER_KB_BASE_BLOCK_REWARD ((uint64_t)10 * (COIN) ) // 10 * pow(10,10)
#define DYNAMIC_FEE_PER_KB_BASE_FEE_V5 ((uint64_t)20000000 * (uint64_t)CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5)

#define RTA_TX_FEE 1000000000

#define ORPHANED_BLOCKS_MAX_COUNT 100


Expand Down
10 changes: 5 additions & 5 deletions src/simplewallet/simplewallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ enum TransferType {
TransferOriginal,
TransferNew,
TransferLocked,
TransferZeroFee,
TransferRTAFee,
TransferStake
};

Expand Down Expand Up @@ -762,7 +762,7 @@ simple_wallet::simple_wallet()
m_cmd_binder.set_handler("bc_height", boost::bind(&simple_wallet::show_blockchain_height, this, _1), tr("Show blockchain height"));
m_cmd_binder.set_handler("transfer_original", boost::bind(&simple_wallet::transfer, this, _1), tr("Same as transfer, but using an older transaction building algorithm"));
m_cmd_binder.set_handler("transfer", boost::bind(&simple_wallet::transfer_new, this, _1), tr("transfer [<priority>] [<ring_size>] <address> <amount> [<payment_id>] - Transfer <amount> to <address>. <priority> is the priority of the transaction. The higher the priority, the higher the fee of the transaction. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \"set priority\") is used. <ring_size> is the number of inputs to include for untraceability. Multiple payments can be made at once by adding <address_2> <amount_2> etcetera (before the payment ID, if it's included)"));
m_cmd_binder.set_handler("transfer_zf", boost::bind(&simple_wallet::transfer_zero_fee, this, _1), tr("transfer_zf [<priority>] [<ring_size>] <address> <amount> [<payment_id>] - Transfer <amount> to <address>. <priority> is the priority of the transaction. The higher the priority, the higher the fee of the transaction. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \"set priority\") is used. <ring_size> is the number of inputs to include for untraceability. Multiple payments can be made at once by adding <address_2> <amount_2> etcetera (before the payment ID, if it's included)"));
m_cmd_binder.set_handler("transfer_rta", boost::bind(&simple_wallet::transfer_rta, this, _1), tr("transfer_rta [<priority>] [<ring_size>] <address> <amount> [<payment_id>] - Transfer <amount> to <address>. <priority> is the priority of the transaction. The higher the priority, the higher the fee of the transaction. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \"set priority\") is used. <ring_size> is the number of inputs to include for untraceability. Multiple payments can be made at once by adding <address_2> <amount_2> etcetera (before the payment ID, if it's included)"));
m_cmd_binder.set_handler("locked_transfer", boost::bind(&simple_wallet::locked_transfer, this, _1), tr("locked_transfer [<ring_size>] <addr> <amount> <lockblocks>(Number of blocks to lock the transaction for, max 1000000) [<payment_id>]"));
m_cmd_binder.set_handler("stake_transfer", boost::bind(&simple_wallet::stake_transfer, this, _1), tr("stake_transfer [<ring_size>] <addr> <amount> <lockblocks>(Number of blocks to lock the stake transaction for, max 1000000) <sn_public_id_key> <sn_signature> [<payment_id>]"));
m_cmd_binder.set_handler("sweep_unmixable", boost::bind(&simple_wallet::sweep_unmixable, this, _1), tr("Send all unmixable outputs to yourself with ring_size 1"));
Expand Down Expand Up @@ -2619,7 +2619,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
case TransferNew:
ptx_vector = m_wallet->create_transactions_2(dsts, fake_outs_count, 0 /* unlock_time */, priority, extra, m_trusted_daemon);
break;
case TransferZeroFee:
case TransferRTAFee:
ptx_vector = m_wallet->create_transactions_2(dsts, fake_outs_count, 0 /* unlock_time */, priority, extra, m_trusted_daemon, true);
break;
default:
Expand Down Expand Up @@ -2873,9 +2873,9 @@ bool simple_wallet::transfer_new(const std::vector<std::string> &args_)
return transfer_main(TransferNew, args_);
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::transfer_zero_fee(const std::vector<std::string> &args_)
bool simple_wallet::transfer_rta(const std::vector<std::string> &args_)
{
return transfer_main(TransferZeroFee, args_);
return transfer_main(TransferRTAFee, args_);
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::locked_transfer(const std::vector<std::string> &args_)
Expand Down
2 changes: 1 addition & 1 deletion src/simplewallet/simplewallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ namespace cryptonote
bool transfer_main(int transfer_type, const std::vector<std::string> &args);
bool transfer(const std::vector<std::string> &args);
bool transfer_new(const std::vector<std::string> &args);
bool transfer_zero_fee(const std::vector<std::string> &args);
bool transfer_rta(const std::vector<std::string> &args);
bool locked_transfer(const std::vector<std::string> &args);
bool stake_transfer(const std::vector<std::string> &args);
bool sweep_main(uint64_t below, const std::vector<std::string> &args);
Expand Down
30 changes: 15 additions & 15 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ void do_prepare_file_names(const std::string& file_path, std::string& keys_file,
}
}

uint64_t calculate_fee(uint64_t fee_per_kb, size_t bytes, uint64_t fee_multiplier, bool allow_zero_fee)
uint64_t calculate_fee(uint64_t fee_per_kb, size_t bytes, uint64_t fee_multiplier, bool rta_tx_fee)
{
if (allow_zero_fee)
return 0;
if (rta_tx_fee)
return RTA_TX_FEE;
uint64_t kB = (bytes + 1023) / 1024;
return kB * fee_per_kb * fee_multiplier;
}

uint64_t calculate_fee(uint64_t fee_per_kb, const cryptonote::blobdata &blob, uint64_t fee_multiplier, bool allow_zero_fee)
uint64_t calculate_fee(uint64_t fee_per_kb, const cryptonote::blobdata &blob, uint64_t fee_multiplier, bool rta_tx_fee)
{
return calculate_fee(fee_per_kb, blob.size(), fee_multiplier, allow_zero_fee);
return calculate_fee(fee_per_kb, blob.size(), fee_multiplier, rta_tx_fee);
}

std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variables_map& vm, const options& opts)
Expand Down Expand Up @@ -3741,7 +3741,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions(std::vector<crypto
// failsafe split attempt counter
size_t attempt_count = 0;

bool allow_zero_fee = true;
bool allow_rta_fee = true;

for(attempt_count = 1; ;attempt_count++)
{
Expand Down Expand Up @@ -3770,7 +3770,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(fee_per_kb, txBlob, fee_multiplier, allow_zero_fee);
needed_fee = calculate_fee(fee_per_kb, txBlob, fee_multiplier, allow_rta_fee);
} while (ptx.fee < needed_fee);

ptx_vector.push_back(ptx);
Expand Down Expand Up @@ -4542,7 +4542,7 @@ static uint32_t get_count_above(const std::vector<wallet2::transfer_details> &tr
// not generate spurious change in all txes, thus decreasing the instantaneous
// usable balance.
std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time,
uint32_t priority, const std::vector<uint8_t> extra, bool trusted_daemon, bool zero_fee_tx)
uint32_t priority, const std::vector<uint8_t> extra, bool trusted_daemon, bool rta_tx_fee)
{
std::vector<size_t> unused_transfers_indices;
std::vector<size_t> unused_dust_indices;
Expand Down Expand Up @@ -4650,7 +4650,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(fee_per_kb, estimate_rct_tx_size(2, fake_outs_count + 1, 2), fee_multiplier, zero_fee_tx);
uint64_t estimated_fee = calculate_fee(fee_per_kb, estimate_rct_tx_size(2, fake_outs_count + 1, 2), fee_multiplier, rta_tx_fee);
preferred_inputs = pick_preferred_rct_inputs(needed_money + estimated_fee);
if (!preferred_inputs.empty())
{
Expand Down Expand Up @@ -4790,7 +4790,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, outs, 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(fee_per_kb, txBlob, fee_multiplier, zero_fee_tx);
needed_fee = calculate_fee(fee_per_kb, txBlob, fee_multiplier, rta_tx_fee);
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() + 1023) / 1024) << " kB tx, with " << print_money(available_for_fee) << " available for fee (" <<
print_money(needed_fee) << " needed)");
Expand Down Expand Up @@ -4827,15 +4827,15 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
LOG_PRINT_L2("We made a tx, adjusting fee and saving it");
do {

size_t tx_type = zero_fee_tx ? cryptonote::transaction::tx_type_rta : cryptonote::transaction::tx_type_generic;
size_t tx_type = rta_tx_fee ? cryptonote::transaction::tx_type_rta : cryptonote::transaction::tx_type_generic;
if (use_rct)
transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, outs, unlock_time, needed_fee, extra,
test_tx, test_ptx, tx_type);
else
transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, outs, unlock_time, needed_fee, extra,
detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), test_tx, test_ptx, tx_type);
txBlob = t_serializable_object_to_blob(test_ptx.tx);
needed_fee = calculate_fee(fee_per_kb, txBlob, fee_multiplier, zero_fee_tx);
needed_fee = calculate_fee(fee_per_kb, txBlob, fee_multiplier, rta_tx_fee);
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);
Expand Down Expand Up @@ -4972,7 +4972,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_from(const crypton
uint64_t needed_fee, available_for_fee = 0;
uint64_t upper_transaction_size_limit = get_upper_transaction_size_limit();
std::vector<std::vector<get_outs_entry>> outs;
bool allow_zero_fee = false;
bool allow_rta_fee = false;

const bool use_rct = fake_outs_count > 0 && use_fork_rules(4, 0);
const uint64_t fee_per_kb = get_per_kb_fee();
Expand Down Expand Up @@ -5033,7 +5033,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_from(const crypton
transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, outs, 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(fee_per_kb, txBlob, fee_multiplier, allow_zero_fee);
needed_fee = calculate_fee(fee_per_kb, txBlob, fee_multiplier, allow_rta_fee);
available_for_fee = test_ptx.fee + test_ptx.dests[0].amount + test_ptx.change_dts.amount;
LOG_PRINT_L2("Made a " << ((txBlob.size() + 1023) / 1024) << " kB tx, with " << print_money(available_for_fee) << " available for fee (" <<
print_money(needed_fee) << " needed)");
Expand All @@ -5050,7 +5050,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_from(const crypton
transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, outs, 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(fee_per_kb, txBlob, fee_multiplier, allow_zero_fee);
needed_fee = calculate_fee(fee_per_kb, txBlob, fee_multiplier, allow_rta_fee);
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);
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ namespace tools
std::vector<wallet2::pending_tx> create_transactions_2(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count,
const uint64_t unlock_time, uint32_t priority,
const std::vector<uint8_t> extra, bool trusted_daemon,
bool zero_fee_tx = false);
bool rta_tx_fee = false);

/*!
* \brief create_transactions_graft - creates graft transaction
Expand Down

0 comments on commit 8d78cbb

Please sign in to comment.