aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_protocol
diff options
context:
space:
mode:
Diffstat (limited to 'src/cryptonote_protocol')
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_defs.h28
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.h7
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl76
-rw-r--r--src/cryptonote_protocol/levin_notify.cpp21
4 files changed, 116 insertions, 16 deletions
diff --git a/src/cryptonote_protocol/cryptonote_protocol_defs.h b/src/cryptonote_protocol/cryptonote_protocol_defs.h
index 201001c8e..f809bff74 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_defs.h
+++ b/src/cryptonote_protocol/cryptonote_protocol_defs.h
@@ -257,7 +257,10 @@ namespace cryptonote
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(current_height)
KV_SERIALIZE(cumulative_difficulty)
- KV_SERIALIZE(cumulative_difficulty_top64)
+ if (is_store)
+ KV_SERIALIZE(cumulative_difficulty_top64)
+ else
+ KV_SERIALIZE_OPT(cumulative_difficulty_top64, (uint64_t)0)
KV_SERIALIZE_VAL_POD_AS_BLOB(top_id)
KV_SERIALIZE_OPT(top_version, (uint8_t)0)
KV_SERIALIZE_OPT(pruning_seed, (uint32_t)0)
@@ -298,7 +301,10 @@ namespace cryptonote
KV_SERIALIZE(start_height)
KV_SERIALIZE(total_height)
KV_SERIALIZE(cumulative_difficulty)
- KV_SERIALIZE(cumulative_difficulty_top64)
+ if (is_store)
+ KV_SERIALIZE(cumulative_difficulty_top64)
+ else
+ KV_SERIALIZE_OPT(cumulative_difficulty_top64, (uint64_t)0)
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(m_block_ids)
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(m_block_weights)
END_KV_SERIALIZE_MAP()
@@ -347,5 +353,23 @@ namespace cryptonote
};
typedef epee::misc_utils::struct_init<request_t> request;
};
+
+ /************************************************************************/
+ /* */
+ /************************************************************************/
+ struct NOTIFY_GET_TXPOOL_COMPLEMENT
+ {
+ const static int ID = BC_COMMANDS_POOL_BASE + 10;
+
+ struct request_t
+ {
+ std::vector<crypto::hash> hashes;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE_CONTAINER_POD_AS_BLOB(hashes)
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<request_t> request;
+ };
}
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.h b/src/cryptonote_protocol/cryptonote_protocol_handler.h
index ddbd45a61..2664716a8 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.h
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.h
@@ -45,7 +45,6 @@
#include "block_queue.h"
#include "common/perf_timer.h"
#include "cryptonote_basic/connection_context.h"
-#include "cryptonote_basic/cryptonote_stat_info.h"
#include <boost/circular_buffer.hpp>
PUSH_WARNINGS
@@ -77,7 +76,6 @@ namespace cryptonote
{
public:
typedef cryptonote_connection_context connection_context;
- typedef core_stat_info stat_info;
typedef t_cryptonote_protocol_handler<t_core> cryptonote_protocol_handler;
typedef CORE_SYNC_DATA payload_type;
@@ -92,6 +90,7 @@ namespace cryptonote
HANDLE_NOTIFY_T2(NOTIFY_RESPONSE_CHAIN_ENTRY, &cryptonote_protocol_handler::handle_response_chain_entry)
HANDLE_NOTIFY_T2(NOTIFY_NEW_FLUFFY_BLOCK, &cryptonote_protocol_handler::handle_notify_new_fluffy_block)
HANDLE_NOTIFY_T2(NOTIFY_REQUEST_FLUFFY_MISSING_TX, &cryptonote_protocol_handler::handle_request_fluffy_missing_tx)
+ HANDLE_NOTIFY_T2(NOTIFY_GET_TXPOOL_COMPLEMENT, &cryptonote_protocol_handler::handle_notify_get_txpool_complement)
END_INVOKE_MAP2()
bool on_idle();
@@ -102,7 +101,6 @@ namespace cryptonote
bool process_payload_sync_data(const CORE_SYNC_DATA& hshd, cryptonote_connection_context& context, bool is_inital);
bool get_payload_sync_data(blobdata& data);
bool get_payload_sync_data(CORE_SYNC_DATA& hshd);
- bool get_stat_info(core_stat_info& stat_inf);
bool on_callback(cryptonote_connection_context& context);
t_core& get_core(){return m_core;}
bool is_synchronized(){return m_synchronized;}
@@ -127,6 +125,7 @@ namespace cryptonote
int handle_response_chain_entry(int command, NOTIFY_RESPONSE_CHAIN_ENTRY::request& arg, cryptonote_connection_context& context);
int handle_notify_new_fluffy_block(int command, NOTIFY_NEW_FLUFFY_BLOCK::request& arg, cryptonote_connection_context& context);
int handle_request_fluffy_missing_tx(int command, NOTIFY_REQUEST_FLUFFY_MISSING_TX::request& arg, cryptonote_connection_context& context);
+ int handle_notify_get_txpool_complement(int command, NOTIFY_GET_TXPOOL_COMPLEMENT::request& arg, cryptonote_connection_context& context);
//----------------- i_bc_protocol_layout ---------------------------------------
virtual bool relay_block(NOTIFY_NEW_BLOCK::request& arg, cryptonote_connection_context& exclude_context);
@@ -147,6 +146,7 @@ namespace cryptonote
int try_add_next_blocks(cryptonote_connection_context &context);
void notify_new_stripe(cryptonote_connection_context &context, uint32_t stripe);
void skip_unneeded_hashes(cryptonote_connection_context& context, bool check_block_queue) const;
+ bool request_txpool_complement(cryptonote_connection_context &context);
t_core& m_core;
@@ -156,6 +156,7 @@ namespace cryptonote
std::atomic<bool> m_synchronized;
std::atomic<bool> m_stopping;
std::atomic<bool> m_no_sync;
+ std::atomic<bool> m_ask_for_txpool_complement;
boost::mutex m_sync_lock;
block_queue m_block_queue;
epee::math_helper::once_a_time_seconds<30> m_idle_peer_kicker;
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index d11f198aa..3aacce421 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -83,6 +83,7 @@ namespace cryptonote
m_p2p(p_net_layout),
m_syncronized_connections_count(0),
m_synchronized(offline),
+ m_ask_for_txpool_complement(true),
m_stopping(false),
m_no_sync(false)
@@ -154,12 +155,6 @@ namespace cryptonote
}
//------------------------------------------------------------------------------------------------------------------------
template<class t_core>
- bool t_cryptonote_protocol_handler<t_core>::get_stat_info(core_stat_info& stat_inf)
- {
- return m_core.get_stat_info(stat_inf);
- }
- //------------------------------------------------------------------------------------------------------------------------
- template<class t_core>
void t_cryptonote_protocol_handler<t_core>::log_connections()
{
std::stringstream ss;
@@ -344,7 +339,7 @@ namespace cryptonote
if(m_core.have_block(hshd.top_id))
{
context.m_state = cryptonote_connection_context::state_normal;
- if(is_inital && target == m_core.get_current_blockchain_height())
+ if(is_inital && hshd.current_height >= target && target == m_core.get_current_blockchain_height())
on_connection_synchronized();
return true;
}
@@ -885,6 +880,34 @@ namespace cryptonote
}
//------------------------------------------------------------------------------------------------------------------------
template<class t_core>
+ int t_cryptonote_protocol_handler<t_core>::handle_notify_get_txpool_complement(int command, NOTIFY_GET_TXPOOL_COMPLEMENT::request& arg, cryptonote_connection_context& context)
+ {
+ MLOG_P2P_MESSAGE("Received NOTIFY_GET_TXPOOL_COMPLEMENT (" << arg.hashes.size() << " txes)");
+
+ std::vector<std::pair<cryptonote::blobdata, block>> local_blocks;
+ std::vector<cryptonote::blobdata> local_txs;
+
+ std::vector<cryptonote::blobdata> txes;
+ if (!m_core.get_txpool_complement(arg.hashes, txes))
+ {
+ LOG_ERROR_CCONTEXT("failed to get txpool complement");
+ return 1;
+ }
+
+ NOTIFY_NEW_TRANSACTIONS::request new_txes;
+ new_txes.txs = std::move(txes);
+
+ MLOG_P2P_MESSAGE
+ (
+ "-->>NOTIFY_NEW_TRANSACTIONS: "
+ << ", txs.size()=" << new_txes.txs.size()
+ );
+
+ post_notify<NOTIFY_NEW_TRANSACTIONS>(new_txes, context);
+ return 1;
+ }
+ //------------------------------------------------------------------------------------------------------------------------
+ template<class t_core>
int t_cryptonote_protocol_handler<t_core>::handle_notify_new_transactions(int command, NOTIFY_NEW_TRANSACTIONS::request& arg, cryptonote_connection_context& context)
{
MLOG_P2P_MESSAGE("Received NOTIFY_NEW_TRANSACTIONS (" << arg.txs.size() << " txes)");
@@ -2201,6 +2224,27 @@ skip:
}
m_core.safesyncmode(true);
m_p2p->clear_used_stripe_peers();
+
+ // ask for txpool complement from any suitable node if we did not yet
+ val_expected = true;
+ if (m_ask_for_txpool_complement.compare_exchange_strong(val_expected, false))
+ {
+ m_p2p->for_each_connection([&](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t support_flags)->bool
+ {
+ if(context.m_state < cryptonote_connection_context::state_synchronizing)
+ {
+ MDEBUG(context << "not ready, ignoring");
+ return true;
+ }
+ if (!request_txpool_complement(context))
+ {
+ MERROR(context << "Failed to request txpool complement");
+ return true;
+ }
+ return false;
+ });
+ }
+
return true;
}
//------------------------------------------------------------------------------------------------------------------------
@@ -2354,6 +2398,21 @@ skip:
}
//------------------------------------------------------------------------------------------------------------------------
template<class t_core>
+ bool t_cryptonote_protocol_handler<t_core>::request_txpool_complement(cryptonote_connection_context &context)
+ {
+ NOTIFY_GET_TXPOOL_COMPLEMENT::request r = {};
+ if (!m_core.get_pool_transaction_hashes(r.hashes, false))
+ {
+ MERROR("Failed to get txpool hashes");
+ return false;
+ }
+ MLOG_P2P_MESSAGE("-->>NOTIFY_GET_TXPOOL_COMPLEMENT: hashes.size()=" << r.hashes.size() );
+ post_notify<NOTIFY_GET_TXPOOL_COMPLEMENT>(r, context);
+ MLOG_PEER_STATE("requesting txpool complement");
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------
+ template<class t_core>
std::string t_cryptonote_protocol_handler<t_core>::get_peers_overview() const
{
std::stringstream ss;
@@ -2463,7 +2522,10 @@ skip:
MINFO("Target height decreasing from " << previous_target << " to " << target);
m_core.set_target_blockchain_height(target);
if (target == 0 && context.m_state > cryptonote_connection_context::state_before_handshake && !m_stopping)
+ {
MCWARNING("global", "monerod is now disconnected from the network");
+ m_ask_for_txpool_complement = true;
+ }
}
m_block_queue.flush_spans(context.m_connection_id, false);
diff --git a/src/cryptonote_protocol/levin_notify.cpp b/src/cryptonote_protocol/levin_notify.cpp
index 5abd0d506..428b739bc 100644
--- a/src/cryptonote_protocol/levin_notify.cpp
+++ b/src/cryptonote_protocol/levin_notify.cpp
@@ -44,6 +44,9 @@
#include "net/dandelionpp.h"
#include "p2p/net_node.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.p2p.tx"
+
namespace
{
int get_command_from_message(const cryptonote::blobdata &msg)
@@ -298,6 +301,8 @@ namespace levin
if (!channel.connection.is_nil())
channel.queue.push_back(std::move(message_));
+ else if (destination_ == 0 && zone_->connection_count == 0)
+ MWARNING("Unable to send transaction(s) over anonymity network - no available outbound connections");
}
};
@@ -393,10 +398,12 @@ namespace levin
random_poisson in_duration(fluff_average_in);
random_poisson out_duration(fluff_average_out);
- zone_->p2p->foreach_connection([this, now, &in_duration, &out_duration, &next_flush] (detail::p2p_context& context)
+ bool available = false;
+ zone_->p2p->foreach_connection([this, now, &in_duration, &out_duration, &next_flush, &available] (detail::p2p_context& context)
{
if (this->source_ != context.m_connection_id && (this->zone_->is_public || !context.m_is_income))
{
+ available = true;
if (context.fluff_txs.empty())
context.flush_time = now + (context.m_is_income ? in_duration() : out_duration());
@@ -408,6 +415,9 @@ namespace levin
return true;
});
+ if (!available)
+ MWARNING("Unable to send transaction(s), no available connections");
+
if (next_flush < zone_->flush_time)
fluff_flush::queue(std::move(zone_), next_flush);
}
@@ -567,9 +577,12 @@ namespace levin
{
channel.active = nullptr;
channel.connection = boost::uuids::nil_uuid();
- zone_->strand.post(
- update_channels{zone_, get_out_connections(*zone_->p2p)}
- );
+
+ auto connections = get_out_connections(*zone_->p2p);
+ if (connections.empty())
+ MWARNING("Lost all outbound connections to anonymity network - currently unable to send transaction(s)");
+
+ zone_->strand.post(update_channels{zone_, std::move(connections)});
}
}