Optimize vote distribution between PRs and non-PRs (#4766)
* Publish votes to all PRs and a subset of non PRs This avoids potential duplicate votes to PRs and better confirmation times for non PRs * small optimisation for list_non_pr --------- Co-authored-by: gr0vity-dev <homebot@users.noreply.github.com>
This commit is contained in:
parent
9efd84972e
commit
e1a4fcbec5
3 changed files with 17 additions and 5 deletions
|
|
@ -281,6 +281,15 @@ void nano::network::flood_vote (std::shared_ptr<nano::vote> const & vote, float
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nano::network::flood_vote_non_pr (std::shared_ptr<nano::vote> const & vote, float scale, bool rebroadcasted)
|
||||||
|
{
|
||||||
|
nano::confirm_ack message{ node.network_params.network, vote, rebroadcasted };
|
||||||
|
for (auto & i : list_non_pr (fanout (scale)))
|
||||||
|
{
|
||||||
|
i->send (message, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void nano::network::flood_vote_pr (std::shared_ptr<nano::vote> const & vote, bool rebroadcasted)
|
void nano::network::flood_vote_pr (std::shared_ptr<nano::vote> const & vote, bool rebroadcasted)
|
||||||
{
|
{
|
||||||
nano::confirm_ack message{ node.network_params.network, vote, rebroadcasted };
|
nano::confirm_ack message{ node.network_params.network, vote, rebroadcasted };
|
||||||
|
|
@ -377,11 +386,13 @@ std::deque<std::shared_ptr<nano::transport::channel>> nano::network::list_non_pr
|
||||||
{
|
{
|
||||||
std::deque<std::shared_ptr<nano::transport::channel>> result;
|
std::deque<std::shared_ptr<nano::transport::channel>> result;
|
||||||
tcp_channels.list (result);
|
tcp_channels.list (result);
|
||||||
|
|
||||||
|
auto partition_point = std::partition (result.begin (), result.end (),
|
||||||
|
[this] (std::shared_ptr<nano::transport::channel> const & channel) {
|
||||||
|
return !node.rep_crawler.is_pr (channel);
|
||||||
|
});
|
||||||
|
result.resize (std::distance (result.begin (), partition_point));
|
||||||
nano::random_pool_shuffle (result.begin (), result.end ());
|
nano::random_pool_shuffle (result.begin (), result.end ());
|
||||||
result.erase (std::remove_if (result.begin (), result.end (), [this] (std::shared_ptr<nano::transport::channel> const & channel) {
|
|
||||||
return node.rep_crawler.is_pr (channel);
|
|
||||||
}),
|
|
||||||
result.end ());
|
|
||||||
if (result.size () > count_a)
|
if (result.size () > count_a)
|
||||||
{
|
{
|
||||||
result.resize (count_a, nullptr);
|
result.resize (count_a, nullptr);
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,7 @@ public:
|
||||||
void flood_keepalive_self (float const scale_a = 0.5f);
|
void flood_keepalive_self (float const scale_a = 0.5f);
|
||||||
void flood_vote (std::shared_ptr<nano::vote> const &, float scale, bool rebroadcasted = false);
|
void flood_vote (std::shared_ptr<nano::vote> const &, float scale, bool rebroadcasted = false);
|
||||||
void flood_vote_pr (std::shared_ptr<nano::vote> const &, bool rebroadcasted = false);
|
void flood_vote_pr (std::shared_ptr<nano::vote> const &, bool rebroadcasted = false);
|
||||||
|
void flood_vote_non_pr (std::shared_ptr<nano::vote> const &, float scale, bool rebroadcasted = false);
|
||||||
// Flood block to all PRs and a random selection of non-PRs
|
// Flood block to all PRs and a random selection of non-PRs
|
||||||
void flood_block_initial (std::shared_ptr<nano::block> const &);
|
void flood_block_initial (std::shared_ptr<nano::block> const &);
|
||||||
// Flood block to a random selection of peers
|
// Flood block to a random selection of peers
|
||||||
|
|
|
||||||
|
|
@ -277,7 +277,7 @@ void nano::vote_generator::vote (std::vector<nano::block_hash> const & hashes_a,
|
||||||
void nano::vote_generator::broadcast_action (std::shared_ptr<nano::vote> const & vote_a) const
|
void nano::vote_generator::broadcast_action (std::shared_ptr<nano::vote> const & vote_a) const
|
||||||
{
|
{
|
||||||
network.flood_vote_pr (vote_a);
|
network.flood_vote_pr (vote_a);
|
||||||
network.flood_vote (vote_a, 2.0f);
|
network.flood_vote_non_pr (vote_a, 2.0f);
|
||||||
vote_processor.vote (vote_a, inproc_channel);
|
vote_processor.vote (vote_a, inproc_channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue