From d5a2f16050dae6e51150c7009f214f5aa4829d7c Mon Sep 17 00:00:00 2001 From: sumogr Date: Mon, 14 Dec 2020 12:36:01 +0200 Subject: [PATCH 01/19] [cryptonote_protocol] fix switching to adding blocks if noone's adding the next span monero ref # 7109 --- src/cryptonote_protocol/cryptonote_protocol_handler.inl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index 356a75f9b2..91ff1b25d2 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -2263,8 +2263,7 @@ skip: uint64_t start_height; std::vector blocks; boost::uuids::uuid span_connection_id; - bool filled = false; - if (m_block_queue.get_next_span(start_height, blocks, span_connection_id, filled) && filled) + if (m_block_queue.get_next_span(start_height, blocks, span_connection_id, true)) { LOG_DEBUG_CC(context, "No other thread is adding blocks, resuming"); MLOG_PEER_STATE("will try to add blocks next"); @@ -2578,7 +2577,7 @@ skip: MERROR("Negative score hit"); return; } - context.m_score -= score; + context.m_score -= score; if (context.m_score <= DROP_PEERS_ON_SCORE) drop_connection_with_score(context, 5, false); } From b40ea33b73afa27c4787f2185049e76128c011fe Mon Sep 17 00:00:00 2001 From: sumogr Date: Mon, 14 Dec 2020 12:39:35 +0200 Subject: [PATCH 02/19] [cryptonote_protocol] more restrictive checks on chain entry response monero ref # 7107 --- src/cryptonote_protocol/cryptonote_protocol_handler.inl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index 91ff1b25d2..6e5705274b 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -2429,7 +2429,7 @@ skip: drop_connection(context, true, false); return 1; } - if (arg.total_height < arg.m_block_ids.size() || arg.start_height > arg.total_height - arg.m_block_ids.size()) + if (arg.total_height < arg.m_block_ids.size() || arg.start_height > arg.total_height - arg.m_block_ids.size() || arg.start_height >= m_core.get_current_blockchain_height()) { LOG_ERROR_CCONTEXT("sent invalid start/nblocks/height, dropping connection"); drop_connection(context, true, false); @@ -2475,8 +2475,15 @@ skip: context.m_needed_objects.clear(); uint64_t added = 0; + std::unordered_set blocks_found; for (size_t i = 0; i < arg.m_block_ids.size(); ++i) { + if (!blocks_found.insert(arg.m_block_ids[i]).second) + { + LOG_ERROR_CCONTEXT("Duplicate blocks in chain entry response, dropping connection"); + drop_connection(context, true, false); + return 1; + } const uint64_t block_weight = arg.m_block_weights.empty() ? 0 : arg.m_block_weights[i]; context.m_needed_objects.push_back(std::make_pair(arg.m_block_ids[i], block_weight)); if (++added == n_use_blocks) From af14ecaad508ca5d722631d15ad54e82b5c13353 Mon Sep 17 00:00:00 2001 From: sumogr Date: Mon, 14 Dec 2020 12:42:04 +0200 Subject: [PATCH 03/19] [cryptonote_protocol] add a sanity check to the number of block hashes sent monero ref # 7118 --- src/cryptonote_protocol/cryptonote_protocol_handler.inl | 4 ++-- src/p2p_config.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index 6e5705274b..cd8505d86e 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -2443,7 +2443,7 @@ skip: } MDEBUG(context << "first block hash " << arg.m_block_ids.front() << ", last " << arg.m_block_ids.back()); - if (arg.total_height >= CRYPTONOTE_MAX_BLOCK_NUMBER || arg.m_block_ids.size() >= CRYPTONOTE_MAX_BLOCK_NUMBER) + if (arg.total_height >= CRYPTONOTE_MAX_BLOCK_NUMBER || arg.m_block_ids.size() > BLOCKS_IDS_SYNCHRONIZING_MAX_COUNT) { LOG_ERROR_CCONTEXT("sent wrong NOTIFY_RESPONSE_CHAIN_ENTRY, with total_height=" << arg.total_height << " and block_ids=" << arg.m_block_ids.size()); drop_connection(context, false, false); @@ -2483,7 +2483,7 @@ skip: LOG_ERROR_CCONTEXT("Duplicate blocks in chain entry response, dropping connection"); drop_connection(context, true, false); return 1; - } + } const uint64_t block_weight = arg.m_block_weights.empty() ? 0 : arg.m_block_weights[i]; context.m_needed_objects.push_back(std::make_pair(arg.m_block_ids[i], block_weight)); if (++added == n_use_blocks) diff --git a/src/p2p_config.h b/src/p2p_config.h index 6760c667ca..f828ce02c7 100644 --- a/src/p2p_config.h +++ b/src/p2p_config.h @@ -49,6 +49,7 @@ namespace config #define CRYPTONOTE_DNS_TIMEOUT_MS 20000 #define BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT 10000 //by default, blocks ids count in synchronizing +#define BLOCKS_IDS_SYNCHRONIZING_MAX_COUNT 25000 //max blocks ids count in synchronizing #define BLOCKS_SYNCHRONIZING_DEFAULT_COUNT 10 //by default, blocks count in blocks downloading #define COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT 1000 From 51d892335e77ef5d003fce87b9e605dfb6a99d83 Mon Sep 17 00:00:00 2001 From: sumogr Date: Mon, 14 Dec 2020 13:28:55 +0200 Subject: [PATCH 04/19] [cryptonote_protocol] drop origin IP if a block fails to verify in sync mode It would otherwise be possible for a peer to send bad blocks, then disconnect and reconnect again, escaping bans monero ref # 7111 --- src/cryptonote_protocol/block_queue.cpp | 29 ++++++++------- src/cryptonote_protocol/block_queue.h | 32 ++++++++-------- .../cryptonote_protocol_handler.h | 3 +- .../cryptonote_protocol_handler.inl | 37 +++++++++++++++++-- src/rpc/core_rpc_server.cpp | 6 +-- tests/unit_tests/block_queue.cpp | 32 ++++++++-------- 6 files changed, 85 insertions(+), 54 deletions(-) diff --git a/src/cryptonote_protocol/block_queue.cpp b/src/cryptonote_protocol/block_queue.cpp index f08fc51d4f..3d2250da31 100644 --- a/src/cryptonote_protocol/block_queue.cpp +++ b/src/cryptonote_protocol/block_queue.cpp @@ -1,21 +1,21 @@ // Copyright (c) 2017-2020, The Monero Project -// +// // 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 @@ -25,7 +25,7 @@ // 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. -// +// // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #include @@ -52,12 +52,12 @@ namespace std { namespace cryptonote { -void block_queue::add_blocks(uint64_t height, std::vector bcel, const boost::uuids::uuid &connection_id, float rate, size_t size) +void block_queue::add_blocks(uint64_t height, std::vector bcel, const boost::uuids::uuid &connection_id, const epee::net_utils::network_address &addr, float rate, size_t size) { boost::unique_lock lock(mutex); std::vector hashes; bool has_hashes = remove_span(height, &hashes); - blocks.insert(span(height, std::move(bcel), connection_id, rate, size)); + blocks.insert(span(height, std::move(bcel), connection_id, addr, rate, size)); if (has_hashes) { for (const crypto::hash &h: hashes) @@ -69,11 +69,11 @@ void block_queue::add_blocks(uint64_t height, std::vector 0, "Empty span"); boost::unique_lock lock(mutex); - blocks.insert(span(height, nblocks, connection_id, time)); + blocks.insert(span(height, nblocks, connection_id, addr, time)); } void block_queue::flush_spans(const boost::uuids::uuid &connection_id, bool all) @@ -228,7 +228,7 @@ bool block_queue::have(const crypto::hash &hash) const return have_blocks.find(hash) != have_blocks.end(); } -std::pair block_queue::reserve_span(uint64_t first_block_height, uint64_t last_block_height, uint64_t max_blocks, const boost::uuids::uuid &connection_id, bool sync_pruned_blocks, uint32_t local_pruning_seed, uint32_t pruning_seed, uint64_t blockchain_height, const std::vector> &block_hashes, boost::posix_time::ptime time) +std::pair block_queue::reserve_span(uint64_t first_block_height, uint64_t last_block_height, uint64_t max_blocks, const boost::uuids::uuid &connection_id, const epee::net_utils::network_address &addr, bool sync_pruned_blocks, uint32_t local_pruning_seed, uint32_t pruning_seed, uint64_t blockchain_height, const std::vector> &block_hashes, boost::posix_time::ptime time) { boost::unique_lock lock(mutex); @@ -305,7 +305,7 @@ std::pair block_queue::reserve_span(uint64_t first_block_hei return std::make_pair(0, 0); } MDEBUG("Reserving span " << span_start_height << " - " << (span_start_height + span_length - 1) << " for " << connection_id); - add_blocks(span_start_height, span_length, connection_id, time); + add_blocks(span_start_height, span_length, connection_id, addr, time); set_span_hashes(span_start_height, connection_id, hashes); return std::make_pair(span_start_height, span_length); } @@ -354,7 +354,7 @@ void block_queue::set_span_hashes(uint64_t start_height, const boost::uuids::uui } } -bool block_queue::get_next_span(uint64_t &height, std::vector &bcel, boost::uuids::uuid &connection_id, bool filled) const +bool block_queue::get_next_span(uint64_t &height, std::vector &bcel, boost::uuids::uuid &connection_id, epee::net_utils::network_address &addr, bool filled) const { boost::unique_lock lock(mutex); if (blocks.empty()) @@ -367,6 +367,7 @@ bool block_queue::get_next_span(uint64_t &height, std::vectorstart_block_height; bcel = i->blocks; connection_id = i->connection_id; + addr = i->origin; return true; } } diff --git a/src/cryptonote_protocol/block_queue.h b/src/cryptonote_protocol/block_queue.h index 57d2a64906..ded76c9ede 100644 --- a/src/cryptonote_protocol/block_queue.h +++ b/src/cryptonote_protocol/block_queue.h @@ -1,21 +1,21 @@ // Copyright (c) 2017-2020, The Monero Project -// +// // 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 @@ -25,7 +25,7 @@ // 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. -// +// // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #pragma once @@ -36,6 +36,7 @@ #include #include #include +#include "net/net_utils_base.h" #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "cn.block_queue" @@ -57,19 +58,20 @@ namespace cryptonote float rate; size_t size; boost::posix_time::ptime time; + epee::net_utils::network_address origin{}; - span(uint64_t start_block_height, std::vector blocks, const boost::uuids::uuid &connection_id, float rate, size_t size): - start_block_height(start_block_height), blocks(std::move(blocks)), connection_id(connection_id), nblocks(this->blocks.size()), rate(rate), size(size), time() {} - span(uint64_t start_block_height, uint64_t nblocks, const boost::uuids::uuid &connection_id, boost::posix_time::ptime time): - start_block_height(start_block_height), connection_id(connection_id), nblocks(nblocks), rate(0.0f), size(0), time(time) {} + span(uint64_t start_block_height, std::vector blocks, const boost::uuids::uuid &connection_id, const epee::net_utils::network_address &addr, float rate, size_t size): + start_block_height(start_block_height), blocks(std::move(blocks)), connection_id(connection_id), nblocks(this->blocks.size()), rate(rate), size(size), time(boost::date_time::min_date_time), origin(addr) {} + span(uint64_t start_block_height, uint64_t nblocks, const boost::uuids::uuid &connection_id, const epee::net_utils::network_address &addr, boost::posix_time::ptime time): + start_block_height(start_block_height), connection_id(connection_id), nblocks(nblocks), rate(0.0f), size(0), time(time), origin(addr) {} bool operator<(const span &s) const { return start_block_height < s.start_block_height; } }; typedef std::set block_map; public: - void add_blocks(uint64_t height, std::vector bcel, const boost::uuids::uuid &connection_id, float rate, size_t size); - void add_blocks(uint64_t height, uint64_t nblocks, const boost::uuids::uuid &connection_id, boost::posix_time::ptime time = boost::date_time::min_date_time); + void add_blocks(uint64_t height, std::vector bcel, const boost::uuids::uuid &connection_id, const epee::net_utils::network_address &addr, float rate, size_t size); + void add_blocks(uint64_t height, uint64_t nblocks, const boost::uuids::uuid &connection_id, const epee::net_utils::network_address &addr, boost::posix_time::ptime time = boost::date_time::min_date_time); void flush_spans(const boost::uuids::uuid &connection_id, bool all = false); void flush_stale_spans(const std::set &live_connections); bool remove_span(uint64_t start_block_height, std::vector *hashes = NULL); @@ -78,12 +80,12 @@ namespace cryptonote void print() const; std::string get_overview(uint64_t blockchain_height) const; bool has_unpruned_height(uint64_t block_height, uint64_t blockchain_height, uint32_t pruning_seed) const; - std::pair reserve_span(uint64_t first_block_height, uint64_t last_block_height, uint64_t max_blocks, const boost::uuids::uuid &connection_id, bool sync_pruned_blocks, uint32_t local_pruning_seed, uint32_t pruning_seed, uint64_t blockchain_height, const std::vector> &block_hashes, boost::posix_time::ptime time = boost::posix_time::microsec_clock::universal_time()); + std::pair reserve_span(uint64_t first_block_height, uint64_t last_block_height, uint64_t max_blocks, const boost::uuids::uuid &connection_id, const epee::net_utils::network_address &addr, bool sync_pruned_blocks, uint32_t local_pruning_seed, uint32_t pruning_seed, uint64_t blockchain_height, const std::vector> &block_hashes, boost::posix_time::ptime time = boost::posix_time::microsec_clock::universal_time()); uint64_t get_next_needed_height(uint64_t blockchain_height) const; std::pair get_next_span_if_scheduled(std::vector &hashes, boost::uuids::uuid &connection_id, boost::posix_time::ptime &time) const; void reset_next_span_time(boost::posix_time::ptime t = boost::posix_time::microsec_clock::universal_time()); void set_span_hashes(uint64_t start_height, const boost::uuids::uuid &connection_id, std::vector hashes); - bool get_next_span(uint64_t &height, std::vector &bcel, boost::uuids::uuid &connection_id, bool filled = true) const; + bool get_next_span(uint64_t &height, std::vector &bcel, boost::uuids::uuid &connection_id, epee::net_utils::network_address &addr, bool filled = true) const; bool has_next_span(const boost::uuids::uuid &connection_id, bool &filled, boost::posix_time::ptime &time) const; bool has_next_span(uint64_t height, bool &filled, boost::posix_time::ptime &time, boost::uuids::uuid &connection_id) const; size_t get_data_size() const; diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.h b/src/cryptonote_protocol/cryptonote_protocol_handler.h index 6e9cf0c703..286a12375f 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.h +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.h @@ -139,6 +139,7 @@ namespace cryptonote bool should_ask_for_pruned_data(cryptonote_connection_context& context, uint64_t first_block_height, uint64_t nblocks, bool check_block_weights) const; void drop_connection(cryptonote_connection_context &context, bool add_fail, bool flush_all_spans); void drop_connection_with_score(cryptonote_connection_context &context, uint64_t score, bool flush_all_spans); + void drop_connections(const epee::net_utils::network_address address); bool kick_idle_peers(); bool check_standby_peers(); bool update_sync_search(); @@ -175,7 +176,7 @@ namespace cryptonote double get_avg_block_size(); boost::circular_buffer m_avg_buffer = boost::circular_buffer(10); - boost::mutex m_bad_peer_check_lock; + boost::mutex m_bad_peer_check_lock; template bool post_notify(typename t_parameter::request& arg, cryptonote_connection_context& context) diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index cd8505d86e..c6fdca2021 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -1249,7 +1249,7 @@ namespace cryptonote const boost::posix_time::time_duration dt = now - request_time; const float rate = size * 1e6 / (dt.total_microseconds() + 1); MDEBUG(context << " adding span: " << arg.blocks.size() << " at height " << start_height << ", " << dt.total_microseconds()/1e6 << " seconds, " << (rate/1024) << " kB/s, size now " << (m_block_queue.get_data_size() + blocks_size) / 1048576.f << " MB"); - m_block_queue.add_blocks(start_height, arg.blocks, context.m_connection_id, rate, blocks_size); + m_block_queue.add_blocks(start_height, arg.blocks, context.m_connection_id, context.m_remote_address, rate, blocks_size); const crypto::hash last_block_hash = cryptonote::get_block_hash(b); context.m_last_known_hash = last_block_hash; @@ -1298,7 +1298,8 @@ namespace cryptonote uint64_t start_height; std::vector blocks; boost::uuids::uuid span_connection_id; - if (!m_block_queue.get_next_span(start_height, blocks, span_connection_id)) + epee::net_utils::network_address span_origin; + if (!m_block_queue.get_next_span(start_height, blocks, span_connection_id, span_origin)) { MDEBUG(context << " no next span found, going back to download"); break; @@ -1395,6 +1396,7 @@ namespace cryptonote if (!m_core.prepare_handle_incoming_blocks(blocks, pblocks)) { LOG_ERROR_CCONTEXT("Failure in prepare_handle_incoming_blocks"); + drop_connections(span_origin); return 1; } if (!pblocks.empty() && pblocks.size() != blocks.size()) @@ -1434,6 +1436,7 @@ namespace cryptonote { if(tvc[i].m_verifivation_failed) { + drop_connections(span_origin); if (!m_p2p->for_connection(span_connection_id, [&](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t f)->bool{ cryptonote::transaction tx; crypto::hash txid; @@ -1475,6 +1478,7 @@ namespace cryptonote if(bvc.m_verifivation_failed) { + drop_connections(span_origin); if (!m_p2p->for_connection(span_connection_id, [&](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t f)->bool{ LOG_PRINT_CCONTEXT_L1("Block verification failed, dropping connection"); drop_connection_with_score(context, bvc.m_bad_pow ? P2P_IP_FAILS_BEFORE_BLOCK : 1, true); @@ -1494,6 +1498,7 @@ namespace cryptonote } if(bvc.m_marked_as_orphaned) { + drop_connections(span_origin); if (!m_p2p->for_connection(span_connection_id, [&](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t f)->bool{ LOG_PRINT_CCONTEXT_L1("Block received at sync phase was marked as orphaned, dropping connection"); drop_connection(context, true, true); @@ -2127,7 +2132,7 @@ skip: const uint64_t first_block_height = context.m_last_response_height - context.m_needed_objects.size() + 1; static const uint64_t bp_fork_height = m_core.get_earliest_ideal_height_for_version(7); bool sync_pruned_blocks = m_sync_pruned_blocks && first_block_height >= bp_fork_height && m_core.get_blockchain_pruning_seed(); - span = m_block_queue.reserve_span(first_block_height, context.m_last_response_height, count_limit, context.m_connection_id, sync_pruned_blocks, m_core.get_blockchain_pruning_seed(), context.m_pruning_seed, context.m_remote_blockchain_height, context.m_needed_objects); + span = m_block_queue.reserve_span(first_block_height, context.m_last_response_height, count_limit, context.m_connection_id, context.m_remote_address, sync_pruned_blocks, m_core.get_blockchain_pruning_seed(), context.m_pruning_seed, context.m_remote_blockchain_height, context.m_needed_objects); MDEBUG(context << " span from " << first_block_height << ": " << span.first << "/" << span.second); if (span.second > 0) { @@ -2263,7 +2268,8 @@ skip: uint64_t start_height; std::vector blocks; boost::uuids::uuid span_connection_id; - if (m_block_queue.get_next_span(start_height, blocks, span_connection_id, true)) + epee::net_utils::network_address span_origin; + if (m_block_queue.get_next_span(start_height, blocks, span_connection_id, span_origin, true)) { LOG_DEBUG_CC(context, "No other thread is adding blocks, resuming"); MLOG_PEER_STATE("will try to add blocks next"); @@ -2685,6 +2691,29 @@ template } //------------------------------------------------------------------------------------------------------------------------ template + void t_cryptonote_protocol_handler::drop_connections(const epee::net_utils::network_address address) + { + MWARNING("dropping connections to " << address.str()); + + m_p2p->add_host_fail(address, 5); + + std::vector drop; + m_p2p->for_each_connection([&](const connection_context& cntxt, nodetool::peerid_type peer_id, uint32_t support_flags) { + if (address.is_same_host(cntxt.m_remote_address)) + drop.push_back(cntxt.m_connection_id); + return true; + }); + for (const boost::uuids::uuid &id: drop) + { + m_block_queue.flush_spans(id, true); + m_p2p->for_connection(id, [&](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t f)->bool{ + drop_connection(context, true, false); + return true; + }); + } + } + //------------------------------------------------------------------------------------------------------------------------ + template void t_cryptonote_protocol_handler::on_connection_close(cryptonote_connection_context &context) { uint64_t target = 0; diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index c11e163feb..c463a18b79 100755 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -3046,11 +3046,7 @@ namespace cryptonote block_queue.foreach([&](const cryptonote::block_queue::span &span) { const std::string span_connection_id = epee::string_tools::pod_to_hex(span.connection_id); uint32_t speed = (uint32_t)(100.0f * block_queue.get_speed(span.connection_id) + 0.5f); - std::string address = ""; - for (const auto &c: m_p2p.get_payload_object().get_connections()) - if (c.connection_id == span_connection_id) - address = c.address; - res.spans.push_back({span.start_block_height, span.nblocks, span_connection_id, (uint32_t)(span.rate + 0.5f), speed, span.size, address}); + res.spans.push_back({span.start_block_height, span.nblocks, span_connection_id, (uint32_t)(span.rate + 0.5f), speed, span.size, span.origin.str()}); return true; }); res.overview = block_queue.get_overview(res.height); diff --git a/tests/unit_tests/block_queue.cpp b/tests/unit_tests/block_queue.cpp index 77c7f97ff2..21018d9766 100644 --- a/tests/unit_tests/block_queue.cpp +++ b/tests/unit_tests/block_queue.cpp @@ -1,21 +1,21 @@ // Copyright (c) 2017-2020, The Monero Project -// +// // 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 @@ -52,36 +52,38 @@ TEST(block_queue, empty) TEST(block_queue, add_stepwise) { + epee::net_utils::network_address na; cryptonote::block_queue bq; - bq.add_blocks(0, 200, uuid1()); + bq.add_blocks(0, 200, uuid1(), na); ASSERT_EQ(bq.get_max_block_height(), 199); - bq.add_blocks(200, 200, uuid1()); + bq.add_blocks(200, 200, uuid1(), na); ASSERT_EQ(bq.get_max_block_height(), 399); - bq.add_blocks(401, 200, uuid1()); + bq.add_blocks(401, 200, uuid1(), na); ASSERT_EQ(bq.get_max_block_height(), 600); - bq.add_blocks(400, 10, uuid1()); + bq.add_blocks(400, 10, uuid1(), na); ASSERT_EQ(bq.get_max_block_height(), 600); } TEST(block_queue, flush_uuid) { cryptonote::block_queue bq; + epee::net_utils::network_address na; - bq.add_blocks(0, 200, uuid1()); + bq.add_blocks(0, 200, uuid1(), na); ASSERT_EQ(bq.get_max_block_height(), 199); - bq.add_blocks(200, 200, uuid2()); + bq.add_blocks(200, 200, uuid2(), na); ASSERT_EQ(bq.get_max_block_height(), 399); bq.flush_spans(uuid2()); ASSERT_EQ(bq.get_max_block_height(), 199); bq.flush_spans(uuid1()); ASSERT_EQ(bq.get_max_block_height(), 0); - bq.add_blocks(0, 200, uuid1()); + bq.add_blocks(0, 200, uuid1(), na); ASSERT_EQ(bq.get_max_block_height(), 199); - bq.add_blocks(200, 200, uuid2()); + bq.add_blocks(200, 200, uuid2(), na); ASSERT_EQ(bq.get_max_block_height(), 399); bq.flush_spans(uuid1()); ASSERT_EQ(bq.get_max_block_height(), 399); - bq.add_blocks(0, 200, uuid1()); + bq.add_blocks(0, 200, uuid1(), na); ASSERT_EQ(bq.get_max_block_height(), 399); } From 4c73e93a732901617b725f9cab47b17bd12d6f0a Mon Sep 17 00:00:00 2001 From: sumogr Date: Mon, 14 Dec 2020 13:40:25 +0200 Subject: [PATCH 05/19] [cryptonote_protocol] fix asking for pruned blocks monero ref # 6753 # 7120 --- src/cryptonote_protocol/cryptonote_protocol_handler.inl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index c6fdca2021..1508ce7cca 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -1953,8 +1953,8 @@ skip: if (local_stripe == 0) return false; // don't request pre-bulletprooof pruned blocks, we can't reconstruct their weight (yet) - static const uint64_t bp_fork_height = m_core.get_earliest_ideal_height_for_version(7); - if (first_block_height + nblocks - 1 < bp_fork_height) + static const uint64_t bp_fork_height = m_core.get_earliest_ideal_height_for_version(HF_VERSION_SMALLER_BP + 1); + if (first_block_height < bp_fork_height) return false; // assumes the span size is less or equal to the stripe size bool full_data_needed = tools::get_pruning_stripe(first_block_height, context.m_remote_blockchain_height, CRYPTONOTE_PRUNING_LOG_STRIPES) == local_stripe @@ -2713,7 +2713,7 @@ template } } //------------------------------------------------------------------------------------------------------------------------ - template + template void t_cryptonote_protocol_handler::on_connection_close(cryptonote_connection_context &context) { uint64_t target = 0; From 3ad32c4561e883c3911fd86430c5863490ad019f Mon Sep 17 00:00:00 2001 From: sumogr Date: Mon, 14 Dec 2020 14:38:38 +0200 Subject: [PATCH 06/19] [cryptonote_protocol] sanity check on usable data from a peer monero ref # 7122 --- src/cryptonote_protocol/cryptonote_protocol_handler.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index 1508ce7cca..a6cbadf239 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -2472,7 +2472,7 @@ skip: } uint64_t n_use_blocks = m_core.prevalidate_block_hashes(arg.start_height, arg.m_block_ids, arg.m_block_weights); - if (n_use_blocks + HASH_OF_HASHES_STEP <= arg.m_block_ids.size()) + if (n_use_blocks == 0 || n_use_blocks + HASH_OF_HASHES_STEP <= arg.m_block_ids.size()) { LOG_ERROR_CCONTEXT("Most blocks are invalid, dropping connection"); drop_connection(context, true, false); From 101e8b86cff6339b9e1a5c4189c0ebfd763ac080 Mon Sep 17 00:00:00 2001 From: sumogr Date: Mon, 14 Dec 2020 14:43:27 +0200 Subject: [PATCH 07/19] [cryptonote_protocol] revert incoming chain height check against local chain We can actually request a chain that's further away from what we have as we buffer more and more monero ref # 7124 --- src/cryptonote_protocol/cryptonote_protocol_handler.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index a6cbadf239..6a78333dfd 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -2435,7 +2435,7 @@ skip: drop_connection(context, true, false); return 1; } - if (arg.total_height < arg.m_block_ids.size() || arg.start_height > arg.total_height - arg.m_block_ids.size() || arg.start_height >= m_core.get_current_blockchain_height()) + if (arg.total_height < arg.m_block_ids.size() || arg.start_height > arg.total_height - arg.m_block_ids.size()) { LOG_ERROR_CCONTEXT("sent invalid start/nblocks/height, dropping connection"); drop_connection(context, true, false); From 1e429b0ea669c0faf6ce6293d2ac7339470e0fce Mon Sep 17 00:00:00 2001 From: sumogr Date: Mon, 14 Dec 2020 14:54:02 +0200 Subject: [PATCH 08/19] [cryptonote_protocol] stricter checks on received chain hash list monero ref # 7128 --- src/cryptonote_basic/connection_context.h | 1 + .../cryptonote_protocol_handler.inl | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/cryptonote_basic/connection_context.h b/src/cryptonote_basic/connection_context.h index bf39736e33..80e7669080 100644 --- a/src/cryptonote_basic/connection_context.h +++ b/src/cryptonote_basic/connection_context.h @@ -69,6 +69,7 @@ namespace cryptonote bool m_anchor; int32_t m_score; int m_expect_response; + uint64_t m_expect_height; }; inline std::string get_protocol_state_string(cryptonote_connection_context::state s) diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index 6a78333dfd..588317ed9f 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -141,6 +141,7 @@ namespace cryptonote { NOTIFY_REQUEST_CHAIN::request r = {}; context.m_needed_objects.clear(); + context.m_expect_height = m_core.get_current_blockchain_height(); m_core.get_short_chain_history(r.block_ids); handler_request_blocks_history( r.block_ids ); // change the limit(?), sleep(?) r.prune = m_sync_pruned_blocks; @@ -491,6 +492,7 @@ namespace cryptonote context.m_needed_objects.clear(); context.m_state = cryptonote_connection_context::state_synchronizing; NOTIFY_REQUEST_CHAIN::request r = {}; + context.m_expect_height = m_core.get_current_blockchain_height(); m_core.get_short_chain_history(r.block_ids); r.prune = m_sync_pruned_blocks; handler_request_blocks_history( r.block_ids ); // change the limit(?), sleep(?) @@ -771,6 +773,7 @@ namespace cryptonote context.m_needed_objects.clear(); context.m_state = cryptonote_connection_context::state_synchronizing; NOTIFY_REQUEST_CHAIN::request r = {}; + context.m_expect_height = m_core.get_current_blockchain_height(); m_core.get_short_chain_history(r.block_ids); handler_request_blocks_history( r.block_ids ); // change the limit(?), sleep(?) r.prune = m_sync_pruned_blocks; @@ -1160,7 +1163,16 @@ namespace cryptonote return 1; } if (start_height == std::numeric_limits::max()) + { start_height = boost::get(b.miner_tx.vin[0]).height; + if (start_height > context.m_expect_height) + { + LOG_ERROR_CCONTEXT("sent block ahead of expected height, dropping connection"); + drop_connection(context, false, false); + ++m_sync_bad_spans_downloaded; + return 1; + } + } auto req_it = context.m_requested_objects.find(block_hash); if(req_it == context.m_requested_objects.end()) @@ -1670,6 +1682,7 @@ skip: LOG_PRINT_CCONTEXT_L2("requesting callback"); context.m_last_request_time = boost::date_time::not_a_date_time; context.m_expect_response = 0; + context.m_expect_height = 0; context.m_state = cryptonote_connection_context::state_standby; // we'll go back to adding, then (if we can't), download ++context.m_callback_request_count; m_p2p->request_callback(context); @@ -2213,6 +2226,7 @@ skip: } } context.m_last_request_time = boost::posix_time::microsec_clock::universal_time(); + context.m_expect_height = span.first; context.m_expect_response = NOTIFY_RESPONSE_GET_OBJECTS::ID; MLOG_P2P_MESSAGE("-->>NOTIFY_REQUEST_GET_OBJECTS: blocks.size()=" << req.blocks.size() << "requested blocks count=" << count << " / " << count_limit << " from " << span.first << ", first hash " << req.blocks.front()); @@ -2285,6 +2299,7 @@ skip: {//we have to fetch more objects ids, request blockchain entry NOTIFY_REQUEST_CHAIN::request r = {}; + context.m_expect_height = m_core.get_current_blockchain_height(); m_core.get_short_chain_history(r.block_ids); CHECK_AND_ASSERT_MES(!r.block_ids.empty(), false, "Short chain history is empty"); @@ -2292,7 +2307,10 @@ skip: { // we'll want to start off from where we are on that peer, which may not be added yet if (context.m_last_known_hash != crypto::null_hash && r.block_ids.front() != context.m_last_known_hash) + { + context.m_expect_height = std::numeric_limits::max(); r.block_ids.push_front(context.m_last_known_hash); + } } handler_request_blocks_history( r.block_ids ); // change the limit(?), sleep(?) @@ -2424,6 +2442,12 @@ skip: return 1; } context.m_expect_response = 0; + if (arg.start_height + 1 > context.m_expect_height) // we expect an overlapping block + { + LOG_ERROR_CCONTEXT("Got NOTIFY_RESPONSE_CHAIN_ENTRY past expected height, dropping connection"); + drop_connection(context, true, false); + return 1; + } context.m_last_request_time = boost::date_time::not_a_date_time; @@ -2471,6 +2495,17 @@ skip: return 1; } + std::unordered_set hashes; + for (const auto &h: arg.m_block_ids) + { + if (!hashes.insert(h).second) + { + LOG_ERROR_CCONTEXT("sent duplicate block, dropping connection"); + drop_connection(context, true, false); + return 1; + } + } + uint64_t n_use_blocks = m_core.prevalidate_block_hashes(arg.start_height, arg.m_block_ids, arg.m_block_weights); if (n_use_blocks == 0 || n_use_blocks + HASH_OF_HASHES_STEP <= arg.m_block_ids.size()) { From 2f4ecaab390883e979ef337a32aa0f048c97a779 Mon Sep 17 00:00:00 2001 From: sumogr Date: Mon, 14 Dec 2020 15:09:52 +0200 Subject: [PATCH 09/19] [cryptonote_protocol] include first new block in chain entry response monero ref # 7131 --- src/cryptonote_protocol/cryptonote_protocol_defs.h | 4 +++- .../cryptonote_protocol_handler.inl | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cryptonote_protocol/cryptonote_protocol_defs.h b/src/cryptonote_protocol/cryptonote_protocol_defs.h index f947f413f5..2ebdd784ba 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_defs.h +++ b/src/cryptonote_protocol/cryptonote_protocol_defs.h @@ -202,7 +202,7 @@ namespace cryptonote BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(txs) KV_SERIALIZE(_) - KV_SERIALIZE_OPT(dandelionpp_fluff, true) // backwards compatible mode is fluff + KV_SERIALIZE_OPT(dandelionpp_fluff, true) // backwards compatible mode is fluff END_KV_SERIALIZE_MAP() }; typedef epee::misc_utils::struct_init request; @@ -298,6 +298,7 @@ namespace cryptonote uint64_t cumulative_difficulty_top64; std::vector m_block_ids; std::vector m_block_weights; + cryptonote::blobdata first_block; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(start_height) @@ -309,6 +310,7 @@ namespace cryptonote 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) + KV_SERIALIZE(first_block) END_KV_SERIALIZE_MAP() }; typedef epee::misc_utils::struct_init request; diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index 588317ed9f..e31a90f497 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -1782,6 +1782,16 @@ skip: LOG_ERROR_CCONTEXT("Failed to handle NOTIFY_REQUEST_CHAIN."); return 1; } + if (r.m_block_ids.size() >= 2) + { + cryptonote::block b; + if (!m_core.get_block_by_hash(r.m_block_ids[1], b)) + { + LOG_ERROR_CCONTEXT("Failed to handle NOTIFY_REQUEST_CHAIN: first block not found"); + return 1; + } + r.first_block = cryptonote::block_to_blob(b); + } MLOG_P2P_MESSAGE("-->>NOTIFY_RESPONSE_CHAIN_ENTRY: m_start_height=" << r.start_height << ", m_total_height=" << r.total_height << ", m_block_ids.size()=" << r.m_block_ids.size()); post_notify(r, context); return 1; From a476df5229b007a8297f9acdbc5411a0fc108bd4 Mon Sep 17 00:00:00 2001 From: Sumo Gr Date: Tue, 15 Dec 2020 23:30:56 +0200 Subject: [PATCH 10/19] [workflows] add cache action where possible macos and linux release and static builds (not on cross-compilations and msys2 windows builds) stole the method from a recent commit from selsta on monero --- .github/workflows/build.yml | 55 ++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5988b0b1df..cfb8239914 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,12 +5,22 @@ on: [push, pull_request] jobs: build-macos-native: runs-on: macOS-latest + env: + CCACHE_COMPRESS: 1 + CCACHE_TEMPDIR: /tmp/.ccache-temp steps: - uses: actions/checkout@v1 + - uses: actions/cache@v2 + with: + path: ~/.ccache + key: ccache-macos-build-${{ github.sha }} + restore-keys: ccache-macos-build- - name: install dependencies - run: brew install boost hidapi zmq libpgm ldns expat libunwind-headers protobuf + run: brew install boost hidapi zmq libpgm ldns expat libunwind-headers protobuf ccache - name: build - run: make -j3 + run: | + ccache --max-size=150M + make -j3 macOS-cross-on-bionic: runs-on: ubuntu-18.04 @@ -87,8 +97,16 @@ jobs: build-ubuntu-bionic-native: runs-on: ubuntu-18.04 + env: + CCACHE_COMPRESS: 1 + CCACHE_TEMPDIR: /tmp/.ccache-temp steps: - uses: actions/checkout@v1 + - uses: actions/cache@v2 + with: + path: ~/.ccache + key: ccache-ubuntu-bionic-build-${{ github.sha }} + restore-keys: ccache-ubuntu-bionic-build- - name: remove bundled boost run: sudo rm -rf /usr/local/share/boost - name: set apt conf @@ -101,12 +119,19 @@ jobs: - name: install sumokoin dependencies run: sudo apt -y install build-essential cmake libboost-all-dev miniupnpc libunbound-dev libevent-dev graphviz doxygen libunwind8-dev pkg-config libssl-dev libzmq3-dev libsodium-dev libhidapi-dev libnorm-dev libusb-1.0-0-dev libpgm-dev ccache - name: build sumokoin - run: make -j 3 + run: | + ccache --max-size=150M + make -j3 build-bionic-debug-native: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v1 + - uses: actions/cache@v2 + with: + path: ~/.ccache + key: ccache-ubuntu-debug-build-${{ github.sha }} + restore-keys: ccache-ubuntu-debug-build- - name: remove bundled boost run: sudo rm -rf /usr/local/share/boost - name: set apt conf @@ -119,12 +144,19 @@ jobs: - name: install sumokoin dependencies run: sudo apt -y install build-essential cmake libboost-all-dev miniupnpc libunbound-dev graphviz doxygen libunwind8-dev pkg-config libssl-dev libzmq3-dev libsodium-dev libhidapi-dev libnorm-dev libusb-1.0-0-dev libpgm-dev ccache - name: build sumokoin - run: make debug -j 3 + run: | + ccache --max-size=150M + make -j3 build-ubuntu-focal-fossa-native: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v1 + - uses: actions/cache@v2 + with: + path: ~/.ccache + key: ccache-ubuntu-focal-build-${{ github.sha }} + restore-keys: ccache-ubuntu-focal-build- - name: remove bundled boost run: sudo rm -rf /usr/local/share/boost - name: set apt conf @@ -137,12 +169,19 @@ jobs: - name: install sumokoin dependencies run: sudo apt -y install build-essential cmake libboost-all-dev miniupnpc libunbound-dev graphviz doxygen libunwind8-dev pkg-config libssl-dev libzmq3-dev libsodium-dev libhidapi-dev libnorm-dev libusb-1.0-0-dev libpgm-dev ccache - name: build sumokoin - run: make -j 3 + run: | + ccache --max-size=150M + make -j3 build-ubuntu-bionic-static-native: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v1 + - uses: actions/cache@v2 + with: + path: ~/.ccache + key: ccache-ubuntu-bionic-static-build-${{ github.sha }} + restore-keys: ccache-ubuntu-bionic-static-build- - name: remove bundled boost run: sudo rm -rf /usr/local/share/boost - name: set apt conf @@ -153,7 +192,7 @@ jobs: - name: update apt run: sudo apt update - name: install sumokoin dependencies - run: sudo apt -y install build-essential cmake miniupnpc libunbound-dev libevent-dev graphviz doxygen pkg-config libssl-dev libsodium-dev libhidapi-dev libnorm-dev libusb-1.0-0-dev libpgm-dev libudev-dev ccache libtool autoconf automake python libtinfo5 + run: sudo apt -y install build-essential cmake miniupnpc libunbound-dev libevent-dev graphviz doxygen pkg-config libssl-dev libsodium-dev libhidapi-dev libnorm-dev libusb-1.0-0-dev libpgm-dev libudev-dev ccache libtool autoconf automake python libtinfo5 ccache - name: build boost 1_74 run: | wget https://dl.bintray.com/boostorg/release/1.74.0/source/boost_1_74_0.tar.bz2 @@ -183,7 +222,9 @@ jobs: sudo make install cd .. - name: build sumokoin - run: make release-static -j 3 + run: | + ccache --max-size=150M + make release-static -j 3 FreeBSD-cross-on-bionic: runs-on: ubuntu-18.04 From f210d8e09928a83b434451919d061411402d0533 Mon Sep 17 00:00:00 2001 From: Sumo Gr Date: Tue, 15 Dec 2020 23:40:45 +0200 Subject: [PATCH 11/19] [cmake] fix deprecated cmake version warnings --- .github/workflows/build.yml | 14 +++++++------- CMakeLists.txt | 2 +- src/cryptonote_protocol/CMakeLists.txt | 2 +- src/p2p/CMakeLists.txt | 3 +-- thirdparty/easylogging++/CMakeLists.txt | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cfb8239914..dfdd972a53 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,14 +7,14 @@ jobs: runs-on: macOS-latest env: CCACHE_COMPRESS: 1 - CCACHE_TEMPDIR: /tmp/.ccache-temp + CCACHE_TEMPDIR: /tmp/.ccache-temp steps: - uses: actions/checkout@v1 - uses: actions/cache@v2 with: path: ~/.ccache key: ccache-macos-build-${{ github.sha }} - restore-keys: ccache-macos-build- + restore-keys: ccache-macos-build- - name: install dependencies run: brew install boost hidapi zmq libpgm ldns expat libunwind-headers protobuf ccache - name: build @@ -99,14 +99,14 @@ jobs: runs-on: ubuntu-18.04 env: CCACHE_COMPRESS: 1 - CCACHE_TEMPDIR: /tmp/.ccache-temp + CCACHE_TEMPDIR: /tmp/.ccache-temp steps: - uses: actions/checkout@v1 - uses: actions/cache@v2 with: path: ~/.ccache key: ccache-ubuntu-bionic-build-${{ github.sha }} - restore-keys: ccache-ubuntu-bionic-build- + restore-keys: ccache-ubuntu-bionic-build- - name: remove bundled boost run: sudo rm -rf /usr/local/share/boost - name: set apt conf @@ -131,7 +131,7 @@ jobs: with: path: ~/.ccache key: ccache-ubuntu-debug-build-${{ github.sha }} - restore-keys: ccache-ubuntu-debug-build- + restore-keys: ccache-ubuntu-debug-build- - name: remove bundled boost run: sudo rm -rf /usr/local/share/boost - name: set apt conf @@ -156,7 +156,7 @@ jobs: with: path: ~/.ccache key: ccache-ubuntu-focal-build-${{ github.sha }} - restore-keys: ccache-ubuntu-focal-build- + restore-keys: ccache-ubuntu-focal-build- - name: remove bundled boost run: sudo rm -rf /usr/local/share/boost - name: set apt conf @@ -181,7 +181,7 @@ jobs: with: path: ~/.ccache key: ccache-ubuntu-bionic-static-build-${{ github.sha }} - restore-keys: ccache-ubuntu-bionic-static-build- + restore-keys: ccache-ubuntu-bionic-static-build- - name: remove bundled boost run: sudo rm -rf /usr/local/share/boost - name: set apt conf diff --git a/CMakeLists.txt b/CMakeLists.txt index 642a9427d0..60d9dff9ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ # # Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers -cmake_minimum_required(VERSION 2.8.7) +cmake_minimum_required(VERSION 2.8.12) message(STATUS "CMake version ${CMAKE_VERSION}") cmake_host_system_information(RESULT freememsys QUERY AVAILABLE_PHYSICAL_MEMORY) diff --git a/src/cryptonote_protocol/CMakeLists.txt b/src/cryptonote_protocol/CMakeLists.txt index d28b44bb7b..57b2477754 100644 --- a/src/cryptonote_protocol/CMakeLists.txt +++ b/src/cryptonote_protocol/CMakeLists.txt @@ -26,7 +26,7 @@ # 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. -cmake_minimum_required (VERSION 2.6) +cmake_minimum_required (VERSION 2.8.12) project (monero CXX) file(GLOB CRYPTONOTE_PROTOCOL *) diff --git a/src/p2p/CMakeLists.txt b/src/p2p/CMakeLists.txt index e3d58ac852..44364a646e 100644 --- a/src/p2p/CMakeLists.txt +++ b/src/p2p/CMakeLists.txt @@ -26,7 +26,7 @@ # 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. -cmake_minimum_required (VERSION 2.6) +cmake_minimum_required (VERSION 2.8.12) project (monero CXX) file(GLOB P2P *) @@ -53,4 +53,3 @@ target_link_libraries(p2p ${Boost_SERIALIZATION_LIBRARY} PRIVATE ${EXTRA_LIBRARIES}) - diff --git a/thirdparty/easylogging++/CMakeLists.txt b/thirdparty/easylogging++/CMakeLists.txt index 7705b4ae7e..41a117ec68 100644 --- a/thirdparty/easylogging++/CMakeLists.txt +++ b/thirdparty/easylogging++/CMakeLists.txt @@ -26,7 +26,7 @@ # 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. -cmake_minimum_required(VERSION 2.8.7) +cmake_minimum_required(VERSION 2.8.12) project(easylogging CXX) From 46cc66c6118123f9058e9e08669baf9b07ad12ee Mon Sep 17 00:00:00 2001 From: sumogr Date: Thu, 17 Dec 2020 20:24:58 +0200 Subject: [PATCH 12/19] [depends] upgrade openssl to 1.1.1i due to the recently disclosed vulnerability https://www.openssl.org/news/secadv/20201208.txt --- contrib/depends/packages/ncurses.mk | 1 - contrib/depends/packages/openssl.mk | 31 +++++++------------ .../depends/patches/openssl/fix_arflags.patch | 24 -------------- 3 files changed, 12 insertions(+), 44 deletions(-) delete mode 100644 contrib/depends/patches/openssl/fix_arflags.patch diff --git a/contrib/depends/packages/ncurses.mk b/contrib/depends/packages/ncurses.mk index bbcf857c64..bb57f39561 100644 --- a/contrib/depends/packages/ncurses.mk +++ b/contrib/depends/packages/ncurses.mk @@ -61,4 +61,3 @@ endef define $(package)_stage_cmds $(MAKE) install.libs DESTDIR=$($(package)_staging_dir) endef - diff --git a/contrib/depends/packages/openssl.mk b/contrib/depends/packages/openssl.mk index 9d3c284653..62e975e50d 100644 --- a/contrib/depends/packages/openssl.mk +++ b/contrib/depends/packages/openssl.mk @@ -1,36 +1,31 @@ package=openssl -$(package)_version=1.0.2r -$(package)_download_path=https://ftp.openssl.org/source/old/1.0.2 +$(package)_version=1.1.1i +$(package)_download_path=https://www.openssl.org/source $(package)_file_name=$(package)-$($(package)_version).tar.gz -$(package)_sha256_hash=ae51d08bba8a83958e894946f15303ff894d75c2b8bbd44a852b64e3fe11d0d6 -$(package)_patches=fix_arflags.patch +$(package)_sha256_hash=e8be6a35fe41d10603c3cc635e93289ed00bf34b79671a3a4de64fcee00d5242 define $(package)_set_vars $(package)_config_env=AR="$($(package)_ar)" ARFLAGS=$($(package)_arflags) RANLIB="$($(package)_ranlib)" CC="$($(package)_cc)" +$(package)_config_env_arm_android=ANDROID_NDK_HOME="$(host_prefix)/native" PATH="$(host_prefix)/native/bin" CC=clang AR=ar RANLIB=ranlib +$(package)_config_env_aarch64_android=ANDROID_NDK_HOME="$(host_prefix)/native" PATH="$(host_prefix)/native/bin" CC=clang AR=ar RANLIB=ranlib +$(package)_build_env_arm_android=ANDROID_NDK_HOME="$(host_prefix)/native" +$(package)_build_env_aarch64_android=ANDROID_NDK_HOME="$(host_prefix)/native" $(package)_config_opts=--prefix=$(host_prefix) --openssldir=$(host_prefix)/etc/openssl $(package)_config_opts+=no-capieng $(package)_config_opts+=no-dso $(package)_config_opts+=no-dtls1 $(package)_config_opts+=no-ec_nistp_64_gcc_128 $(package)_config_opts+=no-gost -$(package)_config_opts+=no-gmp $(package)_config_opts+=no-heartbeats -$(package)_config_opts+=no-jpake -$(package)_config_opts+=no-krb5 -$(package)_config_opts+=no-libunbound $(package)_config_opts+=no-md2 $(package)_config_opts+=no-rc5 $(package)_config_opts+=no-rdrand $(package)_config_opts+=no-rfc3779 -$(package)_config_opts+=no-rsax $(package)_config_opts+=no-sctp -$(package)_config_opts+=no-sha0 $(package)_config_opts+=no-shared $(package)_config_opts+=no-ssl-trace $(package)_config_opts+=no-ssl2 $(package)_config_opts+=no-ssl3 -$(package)_config_opts+=no-static_engine -$(package)_config_opts+=no-store $(package)_config_opts+=no-unit-test $(package)_config_opts+=no-weak-ssl-ciphers $(package)_config_opts+=no-zlib @@ -42,8 +37,8 @@ $(package)_config_opts_x86_64_linux=linux-x86_64 $(package)_config_opts_i686_linux=linux-generic32 $(package)_config_opts_arm_linux=linux-generic32 $(package)_config_opts_aarch64_linux=linux-generic64 -$(package)_config_opts_arm_android=--static android-armv7 no-asm -$(package)_config_opts_aarch64_android=--static android no-asm +$(package)_config_opts_arm_android=--static android-arm +$(package)_config_opts_aarch64_android=--static android-arm64 $(package)_config_opts_riscv64_linux=linux-generic64 $(package)_config_opts_mipsel_linux=linux-generic32 $(package)_config_opts_mips_linux=linux-generic32 @@ -55,10 +50,8 @@ $(package)_config_opts_x86_64_freebsd=BSD-x86_64 endef define $(package)_preprocess_cmds - sed -i.old "/define DATE/d" util/mkbuildinf.pl && \ - sed -i.old "s|engines apps test|engines|" Makefile.org && \ - sed -i -e "s/-mandroid //" Configure && \ - patch < $($(package)_patch_dir)/fix_arflags.patch + sed -i.old 's|"engines", "apps", "test", "util", "tools", "fuzz"|"engines", "tools"|' Configure && \ + sed -i -e 's|cflags --sysroot.*",|cflags",|' Configurations/15-android.conf endef define $(package)_config_cmds @@ -70,7 +63,7 @@ define $(package)_build_cmds endef define $(package)_stage_cmds - $(MAKE) INSTALL_PREFIX=$($(package)_staging_dir) -j1 install_sw + $(MAKE) DESTDIR=$($(package)_staging_dir) -j1 install_sw endef define $(package)_postprocess_cmds diff --git a/contrib/depends/patches/openssl/fix_arflags.patch b/contrib/depends/patches/openssl/fix_arflags.patch deleted file mode 100644 index 2d2900d80a..0000000000 --- a/contrib/depends/patches/openssl/fix_arflags.patch +++ /dev/null @@ -1,24 +0,0 @@ ---- Makefile.org.O 2019-02-26 14:20:20.000000000 +0000 -+++ Makefile.org 2019-11-15 13:05:54.370086856 +0000 -@@ -63,8 +63,8 @@ - PEX_LIBS= - EX_LIBS= - EXE_EXT= --ARFLAGS= --AR=ar $(ARFLAGS) r -+ARFLAGS= r -+AR=ar $(ARFLAGS) - RANLIB= ranlib - RC= windres - NM= nm ---- Configure.O 2019-02-26 14:20:20.000000000 +0000 -+++ Configure 2019-11-16 07:43:14.933990774 +0000 -@@ -1251,7 +1251,7 @@ - my $shared_extension = $fields[$idx_shared_extension]; - my $ranlib = $ENV{'RANLIB'} || $fields[$idx_ranlib]; - my $ar = $ENV{'AR'} || "ar"; --my $arflags = $fields[$idx_arflags]; -+my $arflags = $ENV{'ARFLAGS'} || $fields[$idx_arflags]; - my $windres = $ENV{'RC'} || $ENV{'WINDRES'} || "windres"; - my $multilib = $fields[$idx_multilib]; - From ca395767943bdcb8c1863a0b8fbbab8bdc2f37f1 Mon Sep 17 00:00:00 2001 From: sumogr Date: Fri, 18 Dec 2020 21:07:07 +0200 Subject: [PATCH 13/19] [rpc] add a busy_syncing field to get_info monero ref # 7156 --- src/cryptonote_protocol/cryptonote_protocol_handler.h | 4 +++- src/cryptonote_protocol/cryptonote_protocol_handler.inl | 9 ++++++++- src/rpc/core_rpc_server.cpp | 1 + src/rpc/core_rpc_server_commands_defs.h | 4 +++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.h b/src/cryptonote_protocol/cryptonote_protocol_handler.h index 286a12375f..401aef101e 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.h +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.h @@ -114,6 +114,8 @@ namespace cryptonote std::string get_peers_overview() const; std::pair get_next_needed_pruning_stripe() const; bool needs_new_sync_connections() const; + bool is_busy_syncing(); + private: //----------------- commands handlers ---------------------------------------------- int handle_notify_new_block(int command, NOTIFY_NEW_BLOCK::request& arg, cryptonote_connection_context& context); @@ -139,7 +141,7 @@ namespace cryptonote bool should_ask_for_pruned_data(cryptonote_connection_context& context, uint64_t first_block_height, uint64_t nblocks, bool check_block_weights) const; void drop_connection(cryptonote_connection_context &context, bool add_fail, bool flush_all_spans); void drop_connection_with_score(cryptonote_connection_context &context, uint64_t score, bool flush_all_spans); - void drop_connections(const epee::net_utils::network_address address); + void drop_connections(const epee::net_utils::network_address address); bool kick_idle_peers(); bool check_standby_peers(); bool update_sync_search(); diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index e31a90f497..4f0f68524d 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -1791,7 +1791,7 @@ skip: return 1; } r.first_block = cryptonote::block_to_blob(b); - } + } MLOG_P2P_MESSAGE("-->>NOTIFY_RESPONSE_CHAIN_ENTRY: m_start_height=" << r.start_height << ", m_total_height=" << r.total_height << ", m_block_ids.size()=" << r.m_block_ids.size()); post_notify(r, context); return 1; @@ -2715,6 +2715,13 @@ template } //------------------------------------------------------------------------------------------------------------------------ template + bool t_cryptonote_protocol_handler::is_busy_syncing() + { + const boost::unique_lock sync{m_sync_lock, boost::try_to_lock}; + return !sync.owns_lock(); + } + //------------------------------------------------------------------------------------------------------------------------ + template void t_cryptonote_protocol_handler::drop_connection_with_score(cryptonote_connection_context &context, uint64_t score, bool flush_all_spans) { LOG_DEBUG_CC(context, "dropping connection id " << context.m_connection_id << " (pruning seed " << diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index c463a18b79..ca245d5dd3 100755 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -478,6 +478,7 @@ namespace cryptonote res.database_size = round_up(res.database_size, 5ull* 1024 * 1024 * 1024); // res.update_available = restricted ? false : m_core.is_update_available(); res.version = restricted ? "" : SUMOKOIN_VERSION_FULL; + res.busy_syncing = m_p2p.get_payload_object().is_busy_syncing(); res.status = CORE_RPC_STATUS_OK; return true; diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 7b1b105b33..875cfffc9a 100755 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -88,7 +88,7 @@ namespace cryptonote // advance which version they will stop working with // Don't go over 32767 for any of these #define CORE_RPC_VERSION_MAJOR 3 -#define CORE_RPC_VERSION_MINOR 3 +#define CORE_RPC_VERSION_MINOR 4 #define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor)) #define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR) @@ -745,6 +745,7 @@ namespace cryptonote bool was_bootstrap_ever_used; uint64_t database_size; // bool update_available; + bool busy_syncing; std::string version; BEGIN_KV_SERIALIZE_MAP() @@ -784,6 +785,7 @@ namespace cryptonote KV_SERIALIZE(was_bootstrap_ever_used) KV_SERIALIZE(database_size) // KV_SERIALIZE(update_available) + KV_SERIALIZE(busy_syncing) KV_SERIALIZE(version) END_KV_SERIALIZE_MAP() }; From db2bed49da3a8814019928e1fffbf64f43de6d66 Mon Sep 17 00:00:00 2001 From: sumogr Date: Fri, 18 Dec 2020 21:11:01 +0200 Subject: [PATCH 14/19] [rpc] get_info - add 'synchronized' field monero ref # 7030 --- src/rpc/core_rpc_server.cpp | 3 ++- src/rpc/core_rpc_server_commands_defs.h | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index ca245d5dd3..e97861126c 100755 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -478,7 +478,8 @@ namespace cryptonote res.database_size = round_up(res.database_size, 5ull* 1024 * 1024 * 1024); // res.update_available = restricted ? false : m_core.is_update_available(); res.version = restricted ? "" : SUMOKOIN_VERSION_FULL; - res.busy_syncing = m_p2p.get_payload_object().is_busy_syncing(); + res.synchronized = check_core_ready(); + res.busy_syncing = m_p2p.get_payload_object().is_busy_syncing(); res.status = CORE_RPC_STATUS_OK; return true; diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 875cfffc9a..df57bf2092 100755 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -88,7 +88,7 @@ namespace cryptonote // advance which version they will stop working with // Don't go over 32767 for any of these #define CORE_RPC_VERSION_MAJOR 3 -#define CORE_RPC_VERSION_MINOR 4 +#define CORE_RPC_VERSION_MINOR 5 #define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor)) #define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR) @@ -747,6 +747,7 @@ namespace cryptonote // bool update_available; bool busy_syncing; std::string version; + bool synchronized; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE_PARENT(rpc_access_response_base) @@ -787,6 +788,7 @@ namespace cryptonote // KV_SERIALIZE(update_available) KV_SERIALIZE(busy_syncing) KV_SERIALIZE(version) + KV_SERIALIZE(synchronized) END_KV_SERIALIZE_MAP() }; typedef epee::misc_utils::struct_init response; From fc9fd4ed61d839733500832a43ab8db846aeaf39 Mon Sep 17 00:00:00 2001 From: Sumo Gr Date: Sat, 19 Dec 2020 10:24:46 +0200 Subject: [PATCH 15/19] [checkpoints] add mainnet checkpoint at height 492000 --- src/hardforks_checkpoints_config.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hardforks_checkpoints_config.h b/src/hardforks_checkpoints_config.h index 046aa43954..6a4498da75 100644 --- a/src/hardforks_checkpoints_config.h +++ b/src/hardforks_checkpoints_config.h @@ -84,6 +84,7 @@ ADD_CHECKPOINT(435000, "ee11193a62f74d2ed681fd2e9212e9e4061774d9dd90039cc5a4d0b65f2c5522"); \ ADD_CHECKPOINT(446000, "c50f8599b0c0cf5ad620217e9a496fdfa1f82b485995cfd73a04a1509bb902a2"); \ ADD_CHECKPOINT(465000, "985a03585380e5a8ba30a2515174c05afbc71a858ec171a1c1a8658df322935e"); \ + ADD_CHECKPOINT(492000, "a2efbec083be4f1aadb1e368e85fc861a3014bcef6e58dad2161b46cc6fa0cea"); \ // testnet checkpoints #define TESTNET_CHECKPOINTS \ From eeba03541fe6b8270491527ed29086fcc92b3036 Mon Sep 17 00:00:00 2001 From: Sumo Gr Date: Sat, 19 Dec 2020 10:45:23 +0200 Subject: [PATCH 16/19] [HF] Set hardfork 10 (clsag) and hardfork 11 dates --- src/hardforks/hardforks.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardforks/hardforks.cpp b/src/hardforks/hardforks.cpp index 248417dce6..cd16fec769 100644 --- a/src/hardforks/hardforks.cpp +++ b/src/hardforks/hardforks.cpp @@ -42,8 +42,8 @@ const hardfork_t mainnet_hard_forks[] = { { 7, MAINNET_HARDFORK_V7_HEIGHT, 0, 1555234940 }, { 8, MAINNET_HARDFORK_V8_HEIGHT, 0, 1555321375 }, { 9, 350000, 0, 1574120819 }, // abt 6h47' Nov 19, 2019 -//{ 10, XXXXXX, 0, XXXXXXXXXX }, // CLSAG & EXACT COINBASE - ALLOW BOTH MLSAG AND CLSAG -//{ 11, XXXXXX, 0, XXXXXXXXXX }, // FORBID MLSAG ALLOW CLSAG ONLY - SHOULD HAPPEN A DAY OR TWO AFTER HF 10 + { 10, 498657, 0, 1609836171 }, // CLSAG & EXACT COINBASE - ALLOW BOTH MLSAG AND CLSAG (abt January 5, 2021 8:42:51 AM GMT) + { 11, 499017, 0, 1609922571 }, // FORBID MLSAG ALLOW CLSAG ONLY - A DAY AFTER HF 10 }; const size_t num_mainnet_hard_forks = sizeof(mainnet_hard_forks) / sizeof(mainnet_hard_forks[0]); From 159b18b7cf8ff02a7d3706e21b5fc6da25eae2fd Mon Sep 17 00:00:00 2001 From: sumogr Date: Sun, 20 Dec 2020 12:25:18 +0200 Subject: [PATCH 17/19] [epee] fix byte_stream::put_n monero ref # 7151 --- contrib/epee/include/byte_stream.h | 4 ++-- tests/unit_tests/epee_utils.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/contrib/epee/include/byte_stream.h b/contrib/epee/include/byte_stream.h index 3223538fd7..855e51d840 100755 --- a/contrib/epee/include/byte_stream.h +++ b/contrib/epee/include/byte_stream.h @@ -118,7 +118,7 @@ namespace epee } //! Reset write position, but do not release internal memory. \post `size() == 0`. - void clear() noexcept { next_write_ = buffer_.get(); } + void clear() noexcept { next_write_ = buffer_.get(); } /*! Copy `length` bytes starting at `ptr` to end of stream. \throw std::range_error If exceeding max size_t value. @@ -188,7 +188,7 @@ namespace epee void put_n(const std::uint8_t ch, const std::size_t count) { check(count); - std::memset(tellp(), count, ch); + std::memset(tellp(), ch, count); next_write_ += count; } diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp index 9fc6f7073b..46aaa9f582 100644 --- a/tests/unit_tests/epee_utils.cpp +++ b/tests/unit_tests/epee_utils.cpp @@ -972,6 +972,23 @@ TEST(ByteStream, Put) EXPECT_TRUE(equal(bytes, byte_span{stream.data(), stream.size()})); } +TEST(ByteStream, PutN) +{ + using boost::range::equal; + using byte_span = epee::span; + + std::vector bytes; + bytes.resize(1000, 'f'); + + epee::byte_stream stream; + stream.put_n('f', 1000); + + EXPECT_EQ(1000u, stream.size()); + EXPECT_LE(1000u, stream.capacity()); + EXPECT_EQ(stream.available(), stream.capacity() - stream.size()); + EXPECT_TRUE(equal(bytes, byte_span{stream.data(), stream.size()})); +} + TEST(ByteStream, Reserve) { using boost::range::equal; From 56e31cace38280ed212bfdea112856621a874c7e Mon Sep 17 00:00:00 2001 From: Sumo Gr Date: Sun, 20 Dec 2020 12:29:31 +0200 Subject: [PATCH 18/19] [p2p] ignore incoming peer list entries when we have them blocked monero ref # 7143 --- src/p2p/net_node.inl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 1ce8383dcb..afb3ebcb25 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -1990,7 +1990,9 @@ namespace nodetool LOG_DEBUG_CC(context, "REMOTE PEERLIST: remote peerlist size=" << peerlist_.size()); LOG_TRACE_CC(context, "REMOTE PEERLIST: " << ENDL << print_peerlist_to_string(peerlist_)); - return m_network_zones.at(context.m_remote_address.get_zone()).m_peerlist.merge_peerlist(peerlist_, [this](const peerlist_entry &pe) { return !is_addr_recently_failed(pe.adr); }); + return m_network_zones.at(context.m_remote_address.get_zone()).m_peerlist.merge_peerlist(peerlist_, [this](const peerlist_entry &pe) { + return !is_addr_recently_failed(pe.adr) && is_remote_host_allowed(pe.adr); + }); } //----------------------------------------------------------------------------------- template From 6f5df8d4b388ae029e5537668404daa4348d2a90 Mon Sep 17 00:00:00 2001 From: Sumo Gr Date: Sun, 20 Dec 2020 15:15:08 +0200 Subject: [PATCH 19/19] [hardfork 10 and 11] Move it for the 15th of January --- src/hardforks/hardforks.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardforks/hardforks.cpp b/src/hardforks/hardforks.cpp index cd16fec769..008eabd28d 100644 --- a/src/hardforks/hardforks.cpp +++ b/src/hardforks/hardforks.cpp @@ -42,8 +42,8 @@ const hardfork_t mainnet_hard_forks[] = { { 7, MAINNET_HARDFORK_V7_HEIGHT, 0, 1555234940 }, { 8, MAINNET_HARDFORK_V8_HEIGHT, 0, 1555321375 }, { 9, 350000, 0, 1574120819 }, // abt 6h47' Nov 19, 2019 - { 10, 498657, 0, 1609836171 }, // CLSAG & EXACT COINBASE - ALLOW BOTH MLSAG AND CLSAG (abt January 5, 2021 8:42:51 AM GMT) - { 11, 499017, 0, 1609922571 }, // FORBID MLSAG ALLOW CLSAG ONLY - A DAY AFTER HF 10 + { 10, 502257, 0, 1610700171 }, // CLSAG & EXACT COINBASE - ALLOW BOTH MLSAG AND CLSAG (abt January 15, 2021 8:42:51 AM GMT) + { 11, 502617, 0, 1610786571 }, // FORBID MLSAG ALLOW CLSAG ONLY - A DAY AFTER HF 10 }; const size_t num_mainnet_hard_forks = sizeof(mainnet_hard_forks) / sizeof(mainnet_hard_forks[0]);