Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use confirm_req by hash + root for upgraded peers #2164

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 21 additions & 37 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,26 @@ void nano::active_transactions::request_confirm (std::unique_lock<std::mutex> &

rep_channels->insert (rep_channels->end (), channels.begin (), channels.end ());

if ((!rep_channels->empty () && node.rep_crawler.total_weight () > node.config.online_weight_minimum.number ()) || roots_size > 5)
bool low_reps_weight (rep_channels->empty () || node.rep_crawler.total_weight () < node.config.online_weight_minimum.number ());
if (low_reps_weight && roots_size <= 5 && !node.network_params.network.is_test_network ())
{
// broadcast_confirm_req_base modifies reps, so we clone it once to avoid aliasing
if (node.network_params.network.is_live_network ())
// Spam mode
auto deque_l (node.network.udp_channels.random_set (100));
auto vec (std::make_shared<std::vector<std::shared_ptr<nano::transport::channel>>> ());
for (auto i : deque_l)
{
if (confirm_req_bundle.size () < max_broadcast_queue)
{
confirm_req_bundle.push_back (std::make_pair (election_l->status.winner, rep_channels));
}
vec->push_back (i);
}
else
confirm_req_bundle.push_back (std::make_pair (election_l->status.winner, vec));
}
else
{
auto single_confirm_req_channels (std::make_shared<std::vector<std::shared_ptr<nano::transport::channel>>> ());
for (auto & rep : *rep_channels)
{
for (auto & rep : *rep_channels)
if (rep->get_network_version () >= nano::tcp_realtime_protocol_version_min)
{
// Send batch request to peers supporting confirm_req by hash + root
auto rep_request (requests_bundle.find (rep));
auto block (election_l->status.winner);
auto root_hash (std::make_pair (block->hash (), block->root ()));
Expand All @@ -247,37 +253,15 @@ void nano::active_transactions::request_confirm (std::unique_lock<std::mutex> &
rep_request->second.push_back (root_hash);
}
}
}
}
else
{
if (node.network_params.network.is_live_network ())
{
auto deque_l (node.network.udp_channels.random_set (100));
auto vec (std::make_shared<std::vector<std::shared_ptr<nano::transport::channel>>> ());
for (auto i : deque_l)
else
{
vec->push_back (i);
single_confirm_req_channels->push_back (rep);
}
confirm_req_bundle.push_back (std::make_pair (election_l->status.winner, vec));
}
else
// broadcast_confirm_req_base modifies reps, so we clone it once to avoid aliasing
if (confirm_req_bundle.size () < max_broadcast_queue && !single_confirm_req_channels->empty ())
{
for (auto & rep : *rep_channels)
{
auto rep_request (requests_bundle.find (rep));
auto block (election_l->status.winner);
auto root_hash (std::make_pair (block->hash (), block->root ()));
if (rep_request == requests_bundle.end ())
{
std::vector<std::pair<nano::block_hash, nano::block_hash>> insert_vector = { root_hash };
requests_bundle.insert (std::make_pair (rep, insert_vector));
}
else
{
rep_request->second.push_back (root_hash);
}
}
confirm_req_bundle.push_back (std::make_pair (election_l->status.winner, single_confirm_req_channels));
}
}
}
Expand All @@ -290,7 +274,7 @@ void nano::active_transactions::request_confirm (std::unique_lock<std::mutex> &
node.network.flood_block_batch (std::move (rebroadcast_bundle));
}
// Batch confirmation request
if (!node.network_params.network.is_live_network () && !requests_bundle.empty ())
if (!requests_bundle.empty ())
{
node.network.broadcast_confirm_req_batch (requests_bundle, 50);
}
Expand Down
29 changes: 17 additions & 12 deletions nano/node/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,22 @@ void nano::network::flood_block_batch (std::deque<std::shared_ptr<nano::block>>
}
}

void nano::network::send_confirm_req (std::shared_ptr<nano::transport::channel> channel_a, std::shared_ptr<nano::block> block_a)
{
// Confirmation request with hash + root
if (channel_a->get_network_version () >= nano::tcp_realtime_protocol_version_min)
{
nano::confirm_req req (block_a->hash (), block_a->root ());
channel_a->send (req);
}
// Confirmation request with full block
else
{
nano::confirm_req req (block_a);
channel_a->send (req);
}
}

void nano::network::broadcast_confirm_req (std::shared_ptr<nano::block> block_a)
{
auto list (std::make_shared<std::vector<std::shared_ptr<nano::transport::channel>>> (node.rep_crawler.representative_endpoints (std::numeric_limits<size_t>::max ())));
Expand Down Expand Up @@ -285,18 +301,7 @@ void nano::network::broadcast_confirm_req_base (std::shared_ptr<nano::block> blo
while (!endpoints_a->empty () && count < max_reps)
{
auto channel (endpoints_a->back ());
// Confirmation request with full block
if (node.network_params.network.is_live_network ())
{
nano::confirm_req req (block_a);
channel->send (req);
}
// Confirmation request with hash + root
else
{
nano::confirm_req req (block_a->hash (), block_a->root ());
channel->send (req);
}
send_confirm_req (channel, block_a);
endpoints_a->pop_back ();
count++;
}
Expand Down
1 change: 1 addition & 0 deletions nano/node/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class network final
void send_keepalive (std::shared_ptr<nano::transport::channel>);
void send_keepalive_self (std::shared_ptr<nano::transport::channel>);
void send_node_id_handshake (std::shared_ptr<nano::transport::channel>, boost::optional<nano::uint256_union> const & query, boost::optional<nano::uint256_union> const & respond_to);
void send_confirm_req (std::shared_ptr<nano::transport::channel>, std::shared_ptr<nano::block>);
void broadcast_confirm_req (std::shared_ptr<nano::block>);
void broadcast_confirm_req_base (std::shared_ptr<nano::block>, std::shared_ptr<std::vector<std::shared_ptr<nano::transport::channel>>>, unsigned, bool = false);
void broadcast_confirm_req_batch (std::unordered_map<std::shared_ptr<nano::transport::channel>, std::vector<std::pair<nano::block_hash, nano::block_hash>>>, unsigned = broadcast_interval_ms, bool = false);
Expand Down
3 changes: 1 addition & 2 deletions nano/node/repcrawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ void nano::rep_crawler::query (std::vector<std::shared_ptr<nano::transport::chan
for (auto i (channels_a.begin ()), n (channels_a.end ()); i != n; ++i)
{
on_rep_request (*i);
nano::confirm_req message (block);
(*i)->send (message);
node.network.send_confirm_req (*i, block);
}

// A representative must respond with a vote within the deadline
Expand Down