Skip to content

Commit

Permalink
Merge pull request monero-project#1 from electroneum/master
Browse files Browse the repository at this point in the history
Upstream Merge
  • Loading branch information
Chris Harrison authored May 4, 2018
2 parents 52d3e73 + 8c2d639 commit 1321485
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 19 deletions.
10 changes: 7 additions & 3 deletions src/cryptonote_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@
#define BLOCKS_SYNCHRONIZING_DEFAULT_COUNT 20 //by default, blocks count in blocks downloading
#define CRYPTONOTE_PROTOCOL_HOP_RELAX_COUNT 3 //value of hop, after which we use only announce of new block

#define CRYPTONOTE_MEMPOOL_TX_LIVETIME 86400 //seconds, one day
#define CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME 604800 //seconds, one week
#define CRYPTONOTE_MEMPOOL_TX_LIVETIME 86400 //seconds, one day
#define CRYPTONOTE_MEMPOOL_TX_LIVETIME_V6 (86400*3) //seconds, three days
#define CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME 604800 //seconds, one week

#define COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT 1000

Expand Down Expand Up @@ -131,7 +132,10 @@

#define HF_VERSION_DYNAMIC_FEE 4
#define HF_VERSION_MIN_MIXIN_4 6
#define HF_VERSION_ENFORCE_RCT 6

//RingCT
#define HF_VERSION_ENABLE_RCT 7 //Make RCT enabled from v7
#define HF_VERSION_ENFORCE_RCT 8 //Make RCT a requirment from v8

#define PER_KB_FEE_QUANTIZATION_DECIMALS 8

