From a9b99cedfab23d03bd9e10fbd135ae3cba38c676 Mon Sep 17 00:00:00 2001 From: SergiySW Date: Thu, 8 Mar 2018 21:15:07 +0300 Subject: [PATCH] Broadcasting active elections blocks to discovered representatives (#711) * Broadcasting active elections blocks * Improve formatting for clang --- rai/node/node.cpp | 23 ++++++++++++++++++++++- rai/node/node.hpp | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/rai/node/node.cpp b/rai/node/node.cpp index edf9c1fc..600d3fce 100644 --- a/rai/node/node.cpp +++ b/rai/node/node.cpp @@ -254,7 +254,7 @@ void rai::network::broadcast_confirm_req (std::shared_ptr block_a) } if (node.config.logging.network_logging ()) { - BOOST_LOG (node.log) << boost::str (boost::format ("Broadcasted confirm req to %1% representatives") % list.size ()); + BOOST_LOG (node.log) << boost::str (boost::format ("Broadcasted confirm req for block %1% to %2% representatives") % block_a->hash ().to_string () % list.size ()); } } @@ -1548,6 +1548,15 @@ block_processor_thread ([this]() { this->block_processor.process_blocks (); }) if (peers.rep_response (endpoint_a, weight_l)) { BOOST_LOG (log) << boost::str (boost::format ("Found a representative at %1%") % endpoint_a); + // Rebroadcasting all active votes to new representative + auto blocks (active.list_blocks ()); + for (auto i (blocks.begin ()), n (blocks.end ()); i != n; ++i) + { + if (*i != nullptr) + { + this->network.send_confirm_req (endpoint_a, *i); + } + } } } }); @@ -2964,6 +2973,18 @@ bool rai::active_transactions::active (rai::block const & block_a) return roots.find (block_a.root ()) != roots.end (); } +// List of active blocks in elections +std::deque> rai::active_transactions::list_blocks () +{ + std::deque> result; + std::lock_guard lock (mutex); + for (auto i (roots.begin ()), n (roots.end ()); i != n; ++i) + { + result.push_back (i->election->last_winner); + } + return result; +} + rai::active_transactions::active_transactions (rai::node & node_a) : node (node_a) { diff --git a/rai/node/node.hpp b/rai/node/node.hpp index f5411f84..4b6792f6 100644 --- a/rai/node/node.hpp +++ b/rai/node/node.hpp @@ -83,6 +83,7 @@ public: // Is the root of this block in the roots container bool active (rai::block const &); void announce_votes (); + std::deque> list_blocks (); void stop (); boost::multi_index_container< rai::conflict_info,