initial fee updates for block weight based tx construction; moved some functions around (+monero_fee_utils)

pull/29/head
Paul Shapiro 6 years ago
parent 4ae115f842
commit bb9e55d4fe

@ -69,6 +69,8 @@ set(
src/monero_paymentID_utils.cpp
src/monero_key_image_utils.hpp
src/monero_key_image_utils.cpp
src/monero_fee_utils.hpp
src/monero_fee_utils.cpp
src/monero_transfer_utils.hpp
src/monero_transfer_utils.cpp
src/monero_fork_rules.hpp

@ -0,0 +1,277 @@
//
// monero_fee_utils.cpp
// Copyright © 2018 MyMonero. All rights reserved.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//
//
//
#include "monero_fee_utils.hpp"
#include "wallet_errors.h"
#include "string_tools.h"
//
using namespace std;
using namespace boost;
using namespace epee;
using namespace crypto;
using namespace cryptonote;
using namespace tools; // for error::
using namespace monero_fork_rules;
//
// used to choose when to stop adding outputs to a tx
#define APPROXIMATE_INPUT_BYTES 80
//
uint32_t monero_fee_utils::default_priority()
{
return 1; // lowest
}
//
uint64_t monero_fee_utils::get_base_fee( // added as of v8
uint64_t fee_per_kb,
use_fork_rules_fn_type use_fork_rules_fn
) {
// since this is the lightwallet…
if (use_fork_rules_fn(HF_VERSION_PER_BYTE_FEE, 0/*default*/)) {
return fee_per_kb / 1024;
} else {
return fee_per_kb;
}
}
uint64_t monero_fee_utils::get_fee_quantization_mask(
use_fork_rules_fn_type use_fork_rules_fn
) {
// if(m_light_wallet) {
return 1; // "TODO"
// }
// bool use_per_byte_fee = use_fork_rules(HF_VERSION_PER_BYTE_FEE, 0);
// if (!use_per_byte_fee)
// return 1;
//
// uint64_t fee_quantization_mask;
// boost::optional<std::string> result = m_node_rpc_proxy.get_fee_quantization_mask(fee_quantization_mask);
// if (result)
// return 1;
// return fee_quantization_mask;
}
//
uint64_t monero_fee_utils::estimated_tx_network_fee(
uint64_t fee_per_kb,
uint32_t priority,
use_fork_rules_fn_type use_fork_rules_fn
) {
bool bulletproof = use_fork_rules_fn(get_bulletproof_fork(), 0); // eventually just hardcode this to true (?)
uint64_t fee_multiplier = get_fee_multiplier(priority, default_priority(), get_fee_algorithm(use_fork_rules_fn), use_fork_rules_fn);
std::vector<uint8_t> extra; // blank extra
size_t est_tx_size = estimate_rct_tx_size(2, fixed_mixinsize(), 2, extra.size(), bulletproof); // typically ~14kb post-rct, pre-bulletproofs
uint64_t estimated_fee = calculate_fee(fee_per_kb, est_tx_size, fee_multiplier);
//
return estimated_fee;
}
uint64_t monero_fee_utils::get_upper_transaction_weight_limit(
uint64_t upper_transaction_weight_limit__or_0_for_default,
use_fork_rules_fn_type use_fork_rules_fn
) {
if (upper_transaction_weight_limit__or_0_for_default > 0)
return upper_transaction_weight_limit__or_0_for_default;
uint64_t full_reward_zone = use_fork_rules_fn(5, 10) ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : use_fork_rules_fn(2, 10) ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 : CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1;
if (use_fork_rules_fn(8, 10))
return full_reward_zone / 2 - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE;
else
return full_reward_zone - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE;
}
uint64_t monero_fee_utils::get_fee_multiplier(
uint32_t priority,
uint32_t default_priority,
int fee_algorithm,
use_fork_rules_fn_type use_fork_rules_fn
) {
static const struct
{
size_t count;
uint64_t multipliers[4];
}
multipliers[] =
{
{ 3, {1, 2, 3} },
{ 3, {1, 20, 166} },
{ 4, {1, 4, 20, 166} },
{ 4, {1, 5, 25, 1000} },
};
if (fee_algorithm == -1)
fee_algorithm = get_fee_algorithm(use_fork_rules_fn);
// 0 -> default (here, x1 till fee algorithm 2, x4 from it)
if (priority == 0)
priority = default_priority;
if (priority == 0)
{
if (fee_algorithm >= 2)
priority = 2;
else
priority = 1;
}
THROW_WALLET_EXCEPTION_IF(fee_algorithm < 0 || fee_algorithm > 3, error::invalid_priority);
// 1 to 3/4 are allowed as priorities
const uint32_t max_priority = multipliers[fee_algorithm].count;
if (priority >= 1 && priority <= max_priority)
{
return multipliers[fee_algorithm].multipliers[priority-1];
}
THROW_WALLET_EXCEPTION_IF (false, error::invalid_priority);
return 1;
}
int monero_fee_utils::get_fee_algorithm(use_fork_rules_fn_type use_fork_rules_fn)
{
// changes at v3, v5, v8
if (use_fork_rules_fn(HF_VERSION_PER_BYTE_FEE, 0))
return 3;
if (use_fork_rules_fn(5, 0))
return 2;
if (use_fork_rules_fn(3, -720 * 14))
return 1;
return 0;
}
size_t monero_fee_utils::estimate_rct_tx_size(int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof)
{
size_t size = 0;
// tx prefix
// first few bytes
size += 1 + 6;
// vin
size += n_inputs * (1+6+(mixin+1)*2+32);
// vout
size += n_outputs * (6+32);
// extra
size += extra_size;
// rct signatures
// type
size += 1;
// rangeSigs
if (bulletproof)
{
size_t log_padded_outputs = 0;
while ((1<<log_padded_outputs) < n_outputs)
++log_padded_outputs;
size += (2 * (6 + log_padded_outputs) + 4 + 5) * 32 + 3;
}
else
size += (2*64*32+32+64*32) * n_outputs;
// MGs
size += n_inputs * (64 * (mixin+1) + 32);
// mixRing - not serialized, can be reconstructed
/* size += 2 * 32 * (mixin+1) * n_inputs; */
// pseudoOuts
size += 32 * n_inputs;
// ecdhInfo
size += 2 * 32 * n_outputs;
// outPk - only commitment is saved
size += 32 * n_outputs;
// txnFee
size += 4;
LOG_PRINT_L2("estimated " << (bulletproof ? "bulletproof" : "borromean") << " rct tx size for " << n_inputs << " inputs with ring size " << (mixin+1) << " and " << n_outputs << " outputs: " << size << " (" << ((32 * n_inputs/*+1*/) + 2 * 32 * (mixin+1) * n_inputs + 32 * n_outputs) << " saved)");
return size;
}
size_t monero_fee_utils::estimate_tx_size(bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof)
{
if (use_rct)
return estimate_rct_tx_size(n_inputs, mixin, n_outputs, extra_size, bulletproof);
else
return n_inputs * (mixin+1) * APPROXIMATE_INPUT_BYTES + extra_size;
}
uint64_t monero_fee_utils::estimate_tx_weight(bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof)
{
size_t size = estimate_tx_size(use_rct, n_inputs, mixin, n_outputs, extra_size, bulletproof);
if (use_rct && bulletproof && n_outputs > 2)
{
const uint64_t bp_base = 368;
size_t log_padded_outputs = 2;
while ((1<<log_padded_outputs) < n_outputs)
++log_padded_outputs;
uint64_t nlr = 2 * (6 + log_padded_outputs);
const uint64_t bp_size = 32 * (9 + nlr);
const uint64_t bp_clawback = (bp_base * (1<<log_padded_outputs) - bp_size) * 4 / 5;
MDEBUG("clawback on size " << size << ": " << bp_clawback);
size += bp_clawback;
}
return size;
}
uint64_t monero_fee_utils::estimate_fee(bool use_per_byte_fee, bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof, uint64_t base_fee, uint64_t fee_multiplier, uint64_t fee_quantization_mask)
{
if (use_per_byte_fee)
{
const size_t estimated_tx_weight = estimate_tx_weight(use_rct, n_inputs, mixin, n_outputs, extra_size, bulletproof);
return calculate_fee_from_weight(base_fee, estimated_tx_weight, fee_multiplier, fee_quantization_mask);
}
else
{
const size_t estimated_tx_size = estimate_tx_size(use_rct, n_inputs, mixin, n_outputs, extra_size, bulletproof);
return calculate_fee(base_fee, estimated_tx_size, fee_multiplier);
}
}
//
uint64_t monero_fee_utils::calculate_fee_from_weight(uint64_t base_fee, uint64_t weight, uint64_t fee_multiplier, uint64_t fee_quantization_mask)
{
uint64_t fee = weight * base_fee * fee_multiplier;
fee = (fee + fee_quantization_mask - 1) / fee_quantization_mask * fee_quantization_mask;
return fee;
}
uint64_t monero_fee_utils::calculate_fee(uint64_t fee_per_kb, const cryptonote::blobdata &blob, uint64_t fee_multiplier)
{
return calculate_fee(fee_per_kb, blob.size(), fee_multiplier);
}
uint64_t monero_fee_utils::calculate_fee(bool use_per_byte_fee, const cryptonote::transaction &tx, size_t blob_size, uint64_t base_fee, uint64_t fee_multiplier, uint64_t fee_quantization_mask)
{
if (use_per_byte_fee) {
return calculate_fee_from_weight(base_fee, cryptonote::get_transaction_weight(tx, blob_size), fee_multiplier, fee_quantization_mask);
} else {
return calculate_fee(base_fee, blob_size, fee_multiplier);
}
}
uint64_t monero_fee_utils::calculate_fee(uint64_t fee_per_kb, size_t bytes, uint64_t fee_multiplier)
{
uint64_t kB = (bytes + 1023) / 1024;
//
return kB * fee_per_kb * fee_multiplier;
}

@ -0,0 +1,78 @@
//
// monero_fee_utils.hpp
// Copyright (c) 2014-2018, MyMonero.com
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//
#ifndef monero_fee_utils_hpp
#define monero_fee_utils_hpp
//
#include <boost/optional.hpp>
//
#include "string_tools.h"
//
#include "crypto.h"
#include "cryptonote_basic.h"
#include "cryptonote_format_utils.h"
//
#include "monero_fork_rules.hpp"
//
namespace monero_fee_utils
{
using namespace std;
using namespace boost;
using namespace cryptonote;
using namespace monero_fork_rules;
using namespace crypto;
//
uint32_t default_priority();
//
uint64_t get_upper_transaction_weight_limit(uint64_t upper_transaction_weight_limit__or_0_for_default, use_fork_rules_fn_type use_fork_rules_fn);
uint64_t get_fee_multiplier(uint32_t priority, uint32_t default_priority, int fee_algorithm, use_fork_rules_fn_type use_fork_rules_fn);
int get_fee_algorithm(use_fork_rules_fn_type use_fork_rules_fn);
uint64_t get_base_fee(uint64_t fee_per_kb, use_fork_rules_fn_type use_fork_rules_fn);
uint64_t get_fee_quantization_mask(use_fork_rules_fn_type use_fork_rules_fn);
//
uint64_t estimate_fee(bool use_per_byte_fee, bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof, uint64_t base_fee, uint64_t fee_multiplier, uint64_t fee_quantization_mask);
//
uint64_t calculate_fee_from_weight(uint64_t base_fee, uint64_t weight, uint64_t fee_multiplier, uint64_t fee_quantization_mask);
uint64_t calculate_fee(uint64_t fee_per_kb, size_t bytes, uint64_t fee_multiplier);
uint64_t calculate_fee(uint64_t fee_per_kb, const blobdata &blob, uint64_t fee_multiplier);
uint64_t calculate_fee(bool use_per_byte_fee, const cryptonote::transaction &tx, size_t blob_size, uint64_t base_fee, uint64_t fee_multiplier, uint64_t fee_quantization_mask);
//
size_t estimate_rct_tx_size(int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof);
uint64_t estimate_tx_weight(bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof);
size_t estimate_tx_size(bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof);
uint64_t estimated_tx_network_fee( // convenience function for size + calc
uint64_t fee_per_kb,
uint32_t priority, // when priority=0, falls back to monero_fee_utils::default_priority()
use_fork_rules_fn_type use_fork_rules_fn // this is extracted to a function so that implementations can optionally query the daemon (although this presently implies that such a call remains blocking)
);
}
#endif /* monero_fee_utils_hpp */

@ -52,6 +52,29 @@ bool monero_fork_rules::lightwallet_hardcoded__use_fork_rules(uint8_t version, i
if (version >= monero_fork_rules::get_bulletproof_fork()) {
return bulletproof;
}
return true;
return true; // TODO - we don't have the actual fork rules from thje lightwallet server yet
//
// full wallets do:
// uint64_t height, earliest_height;
// boost::optional<std::string> result = m_node_rpc_proxy.get_height(height);
// throw_on_rpc_response_error(result, "get_info");
// result = m_node_rpc_proxy.get_earliest_height(version, earliest_height);
// throw_on_rpc_response_error(result, "get_hard_fork_info");
//
// bool close_enough = height >= earliest_height - early_blocks; // start using the rules that many blocks beforehand
// if (close_enough)
// LOG_PRINT_L2("Using v" << (unsigned)version << " rules");
// else
// LOG_PRINT_L2("Not using v" << (unsigned)version << " rules");
// return close_enough;
}
//
// Protocol / Defaults
uint32_t monero_fork_rules::fixed_ringsize()
{
return 11; // v8
}
uint32_t monero_fork_rules::fixed_mixinsize()
{
return monero_fork_rules::fixed_ringsize() - 1;
}

@ -46,6 +46,10 @@ namespace monero_fork_rules
bool lightwallet_hardeded__use_bulletproofs();
//
bool lightwallet_hardcoded__use_fork_rules(uint8_t version, int64_t early_blocks); // convenience
//
//
uint32_t fixed_ringsize(); // not mixinsize, which would be ringsize-1
uint32_t fixed_mixinsize(); // not ringsize, which would be mixinsize+1
}
#endif /* monero_fork_rules */

