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.
This commit is contained in:
parent
7a243623bb
commit
2e90b992be
4 changed files with 13 additions and 15 deletions
|
@ -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 ());
|
||||
}
|
||||
|
||||
|
|
|
@ -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<rai::block> 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<rai::vote> 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::endpoint> rai::peer_container::list_sqrt ()
|
||||
std::deque<rai::endpoint> rai::peer_container::list_fanout ()
|
||||
{
|
||||
auto peers (random_set (2 * size_sqrt ()));
|
||||
std::vector<rai::endpoint> result;
|
||||
result.reserve (peers.size ());
|
||||
std::deque<rai::endpoint> result;
|
||||
for (auto i (peers.begin ()), n (peers.end ()); i != n; ++i)
|
||||
{
|
||||
result.push_back (*i);
|
||||
|
@ -1840,11 +1839,10 @@ std::vector<rai::endpoint> rai::peer_container::list_sqrt ()
|
|||
return result;
|
||||
}
|
||||
|
||||
std::vector<rai::endpoint> rai::peer_container::list ()
|
||||
std::deque<rai::endpoint> rai::peer_container::list ()
|
||||
{
|
||||
std::vector<rai::endpoint> result;
|
||||
std::deque<rai::endpoint> result;
|
||||
std::lock_guard<std::mutex> lock (mutex);
|
||||
result.reserve (peers.size ());
|
||||
for (auto i (peers.begin ()), j (peers.end ()); i != j; ++i)
|
||||
{
|
||||
result.push_back (i->endpoint);
|
||||
|
|
|
@ -195,10 +195,10 @@ public:
|
|||
// Request a list of the top known representatives
|
||||
std::vector<peer_information> representatives (size_t);
|
||||
// List of all peers
|
||||
std::vector<rai::endpoint> list ();
|
||||
std::deque<rai::endpoint> list ();
|
||||
std::map<rai::endpoint, unsigned> list_version ();
|
||||
// A list of random peers with size the square root of total peer count
|
||||
std::vector<rai::endpoint> list_sqrt ();
|
||||
// A list of random peers sized for the configured rebroadcast fanout
|
||||
std::deque<rai::endpoint> 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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue