From 2e90b992be237f8bb2441a290288c94fb814f2aa Mon Sep 17 00:00:00 2001 From: clemahieu Date: Tue, 8 May 2018 03:10:05 +0100 Subject: [PATCH] Renaming list_sqrt to list_fanout so the naming isn't tied to one form of rebroadcast fanout sizing. Changing data structure to a deque since we don't need the entries to be contiguous. --- rai/core_test/peer_container.cpp | 6 +++--- rai/node/node.cpp | 14 ++++++-------- rai/node/node.hpp | 6 +++--- rai/slow_test/node.cpp | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/rai/core_test/peer_container.cpp b/rai/core_test/peer_container.cpp index a0e24185..31df634b 100644 --- a/rai/core_test/peer_container.cpp +++ b/rai/core_test/peer_container.cpp @@ -108,16 +108,16 @@ TEST (peer_container, fill_random_part) ASSERT_TRUE (std::all_of (target.begin () + half, target.end (), [](rai::endpoint const & endpoint_a) { return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::any (), 0); })); } -TEST (peer_container, list_sqrt) +TEST (peer_container, list_fanout) { rai::peer_container peers (rai::endpoint{}); - auto list1 (peers.list_sqrt ()); + auto list1 (peers.list_fanout ()); ASSERT_TRUE (list1.empty ()); for (auto i (0); i < 1000; ++i) { ASSERT_FALSE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000 + i), rai::protocol_version)); } - auto list2 (peers.list_sqrt ()); + auto list2 (peers.list_fanout ()); ASSERT_EQ (64, list2.size ()); } diff --git a/rai/node/node.cpp b/rai/node/node.cpp index 206d641b..9940d951 100644 --- a/rai/node/node.cpp +++ b/rai/node/node.cpp @@ -172,7 +172,7 @@ bool confirm_block (MDB_txn * transaction_a, rai::node & node_a, rai::endpoint & void rai::network::republish_block (MDB_txn * transaction, std::shared_ptr block) { auto hash (block->hash ()); - auto list (node.peers.list_sqrt ()); + auto list (node.peers.list_fanout ()); // If we're a representative, broadcast a signed confirm, otherwise an unsigned publish if (!confirm_block (transaction, node, list, block)) { @@ -216,7 +216,7 @@ void rai::network::republish_vote (std::shared_ptr vote_a) rai::vectorstream stream (*bytes); confirm.serialize (stream); } - auto list (node.peers.list_sqrt ()); + auto list (node.peers.list_fanout ()); for (auto j (list.begin ()), m (list.end ()); j != m; ++j) { node.network.confirm_send (confirm, bytes, *j); @@ -1828,11 +1828,10 @@ rai::process_return rai::node::process (rai::block const & block_a) } // Simulating with sqrt_broadcast_simulate shows we only need to broadcast to sqrt(total_peers) random peers in order to successfully publish to everyone with high probability -std::vector rai::peer_container::list_sqrt () +std::deque rai::peer_container::list_fanout () { auto peers (random_set (2 * size_sqrt ())); - std::vector result; - result.reserve (peers.size ()); + std::deque result; for (auto i (peers.begin ()), n (peers.end ()); i != n; ++i) { result.push_back (*i); @@ -1840,11 +1839,10 @@ std::vector rai::peer_container::list_sqrt () return result; } -std::vector rai::peer_container::list () +std::deque rai::peer_container::list () { - std::vector result; + std::deque result; std::lock_guard lock (mutex); - result.reserve (peers.size ()); for (auto i (peers.begin ()), j (peers.end ()); i != j; ++i) { result.push_back (i->endpoint); diff --git a/rai/node/node.hpp b/rai/node/node.hpp index 9e964e5a..a4af75f4 100644 --- a/rai/node/node.hpp +++ b/rai/node/node.hpp @@ -195,10 +195,10 @@ public: // Request a list of the top known representatives std::vector representatives (size_t); // List of all peers - std::vector list (); + std::deque list (); std::map list_version (); - // A list of random peers with size the square root of total peer count - std::vector list_sqrt (); + // A list of random peers sized for the configured rebroadcast fanout + std::deque list_fanout (); // Get the next peer for attempting bootstrap rai::endpoint bootstrap_peer (); // Purge any peer where last_contact < time_point and return what was left diff --git a/rai/slow_test/node.cpp b/rai/slow_test/node.cpp index 9f9db798..55b78aa4 100644 --- a/rai/slow_test/node.cpp +++ b/rai/slow_test/node.cpp @@ -392,7 +392,7 @@ TEST (peer_container, random_set) auto old (std::chrono::steady_clock::now ()); for (auto i (0); i < 10000; ++i) { - auto list (container.list_sqrt ()); + auto list (container.list_fanout ()); } auto current (std::chrono::steady_clock::now ()); for (auto i (0); i < 10000; ++i)