From 55740220607ab4ef4c189f520855c393d133d070 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Fri, 18 Oct 2019 03:56:25 +0300 Subject: [PATCH 01/22] Reduce retry limit for lazy destinations Also process all lazy destinations instead of only top destinations --- nano/node/bootstrap/bootstrap.cpp | 73 ++++++++++----------- nano/node/bootstrap/bootstrap.hpp | 16 ++--- nano/node/bootstrap/bootstrap_bulk_pull.cpp | 10 +-- nano/node/bootstrap/bootstrap_bulk_pull.hpp | 4 +- nano/node/bootstrap/bootstrap_frontier.cpp | 6 +- nano/secure/common.cpp | 3 + nano/secure/common.hpp | 3 + 7 files changed, 58 insertions(+), 57 deletions(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 970425f96f..6932fa8bbf 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -13,13 +13,10 @@ constexpr double nano::bootstrap_limits::bootstrap_connection_scale_target_blocks; constexpr double nano::bootstrap_limits::bootstrap_minimum_blocks_per_sec; -constexpr unsigned nano::bootstrap_limits::bootstrap_frontier_retry_limit; -constexpr unsigned nano::bootstrap_limits::bootstrap_lazy_retry_limit; constexpr double nano::bootstrap_limits::bootstrap_minimum_termination_time_sec; constexpr unsigned nano::bootstrap_limits::bootstrap_max_new_connections; constexpr std::chrono::seconds nano::bootstrap_limits::lazy_flush_delay_sec; constexpr unsigned nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit; -constexpr std::chrono::seconds nano::bootstrap_limits::lazy_destinations_flush_delay_sec; nano::bootstrap_client::bootstrap_client (std::shared_ptr node_a, std::shared_ptr attempt_a, std::shared_ptr channel_a) : node (node_a), @@ -532,13 +529,13 @@ void nano::bootstrap_attempt::requeue_pull (nano::pull_info const & pull_a) { auto pull (pull_a); ++pull.attempts; - if (pull.attempts < (!node->network_params.network.is_test_network () ? nano::bootstrap_limits::bootstrap_frontier_retry_limit : (nano::bootstrap_limits::bootstrap_frontier_retry_limit / 8) + (pull.processed / 10000))) + if (pull.attempts < pull.retry_limit + (pull.processed / 10000)) { nano::lock_guard lock (mutex); pulls.push_front (pull); condition.notify_all (); } - else if (mode == nano::bootstrap_mode::lazy && (pull.confirmed_head || pull.attempts <= (!node->network_params.network.is_test_network () ? nano::bootstrap_limits::bootstrap_lazy_retry_limit : (nano::bootstrap_limits::bootstrap_frontier_retry_limit / 8) + (pull.processed / node->network_params.bootstrap.lazy_max_pull_blocks)))) + else if (mode == nano::bootstrap_mode::lazy && (pull.retry_limit == std::numeric_limits::max () || pull.attempts <= pull.retry_limit + (pull.processed / node->network_params.bootstrap.lazy_max_pull_blocks))) { assert (pull.account_or_head == pull.head); if (!lazy_processed_or_exists (pull.account_or_head)) @@ -562,7 +559,7 @@ void nano::bootstrap_attempt::requeue_pull (nano::pull_info const & pull_a) { assert (pull.account_or_head == pull.head); nano::lock_guard lazy_lock (lazy_mutex); - lazy_add (pull.account_or_head, pull.confirmed_head); + lazy_add (pull.account_or_head, pull.retry_limit); } } } @@ -581,17 +578,17 @@ void nano::bootstrap_attempt::lazy_start (nano::hash_or_account const & hash_or_ if (lazy_keys.size () < max_keys && lazy_keys.find (hash_or_account_a) == lazy_keys.end () && lazy_blocks.find (hash_or_account_a) == lazy_blocks.end ()) { lazy_keys.insert (hash_or_account_a); - lazy_pulls.emplace_back (hash_or_account_a, confirmed); + lazy_pulls.emplace_back (hash_or_account_a, confirmed ? std::numeric_limits::max () : node->network_params.bootstrap.bootstrap_lazy_retry_limit); } } -void nano::bootstrap_attempt::lazy_add (nano::hash_or_account const & hash_or_account_a, bool confirmed_head) +void nano::bootstrap_attempt::lazy_add (nano::hash_or_account const & hash_or_account_a, unsigned retry_limit) { // Add only unknown blocks assert (!lazy_mutex.try_lock ()); if (lazy_blocks.find (hash_or_account_a) == lazy_blocks.end ()) { - lazy_pulls.emplace_back (hash_or_account_a, confirmed_head); + lazy_pulls.emplace_back (hash_or_account_a, retry_limit); } } @@ -604,7 +601,7 @@ void nano::bootstrap_attempt::lazy_requeue (nano::block_hash const & hash_a, nan { lazy_blocks.erase (existing); lazy_mutex.unlock (); - requeue_pull (nano::pull_info (hash_a, hash_a, previous_a, static_cast (1), confirmed_a)); + requeue_pull (nano::pull_info (hash_a, hash_a, previous_a, static_cast (1), confirmed_a ? std::numeric_limits::max () : node->network_params.bootstrap.bootstrap_lazy_destinations_retry_limit)); } } @@ -628,6 +625,10 @@ void nano::bootstrap_attempt::lazy_pull_flush () bool nano::bootstrap_attempt::lazy_finished () { + if (stopped) + { + return true; + } bool result (true); auto transaction (node->store.tx_begin_read ()); nano::lock_guard lazy_lock (lazy_mutex); @@ -649,6 +650,11 @@ bool nano::bootstrap_attempt::lazy_finished () { result = true; } + // Don't close lazy bootstrap until all destinations are processed + if (result && !lazy_destinations.empty ()) + { + result = false; + } return result; } @@ -694,7 +700,7 @@ void nano::bootstrap_attempt::lazy_run () lazy_pull_flush (); } // Start destinations check & backlog cleanup - if (iterations % 200 == 0 && pulls.empty ()) + if (iterations % nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit == 0 && pulls.size () < nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit * 10) { lazy_backlog_cleanup (); lazy_destinations_flush (); @@ -742,12 +748,12 @@ void nano::bootstrap_attempt::lazy_run () idle.clear (); } -bool nano::bootstrap_attempt::process_block (std::shared_ptr block_a, nano::account const & known_account_a, uint64_t pull_blocks, bool block_expected, bool confirmed_head) +bool nano::bootstrap_attempt::process_block (std::shared_ptr block_a, nano::account const & known_account_a, uint64_t pull_blocks, bool block_expected, unsigned retry_limit) { bool stop_pull (false); if (mode != nano::bootstrap_mode::legacy && block_expected) { - stop_pull = process_block_lazy (block_a, known_account_a, pull_blocks, confirmed_head); + stop_pull = process_block_lazy (block_a, known_account_a, pull_blocks, retry_limit); } else if (mode != nano::bootstrap_mode::legacy) { @@ -762,7 +768,7 @@ bool nano::bootstrap_attempt::process_block (std::shared_ptr block_ return stop_pull; } -bool nano::bootstrap_attempt::process_block_lazy (std::shared_ptr block_a, nano::account const & known_account_a, uint64_t pull_blocks, bool confirmed_head) +bool nano::bootstrap_attempt::process_block_lazy (std::shared_ptr block_a, nano::account const & known_account_a, uint64_t pull_blocks, unsigned retry_limit) { bool stop_pull (false); auto hash (block_a->hash ()); @@ -770,16 +776,16 @@ bool nano::bootstrap_attempt::process_block_lazy (std::shared_ptr b // Processing new blocks if (lazy_blocks.find (hash) == lazy_blocks.end ()) { - nano::unchecked_info info (block_a, known_account_a, 0, nano::signature_verification::unknown, confirmed_head); + nano::unchecked_info info (block_a, known_account_a, 0, nano::signature_verification::unknown, retry_limit == std::numeric_limits::max ()); node->block_processor.add (info); // Search for new dependencies if (!block_a->source ().is_zero () && !node->ledger.block_exists (block_a->source ()) && block_a->source () != node->network_params.ledger.genesis_account) { - lazy_add (block_a->source (), confirmed_head); + lazy_add (block_a->source (), retry_limit); } else if (block_a->type () == nano::block_type::state) { - lazy_block_state (block_a, confirmed_head); + lazy_block_state (block_a, retry_limit); } else if (block_a->type () == nano::block_type::send) { @@ -810,7 +816,7 @@ bool nano::bootstrap_attempt::process_block_lazy (std::shared_ptr b return stop_pull; } -void nano::bootstrap_attempt::lazy_block_state (std::shared_ptr block_a, bool confirmed_head) +void nano::bootstrap_attempt::lazy_block_state (std::shared_ptr block_a, unsigned retry_limit) { std::shared_ptr block_l (std::static_pointer_cast (block_a)); if (block_l != nullptr) @@ -825,14 +831,14 @@ void nano::bootstrap_attempt::lazy_block_state (std::shared_ptr blo // If state block previous is 0 then source block required if (previous.is_zero ()) { - lazy_add (link, confirmed_head); + lazy_add (link, retry_limit); } // In other cases previous block balance required to find out subtype of state block else if (node->store.block_exists (transaction, previous)) { if (node->ledger.balance (transaction, previous) <= balance) { - lazy_add (link, confirmed_head); + lazy_add (link, retry_limit); } else { @@ -847,7 +853,7 @@ void nano::bootstrap_attempt::lazy_block_state (std::shared_ptr blo { if (previous_balance->second <= balance) { - lazy_add (link, confirmed_head); + lazy_add (link, retry_limit); } else { @@ -859,7 +865,7 @@ void nano::bootstrap_attempt::lazy_block_state (std::shared_ptr blo // Insert in backlog state blocks if previous wasn't already processed else { - lazy_state_backlog.emplace (previous, nano::lazy_state_backlog_item{ link, balance, confirmed_head }); + lazy_state_backlog.emplace (previous, nano::lazy_state_backlog_item{ link, balance, retry_limit }); } } } @@ -877,7 +883,7 @@ void nano::bootstrap_attempt::lazy_block_state_backlog_check (std::shared_ptrbalance ().number () <= next_block.balance) // balance { - lazy_add (next_block.link, next_block.confirmed); // link + lazy_add (next_block.link, next_block.retry_limit); // link } else { @@ -887,7 +893,7 @@ void nano::bootstrap_attempt::lazy_block_state_backlog_check (std::shared_ptrnetwork_params.bootstrap.bootstrap_lazy_retry_limit); // Head is not confirmed. It can be account or hash or non-existing lazy_undefined_links.insert (next_block.link); } lazy_state_backlog.erase (find_state); @@ -905,7 +911,7 @@ void nano::bootstrap_attempt::lazy_backlog_cleanup () auto next_block (it->second); if (node->ledger.balance (transaction, it->first) <= next_block.balance) // balance { - lazy_add (next_block.link, next_block.confirmed); // link + lazy_add (next_block.link, next_block.retry_limit); // link } else { @@ -915,7 +921,7 @@ void nano::bootstrap_attempt::lazy_backlog_cleanup () } else { - lazy_add (it->first, it->second.confirmed); + lazy_add (it->first, it->second.retry_limit); ++it; } } @@ -941,18 +947,11 @@ void nano::bootstrap_attempt::lazy_destinations_flush () { size_t count (0); nano::lock_guard lazy_lock (lazy_mutex); - if (last_lazy_destinations_flush + nano::bootstrap_limits::lazy_destinations_flush_delay_sec < std::chrono::steady_clock::now ()) + for (auto it (lazy_destinations.get ().begin ()), end (lazy_destinations.get ().end ()); it != end && count < nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit && !stopped;) { - for (auto it (lazy_destinations.get ().begin ()), end (lazy_destinations.get ().end ()); it != end && count < nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit && !stopped;) - { - lazy_add (it->account, false); - it = lazy_destinations.get ().erase (it); - ++count; - } - if (count > nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit / 4) - { - last_lazy_destinations_flush = std::chrono::steady_clock::now (); - } + lazy_add (it->account, node->network_params.bootstrap.bootstrap_lazy_destinations_retry_limit); + it = lazy_destinations.get ().erase (it); + ++count; } } diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index e6f4883535..3c3fa81156 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -48,7 +48,7 @@ class lazy_state_backlog_item final public: nano::link link{ 0 }; nano::uint128_t balance{ 0 }; - bool confirmed{ false }; + unsigned retry_limit{ 0 }; }; class lazy_destinations_item final { @@ -80,17 +80,17 @@ class bootstrap_attempt final : public std::enable_shared_from_this, nano::account const &, uint64_t, bool, bool); + bool process_block (std::shared_ptr, nano::account const &, uint64_t, bool, unsigned); /** Lazy bootstrap */ void lazy_run (); void lazy_start (nano::hash_or_account const &, bool confirmed = true); - void lazy_add (nano::hash_or_account const &, bool = true); + void lazy_add (nano::hash_or_account const &, unsigned = std::numeric_limits::max ()); void lazy_requeue (nano::block_hash const &, nano::block_hash const &, bool); bool lazy_finished (); void lazy_pull_flush (); void lazy_clear (); - bool process_block_lazy (std::shared_ptr, nano::account const &, uint64_t, bool); - void lazy_block_state (std::shared_ptr, bool); + bool process_block_lazy (std::shared_ptr, nano::account const &, uint64_t, unsigned); + void lazy_block_state (std::shared_ptr, unsigned); void lazy_block_state_backlog_check (std::shared_ptr, nano::block_hash const &); void lazy_backlog_cleanup (); void lazy_destinations_increment (nano::account const &); @@ -130,7 +130,7 @@ class bootstrap_attempt final : public std::enable_shared_from_this lazy_undefined_links; std::unordered_map lazy_balances; std::unordered_set lazy_keys; - std::deque> lazy_pulls; + std::deque> lazy_pulls; std::chrono::steady_clock::time_point last_lazy_flush{ std::chrono::steady_clock::now () }; class account_tag { @@ -144,7 +144,6 @@ class bootstrap_attempt final : public std::enable_shared_from_this, boost::multi_index::member, std::greater>, boost::multi_index::hashed_unique, boost::multi_index::member>>> lazy_destinations; - std::chrono::steady_clock::time_point last_lazy_destinations_flush{ std::chrono::steady_clock::time_point{} }; std::mutex lazy_mutex; // Wallet lazy bootstrap std::deque wallet_accounts; @@ -232,13 +231,10 @@ class bootstrap_limits final static constexpr double bootstrap_minimum_blocks_per_sec = 10.0; static constexpr double bootstrap_minimum_elapsed_seconds_blockrate = 0.02; static constexpr double bootstrap_minimum_frontier_blocks_per_sec = 1000.0; - static constexpr unsigned bootstrap_frontier_retry_limit = 16; - static constexpr unsigned bootstrap_lazy_retry_limit = bootstrap_frontier_retry_limit * 10; static constexpr double bootstrap_minimum_termination_time_sec = 30.0; static constexpr unsigned bootstrap_max_new_connections = 10; static constexpr unsigned bulk_push_cost_limit = 200; static constexpr std::chrono::seconds lazy_flush_delay_sec = std::chrono::seconds (5); static constexpr unsigned bootstrap_lazy_destinations_request_limit = 200; - static constexpr std::chrono::seconds lazy_destinations_flush_delay_sec = std::chrono::minutes (2); }; } diff --git a/nano/node/bootstrap/bootstrap_bulk_pull.cpp b/nano/node/bootstrap/bootstrap_bulk_pull.cpp index 632331678d..333193d38a 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.cpp @@ -3,13 +3,13 @@ #include #include -nano::pull_info::pull_info (nano::hash_or_account const & account_or_head_a, nano::block_hash const & head_a, nano::block_hash const & end_a, count_t count_a, bool confirmed_head_a) : +nano::pull_info::pull_info (nano::hash_or_account const & account_or_head_a, nano::block_hash const & head_a, nano::block_hash const & end_a, count_t count_a, unsigned retry_limit_a) : account_or_head (account_or_head_a), head (head_a), head_original (head_a), end (end_a), count (count_a), -confirmed_head (confirmed_head_a) +retry_limit (retry_limit_a) { } @@ -53,7 +53,7 @@ nano::bulk_pull_client::~bulk_pull_client () void nano::bulk_pull_client::request () { - assert (!pull.head.is_zero () || !pull.confirmed_head); + assert (!pull.head.is_zero () || pull.retry_limit != std::numeric_limits::max ()); expected = pull.head; nano::bulk_pull req; if (pull.head == pull.head_original) @@ -214,7 +214,7 @@ 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.confirmed_head && expected == pull.account_or_head && block->account () == pull.account_or_head); + 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); if (hash == expected || unconfirmed_account_head) { expected = block->previous (); @@ -233,7 +233,7 @@ void nano::bulk_pull_client::received_block (boost::system::error_code const & e connection->start_time = std::chrono::steady_clock::now (); } connection->attempt->total_blocks++; - bool stop_pull (connection->attempt->process_block (block, known_account, pull_blocks, block_expected, pull.confirmed_head)); + bool stop_pull (connection->attempt->process_block (block, known_account, pull_blocks, block_expected, pull.retry_limit)); pull_blocks++; if (!stop_pull && !connection->hard_stop.load ()) { diff --git a/nano/node/bootstrap/bootstrap_bulk_pull.hpp b/nano/node/bootstrap/bootstrap_bulk_pull.hpp index daf849cb86..4d38add74d 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.hpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.hpp @@ -12,7 +12,7 @@ class pull_info public: using count_t = nano::bulk_pull::count_t; pull_info () = default; - pull_info (nano::hash_or_account const &, nano::block_hash const &, nano::block_hash const &, count_t = 0, bool = false); + pull_info (nano::hash_or_account const &, nano::block_hash const &, nano::block_hash const &, count_t = 0, unsigned = 16); nano::hash_or_account account_or_head{ 0 }; nano::block_hash head{ 0 }; nano::block_hash head_original{ 0 }; @@ -20,7 +20,7 @@ class pull_info count_t count{ 0 }; unsigned attempts{ 0 }; uint64_t processed{ 0 }; - bool confirmed_head{ false }; + unsigned retry_limit{ 0 }; }; class bootstrap_client; class bulk_pull_client final : public std::enable_shared_from_this diff --git a/nano/node/bootstrap/bootstrap_frontier.cpp b/nano/node/bootstrap/bootstrap_frontier.cpp index 2da2379dfb..3c18999f3b 100644 --- a/nano/node/bootstrap/bootstrap_frontier.cpp +++ b/nano/node/bootstrap/bootstrap_frontier.cpp @@ -144,7 +144,7 @@ void nano::frontier_req_client::received_frontier (boost::system::error_code con } else { - connection->attempt->add_pull (nano::pull_info (account, latest, frontier)); + connection->attempt->add_pull (nano::pull_info (account, latest, frontier, 0, connection->node->network_params.bootstrap.bootstrap_frontier_retry_limit)); // Either we're behind or there's a fork we differ on // Either way, bulk pushing will probably not be effective bulk_push_cost += 5; @@ -155,12 +155,12 @@ void nano::frontier_req_client::received_frontier (boost::system::error_code con else { assert (account < current); - connection->attempt->add_pull (nano::pull_info (account, latest, nano::block_hash (0))); + connection->attempt->add_pull (nano::pull_info (account, latest, nano::block_hash (0), 0, connection->node->network_params.bootstrap.bootstrap_frontier_retry_limit)); } } else { - connection->attempt->add_pull (nano::pull_info (account, latest, nano::block_hash (0))); + connection->attempt->add_pull (nano::pull_info (account, latest, nano::block_hash (0), 0, connection->node->network_params.bootstrap.bootstrap_frontier_retry_limit)); } receive_frontier (); } diff --git a/nano/secure/common.cpp b/nano/secure/common.cpp index c49865c037..08885ce5fe 100644 --- a/nano/secure/common.cpp +++ b/nano/secure/common.cpp @@ -142,6 +142,9 @@ nano::portmapping_constants::portmapping_constants (nano::network_constants & ne nano::bootstrap_constants::bootstrap_constants (nano::network_constants & network_constants) { lazy_max_pull_blocks = network_constants.is_test_network () ? 2 : 512; + bootstrap_frontier_retry_limit = network_constants.is_test_network () ? 2 : 16; + bootstrap_lazy_retry_limit = network_constants.is_test_network () ? 2 : bootstrap_frontier_retry_limit * 10; + bootstrap_lazy_destinations_retry_limit = network_constants.is_test_network () ? 1 : bootstrap_frontier_retry_limit / 4; } /* Convenience constants for core_test which is always on the test network */ diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index 3226b8f12e..b296177f09 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -424,6 +424,9 @@ class bootstrap_constants public: bootstrap_constants (nano::network_constants & network_constants); uint64_t lazy_max_pull_blocks; + unsigned bootstrap_frontier_retry_limit; + unsigned bootstrap_lazy_retry_limit; + unsigned bootstrap_lazy_destinations_retry_limit; }; /** Constants whose value depends on the active network */ From aa90256de379a0baa0cb7cc008452eaedb0adf41 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Fri, 18 Oct 2019 05:05:15 +0300 Subject: [PATCH 02/22] Shorter lazy mutex lock for process_block_lazy () --- nano/node/bootstrap/bootstrap.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 6932fa8bbf..4ed0ab8efe 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -772,12 +772,10 @@ bool nano::bootstrap_attempt::process_block_lazy (std::shared_ptr b { bool stop_pull (false); auto hash (block_a->hash ()); - nano::lock_guard lazy_lock (lazy_mutex); + nano::unique_lock lazy_lock (lazy_mutex); // Processing new blocks if (lazy_blocks.find (hash) == lazy_blocks.end ()) { - nano::unchecked_info info (block_a, known_account_a, 0, nano::signature_verification::unknown, retry_limit == std::numeric_limits::max ()); - node->block_processor.add (info); // Search for new dependencies if (!block_a->source ().is_zero () && !node->ledger.block_exists (block_a->source ()) && block_a->source () != node->network_params.ledger.genesis_account) { @@ -807,6 +805,9 @@ bool nano::bootstrap_attempt::process_block_lazy (std::shared_ptr b lazy_balances.erase (block_a->previous ()); } lazy_block_state_backlog_check (block_a, hash); + lazy_lock.unlock (); + nano::unchecked_info info (block_a, known_account_a, 0, nano::signature_verification::unknown, retry_limit == std::numeric_limits::max ()); + node->block_processor.add (info); } // Force drop lazy bootstrap connection for long bulk_pull if (pull_blocks > node->network_params.bootstrap.lazy_max_pull_blocks) From c97de41fdc28a2ed96cf029ba2f8c03678101ca0 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Fri, 18 Oct 2019 14:59:03 +0300 Subject: [PATCH 03/22] Adjust bootstrap_lazy_destinations_request_limit --- nano/node/bootstrap/bootstrap.cpp | 3 ++- nano/node/bootstrap/bootstrap.hpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 4ed0ab8efe..70afb49fb1 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -700,10 +700,11 @@ void nano::bootstrap_attempt::lazy_run () lazy_pull_flush (); } // Start destinations check & backlog cleanup - if (iterations % nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit == 0 && pulls.size () < nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit * 10) + if (iterations % (nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit / 2) == 0 && pulls.size () < nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit * 20) { lazy_backlog_cleanup (); lazy_destinations_flush (); + lazy_pull_flush (); } } // Flushing lazy pulls diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index 3c3fa81156..5fcb07530c 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -235,6 +235,6 @@ class bootstrap_limits final static constexpr unsigned bootstrap_max_new_connections = 10; static constexpr unsigned bulk_push_cost_limit = 200; static constexpr std::chrono::seconds lazy_flush_delay_sec = std::chrono::seconds (5); - static constexpr unsigned bootstrap_lazy_destinations_request_limit = 200; + static constexpr unsigned bootstrap_lazy_destinations_request_limit = 1000; }; } From 104f07af3687434cb5a4a4628df9b96e5a46fc86 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Sat, 19 Oct 2019 14:21:42 +0300 Subject: [PATCH 04/22] Move lazy destintions flush after main lazy process is completed --- nano/node/bootstrap/bootstrap.cpp | 8 +++----- nano/node/bootstrap/bootstrap.hpp | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 70afb49fb1..14b6924789 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -699,17 +699,15 @@ void nano::bootstrap_attempt::lazy_run () { lazy_pull_flush (); } - // Start destinations check & backlog cleanup - if (iterations % (nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit / 2) == 0 && pulls.size () < nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit * 20) + // Start backlog cleanup + if (iterations % 200 == 0) { lazy_backlog_cleanup (); - lazy_destinations_flush (); - lazy_pull_flush (); } } // Flushing lazy pulls lazy_pull_flush (); - // Check if some blocks required for backlog were processed + // Check if some blocks required for backlog were processed. Start destinations check if (pulls.empty ()) { lazy_backlog_cleanup (); diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index 5fcb07530c..2bfe841efe 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -235,6 +235,6 @@ class bootstrap_limits final static constexpr unsigned bootstrap_max_new_connections = 10; static constexpr unsigned bulk_push_cost_limit = 200; static constexpr std::chrono::seconds lazy_flush_delay_sec = std::chrono::seconds (5); - static constexpr unsigned bootstrap_lazy_destinations_request_limit = 1000; + static constexpr unsigned bootstrap_lazy_destinations_request_limit = 128 * 1024; }; } From 973ba00774f9a88879a223c6ba1f3fb36da620ac Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Mon, 21 Oct 2019 18:22:07 +0300 Subject: [PATCH 05/22] Increase max time for lazy bootstrap --- nano/node/bootstrap/bootstrap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 14b6924789..a041cf3102 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -674,7 +674,7 @@ void nano::bootstrap_attempt::lazy_run () assert (!node->flags.disable_lazy_bootstrap); populate_connections (); auto start_time (std::chrono::steady_clock::now ()); - auto max_time (std::chrono::minutes (node->flags.disable_legacy_bootstrap ? 48 * 60 : 30)); + auto max_time (std::chrono::minutes (node->flags.disable_legacy_bootstrap ? 7 * 24 * 60 : 30)); nano::unique_lock lock (mutex); while ((still_pulling () || !lazy_finished ()) && std::chrono::steady_clock::now () - start_time < max_time) { From 64e53309c1e069fb98de7c1cbe0155228024fc38 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Tue, 22 Oct 2019 16:52:13 +0300 Subject: [PATCH 06/22] Basic lazy bootstrap improvements - stop lazy bootstrap with stopped node - use bootstrap network params - improve lock in process_block_lazy () - increase max lazy bootstrap duration --- nano/node/bootstrap/bootstrap.cpp | 19 +++++++++++-------- nano/node/bootstrap/bootstrap.hpp | 2 -- nano/secure/common.cpp | 2 ++ nano/secure/common.hpp | 2 ++ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 970425f96f..f4559d2ada 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -13,8 +13,6 @@ constexpr double nano::bootstrap_limits::bootstrap_connection_scale_target_blocks; constexpr double nano::bootstrap_limits::bootstrap_minimum_blocks_per_sec; -constexpr unsigned nano::bootstrap_limits::bootstrap_frontier_retry_limit; -constexpr unsigned nano::bootstrap_limits::bootstrap_lazy_retry_limit; constexpr double nano::bootstrap_limits::bootstrap_minimum_termination_time_sec; constexpr unsigned nano::bootstrap_limits::bootstrap_max_new_connections; constexpr std::chrono::seconds nano::bootstrap_limits::lazy_flush_delay_sec; @@ -532,13 +530,13 @@ void nano::bootstrap_attempt::requeue_pull (nano::pull_info const & pull_a) { auto pull (pull_a); ++pull.attempts; - if (pull.attempts < (!node->network_params.network.is_test_network () ? nano::bootstrap_limits::bootstrap_frontier_retry_limit : (nano::bootstrap_limits::bootstrap_frontier_retry_limit / 8) + (pull.processed / 10000))) + if (pull.attempts < (!node->network_params.bootstrap.bootstrap_frontier_retry_limit + (pull.processed / 10000))) { nano::lock_guard lock (mutex); pulls.push_front (pull); condition.notify_all (); } - else if (mode == nano::bootstrap_mode::lazy && (pull.confirmed_head || pull.attempts <= (!node->network_params.network.is_test_network () ? nano::bootstrap_limits::bootstrap_lazy_retry_limit : (nano::bootstrap_limits::bootstrap_frontier_retry_limit / 8) + (pull.processed / node->network_params.bootstrap.lazy_max_pull_blocks)))) + else if (mode == nano::bootstrap_mode::lazy && (pull.confirmed_head || pull.attempts <= (!node->network_params.bootstrap.bootstrap_lazy_retry_limit + (pull.processed / node->network_params.bootstrap.lazy_max_pull_blocks)))) { assert (pull.account_or_head == pull.head); if (!lazy_processed_or_exists (pull.account_or_head)) @@ -628,6 +626,10 @@ void nano::bootstrap_attempt::lazy_pull_flush () bool nano::bootstrap_attempt::lazy_finished () { + if (stopped) + { + return true; + } bool result (true); auto transaction (node->store.tx_begin_read ()); nano::lock_guard lazy_lock (lazy_mutex); @@ -668,7 +670,7 @@ void nano::bootstrap_attempt::lazy_run () assert (!node->flags.disable_lazy_bootstrap); populate_connections (); auto start_time (std::chrono::steady_clock::now ()); - auto max_time (std::chrono::minutes (node->flags.disable_legacy_bootstrap ? 48 * 60 : 30)); + auto max_time (std::chrono::minutes (node->flags.disable_legacy_bootstrap ? 7 * 24 * 60 : 30)); nano::unique_lock lock (mutex); while ((still_pulling () || !lazy_finished ()) && std::chrono::steady_clock::now () - start_time < max_time) { @@ -766,12 +768,10 @@ bool nano::bootstrap_attempt::process_block_lazy (std::shared_ptr b { bool stop_pull (false); auto hash (block_a->hash ()); - nano::lock_guard lazy_lock (lazy_mutex); + nano::unique_lock lazy_lock (lazy_mutex); // Processing new blocks if (lazy_blocks.find (hash) == lazy_blocks.end ()) { - nano::unchecked_info info (block_a, known_account_a, 0, nano::signature_verification::unknown, confirmed_head); - node->block_processor.add (info); // Search for new dependencies if (!block_a->source ().is_zero () && !node->ledger.block_exists (block_a->source ()) && block_a->source () != node->network_params.ledger.genesis_account) { @@ -801,6 +801,9 @@ bool nano::bootstrap_attempt::process_block_lazy (std::shared_ptr b lazy_balances.erase (block_a->previous ()); } lazy_block_state_backlog_check (block_a, hash); + lazy_lock.unlock (); + nano::unchecked_info info (block_a, known_account_a, 0, nano::signature_verification::unknown, confirmed_head); + node->block_processor.add (info); } // Force drop lazy bootstrap connection for long bulk_pull if (pull_blocks > node->network_params.bootstrap.lazy_max_pull_blocks) diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index e6f4883535..aa7f4de34e 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -232,8 +232,6 @@ class bootstrap_limits final static constexpr double bootstrap_minimum_blocks_per_sec = 10.0; static constexpr double bootstrap_minimum_elapsed_seconds_blockrate = 0.02; static constexpr double bootstrap_minimum_frontier_blocks_per_sec = 1000.0; - static constexpr unsigned bootstrap_frontier_retry_limit = 16; - static constexpr unsigned bootstrap_lazy_retry_limit = bootstrap_frontier_retry_limit * 10; static constexpr double bootstrap_minimum_termination_time_sec = 30.0; static constexpr unsigned bootstrap_max_new_connections = 10; static constexpr unsigned bulk_push_cost_limit = 200; diff --git a/nano/secure/common.cpp b/nano/secure/common.cpp index c49865c037..3096b98549 100644 --- a/nano/secure/common.cpp +++ b/nano/secure/common.cpp @@ -142,6 +142,8 @@ nano::portmapping_constants::portmapping_constants (nano::network_constants & ne nano::bootstrap_constants::bootstrap_constants (nano::network_constants & network_constants) { lazy_max_pull_blocks = network_constants.is_test_network () ? 2 : 512; + bootstrap_frontier_retry_limit = network_constants.is_test_network () ? 2 : 16; + bootstrap_lazy_retry_limit = network_constants.is_test_network () ? 2 : bootstrap_frontier_retry_limit * 10; } /* Convenience constants for core_test which is always on the test network */ diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index 3226b8f12e..8004751d48 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -424,6 +424,8 @@ class bootstrap_constants public: bootstrap_constants (nano::network_constants & network_constants); uint64_t lazy_max_pull_blocks; + unsigned bootstrap_frontier_retry_limit; + unsigned bootstrap_lazy_retry_limit; }; /** Constants whose value depends on the active network */ From b7dc764c2b6f044af107e1010b073ac723a99e6b Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Wed, 23 Oct 2019 03:42:53 +0300 Subject: [PATCH 07/22] Dynamic limiter for lazy pull max processed blocks --- nano/node/bootstrap/bootstrap.cpp | 35 +++++++++++++++------ nano/node/bootstrap/bootstrap.hpp | 8 +++-- nano/node/bootstrap/bootstrap_bulk_pull.cpp | 2 +- nano/secure/common.cpp | 5 +-- nano/secure/common.hpp | 7 +++-- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index f4559d2ada..58067d2a6f 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -16,8 +16,10 @@ constexpr double nano::bootstrap_limits::bootstrap_minimum_blocks_per_sec; constexpr double nano::bootstrap_limits::bootstrap_minimum_termination_time_sec; constexpr unsigned nano::bootstrap_limits::bootstrap_max_new_connections; constexpr std::chrono::seconds nano::bootstrap_limits::lazy_flush_delay_sec; -constexpr unsigned nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit; +constexpr unsigned nano::bootstrap_limits::lazy_destinations_request_limit; constexpr std::chrono::seconds nano::bootstrap_limits::lazy_destinations_flush_delay_sec; +constexpr uint64_t nano::bootstrap_limits::lazy_batch_pull_count_resize_blocks_limit; +constexpr double nano::bootstrap_limits::lazy_batch_pull_count_resize_ratio; nano::bootstrap_client::bootstrap_client (std::shared_ptr node_a, std::shared_ptr attempt_a, std::shared_ptr channel_a) : node (node_a), @@ -246,6 +248,7 @@ void nano::bootstrap_attempt::run () { lock.unlock (); mode = nano::bootstrap_mode::wallet_lazy; + total_blocks = 0; wallet_run (); lock.lock (); } @@ -254,6 +257,7 @@ void nano::bootstrap_attempt::run () { lock.unlock (); mode = nano::bootstrap_mode::lazy; + total_blocks = 0; lazy_run (); lock.lock (); } @@ -530,13 +534,13 @@ void nano::bootstrap_attempt::requeue_pull (nano::pull_info const & pull_a) { auto pull (pull_a); ++pull.attempts; - if (pull.attempts < (!node->network_params.bootstrap.bootstrap_frontier_retry_limit + (pull.processed / 10000))) + if (pull.attempts < (!node->network_params.bootstrap.frontier_retry_limit + (pull.processed / 10000))) { nano::lock_guard lock (mutex); pulls.push_front (pull); condition.notify_all (); } - else if (mode == nano::bootstrap_mode::lazy && (pull.confirmed_head || pull.attempts <= (!node->network_params.bootstrap.bootstrap_lazy_retry_limit + (pull.processed / node->network_params.bootstrap.lazy_max_pull_blocks)))) + else if (mode == nano::bootstrap_mode::lazy && (pull.confirmed_head || pull.attempts <= (!node->network_params.bootstrap.lazy_retry_limit + (pull.processed / node->network_params.bootstrap.lazy_max_pull_blocks)))) { assert (pull.account_or_head == pull.head); if (!lazy_processed_or_exists (pull.account_or_head)) @@ -618,7 +622,17 @@ void nano::bootstrap_attempt::lazy_pull_flush () if (lazy_blocks.find (pull_start.first) == lazy_blocks.end () && !node->store.block_exists (transaction, pull_start.first)) { assert (node->network_params.bootstrap.lazy_max_pull_blocks <= std::numeric_limits::max ()); - pulls.emplace_back (pull_start.first, pull_start.first, nano::block_hash (0), static_cast (node->network_params.bootstrap.lazy_max_pull_blocks), pull_start.second); + nano::pull_info::count_t batch_count (node->network_params.bootstrap.lazy_max_pull_blocks); + if (total_blocks > nano::bootstrap_limits::lazy_batch_pull_count_resize_blocks_limit && !lazy_blocks.empty ()) + { + double lazy_blocks_ratio (total_blocks / lazy_blocks.size ()); + if (lazy_blocks_ratio > nano::bootstrap_limits::lazy_batch_pull_count_resize_ratio) + { + double processed_blocks_ratio (total_blocks / nano::bootstrap_limits::lazy_batch_pull_count_resize_blocks_limit); + batch_count = std::max (node->network_params.bootstrap.lazy_min_pull_blocks, static_cast (node->network_params.bootstrap.lazy_max_pull_blocks * nano::bootstrap_limits::lazy_batch_pull_count_resize_ratio / (lazy_blocks_ratio * processed_blocks_ratio))); + } + } + pulls.emplace_back (pull_start.first, pull_start.first, nano::block_hash (0), batch_count, pull_start.second); } } lazy_pulls.clear (); @@ -744,12 +758,12 @@ void nano::bootstrap_attempt::lazy_run () idle.clear (); } -bool nano::bootstrap_attempt::process_block (std::shared_ptr block_a, nano::account const & known_account_a, uint64_t pull_blocks, bool block_expected, bool confirmed_head) +bool nano::bootstrap_attempt::process_block (std::shared_ptr block_a, nano::account const & known_account_a, uint64_t pull_blocks, nano::bulk_pull::count_t max_blocks, bool block_expected, bool confirmed_head) { bool stop_pull (false); if (mode != nano::bootstrap_mode::legacy && block_expected) { - stop_pull = process_block_lazy (block_a, known_account_a, pull_blocks, confirmed_head); + stop_pull = process_block_lazy (block_a, known_account_a, pull_blocks, max_blocks, confirmed_head); } else if (mode != nano::bootstrap_mode::legacy) { @@ -764,7 +778,7 @@ bool nano::bootstrap_attempt::process_block (std::shared_ptr block_ return stop_pull; } -bool nano::bootstrap_attempt::process_block_lazy (std::shared_ptr block_a, nano::account const & known_account_a, uint64_t pull_blocks, bool confirmed_head) +bool nano::bootstrap_attempt::process_block_lazy (std::shared_ptr block_a, nano::account const & known_account_a, uint64_t pull_blocks, nano::bulk_pull::count_t max_blocks, bool confirmed_head) { bool stop_pull (false); auto hash (block_a->hash ()); @@ -806,7 +820,7 @@ bool nano::bootstrap_attempt::process_block_lazy (std::shared_ptr b node->block_processor.add (info); } // Force drop lazy bootstrap connection for long bulk_pull - if (pull_blocks > node->network_params.bootstrap.lazy_max_pull_blocks) + if (pull_blocks > max_blocks) { stop_pull = true; } @@ -946,13 +960,13 @@ void nano::bootstrap_attempt::lazy_destinations_flush () nano::lock_guard lazy_lock (lazy_mutex); if (last_lazy_destinations_flush + nano::bootstrap_limits::lazy_destinations_flush_delay_sec < std::chrono::steady_clock::now ()) { - for (auto it (lazy_destinations.get ().begin ()), end (lazy_destinations.get ().end ()); it != end && count < nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit && !stopped;) + for (auto it (lazy_destinations.get ().begin ()), end (lazy_destinations.get ().end ()); it != end && count < nano::bootstrap_limits::lazy_destinations_request_limit && !stopped;) { lazy_add (it->account, false); it = lazy_destinations.get ().erase (it); ++count; } - if (count > nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit / 4) + if (count > nano::bootstrap_limits::lazy_destinations_request_limit / 4) { last_lazy_destinations_flush = std::chrono::steady_clock::now (); } @@ -1046,6 +1060,7 @@ void nano::bootstrap_attempt::wallet_run () if (!lazy_finished ()) { lock.unlock (); + total_blocks = 0; lazy_run (); lock.lock (); } diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index aa7f4de34e..4cc3730fa5 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -80,7 +80,7 @@ class bootstrap_attempt final : public std::enable_shared_from_this, nano::account const &, uint64_t, bool, bool); + bool process_block (std::shared_ptr, nano::account const &, uint64_t, nano::bulk_pull::count_t, bool, bool); /** Lazy bootstrap */ void lazy_run (); void lazy_start (nano::hash_or_account const &, bool confirmed = true); @@ -89,7 +89,7 @@ class bootstrap_attempt final : public std::enable_shared_from_this, nano::account const &, uint64_t, bool); + bool process_block_lazy (std::shared_ptr, nano::account const &, uint64_t, nano::bulk_pull::count_t, bool); void lazy_block_state (std::shared_ptr, bool); void lazy_block_state_backlog_check (std::shared_ptr, nano::block_hash const &); void lazy_backlog_cleanup (); @@ -236,7 +236,9 @@ class bootstrap_limits final static constexpr unsigned bootstrap_max_new_connections = 10; static constexpr unsigned bulk_push_cost_limit = 200; static constexpr std::chrono::seconds lazy_flush_delay_sec = std::chrono::seconds (5); - static constexpr unsigned bootstrap_lazy_destinations_request_limit = 200; + static constexpr unsigned lazy_destinations_request_limit = 200; static constexpr std::chrono::seconds lazy_destinations_flush_delay_sec = std::chrono::minutes (2); + static constexpr uint64_t lazy_batch_pull_count_resize_blocks_limit = 1024 * 1024; + static constexpr double lazy_batch_pull_count_resize_ratio = 2.0; }; } diff --git a/nano/node/bootstrap/bootstrap_bulk_pull.cpp b/nano/node/bootstrap/bootstrap_bulk_pull.cpp index 632331678d..ccf365ad61 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.cpp @@ -233,7 +233,7 @@ void nano::bulk_pull_client::received_block (boost::system::error_code const & e connection->start_time = std::chrono::steady_clock::now (); } connection->attempt->total_blocks++; - bool stop_pull (connection->attempt->process_block (block, known_account, pull_blocks, block_expected, pull.confirmed_head)); + bool stop_pull (connection->attempt->process_block (block, known_account, pull_blocks, pull.count, block_expected, pull.confirmed_head)); pull_blocks++; if (!stop_pull && !connection->hard_stop.load ()) { diff --git a/nano/secure/common.cpp b/nano/secure/common.cpp index 3096b98549..654f6a8ef5 100644 --- a/nano/secure/common.cpp +++ b/nano/secure/common.cpp @@ -142,8 +142,9 @@ nano::portmapping_constants::portmapping_constants (nano::network_constants & ne nano::bootstrap_constants::bootstrap_constants (nano::network_constants & network_constants) { lazy_max_pull_blocks = network_constants.is_test_network () ? 2 : 512; - bootstrap_frontier_retry_limit = network_constants.is_test_network () ? 2 : 16; - bootstrap_lazy_retry_limit = network_constants.is_test_network () ? 2 : bootstrap_frontier_retry_limit * 10; + lazy_min_pull_blocks = network_constants.is_test_network () ? 1 : 32; + frontier_retry_limit = network_constants.is_test_network () ? 2 : 16; + lazy_retry_limit = network_constants.is_test_network () ? 2 : frontier_retry_limit * 10; } /* Convenience constants for core_test which is always on the test network */ diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index 8004751d48..f4b6cbee35 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -423,9 +423,10 @@ class bootstrap_constants { public: bootstrap_constants (nano::network_constants & network_constants); - uint64_t lazy_max_pull_blocks; - unsigned bootstrap_frontier_retry_limit; - unsigned bootstrap_lazy_retry_limit; + uint32_t lazy_max_pull_blocks; + uint32_t lazy_min_pull_blocks; + unsigned frontier_retry_limit; + unsigned lazy_retry_limit; }; /** Constants whose value depends on the active network */ From 23301ee198e921ad6e5a7fe9b392cc34be5e17c4 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Wed, 23 Oct 2019 03:55:19 +0300 Subject: [PATCH 08/22] Fix naming --- nano/node/bootstrap/bootstrap.cpp | 2 +- nano/node/bootstrap/bootstrap_frontier.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 84ba1818ff..f62a972180 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -961,7 +961,7 @@ void nano::bootstrap_attempt::lazy_destinations_flush () { size_t count (0); nano::lock_guard lazy_lock (lazy_mutex); - for (auto it (lazy_destinations.get ().begin ()), end (lazy_destinations.get ().end ()); it != end && count < nano::bootstrap_limits::bootstrap_lazy_destinations_request_limit && !stopped;) + for (auto it (lazy_destinations.get ().begin ()), end (lazy_destinations.get ().end ()); it != end && count < nano::bootstrap_limits::lazy_destinations_request_limit && !stopped;) { lazy_add (it->account, node->network_params.bootstrap.lazy_destinations_retry_limit); it = lazy_destinations.get ().erase (it); diff --git a/nano/node/bootstrap/bootstrap_frontier.cpp b/nano/node/bootstrap/bootstrap_frontier.cpp index 3c18999f3b..90f9281fcc 100644 --- a/nano/node/bootstrap/bootstrap_frontier.cpp +++ b/nano/node/bootstrap/bootstrap_frontier.cpp @@ -144,7 +144,7 @@ void nano::frontier_req_client::received_frontier (boost::system::error_code con } else { - connection->attempt->add_pull (nano::pull_info (account, latest, frontier, 0, connection->node->network_params.bootstrap.bootstrap_frontier_retry_limit)); + connection->attempt->add_pull (nano::pull_info (account, latest, frontier, 0, connection->node->network_params.bootstrap.frontier_retry_limit)); // Either we're behind or there's a fork we differ on // Either way, bulk pushing will probably not be effective bulk_push_cost += 5; @@ -155,12 +155,12 @@ void nano::frontier_req_client::received_frontier (boost::system::error_code con else { assert (account < current); - connection->attempt->add_pull (nano::pull_info (account, latest, nano::block_hash (0), 0, connection->node->network_params.bootstrap.bootstrap_frontier_retry_limit)); + connection->attempt->add_pull (nano::pull_info (account, latest, nano::block_hash (0), 0, connection->node->network_params.bootstrap.frontier_retry_limit)); } } else { - connection->attempt->add_pull (nano::pull_info (account, latest, nano::block_hash (0), 0, connection->node->network_params.bootstrap.bootstrap_frontier_retry_limit)); + connection->attempt->add_pull (nano::pull_info (account, latest, nano::block_hash (0), 0, connection->node->network_params.bootstrap.frontier_retry_limit)); } receive_frontier (); } From 292af2264fed7f9935014285b78c41f01c91edec Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Wed, 23 Oct 2019 17:52:40 +0300 Subject: [PATCH 09/22] Adjust dynamic limiter --- nano/node/bootstrap/bootstrap.cpp | 26 ++++++++++++++------------ nano/node/bootstrap/bootstrap.hpp | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 58067d2a6f..769ae2728d 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -615,23 +615,25 @@ void nano::bootstrap_attempt::lazy_pull_flush () assert (!mutex.try_lock ()); last_lazy_flush = std::chrono::steady_clock::now (); nano::lock_guard lazy_lock (lazy_mutex); + assert (node->network_params.bootstrap.lazy_max_pull_blocks <= std::numeric_limits::max ()); + nano::pull_info::count_t batch_count (node->network_params.bootstrap.lazy_max_pull_blocks); + if (total_blocks > nano::bootstrap_limits::lazy_batch_pull_count_resize_blocks_limit && !lazy_blocks.empty ()) + { + double lazy_blocks_ratio (total_blocks / lazy_blocks.size ()); + if (lazy_blocks_ratio > nano::bootstrap_limits::lazy_batch_pull_count_resize_ratio) + { + double lazy_blocks_factor (std::pow (lazy_blocks_ratio / nano::bootstrap_limits::lazy_batch_pull_count_resize_ratio, 3.0)); + double processed_blocks_factor (std::sqrt (total_blocks / nano::bootstrap_limits::lazy_batch_pull_count_resize_blocks_limit)); + uint32_t batch_count_min (node->network_params.bootstrap.lazy_max_pull_blocks / (lazy_blocks_factor * processed_blocks_factor)); + batch_count = std::max (node->network_params.bootstrap.lazy_min_pull_blocks, batch_count_min); + } + } auto transaction (node->store.tx_begin_read ()); for (auto & pull_start : lazy_pulls) { // Recheck if block was already processed if (lazy_blocks.find (pull_start.first) == lazy_blocks.end () && !node->store.block_exists (transaction, pull_start.first)) { - assert (node->network_params.bootstrap.lazy_max_pull_blocks <= std::numeric_limits::max ()); - nano::pull_info::count_t batch_count (node->network_params.bootstrap.lazy_max_pull_blocks); - if (total_blocks > nano::bootstrap_limits::lazy_batch_pull_count_resize_blocks_limit && !lazy_blocks.empty ()) - { - double lazy_blocks_ratio (total_blocks / lazy_blocks.size ()); - if (lazy_blocks_ratio > nano::bootstrap_limits::lazy_batch_pull_count_resize_ratio) - { - double processed_blocks_ratio (total_blocks / nano::bootstrap_limits::lazy_batch_pull_count_resize_blocks_limit); - batch_count = std::max (node->network_params.bootstrap.lazy_min_pull_blocks, static_cast (node->network_params.bootstrap.lazy_max_pull_blocks * nano::bootstrap_limits::lazy_batch_pull_count_resize_ratio / (lazy_blocks_ratio * processed_blocks_ratio))); - } - } pulls.emplace_back (pull_start.first, pull_start.first, nano::block_hash (0), batch_count, pull_start.second); } } @@ -700,7 +702,7 @@ void nano::bootstrap_attempt::lazy_run () lazy_pull_flush (); if (pulls.empty ()) { - condition.wait_for (lock, std::chrono::seconds (2)); + condition.wait_for (lock, std::chrono::seconds (1)); } } ++iterations; diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index 4cc3730fa5..fc5076d79a 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -238,7 +238,7 @@ class bootstrap_limits final static constexpr std::chrono::seconds lazy_flush_delay_sec = std::chrono::seconds (5); static constexpr unsigned lazy_destinations_request_limit = 200; static constexpr std::chrono::seconds lazy_destinations_flush_delay_sec = std::chrono::minutes (2); - static constexpr uint64_t lazy_batch_pull_count_resize_blocks_limit = 1024 * 1024; + static constexpr uint64_t lazy_batch_pull_count_resize_blocks_limit = 4 * 1024 * 1024; static constexpr double lazy_batch_pull_count_resize_ratio = 2.0; }; } From de6b23f54b7a9ef3c8ab0066aaa72ebb6043e9bf Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Wed, 23 Oct 2019 18:26:06 +0300 Subject: [PATCH 10/22] Proper reuse of of connections after lazy pull stop --- nano/node/bootstrap/bootstrap.cpp | 2 +- nano/node/bootstrap/bootstrap_bulk_pull.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 769ae2728d..b8c3efa8c2 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -480,7 +480,7 @@ void nano::bootstrap_attempt::pool_connection (std::shared_ptrchannel->socket->start_timer (node->network_params.node.idle_timeout); // Push into idle deque - idle.push_front (client_a); + idle.push_back (client_a); } condition.notify_all (); } diff --git a/nano/node/bootstrap/bootstrap_bulk_pull.cpp b/nano/node/bootstrap/bootstrap_bulk_pull.cpp index ccf365ad61..01d75f673d 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.cpp @@ -180,7 +180,7 @@ void nano::bulk_pull_client::received_type () case nano::block_type::not_a_block: { // Avoid re-using slow peers, or peers that sent the wrong blocks. - if (!connection->pending_stop && expected == pull.end) + if (!connection->pending_stop && (expected == pull.end || (pull.count != 0 && pull.count == pull_blocks))) { connection->attempt->pool_connection (connection); } From dd760d8b6dfe76934075ea1921038d4e728ae3cd Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Wed, 23 Oct 2019 18:36:18 +0300 Subject: [PATCH 11/22] Don't clean unchecked for longest bootstrap attempts --- nano/node/node.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index d0b2969f70..206d402519 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -900,8 +900,10 @@ void nano::node::bootstrap_wallet () void nano::node::unchecked_cleanup () { std::deque cleaning_list; + auto attempt (bootstrap_initiator.current_attempt ()); + bool long_attempt (attempt != nullptr && std::chrono::duration_cast (std::chrono::steady_clock::now () - attempt->attempt_start).count () > config.unchecked_cutoff_time.count ()); // Collect old unchecked keys - if (!flags.disable_unchecked_cleanup && ledger.block_count_cache >= ledger.bootstrap_weight_max_blocks) + if (!flags.disable_unchecked_cleanup && ledger.block_count_cache >= ledger.bootstrap_weight_max_blocks && !long_attempt) { auto now (nano::seconds_since_epoch ()); auto transaction (store.tx_begin_read ()); From b87798e848a161e3625e2964b598dd2bbb0aba48 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Wed, 23 Oct 2019 19:17:29 +0300 Subject: [PATCH 12/22] Better naming --- nano/node/bootstrap/bootstrap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index b8c3efa8c2..c5ff0fb2d9 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -623,8 +623,8 @@ void nano::bootstrap_attempt::lazy_pull_flush () if (lazy_blocks_ratio > nano::bootstrap_limits::lazy_batch_pull_count_resize_ratio) { double lazy_blocks_factor (std::pow (lazy_blocks_ratio / nano::bootstrap_limits::lazy_batch_pull_count_resize_ratio, 3.0)); - double processed_blocks_factor (std::sqrt (total_blocks / nano::bootstrap_limits::lazy_batch_pull_count_resize_blocks_limit)); - uint32_t batch_count_min (node->network_params.bootstrap.lazy_max_pull_blocks / (lazy_blocks_factor * processed_blocks_factor)); + double total_blocks_factor (std::sqrt (total_blocks / nano::bootstrap_limits::lazy_batch_pull_count_resize_blocks_limit)); + uint32_t batch_count_min (node->network_params.bootstrap.lazy_max_pull_blocks / (lazy_blocks_factor * total_blocks_factor)); batch_count = std::max (node->network_params.bootstrap.lazy_min_pull_blocks, batch_count_min); } } From 691b8d28614f79d13fc84e1c0a578058f402fbf8 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Wed, 23 Oct 2019 23:00:23 +0300 Subject: [PATCH 13/22] Improve lazy destinations flush conditions --- nano/node/bootstrap/bootstrap.cpp | 8 +++++++- nano/node/bootstrap/bootstrap.hpp | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 0cd586da2a..08afb43e73 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -578,7 +578,7 @@ void nano::bootstrap_attempt::lazy_start (nano::hash_or_account const & hash_or_ { nano::lock_guard lazy_lock (lazy_mutex); // Add start blocks, limit 1024 (32k with disabled legacy bootstrap) - size_t max_keys (node->flags.disable_legacy_bootstrap ? 32 * 1024 : 1024); + size_t max_keys (node->flags.disable_legacy_bootstrap ? 16 * 1024 : 1024); if (lazy_keys.size () < max_keys && lazy_keys.find (hash_or_account_a) == lazy_keys.end () && lazy_blocks.find (hash_or_account_a) == lazy_blocks.end ()) { lazy_keys.insert (hash_or_account_a); @@ -720,6 +720,11 @@ void nano::bootstrap_attempt::lazy_run () { lazy_backlog_cleanup (); } + // Destinations check + if (pulls.empty () && lazy_destinations_flushed) + { + lazy_destinations_flush (); + } } // Flushing lazy pulls lazy_pull_flush (); @@ -961,6 +966,7 @@ void nano::bootstrap_attempt::lazy_destinations_increment (nano::account const & void nano::bootstrap_attempt::lazy_destinations_flush () { + lazy_destinations_flushed = true; size_t count (0); nano::lock_guard lazy_lock (lazy_mutex); for (auto it (lazy_destinations.get ().begin ()), end (lazy_destinations.get ().end ()); it != end && count < nano::bootstrap_limits::lazy_destinations_request_limit && !stopped;) diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index 071d724058..80feeeb71b 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -144,6 +144,7 @@ class bootstrap_attempt final : public std::enable_shared_from_this, boost::multi_index::member, std::greater>, boost::multi_index::hashed_unique, boost::multi_index::member>>> lazy_destinations; + std::atomic lazy_destinations_flushed{ false }; std::mutex lazy_mutex; // Wallet lazy bootstrap std::deque wallet_accounts; From 08d2f006301583b21f39ab3d64d42742b3a50c7a Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Thu, 24 Oct 2019 00:15:36 +0300 Subject: [PATCH 14/22] Improve lazy keys limit --- nano/node/bootstrap/bootstrap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 08afb43e73..98b1942b3c 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -577,8 +577,8 @@ void nano::bootstrap_attempt::add_bulk_push_target (nano::block_hash const & hea void nano::bootstrap_attempt::lazy_start (nano::hash_or_account const & hash_or_account_a, bool confirmed) { nano::lock_guard lazy_lock (lazy_mutex); - // Add start blocks, limit 1024 (32k with disabled legacy bootstrap) - size_t max_keys (node->flags.disable_legacy_bootstrap ? 16 * 1024 : 1024); + // Add start blocks, limit 1024 (4k with disabled legacy bootstrap) + size_t max_keys (node->flags.disable_legacy_bootstrap ? 4 * 1024 : 1024); if (lazy_keys.size () < max_keys && lazy_keys.find (hash_or_account_a) == lazy_keys.end () && lazy_blocks.find (hash_or_account_a) == lazy_blocks.end ()) { lazy_keys.insert (hash_or_account_a); From 979a5cba3d5c9aed71f2c5eda7287f9ea3df199e Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Thu, 24 Oct 2019 03:34:05 +0300 Subject: [PATCH 15/22] Increase bootstrap_max_new_connections --- nano/node/bootstrap/bootstrap.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index 80feeeb71b..5f43d49afc 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -233,7 +233,7 @@ class bootstrap_limits final static constexpr double bootstrap_minimum_elapsed_seconds_blockrate = 0.02; static constexpr double bootstrap_minimum_frontier_blocks_per_sec = 1000.0; static constexpr double bootstrap_minimum_termination_time_sec = 30.0; - static constexpr unsigned bootstrap_max_new_connections = 10; + static constexpr unsigned bootstrap_max_new_connections = 16; static constexpr unsigned bulk_push_cost_limit = 200; static constexpr std::chrono::seconds lazy_flush_delay_sec = std::chrono::seconds (5); static constexpr unsigned lazy_destinations_request_limit = 128 * 1024; From 80343dcaffd47162588a46e40adc21ab775ce1d9 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Thu, 24 Oct 2019 03:47:07 +0300 Subject: [PATCH 16/22] Update bootstrap_max_new_connections --- nano/node/bootstrap/bootstrap.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index fc5076d79a..bb37b38060 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -233,7 +233,7 @@ class bootstrap_limits final static constexpr double bootstrap_minimum_elapsed_seconds_blockrate = 0.02; static constexpr double bootstrap_minimum_frontier_blocks_per_sec = 1000.0; static constexpr double bootstrap_minimum_termination_time_sec = 30.0; - static constexpr unsigned bootstrap_max_new_connections = 10; + static constexpr unsigned bootstrap_max_new_connections = 16; static constexpr unsigned bulk_push_cost_limit = 200; static constexpr std::chrono::seconds lazy_flush_delay_sec = std::chrono::seconds (5); static constexpr unsigned lazy_destinations_request_limit = 200; From 3c2f82c7a073d1c9f382f553678ac6cd389fbfb2 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Thu, 24 Oct 2019 04:42:19 +0300 Subject: [PATCH 17/22] Increase lazy_destinations_request_limit --- nano/node/bootstrap/bootstrap.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index 5f43d49afc..188c318213 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -236,7 +236,7 @@ class bootstrap_limits final static constexpr unsigned bootstrap_max_new_connections = 16; static constexpr unsigned bulk_push_cost_limit = 200; static constexpr std::chrono::seconds lazy_flush_delay_sec = std::chrono::seconds (5); - static constexpr unsigned lazy_destinations_request_limit = 128 * 1024; + static constexpr unsigned lazy_destinations_request_limit = 256 * 1024; static constexpr uint64_t lazy_batch_pull_count_resize_blocks_limit = 4 * 1024 * 1024; static constexpr double lazy_batch_pull_count_resize_ratio = 2.0; }; From 4731638ae86fa29f63be437fb0c01b768ad25c7a Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Thu, 24 Oct 2019 05:15:36 +0300 Subject: [PATCH 18/22] Increase max new bootstrap connections --- nano/node/bootstrap/bootstrap.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index bb37b38060..92f525ab8a 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -233,7 +233,7 @@ class bootstrap_limits final static constexpr double bootstrap_minimum_elapsed_seconds_blockrate = 0.02; static constexpr double bootstrap_minimum_frontier_blocks_per_sec = 1000.0; static constexpr double bootstrap_minimum_termination_time_sec = 30.0; - static constexpr unsigned bootstrap_max_new_connections = 16; + static constexpr unsigned bootstrap_max_new_connections = 24; static constexpr unsigned bulk_push_cost_limit = 200; static constexpr std::chrono::seconds lazy_flush_delay_sec = std::chrono::seconds (5); static constexpr unsigned lazy_destinations_request_limit = 200; From 583b70d634bb7bb06cdcca9211711a7038bddf3b Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Thu, 24 Oct 2019 13:38:06 +0300 Subject: [PATCH 19/22] Increase target connections for lazy bootstrap --- nano/node/bootstrap/bootstrap.cpp | 4 +++- nano/node/bootstrap/bootstrap.hpp | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index c5ff0fb2d9..b73dd04e64 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -12,6 +12,7 @@ #include constexpr double nano::bootstrap_limits::bootstrap_connection_scale_target_blocks; +constexpr double nano::bootstrap_limits::bootstrap_connection_scale_target_blocks_lazy; constexpr double nano::bootstrap_limits::bootstrap_minimum_blocks_per_sec; constexpr double nano::bootstrap_limits::bootstrap_minimum_termination_time_sec; constexpr unsigned nano::bootstrap_limits::bootstrap_max_new_connections; @@ -315,7 +316,8 @@ unsigned nano::bootstrap_attempt::target_connections (size_t pulls_remaining) } // Only scale up to bootstrap_connections_max for large pulls. - double step_scale = std::min (1.0, std::max (0.0, (double)pulls_remaining / nano::bootstrap_limits::bootstrap_connection_scale_target_blocks)); + double target_blocks = (mode == nano::bootstrap_mode::lazy) ? nano::bootstrap_limits::bootstrap_connection_scale_target_blocks_lazy : nano::bootstrap_limits::bootstrap_connection_scale_target_blocks; + double step_scale = std::min (1.0, std::max (0.0, (double)pulls_remaining / target_blocks)); double lazy_term = (mode == nano::bootstrap_mode::lazy) ? (double)node->config.bootstrap_connections : 0.0; double target = (double)node->config.bootstrap_connections + (double)(node->config.bootstrap_connections_max - node->config.bootstrap_connections) * step_scale + lazy_term; return std::max (1U, (unsigned)(target + 0.5f)); diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index 92f525ab8a..5a46310df0 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -228,12 +228,13 @@ class bootstrap_limits final { public: static constexpr double bootstrap_connection_scale_target_blocks = 50000.0; + static constexpr double bootstrap_connection_scale_target_blocks_lazy = bootstrap_connection_scale_target_blocks / 5; static constexpr double bootstrap_connection_warmup_time_sec = 5.0; static constexpr double bootstrap_minimum_blocks_per_sec = 10.0; static constexpr double bootstrap_minimum_elapsed_seconds_blockrate = 0.02; static constexpr double bootstrap_minimum_frontier_blocks_per_sec = 1000.0; static constexpr double bootstrap_minimum_termination_time_sec = 30.0; - static constexpr unsigned bootstrap_max_new_connections = 24; + static constexpr unsigned bootstrap_max_new_connections = 32; static constexpr unsigned bulk_push_cost_limit = 200; static constexpr std::chrono::seconds lazy_flush_delay_sec = std::chrono::seconds (5); static constexpr unsigned lazy_destinations_request_limit = 200; From ee8d47573a247f7eb370271b061109656b1d6c72 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Thu, 24 Oct 2019 14:52:44 +0300 Subject: [PATCH 20/22] Dynamic scaling factors comments --- nano/node/bootstrap/bootstrap.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index b73dd04e64..bc0c1428d4 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -624,7 +624,9 @@ void nano::bootstrap_attempt::lazy_pull_flush () double lazy_blocks_ratio (total_blocks / lazy_blocks.size ()); if (lazy_blocks_ratio > nano::bootstrap_limits::lazy_batch_pull_count_resize_ratio) { + // Increasing blocks ratio weight as more important (^3). Small batch count should lower blocks ratio below target double lazy_blocks_factor (std::pow (lazy_blocks_ratio / nano::bootstrap_limits::lazy_batch_pull_count_resize_ratio, 3.0)); + // Decreasing total block count weight as less important (sqrt) double total_blocks_factor (std::sqrt (total_blocks / nano::bootstrap_limits::lazy_batch_pull_count_resize_blocks_limit)); uint32_t batch_count_min (node->network_params.bootstrap.lazy_max_pull_blocks / (lazy_blocks_factor * total_blocks_factor)); batch_count = std::max (node->network_params.bootstrap.lazy_min_pull_blocks, batch_count_min); From 2d31e4e82325d71345c0b2a1102a36acb47e3bda Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Thu, 24 Oct 2019 19:26:33 +0300 Subject: [PATCH 21/22] Fix lazy bootstrap requeue pull --- nano/node/bootstrap/bootstrap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 03b3bd6c0d..f6bebb9c42 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -557,7 +557,7 @@ void nano::bootstrap_attempt::requeue_pull (nano::pull_info const & pull_a) auto pull (pull_a); ++pull.attempts; ++requeued_pulls; - if (pull.attempts < pull.retry_limit + (pull.processed / 10000)) + if (mode != nano::bootstrap_mode::lazy && pull.attempts < pull.retry_limit + (pull.processed / 10000)) { nano::lock_guard lock (mutex); pulls.push_front (pull); From 5d842dd4f6c57b8e6a48cdd3c18b42be88229918 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Fri, 25 Oct 2019 00:16:56 +0300 Subject: [PATCH 22/22] Simplify request_pull function --- nano/node/bootstrap/bootstrap.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 3d304a364b..caef2fe1a7 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -148,9 +148,7 @@ void nano::bootstrap_attempt::request_pull (nano::unique_lock & lock if (mode != nano::bootstrap_mode::legacy) { // Check if pull is obsolete (head was processed) - nano::lock_guard lazy_lock (lazy_mutex); - auto transaction (node->store.tx_begin_read ()); - while (!pulls.empty () && !pull.head.is_zero () && (lazy_blocks.find (pull.head) != lazy_blocks.end () || node->store.block_exists (transaction, pull.head))) + while (!pulls.empty () && !pull.head.is_zero () && lazy_processed_or_exists (pull.head)) { pull = pulls.front (); pulls.pop_front ();