From 81c384e408edef2eeced88ea1cf976720b6fed32 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 14 Jan 2017 13:01:21 +0000 Subject: fix do_not_relay not preventing relaying on a timer Also print its value when printing pool --- src/cryptonote_core/blockchain.cpp | 16 ++++++++-------- src/cryptonote_core/cryptonote_core.cpp | 12 ++++++------ src/cryptonote_core/cryptonote_core.h | 9 ++++++--- src/cryptonote_core/tx_pool.cpp | 16 ++++++++++------ src/cryptonote_core/tx_pool.h | 14 ++++++++++---- 5 files changed, 40 insertions(+), 27 deletions(-) (limited to 'src/cryptonote_core') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index de3af8e02..96b3f6bba 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -508,7 +508,7 @@ block Blockchain::pop_block_from_blockchain() // that might not be always true. Unlikely though, and always relaying // these again might cause a spike of traffic as many nodes re-relay // all the transactions in a popped block when a reorg happens. - bool r = m_tx_pool.add_tx(tx, tvc, true, true, version); + bool r = m_tx_pool.add_tx(tx, tvc, true, true, false, version); if (!r) { LOG_ERROR("Error returning transaction to tx_pool"); @@ -2973,7 +2973,7 @@ void Blockchain::return_tx_to_pool(const std::vector &txs) // that might not be always true. Unlikely though, and always relaying // these again might cause a spike of traffic as many nodes re-relay // all the transactions in a popped block when a reorg happens. - if (!m_tx_pool.add_tx(tx, tvc, true, true, version)) + if (!m_tx_pool.add_tx(tx, tvc, true, true, false, version)) { LOG_PRINT_L0("Failed to return taken transaction with hash: " << get_transaction_hash(tx) << " to tx_pool"); } @@ -2990,9 +2990,9 @@ bool Blockchain::flush_txes_from_pool(const std::list &txids) cryptonote::transaction tx; size_t blob_size; uint64_t fee; - bool relayed; + bool relayed, do_not_relay; LOG_PRINT_L1("Removing txid " << txid << " from the pool"); - if(m_tx_pool.have_tx(txid) && !m_tx_pool.take_tx(txid, tx, blob_size, fee, relayed)) + if(m_tx_pool.have_tx(txid) && !m_tx_pool.take_tx(txid, tx, blob_size, fee, relayed, do_not_relay)) { LOG_PRINT_L0("Failed to remove txid " << txid << " from the pool"); res = false; @@ -3153,7 +3153,7 @@ leave: transaction tx; size_t blob_size = 0; uint64_t fee = 0; - bool relayed = false; + bool relayed = false, do_not_relay = false; TIME_MEASURE_START(aa); // XXX old code does not check whether tx exists @@ -3170,7 +3170,7 @@ leave: TIME_MEASURE_START(bb); // get transaction with hash from tx_pool - if(!m_tx_pool.take_tx(tx_id, tx, blob_size, fee, relayed)) + if(!m_tx_pool.take_tx(tx_id, tx, blob_size, fee, relayed, do_not_relay)) { LOG_PRINT_L1("Block with id: " << id << " has at least one unknown transaction with id: " << tx_id); bvc.m_verifivation_failed = true; @@ -3954,12 +3954,12 @@ void Blockchain::load_compiled_in_block_hashes() size_t blob_size; uint64_t fee; - bool relayed; + bool relayed, do_not_relay; transaction pool_tx; for(const transaction &tx : txs) { crypto::hash tx_hash = get_transaction_hash(tx); - m_tx_pool.take_tx(tx_hash, pool_tx, blob_size, fee, relayed); + m_tx_pool.take_tx(tx_hash, pool_tx, blob_size, fee, relayed, do_not_relay); } } } diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index c63a08ee4..f1574d3c7 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -452,7 +452,7 @@ namespace cryptonote return false; } //----------------------------------------------------------------------------------------------- - bool core::handle_incoming_tx(const blobdata& tx_blob, tx_verification_context& tvc, bool keeped_by_block, bool relayed) + bool core::handle_incoming_tx(const blobdata& tx_blob, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { tvc = boost::value_initialized(); //want to process all transactions sequentially @@ -501,7 +501,7 @@ namespace cryptonote return false; } - bool r = add_new_tx(tx, tx_hash, tx_prefixt_hash, tx_blob.size(), tvc, keeped_by_block, relayed); + bool r = add_new_tx(tx, tx_hash, tx_prefixt_hash, tx_blob.size(), tvc, keeped_by_block, relayed, do_not_relay); if(tvc.m_verifivation_failed) {LOG_PRINT_RED_L1("Transaction verification failed: " << tx_hash);} else if(tvc.m_verifivation_impossible) @@ -640,13 +640,13 @@ namespace cryptonote return true; } //----------------------------------------------------------------------------------------------- - bool core::add_new_tx(const transaction& tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed) + bool core::add_new_tx(const transaction& tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { crypto::hash tx_hash = get_transaction_hash(tx); crypto::hash tx_prefix_hash = get_transaction_prefix_hash(tx); blobdata bl; t_serializable_object_to_blob(tx, bl); - return add_new_tx(tx, tx_hash, tx_prefix_hash, bl.size(), tvc, keeped_by_block, relayed); + return add_new_tx(tx, tx_hash, tx_prefix_hash, bl.size(), tvc, keeped_by_block, relayed, do_not_relay); } //----------------------------------------------------------------------------------------------- size_t core::get_blockchain_total_transactions() const @@ -654,7 +654,7 @@ namespace cryptonote return m_blockchain_storage.get_total_transactions(); } //----------------------------------------------------------------------------------------------- - bool core::add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block, bool relayed) + bool core::add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { if(m_mempool.have_tx(tx_hash)) { @@ -669,7 +669,7 @@ namespace cryptonote } uint8_t version = m_blockchain_storage.get_current_hard_fork_version(); - return m_mempool.add_tx(tx, tx_hash, blob_size, tvc, keeped_by_block, relayed, version); + return m_mempool.add_tx(tx, tx_hash, blob_size, tvc, keeped_by_block, relayed, do_not_relay, version); } //----------------------------------------------------------------------------------------------- bool core::relay_txpool_transactions() diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index a9e80aeee..fa67ff265 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -107,10 +107,11 @@ namespace cryptonote * @param tvc metadata about the transaction's validity * @param keeped_by_block if the transaction has been in a block * @param relayed whether or not the transaction was relayed to us + * @param do_not_relay whether to prevent the transaction from being relayed * * @return true if the transaction made it to the transaction pool, otherwise false */ - bool handle_incoming_tx(const blobdata& tx_blob, tx_verification_context& tvc, bool keeped_by_block, bool relayed); + bool handle_incoming_tx(const blobdata& tx_blob, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay); /** * @brief handles an incoming block @@ -641,9 +642,10 @@ namespace cryptonote * @param tx_prefix_hash the transaction prefix' hash * @param blob_size the size of the transaction * @param relayed whether or not the transaction was relayed to us + * @param do_not_relay whether to prevent the transaction from being relayed * */ - bool add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block, bool relayed); + bool add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay); /** * @brief add a new transaction to the transaction pool @@ -654,12 +656,13 @@ namespace cryptonote * @param tvc return-by-reference metadata about the transaction's verification process * @param keeped_by_block whether or not the transaction has been in a block * @param relayed whether or not the transaction was relayed to us + * @param do_not_relay whether to prevent the transaction from being relayed * * @return true if the transaction is already in the transaction pool, * is already in a block on the Blockchain, or is successfully added * to the transaction pool */ - bool add_new_tx(const transaction& tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed); + bool add_new_tx(const transaction& tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay); /** * @copydoc Blockchain::add_new_block diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 59ac534fe..f60c7cea9 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -83,7 +83,7 @@ namespace cryptonote } //--------------------------------------------------------------------------------- - bool tx_memory_pool::add_tx(const transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block, bool relayed, uint8_t version) + bool tx_memory_pool::add_tx(const transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version) { PERF_TIMER(add_tx); if (tx.version == 0) @@ -201,6 +201,7 @@ namespace cryptonote txd_p.first->second.receive_time = time(nullptr); txd_p.first->second.last_relayed_time = time(NULL); txd_p.first->second.relayed = relayed; + txd_p.first->second.do_not_relay = do_not_relay; tvc.m_verifivation_impossible = true; tvc.m_added_to_pool = true; }else @@ -224,9 +225,10 @@ namespace cryptonote txd_p.first->second.receive_time = time(nullptr); txd_p.first->second.last_relayed_time = time(NULL); txd_p.first->second.relayed = relayed; + txd_p.first->second.do_not_relay = do_not_relay; tvc.m_added_to_pool = true; - if(txd_p.first->second.fee > 0) + if(txd_p.first->second.fee > 0 && !do_not_relay) tvc.m_should_be_relayed = true; } @@ -251,12 +253,12 @@ namespace cryptonote return true; } //--------------------------------------------------------------------------------- - bool tx_memory_pool::add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, uint8_t version) + bool tx_memory_pool::add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay, uint8_t version) { crypto::hash h = null_hash; size_t blob_size = 0; get_transaction_hash(tx, h, blob_size); - return add_tx(tx, h, blob_size, tvc, keeped_by_block, relayed, version); + return add_tx(tx, h, blob_size, tvc, keeped_by_block, relayed, do_not_relay, version); } //--------------------------------------------------------------------------------- //FIXME: Can return early before removal of all of the key images. @@ -292,7 +294,7 @@ namespace cryptonote return true; } //--------------------------------------------------------------------------------- - bool tx_memory_pool::take_tx(const crypto::hash &id, transaction &tx, size_t& blob_size, uint64_t& fee, bool &relayed) + bool tx_memory_pool::take_tx(const crypto::hash &id, transaction &tx, size_t& blob_size, uint64_t& fee, bool &relayed, bool &do_not_relay) { CRITICAL_REGION_LOCAL(m_transactions_lock); auto it = m_transactions.find(id); @@ -308,6 +310,7 @@ namespace cryptonote blob_size = it->second.blob_size; fee = it->second.fee; relayed = it->second.relayed; + do_not_relay = it->second.do_not_relay; remove_transaction_keyimages(it->second.tx); m_transactions.erase(it); m_txs_by_fee.erase(sorted_it); @@ -367,7 +370,7 @@ namespace cryptonote for(auto it = m_transactions.begin(); it!= m_transactions.end();) { // 0 fee transactions are never relayed - if(it->second.fee > 0 && now - it->second.last_relayed_time > get_relay_delay(now, it->second.receive_time)) + if(it->second.fee > 0 && !it->second.do_not_relay && now - it->second.last_relayed_time > get_relay_delay(now, it->second.receive_time)) { // 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 @@ -431,6 +434,7 @@ namespace cryptonote txi.receive_time = txd.receive_time; txi.relayed = txd.relayed; txi.last_relayed_time = txd.last_relayed_time; + txi.do_not_relay = txd.do_not_relay; tx_infos.push_back(txi); } diff --git a/src/cryptonote_core/tx_pool.h b/src/cryptonote_core/tx_pool.h index 32a05b0f4..b330057a6 100644 --- a/src/cryptonote_core/tx_pool.h +++ b/src/cryptonote_core/tx_pool.h @@ -103,7 +103,7 @@ namespace cryptonote * @param id the transaction's hash * @param blob_size the transaction's size */ - bool add_tx(const transaction &tx, const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block, bool relayed, uint8_t version); + bool add_tx(const transaction &tx, const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version); /** * @brief add a transaction to the transaction pool @@ -117,11 +117,12 @@ namespace cryptonote * @param tvc return-by-reference status about the transaction verification * @param kept_by_block has this transaction been in a block? * @param relayed was this transaction from the network or a local client? + * @param do_not_relay to avoid relaying the transaction to the network * @param version the version used to create the transaction * * @return true if the transaction passes validations, otherwise false */ - bool add_tx(const transaction &tx, tx_verification_context& tvc, bool kept_by_block, bool relayed, uint8_t version); + bool add_tx(const transaction &tx, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version); /** * @brief takes a transaction with the given hash from the pool @@ -131,10 +132,11 @@ namespace cryptonote * @param blob_size return-by-reference the transaction's size * @param fee the transaction fee * @param relayed return-by-reference was transaction relayed to us by the network? + * @param do_not_relay return-by-reference is transaction not to be relayed to the network? * * @return true unless the transaction cannot be found in the pool */ - bool take_tx(const crypto::hash &id, transaction &tx, size_t& blob_size, uint64_t& fee, bool &relayed); + bool take_tx(const crypto::hash &id, transaction &tx, size_t& blob_size, uint64_t& fee, bool &relayed, bool &do_not_relay); /** * @brief checks if the pool has a transaction with the given hash @@ -303,7 +305,7 @@ namespace cryptonote #define CURRENT_MEMPOOL_ARCHIVE_VER 11 -#define CURRENT_MEMPOOL_TX_DETAILS_ARCHIVE_VER 11 +#define CURRENT_MEMPOOL_TX_DETAILS_ARCHIVE_VER 12 /** * @brief serialize the transaction pool to/from disk @@ -362,6 +364,7 @@ namespace cryptonote time_t last_relayed_time; //!< the last time the transaction was relayed to the network bool relayed; //!< whether or not the transaction has been relayed to the network + bool do_not_relay; //!< to avoid relay this transaction to the network }; private: @@ -515,6 +518,9 @@ namespace boost if (version < 11) return; ar & td.kept_by_block; + if (version < 12) + return; + ar & td.do_not_relay; } } } -- cgit v1.2.3