Skip to content

Commit

Permalink
Reinsert unblocked with default priority
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Nov 12, 2024
1 parent b851b75 commit 694d975
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 39 deletions.
11 changes: 6 additions & 5 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ TEST (account_sets, block)
nano::account account{ 1 };
nano::account_sets_config config;
nano::bootstrap::account_sets sets{ config, system.stats };
sets.priority_up (account);
sets.block (account, random_hash ());
ASSERT_TRUE (sets.blocked (account));
}
Expand All @@ -67,7 +68,9 @@ TEST (account_sets, unblock)
nano::account_sets_config config;
nano::bootstrap::account_sets sets{ config, system.stats };
auto hash = random_hash ();
sets.priority_up (account);
sets.block (account, hash);
ASSERT_TRUE (sets.blocked (account));
sets.unblock (account, hash);
ASSERT_FALSE (sets.blocked (account));
}
Expand All @@ -93,22 +96,20 @@ TEST (account_sets, priority_blocked)
ASSERT_EQ (0.0, sets.priority (account));
}

// When account is unblocked, check that it retains it former priority
TEST (account_sets, priority_unblock_keep)
TEST (account_sets, priority_unblock)
{
nano::test::system system;

nano::account account{ 1 };
nano::account_sets_config config;
nano::bootstrap::account_sets sets{ config, system.stats };
sets.priority_up (account);
sets.priority_up (account);
ASSERT_EQ (sets.priority (account), nano::bootstrap::account_sets::priority_initial + nano::bootstrap::account_sets::priority_increase);
ASSERT_EQ (sets.priority (account), nano::bootstrap::account_sets::priority_initial);
auto hash = random_hash ();
sets.block (account, hash);
ASSERT_EQ (0.0, sets.priority (account));
sets.unblock (account, hash);
ASSERT_EQ (sets.priority (account), nano::bootstrap::account_sets::priority_initial + nano::bootstrap::account_sets::priority_increase);
ASSERT_EQ (sets.priority (account), nano::bootstrap::account_sets::priority_initial);
}

TEST (account_sets, priority_up_down)
Expand Down
2 changes: 2 additions & 0 deletions nano/lib/stats_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ enum class detail
prioritize,
prioritize_failed,
block,
block_failed,
unblock,
unblock_failed,
dependency_update,
Expand All @@ -490,6 +491,7 @@ enum class detail
blocking_overflow,
priority_insert,
priority_set,
priority_unblocked,
erase_by_threshold,
erase_by_blocking,
priority_overflow,
Expand Down
36 changes: 15 additions & 21 deletions nano/node/bootstrap/account_sets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,20 @@ void nano::bootstrap::account_sets::block (nano::account const & account, nano::
{
debug_assert (!account.is_zero ());

stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::block);

auto existing = priorities.get<tag_account> ().find (account);
auto entry = (existing == priorities.get<tag_account> ().end ()) ? priority_entry{ account, 0 } : *existing;

priorities.get<tag_account> ().erase (account);
stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::erase_by_blocking);

blocking.get<tag_account> ().insert ({ entry, dependency });
stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::blocking_insert);
auto erased = priorities.get<tag_account> ().erase (account);
if (erased > 0)
{
stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::erase_by_blocking);
stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::block);

trim_overflow ();
debug_assert (blocking.get<tag_account> ().count (account) == 0);
blocking.get<tag_account> ().insert ({ account, dependency });
trim_overflow ();
}
else
{
stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::block_failed);
}
}

void nano::bootstrap::account_sets::unblock (nano::account const & account, std::optional<nano::block_hash> const & hash)
Expand All @@ -131,19 +133,11 @@ void nano::bootstrap::account_sets::unblock (nano::account const & account, std:
if (existing != blocking.get<tag_account> ().end () && (!hash || existing->dependency == *hash))
{
stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::unblock);
stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::priority_unblocked);

debug_assert (priorities.get<tag_account> ().count (account) == 0);
if (!existing->original_entry.account.is_zero ())
{
debug_assert (existing->original_entry.account == account);
priorities.get<tag_account> ().insert (existing->original_entry);
}
else
{
priorities.get<tag_account> ().insert ({ account, account_sets::priority_initial });
}
priorities.get<tag_account> ().insert ({ account, account_sets::priority_initial });
blocking.get<tag_account> ().erase (account);

trim_overflow ();
}
else
Expand Down
15 changes: 3 additions & 12 deletions nano/node/bootstrap/account_sets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,16 @@ namespace bootstrap
nano::account account;
double priority;
unsigned fails{ 0 };
id_t id{ generate_id () }; // Uniformly distributed, used for random querying
std::chrono::steady_clock::time_point timestamp{};
id_t id{ generate_id () }; // Uniformly distributed, used for random querying
};

struct blocking_entry
{
priority_entry original_entry;
nano::account account;
nano::block_hash dependency;
nano::account dependency_account{ 0 };
id_t id{ generate_id () }; // Uniformly distributed, used for random querying

nano::account account () const
{
return original_entry.account;
}
double priority () const
{
return original_entry.priority;
}
};

// clang-format off
Expand Down Expand Up @@ -142,7 +133,7 @@ namespace bootstrap
mi::indexed_by<
mi::sequenced<mi::tag<tag_sequenced>>,
mi::ordered_unique<mi::tag<tag_account>,
mi::const_mem_fun<blocking_entry, nano::account, &blocking_entry::account>>,
mi::member<blocking_entry, nano::account, &blocking_entry::account>>,
mi::ordered_non_unique<mi::tag<tag_dependency>,
mi::member<blocking_entry, nano::block_hash, &blocking_entry::dependency>>,
mi::ordered_non_unique<mi::tag<tag_dependency_account>,
Expand Down
2 changes: 1 addition & 1 deletion nano/node/json_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5182,7 +5182,7 @@ void nano::json_handler::debug_bootstrap_priority_info ()
boost::property_tree::ptree response_blocking;
for (auto const & entry : blocking)
{
const auto account = entry.account ();
const auto account = entry.account;
const auto dependency = entry.dependency;

response_blocking.put (account.to_account (), dependency.to_string ());
Expand Down

0 comments on commit 694d975

Please sign in to comment.