@ -45,159 +45,7 @@ using namespace cryptonote;
using namespace tools; // for error::
using namespace monero_transfer_utils;
using namespace monero_fork_rules;
//
// Protocol / Defaults
uint32_t monero_transfer_utils::fixed_ringsize()
{
return 11; // best practice is to conform to fixed default ring size
}
uint32_t monero_transfer_utils::fixed_mixinsize()
{
return monero_transfer_utils::fixed_ringsize() - 1;
}
uint32_t monero_transfer_utils::default_priority()
{
return 1; // lowest (TODO: declare centrally)
}
//
// Fee estimation
uint64_t monero_transfer_utils::estimated_tx_network_fee(
uint64_t fee_per_kb,
uint32_t priority,
use_fork_rules_fn_type use_fork_rules_fn
) {
bool bulletproof = use_fork_rules_fn(get_bulletproof_fork(), 0); // eventually just hardcode this to true (?)
uint64_t fee_multiplier = get_fee_multiplier(priority, default_priority(), get_fee_algorithm(use_fork_rules_fn), use_fork_rules_fn);
std::vector<uint8_t> extra; // blank extra
size_t est_tx_size = estimate_rct_tx_size(2, fixed_mixinsize(), 2, extra.size(), bulletproof); // typically ~14kb post-rct, pre-bulletproofs
uint64_t estimated_fee = calculate_fee(fee_per_kb, est_tx_size, fee_multiplier);
//
return estimated_fee;
}
uint64_t monero_transfer_utils::get_upper_transaction_size_limit(
uint64_t upper_transaction_size_limit__or_0_for_default,
use_fork_rules_fn_type use_fork_rules_fn
) {
if (upper_transaction_size_limit__or_0_for_default > 0)
return upper_transaction_size_limit__or_0_for_default;
uint64_t full_reward_zone = use_fork_rules_fn(5, 10) ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : use_fork_rules_fn(2, 10) ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 : CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1;
return full_reward_zone - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE;
}
uint64_t monero_transfer_utils::get_fee_multiplier(
uint32_t priority,
uint32_t default_priority,
int fee_algorithm,
use_fork_rules_fn_type use_fork_rules_fn
) {
static const uint64_t old_multipliers[3] = {1, 2, 3};
static const uint64_t new_multipliers[3] = {1, 20, 166};
static const uint64_t newer_multipliers[4] = {1, 4, 20, 166};
if (fee_algorithm == -1)
fee_algorithm = get_fee_algorithm(use_fork_rules_fn);
// 0 -> default (here, x1 till fee algorithm 2, x4 from it)
if (priority == 0)
priority = default_priority;
if (priority == 0)
{
if (fee_algorithm >= 2)
priority = 2;
else
priority = 1;
}
// 1 to 3/4 are allowed as priorities
uint32_t max_priority = (fee_algorithm >= 2) ? 4 : 3;
if (priority >= 1 && priority <= max_priority)
{
switch (fee_algorithm)
{
case 0: return old_multipliers[priority-1];
case 1: return new_multipliers[priority-1];
case 2: return newer_multipliers[priority-1];
default: THROW_WALLET_EXCEPTION_IF (true, error::invalid_priority);
}
}
THROW_WALLET_EXCEPTION_IF (false, error::invalid_priority);
return 1;
}
int monero_transfer_utils::get_fee_algorithm(use_fork_rules_fn_type use_fork_rules_fn)
{
// changes at v3 and v5
if (use_fork_rules_fn(5, 0))
return 2;
if (use_fork_rules_fn(3, -720 * 14))
return 1;
return 0;
}
size_t monero_transfer_utils::estimate_rct_tx_size(int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof)
{
size_t size = 0;
// tx prefix
// first few bytes
size += 1 + 6;
// vin
size += n_inputs * (1+6+(mixin+1)*2+32);
// vout
size += n_outputs * (6+32);
// extra
size += extra_size;
// rct signatures
// type
size += 1;
// rangeSigs
if (bulletproof)
size += ((2*6 + 4 + 5)*32 + 3) * n_outputs;
else
size += (2*64*32+32+64*32) * n_outputs;
// MGs
size += n_inputs * (64 * (mixin+1) + 32);
// mixRing - not serialized, can be reconstructed
/* size += 2 * 32 * (mixin+1) * n_inputs; */
// pseudoOuts
size += 32 * n_inputs;
// ecdhInfo
size += 2 * 32 * n_outputs;
// outPk - only commitment is saved
size += 32 * n_outputs;
// txnFee
size += 4;
LOG_PRINT_L2("estimated rct tx size for " << n_inputs << " with ring size " << (mixin+1) << " and " << n_outputs << ": " << size << " (" << ((32 * n_inputs/*+1*/) + 2 * 32 * (mixin+1) * n_inputs + 32 * n_outputs) << " saved)");
return size;
}
size_t monero_transfer_utils::estimate_tx_size(bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof)
{
if (use_rct)
return estimate_rct_tx_size(n_inputs, mixin, n_outputs + 1, extra_size, bulletproof);
else
return n_inputs * (mixin+1) * APPROXIMATE_INPUT_BYTES + extra_size;
}
//
uint64_t monero_transfer_utils::calculate_fee(uint64_t fee_per_kb, size_t bytes, uint64_t fee_multiplier)
{
uint64_t kB = (bytes + 1023) / 1024;
//
return kB * fee_per_kb * fee_multiplier;
}
uint64_t monero_transfer_utils::calculate_fee(uint64_t fee_per_kb, const cryptonote::blobdata &blob, uint64_t fee_multiplier)
{
return calculate_fee(fee_per_kb, blob.size(), fee_multiplier);
}
using namespace monero_fee_utils;
//
// Transfer parsing/derived properties
bool monero_transfer_utils::is_transfer_unlocked(
@ -244,13 +92,6 @@ bool monero_transfer_utils::is_tx_spendtime_unlocked(
}
//
// Constructing transactions
std::string monero_transfer_utils::new_dummy_address_string_for_rct_tx(network_type nettype)
{
cryptonote::account_base account;
account.generate();
//
return account.get_public_address_str(nettype);
}
bool _rct_hex_to_rct_commit(
const std::string &rct_string,
rct::key &rct_commit
@ -531,8 +372,8 @@ void monero_transfer_utils::create_transaction(
retVals.errCode = transactionNotConstructed;
return;
}
if (get_object_blobsize(tx) >= get_upper_transaction_size_limit(0, use_fork_rules_fn)) {
// TODO: return error::tx_too_big, tx, upper_transaction_size_limit
if (get_upper_transaction_weight_limit(0, use_fork_rules_fn) <= get_transaction_weight(tx)) {
// TODO: return error::tx_too_big, tx, upper_transaction_weight_limit
retVals.errCode = transactionTooBig;
return;
}

@ -43,13 +43,11 @@
#include "ringct/rctSigs.h"
//
#include "monero_fork_rules.hpp"
#include "monero_fee_utils.hpp"
//
using namespace tools;
#include "tools__ret_vals.hpp"
//
// used to choose when to stop adding outputs to a tx
#define APPROXIMATE_INPUT_BYTES 80
//
namespace monero_transfer_utils
{
using namespace std;
@ -58,30 +56,9 @@ namespace monero_transfer_utils
using namespace monero_fork_rules;
using namespace crypto;
//
uint64_t get_upper_transaction_size_limit(uint64_t upper_transaction_size_limit__or_0_for_default, use_fork_rules_fn_type use_fork_rules_fn);
uint64_t get_fee_multiplier(uint32_t priority, uint32_t default_priority, int fee_algorithm, use_fork_rules_fn_type use_fork_rules_fn);
int get_fee_algorithm(use_fork_rules_fn_type use_fork_rules_fn);
//
uint64_t calculate_fee(uint64_t fee_per_kb, size_t bytes, uint64_t fee_multiplier);
uint64_t calculate_fee(uint64_t fee_per_kb, const blobdata &blob, uint64_t fee_multiplier);
//
size_t estimate_rct_tx_size(int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof);
size_t estimate_tx_size(bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof);
uint64_t estimated_tx_network_fee( // convenience function for size + calc
uint64_t fee_per_kb,
uint32_t priority, // when priority=0, falls back to monero_transfer_utils::default_priority()
use_fork_rules_fn_type use_fork_rules_fn // this is extracted to a function so that implementations can optionally query the daemon (although this presently implies that such a call remains blocking)
);
//
bool is_transfer_unlocked(uint64_t unlock_time, uint64_t block_height, uint64_t blockchain_size, network_type nettype = MAINNET);
bool is_tx_spendtime_unlocked(uint64_t unlock_time, uint64_t block_height, uint64_t blockchain_size, network_type nettype = MAINNET);
//
uint32_t fixed_ringsize(); // not mixinsize, which would be ringsize-1
uint32_t fixed_mixinsize(); // not ringsize, which would be mixinsize+1
uint32_t default_priority();
//
string new_dummy_address_string_for_rct_tx(network_type nettype = MAINNET);
//
// Types - Arguments
struct SpendableOutput
{

@ -387,7 +387,7 @@ string serial_bridge::estimate_rct_tx_size(const string &args_string)
// it will already have thrown an exception
return error_ret_json_from_message("Invalid JSON");
}
uint32_t size = monero_transfer_utils::estimate_rct_tx_size(
uint32_t size = monero_fee_utils::estimate_rct_tx_size(
json_root.get<int>("n_inputs"),
json_root.get<int>("mixin"),
json_root.get<int>("n_outputs"),
@ -409,7 +409,7 @@ string serial_bridge::calculate_fee(const string &args_string)
// it will already have thrown an exception
return error_ret_json_from_message("Invalid JSON");
}
uint64_t fee = monero_transfer_utils::calculate_fee(
uint64_t fee = monero_fee_utils::calculate_fee(
stoull(json_root.get<string>("fee_per_kb")),
stoul(json_root.get<string>("num_bytes")),
stoull(json_root.get<string>("fee_multiplier"))
@ -429,7 +429,7 @@ string serial_bridge::estimated_tx_network_fee(const string &args_string)
// it will already have thrown an exception
return error_ret_json_from_message("Invalid JSON");
}
uint64_t fee = monero_transfer_utils::estimated_tx_network_fee(
uint64_t fee = monero_fee_utils::estimated_tx_network_fee(
stoull(json_root.get<string>("fee_per_kb")),
stoul(json_root.get<string>("priority")),
[] (uint8_t version, int64_t early_blocks) -> bool

@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(transfers__fee)
};
uint64_t fee_per_kb = 9000000;
uint32_t priority = 2;
uint64_t est_fee = monero_transfer_utils::estimated_tx_network_fee(fee_per_kb, priority, use_fork_rules_fn);
uint64_t est_fee = monero_fee_utils::estimated_tx_network_fee(fee_per_kb, priority, use_fork_rules_fn);
std::cout << "transfers__fee: est_fee with fee_per_kb " << fee_per_kb << ": " << est_fee << std::endl;
BOOST_REQUIRE(est_fee > 0);
}
@ -973,7 +973,7 @@ BOOST_AUTO_TEST_CASE(bridged__estimated_tx_network_fee)
BOOST_REQUIRE(fee_string != none);
BOOST_REQUIRE((*fee_string).size() > 0);
uint64_t fee = stoull(*fee_string);
BOOST_REQUIRE(fee == 144000000); // with bulletproofs on
BOOST_REQUIRE(fee == 135000000);
cout << "bridged__estimated_tx_network_fee: " << fee << endl;
}
@ -985,7 +985,7 @@ BOOST_AUTO_TEST_CASE(bridged__estimate_rct_tx_size)
//
boost::property_tree::ptree root;
root.put("n_inputs", 2);
root.put("mixin", monero_transfer_utils::fixed_mixinsize());
root.put("mixin", monero_fork_rules::fixed_mixinsize());
root.put("n_outputs", 2);
std::vector<uint8_t> extra; // blank extra
root.put("extra_size", extra.size());

Loading…
Cancel
Save