From 3a3c56a5d2cfdcac132e58c6a4915b144a22881b Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Wed, 6 Nov 2019 23:02:24 +0300 Subject: [PATCH] Prevent lazy destinations usage if legacy bootstrap is enabled --- nano/node/bootstrap/bootstrap.cpp | 24 ++++++++++++--------- nano/node/bootstrap/bootstrap_bulk_pull.cpp | 3 ++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index be333fe5f..bf7484f7b 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -1184,17 +1184,21 @@ void nano::bootstrap_attempt::lazy_backlog_cleanup () void nano::bootstrap_attempt::lazy_destinations_increment (nano::account const & destination_a) { - // Update accounts counter for send blocks - auto existing (lazy_destinations.get ().find (destination_a)); - if (existing != lazy_destinations.get ().end ()) + // Enabled only if legacy bootstrap is not available. Legacy bootstrap is a more effective way to receive all existing destinations + if (node->flags.disable_legacy_bootstrap) { - lazy_destinations.get ().modify (existing, [](nano::lazy_destinations_item & item_a) { - ++item_a.count; - }); - } - else - { - lazy_destinations.insert (nano::lazy_destinations_item{ destination_a, 1 }); + // Update accounts counter for send blocks + auto existing (lazy_destinations.get ().find (destination_a)); + if (existing != lazy_destinations.get ().end ()) + { + lazy_destinations.get ().modify (existing, [](nano::lazy_destinations_item & item_a) { + ++item_a.count; + }); + } + else + { + lazy_destinations.insert (nano::lazy_destinations_item{ destination_a, 1 }); + } } } diff --git a/nano/node/bootstrap/bootstrap_bulk_pull.cpp b/nano/node/bootstrap/bootstrap_bulk_pull.cpp index 440b65443..c88a28a61 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.cpp @@ -223,7 +223,8 @@ void nano::bulk_pull_client::received_block (boost::system::error_code const & e } // Is block expected? bool block_expected (false); - bool unconfirmed_account_head (pull_blocks == 0 && pull.retry_limit != std::numeric_limits::max () && expected == pull.account_or_head && block->account () == pull.account_or_head); + // Unconfirmed head is used only for lazy destinations if legacy bootstrap is not available, see nano::bootstrap_attempt::lazy_destinations_increment (...) + bool unconfirmed_account_head (connection->node->flags.disable_legacy_bootstrap && pull_blocks == 0 && pull.retry_limit != std::numeric_limits::max () && expected == pull.account_or_head && block->account () == pull.account_or_head); if (hash == expected || unconfirmed_account_head) { expected = block->previous ();