From f3c374fe08c2f309b3349a2341f4ebf5b8c10609 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 22 Oct 2016 20:46:19 +0100 Subject: [PATCH 1/3] tx_pool: set relayed flag on relay --- src/cryptonote_core/tx_pool.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 178cbda3c..644ad4727 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -387,7 +387,10 @@ namespace cryptonote { auto i = m_transactions.find(it->first); if (i != m_transactions.end()) + { + i->second.relayed = true; i->second.last_relayed_time = now; + } } } //--------------------------------------------------------------------------------- From 1e163666f3c5265d9d091eece0403de6bc5eca96 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 22 Oct 2016 20:46:51 +0100 Subject: [PATCH 2/3] core: notify the txpool when transactions are relayed --- src/cryptonote_core/cryptonote_core.cpp | 14 ++++++++++++++ src/cryptonote_core/cryptonote_core.h | 5 +++++ .../cryptonote_protocol_handler.inl | 3 +++ tests/core_proxy/core_proxy.h | 1 + tests/unit_tests/ban.cpp | 1 + 5 files changed, 24 insertions(+) diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index a82d96416..95c49f627 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -709,6 +709,20 @@ namespace cryptonote return true; } //----------------------------------------------------------------------------------------------- + void core::on_transaction_relayed(const cryptonote::blobdata& tx_blob) + { + std::list> txs; + cryptonote::transaction tx; + crypto::hash tx_hash, tx_prefix_hash; + if (!parse_and_validate_tx_from_blob(tx_blob, tx, tx_hash, tx_prefix_hash)) + { + LOG_ERROR("Failed to parse relayed tranasction"); + return; + } + txs.push_back(std::make_pair(tx_hash, std::move(tx))); + m_mempool.set_relayed(txs); + } + //----------------------------------------------------------------------------------------------- bool core::get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, const blobdata& ex_nonce) { return m_blockchain_storage.create_block_template(b, adr, diffic, height, ex_nonce); diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index d925a184d..a5a97a5ad 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -180,6 +180,11 @@ namespace cryptonote */ virtual bool get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, const blobdata& ex_nonce); + /** + * @brief called when a transaction is relayed + */ + virtual void on_transaction_relayed(const cryptonote::blobdata& tx); + /** * @brief gets the miner instance diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index 1d1cd3631..5232d550a 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -780,6 +780,9 @@ namespace cryptonote template bool t_cryptonote_protocol_handler::relay_transactions(NOTIFY_NEW_TRANSACTIONS::request& arg, cryptonote_connection_context& exclude_context) { + // no check for success, so tell core they're relayed unconditionally + for(auto tx_blob_it = arg.txs.begin(); tx_blob_it!=arg.txs.end(); ++tx_blob_it) + m_core.on_transaction_relayed(*tx_blob_it); return relay_post_notify(arg, exclude_context); } diff --git a/tests/core_proxy/core_proxy.h b/tests/core_proxy/core_proxy.h index 995b0c650..a265ef1ce 100644 --- a/tests/core_proxy/core_proxy.h +++ b/tests/core_proxy/core_proxy.h @@ -88,5 +88,6 @@ namespace tests bool cleanup_handle_incoming_blocks(bool force_sync = false) { return true; } uint64_t get_target_blockchain_height() const { return 1; } size_t get_block_sync_size() const { return BLOCKS_SYNCHRONIZING_DEFAULT_COUNT; } + virtual void on_transaction_relayed(const cryptonote::blobdata& tx) {} }; } diff --git a/tests/unit_tests/ban.cpp b/tests/unit_tests/ban.cpp index 85b0298b7..e82661545 100644 --- a/tests/unit_tests/ban.cpp +++ b/tests/unit_tests/ban.cpp @@ -63,6 +63,7 @@ public: bool cleanup_handle_incoming_blocks(bool force_sync = false) { return true; } uint64_t get_target_blockchain_height() const { return 1; } size_t get_block_sync_size() const { return BLOCKS_SYNCHRONIZING_DEFAULT_COUNT; } + virtual void on_transaction_relayed(const cryptonote::blobdata& tx) {} }; typedef nodetool::node_server> Server; From 10a79eae240753e4e63b9b5ac1b55bbc06da45d3 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 22 Oct 2016 20:47:31 +0100 Subject: [PATCH 3/3] daemon: report transaction relay status in print_pool* commands --- src/cryptonote_core/tx_pool.cpp | 2 ++ src/daemon/rpc_command_executor.cpp | 2 ++ src/rpc/core_rpc_server_commands_defs.h | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 644ad4727..dba05a539 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -425,6 +425,8 @@ namespace cryptonote txi.last_failed_height = txd.last_failed_height; txi.last_failed_id_hash = epee::string_tools::pod_to_hex(txd.last_failed_id); txi.receive_time = txd.receive_time; + txi.relayed = txd.relayed; + txi.last_relayed_time = txd.last_relayed_time; tx_infos.push_back(txi); } diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index bed10715b..c239e2bd1 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -734,6 +734,7 @@ bool t_rpc_command_executor::print_transaction_pool_long() { << "blob_size: " << tx_info.blob_size << std::endl << "fee: " << cryptonote::print_money(tx_info.fee) << std::endl << "receive_time: " << tx_info.receive_time << " (" << get_human_time_ago(tx_info.receive_time, now) << ")" << std::endl + << "relayed: " << [&](const cryptonote::tx_info &tx_info)->std::string { if (!tx_info.relayed) return "no"; return boost::lexical_cast(tx_info.last_relayed_time) + " (" + get_human_time_ago(tx_info.last_relayed_time, now) + ")"; } (tx_info) << std::endl << "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl << "max_used_block_height: " << tx_info.max_used_block_height << std::endl << "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl @@ -813,6 +814,7 @@ bool t_rpc_command_executor::print_transaction_pool_short() { << "blob_size: " << tx_info.blob_size << std::endl << "fee: " << cryptonote::print_money(tx_info.fee) << std::endl << "receive_time: " << tx_info.receive_time << " (" << get_human_time_ago(tx_info.receive_time, now) << ")" << std::endl + << "relayed: " << [&](const cryptonote::tx_info &tx_info)->std::string { if (!tx_info.relayed) return "no"; return boost::lexical_cast(tx_info.last_relayed_time) + " (" + get_human_time_ago(tx_info.last_relayed_time, now) + ")"; } (tx_info) << std::endl << "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl << "max_used_block_height: " << tx_info.max_used_block_height << std::endl << "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 135cf1fe7..cb58d0d07 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -855,6 +855,8 @@ namespace cryptonote uint64_t last_failed_height; std::string last_failed_id_hash; uint64_t receive_time; + bool relayed; + uint64_t last_relayed_time; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(id_hash) @@ -867,6 +869,8 @@ namespace cryptonote KV_SERIALIZE(last_failed_height) KV_SERIALIZE(last_failed_id_hash) KV_SERIALIZE(receive_time) + KV_SERIALIZE(relayed) + KV_SERIALIZE(last_failed_id_hash) END_KV_SERIALIZE_MAP() };