Expand Down
9 changes: 9 additions & 0 deletions src/cryptonote_core/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4061,6 +4061,15 @@ bool Blockchain::for_all_txpool_txes(std::function<bool(const crypto::hash&, con
return m_db->for_all_txpool_txes(f, include_blob);
}

uint32_t Blockchain::get_mempool_tx_livetime() const
{
if(get_hard_fork_version(get_current_blockchain_height()) >= 6)
{
return CRYPTONOTE_MEMPOOL_TX_LIVETIME_V6;
}
return CRYPTONOTE_MEMPOOL_TX_LIVETIME;
}

void Blockchain::set_user_options(uint64_t maxthreads, uint64_t blocks_per_sync, blockchain_db_sync_mode sync_mode, bool fast_sync)
{
if (sync_mode == db_defaultsync)
Expand Down
1 change: 1 addition & 0 deletions src/cryptonote_core/blockchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,7 @@ namespace cryptonote
bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const;
cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const;
bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false) const;
uint32_t get_mempool_tx_livetime() const;

bool is_within_compiled_block_hash_area(uint64_t height) const;
bool is_within_compiled_block_hash_area() const { return is_within_compiled_block_hash_area(m_db->height()); }
Expand Down
2 changes: 1 addition & 1 deletion src/cryptonote_core/cryptonote_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ namespace cryptonote
bool core::check_tx_inputs_ring_members_diff(const transaction& tx) const
{
const uint8_t version = m_blockchain_storage.get_current_hard_fork_version();
if (version >= 6)
if (version >= HF_VERSION_ENFORCE_RCT)
{
for(const auto& in: tx.vin)
{
Expand Down
6 changes: 4 additions & 2 deletions src/cryptonote_core/cryptonote_tx_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace cryptonote

CHECK_AND_ASSERT_MES(summary_amounts == block_reward, false, "Failed to construct miner tx, summary_amounts = " << summary_amounts << " not equal block_reward = " << block_reward);

if (hard_fork_version >= 4)
if (hard_fork_version >= HF_VERSION_ENABLE_RCT)
tx.version = 2;
else
tx.version = 1;
Expand Down Expand Up @@ -163,7 +163,9 @@ namespace cryptonote
tx.set_null();
amount_keys.clear();

tx.version = rct ? 2 : 1;
//tx.version = rct ? 2 : 1;
tx.version = 1;

tx.unlock_time = unlock_time;

tx.extra = extra;
Expand Down
7 changes: 4 additions & 3 deletions src/cryptonote_core/tx_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ namespace cryptonote
std::unordered_set<crypto::hash> remove;
m_blockchain.for_all_txpool_txes([this, &remove](const crypto::hash &txid, const txpool_tx_meta_t &meta, const cryptonote::blobdata*) {
uint64_t tx_age = time(nullptr) - meta.receive_time;

if((tx_age > CRYPTONOTE_MEMPOOL_TX_LIVETIME && !meta.kept_by_block) ||
uint32_t mempool_lifetime = m_blockchain.get_mempool_tx_livetime();
if((tx_age > mempool_lifetime && !meta.kept_by_block) ||
(tx_age > CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME && meta.kept_by_block) )
{
LOG_PRINT_L1("Tx " << txid << " removed from tx pool due to outdated, age: " << tx_age );
Expand Down Expand Up @@ -477,7 +477,8 @@ namespace cryptonote
// if the tx is older than half the max lifetime, we don't re-relay it, to avoid a problem
// mentioned by smooth where nodes would flush txes at slightly different times, causing
// flushed txes to be re-added when received from a node which was just about to flush it
uint64_t max_age = meta.kept_by_block ? CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME : CRYPTONOTE_MEMPOOL_TX_LIVETIME;
uint32_t mempool_lifetime = m_blockchain.get_mempool_tx_livetime();
uint64_t max_age = meta.kept_by_block ? CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME : mempool_lifetime;
if (now - meta.receive_time <= max_age / 2)
{
try
Expand Down
32 changes: 22 additions & 10 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <boost/format.hpp>
#include <boost/optional/optional.hpp>
#include <boost/utility/value_init.hpp>
#include <boost/algorithm/string/join.hpp>
#include "include_base_utils.h"
using namespace epee;

Expand Down Expand Up @@ -427,6 +428,20 @@ static void throw_on_rpc_response_error(const boost::optional<std::string> &stat
THROW_WALLET_EXCEPTION_IF(*status != CORE_RPC_STATUS_OK, tools::error::wallet_generic_rpc_error, method, *status);
}

std::string strjoin(const std::vector<size_t> &V, const char *sep)
{
std::stringstream ss;
bool first = true;
for (const auto &v: V)
{
if (!first)
ss << sep;
ss << std::to_string(v);
first = false;
}
return ss.str();
}

} //namespace

namespace tools
Expand Down Expand Up @@ -4362,7 +4377,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
}
else
{
THROW_WALLET_EXCEPTION_IF(original_output_index > dsts.size(), error::wallet_internal_error, "original_output_index too large");
THROW_WALLET_EXCEPTION_IF(original_output_index > dsts.size(), error::wallet_internal_error, std::string("original_output_index too large: ") + std::to_string(original_output_index) + " > " + std::to_string(dsts.size()));
if (original_output_index == dsts.size())
dsts.push_back(tx_destination_entry(0,addr));
THROW_WALLET_EXCEPTION_IF(memcmp(&dsts[original_output_index].addr, &addr, sizeof(addr)), error::wallet_internal_error, "Mismatched destination address");
Expand All @@ -4374,7 +4389,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
bool adding_fee; // true if new outputs go towards fee, rather than destinations
uint64_t needed_fee, available_for_fee = 0;
uint64_t upper_transaction_size_limit = get_upper_transaction_size_limit();
const bool use_rct = use_fork_rules(4, 0);
const bool use_rct = use_fork_rules(HF_VERSION_ENABLE_RCT, 0);

const uint64_t fee_per_kb = get_per_kb_fee();
const uint64_t fee_multiplier = get_fee_multiplier(priority, get_fee_algorithm());
Expand Down Expand Up @@ -4461,12 +4476,8 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
TX &tx = txes.back();

LOG_PRINT_L2("Start of loop with " << unused_transfers_indices.size() << " " << unused_dust_indices.size());
LOG_PRINT_L2("unused_transfers_indices:");
for (auto t: unused_transfers_indices)
LOG_PRINT_L2(" " << t);
LOG_PRINT_L2("unused_dust_indices:");
for (auto t: unused_dust_indices)
LOG_PRINT_L2(" " << t);
LOG_PRINT_L2("unused_transfers_indices: " << strjoin(unused_transfers_indices, " "));
LOG_PRINT_L2("unused_dust_indices:" << strjoin(unused_dust_indices, " "));
LOG_PRINT_L2("dsts size " << dsts.size() << ", first " << (dsts.empty() ? -1 : dsts[0].amount));
LOG_PRINT_L2("adding_fee " << adding_fee << ", use_rct " << use_rct);

Expand Down Expand Up @@ -4640,6 +4651,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
{
LOG_PRINT_L2("We have more to pay, starting another tx");
txes.push_back(TX());
original_output_index = 0;
}
}
}
Expand Down Expand Up @@ -4676,7 +4688,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_all(uint64_t below
{
std::vector<size_t> unused_transfers_indices;
std::vector<size_t> unused_dust_indices;
const bool use_rct = use_fork_rules(4, 0);
const bool use_rct = use_fork_rules(HF_VERSION_ENABLE_RCT, 0);

// gather all our dust and non dust outputs
for (size_t i = 0; i < m_transfers.size(); ++i)
Expand Down Expand Up @@ -4712,7 +4724,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_from(const crypton
uint64_t upper_transaction_size_limit = get_upper_transaction_size_limit();
std::vector<std::vector<get_outs_entry>> outs;

const bool use_rct = fake_outs_count > 0 && use_fork_rules(4, 0);
const bool use_rct = fake_outs_count > 0 && use_fork_rules(HF_VERSION_ENABLE_RCT, 0);
const uint64_t fee_per_kb = get_per_kb_fee();
const uint64_t fee_multiplier = get_fee_multiplier(priority, get_fee_algorithm());

Expand Down

0 comments on commit 1321485

Please sign in to comment.