From 9d02d03bcb85e77976939d9e17cfbea25252c815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Sun, 11 Aug 2024 13:06:13 +0200 Subject: [PATCH] Bootstrap fixes (#4699) --- nano/node/bootstrap_ascending/account_sets.cpp | 10 ++++++++++ nano/node/bootstrap_ascending/account_sets.hpp | 2 ++ nano/node/bootstrap_ascending/service.cpp | 14 +++++++++----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/nano/node/bootstrap_ascending/account_sets.cpp b/nano/node/bootstrap_ascending/account_sets.cpp index c92308793a..404f337b77 100644 --- a/nano/node/bootstrap_ascending/account_sets.cpp +++ b/nano/node/bootstrap_ascending/account_sets.cpp @@ -316,6 +316,16 @@ std::size_t nano::bootstrap_ascending::account_sets::blocked_size () const return blocking.size (); } +bool nano::bootstrap_ascending::account_sets::priority_half_full () const +{ + return priorities.size () > config.priorities_max / 2; +} + +bool nano::bootstrap_ascending::account_sets::blocked_half_full () const +{ + return blocking.size () > config.blocking_max / 2; +} + double nano::bootstrap_ascending::account_sets::priority (nano::account const & account) const { if (!blocked (account)) diff --git a/nano/node/bootstrap_ascending/account_sets.hpp b/nano/node/bootstrap_ascending/account_sets.hpp index c3f9b187da..4b2d0cedb9 100644 --- a/nano/node/bootstrap_ascending/account_sets.hpp +++ b/nano/node/bootstrap_ascending/account_sets.hpp @@ -71,6 +71,8 @@ namespace bootstrap_ascending std::size_t priority_size () const; std::size_t blocked_size () const; + bool priority_half_full () const; + bool blocked_half_full () const; std::unique_ptr collect_container_info (std::string const & name); diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index f0f1b531ad..59e989aadb 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -215,16 +215,20 @@ void nano::bootstrap_ascending::service::inspect (secure::transaction const & tx break; case nano::block_status::gap_source: { - const auto account = block.previous ().is_zero () ? block.account_field ().value () : ledger.any.block_account (tx, block.previous ()).value (); - const auto source = block.source_field ().value_or (block.link_field ().value_or (0).as_block_hash ()); + if (source == nano::block_source::bootstrap) + { + const auto account = block.previous ().is_zero () ? block.account_field ().value () : ledger.any.block_account (tx, block.previous ()).value (); + const auto source_hash = block.source_field ().value_or (block.link_field ().value_or (0).as_block_hash ()); - // Mark account as blocked because it is missing the source block - accounts.block (account, source); + // Mark account as blocked because it is missing the source block + accounts.block (account, source_hash); + } } break; case nano::block_status::gap_previous: { - if (source == nano::block_source::live) + // Prevent live traffic from evicting accounts from the priority list + if (source == nano::block_source::live && !accounts.priority_half_full () && !accounts.blocked_half_full ()) { if (block.type () == block_type::state) {