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

Limit nested bootstrap runs #1568

Merged
merged 8 commits into from
Jan 28, 2019
Merged
8 changes: 6 additions & 2 deletions nano/node/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ pulling (0),
node (node_a),
account_count (0),
total_blocks (0),
runs_count (0),
stopped (false),
mode (nano::bootstrap_mode::legacy),
lazy_stopped (0)
Expand Down Expand Up @@ -1073,6 +1074,7 @@ void nano::bootstrap_attempt::run ()
{
BOOST_LOG (node->log) << "Completed pulls";
request_push (lock);
runs_count++;
// Start wallet lazy bootstrap if required
if (!wallet_accounts.empty () && !node->flags.disable_wallet_bootstrap)
{
Expand All @@ -1082,7 +1084,7 @@ void nano::bootstrap_attempt::run ()
lock.lock ();
}
// Start lazy bootstrap if some lazy keys were inserted
else if (!lazy_finished () && !node->flags.disable_lazy_bootstrap)
else if (runs_count < 3 && !lazy_finished () && !node->flags.disable_lazy_bootstrap)
{
lock.unlock ();
mode = nano::bootstrap_mode::lazy;
Expand Down Expand Up @@ -1470,6 +1472,7 @@ void nano::bootstrap_attempt::lazy_run ()
{
BOOST_LOG (node->log) << "Completed lazy pulls";
std::unique_lock<std::mutex> lazy_lock (lazy_mutex);
runs_count++;
// Start wallet lazy bootstrap if required
if (!wallet_accounts.empty () && !node->flags.disable_wallet_bootstrap)
{
Expand All @@ -1482,7 +1485,7 @@ void nano::bootstrap_attempt::lazy_run ()
lock.lock ();
}
// Fallback to legacy bootstrap
else if (!lazy_keys.empty () && !node->flags.disable_legacy_bootstrap)
else if (runs_count < 3 && !lazy_keys.empty () && !node->flags.disable_legacy_bootstrap)
{
pulls.clear ();
lazy_clear ();
Expand Down Expand Up @@ -1714,6 +1717,7 @@ void nano::bootstrap_attempt::wallet_run ()
if (!stopped)
{
BOOST_LOG (node->log) << "Completed wallet lazy pulls";
runs_count++;
// Start lazy bootstrap if some lazy keys were inserted
if (!lazy_finished ())
{
Expand Down
1 change: 1 addition & 0 deletions nano/node/bootstrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class bootstrap_attempt : public std::enable_shared_from_this<bootstrap_attempt>
std::shared_ptr<nano::node> node;
std::atomic<unsigned> account_count;
std::atomic<uint64_t> total_blocks;
std::atomic<unsigned> runs_count;
std::vector<std::pair<nano::block_hash, nano::block_hash>> bulk_push_targets;
bool stopped;
nano::bootstrap_mode mode;
Expand Down
1 change: 1 addition & 0 deletions nano/node/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,7 @@ void nano::rpc_handler::bootstrap_status ()
response_l.put ("idle", std::to_string (attempt->idle.size ()));
response_l.put ("target_connections", std::to_string (attempt->target_connections (attempt->pulls.size ())));
response_l.put ("total_blocks", std::to_string (attempt->total_blocks));
response_l.put ("runs_count", std::to_string (attempt->runs_count));
std::string mode_text;
if (attempt->mode == nano::bootstrap_mode::legacy)
{
Expand Down