Limit nested bootstrap runs (#1568)

* Limit nested bootstrap runs

* Correct order

* Increase runs_count with wallet_run ()

* Update bootstrap.cpp
This commit is contained in:
Sergey Kroshnin 2019-01-28 20:29:21 +03:00 committed by GitHub
commit 4e4b597644
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View file

@ -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)
@ -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)
{
@ -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;
@ -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)
{
@ -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 ();
@ -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 ())
{

View file

@ -116,6 +116,7 @@ public:
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;

View file

@ -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)
{