From 91673937bd4a41c7eecf17e9cc8f1cd6ee99ca4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 6 Jan 2025 21:02:19 +0100 Subject: [PATCH] Handle `gap_epoch_open_pending` block status --- nano/lib/stats_enums.hpp | 1 + nano/node/bootstrap/account_sets.cpp | 13 +++++++++++++ nano/node/bootstrap/account_sets.hpp | 10 +--------- nano/node/bootstrap/bootstrap_service.cpp | 9 +++++++++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/nano/lib/stats_enums.hpp b/nano/lib/stats_enums.hpp index 429741d2f3..31b3c71821 100644 --- a/nano/lib/stats_enums.hpp +++ b/nano/lib/stats_enums.hpp @@ -528,6 +528,7 @@ enum class detail blocking_overflow, priority_insert, priority_set, + priority_erase, priority_unblocked, erase_by_threshold, erase_by_blocking, diff --git a/nano/node/bootstrap/account_sets.cpp b/nano/node/bootstrap/account_sets.cpp index 421ffddb46..dfd33cc801 100644 --- a/nano/node/bootstrap/account_sets.cpp +++ b/nano/node/bootstrap/account_sets.cpp @@ -104,6 +104,19 @@ void nano::bootstrap::account_sets::priority_set (nano::account const & account, } } +void nano::bootstrap::account_sets::priority_erase (nano::account const & account) +{ + if (account.is_zero ()) + { + return; + } + + if (priorities.get ().erase (account) > 0) + { + stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::priority_erase); + } +} + void nano::bootstrap::account_sets::block (nano::account const & account, nano::block_hash const & dependency) { debug_assert (!account.is_zero ()); diff --git a/nano/node/bootstrap/account_sets.hpp b/nano/node/bootstrap/account_sets.hpp index cac5785c8a..bf398e9328 100644 --- a/nano/node/bootstrap/account_sets.hpp +++ b/nano/node/bootstrap/account_sets.hpp @@ -33,18 +33,10 @@ class account_sets public: account_sets (account_sets_config const &, nano::stats &); - /** - * If an account is not blocked, increase its priority. - * If the account does not exist in priority set and is not blocked, inserts a new entry. - * Current implementation increases priority by 1.0f each increment - */ void priority_up (nano::account const & account); - /** - * Decreases account priority - * Current implementation divides priority by 2.0f and saturates down to 1.0f. - */ void priority_down (nano::account const & account); void priority_set (nano::account const & account, double priority = priority_initial); + void priority_erase (nano::account const & account); void block (nano::account const & account, nano::block_hash const & dependency); void unblock (nano::account const & account, std::optional const & hash = std::nullopt); diff --git a/nano/node/bootstrap/bootstrap_service.cpp b/nano/node/bootstrap/bootstrap_service.cpp index 8f60f9924f..5d864a0909 100644 --- a/nano/node/bootstrap/bootstrap_service.cpp +++ b/nano/node/bootstrap/bootstrap_service.cpp @@ -326,7 +326,16 @@ void nano::bootstrap_service::inspect (secure::transaction const & tx, nano::blo } } break; + case nano::block_status::gap_epoch_open_pending: + { + // Epoch open blocks for accounts that don't have any pending blocks yet + debug_assert (block.type () == block_type::state); // Only state blocks can have epoch open pending status + const auto account = block.account_field ().value_or (0); + accounts.priority_erase (account); + } + break; default: // No need to handle other cases + // TODO: If we receive blocks that are invalid (bad signature, fork, etc.), we should penalize the peer that sent them break; } }