Skip to content

Commit

Permalink
Limit nested bootstrap runs (#1568)
Browse files Browse the repository at this point in the history
* Limit nested bootstrap runs

* Correct order

* Increase runs_count with wallet_run ()

* Update bootstrap.cpp
  • Loading branch information
SergiySW authored Jan 28, 2019
1 parent 598e8a3 commit 4e4b597
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
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 @@ -1392,6 +1392,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

0 comments on commit 4e4b597

Please sign in to comment.