Track fails
This commit is contained in:
parent
a6aa9a7924
commit
e9608c89e5
3 changed files with 49 additions and 38 deletions
|
|
@ -27,11 +27,13 @@ nano::block_hash random_hash ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* account_sets
|
||||||
|
*/
|
||||||
|
|
||||||
TEST (account_sets, construction)
|
TEST (account_sets, construction)
|
||||||
{
|
{
|
||||||
nano::test::system system;
|
nano::test::system system;
|
||||||
auto store = nano::make_store (system.logger, nano::unique_path (), nano::dev::constants);
|
|
||||||
ASSERT_FALSE (store->init_error ());
|
|
||||||
nano::account_sets_config config;
|
nano::account_sets_config config;
|
||||||
nano::bootstrap::account_sets sets{ config, system.stats };
|
nano::bootstrap::account_sets sets{ config, system.stats };
|
||||||
}
|
}
|
||||||
|
|
@ -41,8 +43,6 @@ TEST (account_sets, empty_blocked)
|
||||||
nano::test::system system;
|
nano::test::system system;
|
||||||
|
|
||||||
nano::account account{ 1 };
|
nano::account account{ 1 };
|
||||||
auto store = nano::make_store (system.logger, nano::unique_path (), nano::dev::constants);
|
|
||||||
ASSERT_FALSE (store->init_error ());
|
|
||||||
nano::account_sets_config config;
|
nano::account_sets_config config;
|
||||||
nano::bootstrap::account_sets sets{ config, system.stats };
|
nano::bootstrap::account_sets sets{ config, system.stats };
|
||||||
ASSERT_FALSE (sets.blocked (account));
|
ASSERT_FALSE (sets.blocked (account));
|
||||||
|
|
@ -53,8 +53,6 @@ TEST (account_sets, block)
|
||||||
nano::test::system system;
|
nano::test::system system;
|
||||||
|
|
||||||
nano::account account{ 1 };
|
nano::account account{ 1 };
|
||||||
auto store = nano::make_store (system.logger, nano::unique_path (), nano::dev::constants);
|
|
||||||
ASSERT_FALSE (store->init_error ());
|
|
||||||
nano::account_sets_config config;
|
nano::account_sets_config config;
|
||||||
nano::bootstrap::account_sets sets{ config, system.stats };
|
nano::bootstrap::account_sets sets{ config, system.stats };
|
||||||
sets.block (account, random_hash ());
|
sets.block (account, random_hash ());
|
||||||
|
|
@ -66,8 +64,6 @@ TEST (account_sets, unblock)
|
||||||
nano::test::system system;
|
nano::test::system system;
|
||||||
|
|
||||||
nano::account account{ 1 };
|
nano::account account{ 1 };
|
||||||
auto store = nano::make_store (system.logger, nano::unique_path (), nano::dev::constants);
|
|
||||||
ASSERT_FALSE (store->init_error ());
|
|
||||||
nano::account_sets_config config;
|
nano::account_sets_config config;
|
||||||
nano::bootstrap::account_sets sets{ config, system.stats };
|
nano::bootstrap::account_sets sets{ config, system.stats };
|
||||||
auto hash = random_hash ();
|
auto hash = random_hash ();
|
||||||
|
|
@ -81,8 +77,6 @@ TEST (account_sets, priority_base)
|
||||||
nano::test::system system;
|
nano::test::system system;
|
||||||
|
|
||||||
nano::account account{ 1 };
|
nano::account account{ 1 };
|
||||||
auto store = nano::make_store (system.logger, nano::unique_path (), nano::dev::constants);
|
|
||||||
ASSERT_FALSE (store->init_error ());
|
|
||||||
nano::account_sets_config config;
|
nano::account_sets_config config;
|
||||||
nano::bootstrap::account_sets sets{ config, system.stats };
|
nano::bootstrap::account_sets sets{ config, system.stats };
|
||||||
ASSERT_EQ (0.0, sets.priority (account));
|
ASSERT_EQ (0.0, sets.priority (account));
|
||||||
|
|
@ -93,8 +87,6 @@ TEST (account_sets, priority_blocked)
|
||||||
nano::test::system system;
|
nano::test::system system;
|
||||||
|
|
||||||
nano::account account{ 1 };
|
nano::account account{ 1 };
|
||||||
auto store = nano::make_store (system.logger, nano::unique_path (), nano::dev::constants);
|
|
||||||
ASSERT_FALSE (store->init_error ());
|
|
||||||
nano::account_sets_config config;
|
nano::account_sets_config config;
|
||||||
nano::bootstrap::account_sets sets{ config, system.stats };
|
nano::bootstrap::account_sets sets{ config, system.stats };
|
||||||
sets.block (account, random_hash ());
|
sets.block (account, random_hash ());
|
||||||
|
|
@ -107,8 +99,6 @@ TEST (account_sets, priority_unblock_keep)
|
||||||
nano::test::system system;
|
nano::test::system system;
|
||||||
|
|
||||||
nano::account account{ 1 };
|
nano::account account{ 1 };
|
||||||
auto store = nano::make_store (system.logger, nano::unique_path (), nano::dev::constants);
|
|
||||||
ASSERT_FALSE (store->init_error ());
|
|
||||||
nano::account_sets_config config;
|
nano::account_sets_config config;
|
||||||
nano::bootstrap::account_sets sets{ config, system.stats };
|
nano::bootstrap::account_sets sets{ config, system.stats };
|
||||||
sets.priority_up (account);
|
sets.priority_up (account);
|
||||||
|
|
@ -126,37 +116,58 @@ TEST (account_sets, priority_up_down)
|
||||||
nano::test::system system;
|
nano::test::system system;
|
||||||
|
|
||||||
nano::account account{ 1 };
|
nano::account account{ 1 };
|
||||||
auto store = nano::make_store (system.logger, nano::unique_path (), nano::dev::constants);
|
|
||||||
ASSERT_FALSE (store->init_error ());
|
|
||||||
nano::account_sets_config config;
|
nano::account_sets_config config;
|
||||||
nano::bootstrap::account_sets sets{ config, system.stats };
|
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);
|
ASSERT_EQ (sets.priority (account), nano::bootstrap::account_sets::priority_initial);
|
||||||
sets.priority_down (account);
|
sets.priority_down (account);
|
||||||
ASSERT_EQ (sets.priority (account), nano::bootstrap::account_sets::priority_initial / nano::bootstrap::account_sets::priority_divide);
|
ASSERT_EQ (sets.priority (account), nano::bootstrap::account_sets::priority_initial);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST (account_sets, priority_down_sat)
|
TEST (account_sets, priority_down_empty)
|
||||||
{
|
{
|
||||||
nano::test::system system;
|
nano::test::system system;
|
||||||
|
|
||||||
nano::account account{ 1 };
|
nano::account account{ 1 };
|
||||||
auto store = nano::make_store (system.logger, nano::unique_path (), nano::dev::constants);
|
|
||||||
ASSERT_FALSE (store->init_error ());
|
|
||||||
nano::account_sets_config config;
|
nano::account_sets_config config;
|
||||||
nano::bootstrap::account_sets sets{ config, system.stats };
|
nano::bootstrap::account_sets sets{ config, system.stats };
|
||||||
sets.priority_down (account);
|
sets.priority_down (account);
|
||||||
ASSERT_EQ (0.0, sets.priority (account));
|
ASSERT_EQ (0.0, sets.priority (account));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST (account_sets, priority_down_saturate)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
ASSERT_EQ (sets.priority (account), nano::bootstrap::account_sets::priority_initial);
|
||||||
|
for (int n = 0; n < 1000; ++n)
|
||||||
|
{
|
||||||
|
sets.priority_down (account);
|
||||||
|
}
|
||||||
|
ASSERT_FALSE (sets.prioritized (account));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST (account_sets, priority_set)
|
||||||
|
{
|
||||||
|
nano::test::system system;
|
||||||
|
|
||||||
|
nano::account account{ 1 };
|
||||||
|
nano::account_sets_config config;
|
||||||
|
nano::bootstrap::account_sets sets{ config, system.stats };
|
||||||
|
sets.priority_set (account, 10.0);
|
||||||
|
ASSERT_EQ (sets.priority (account), 10.0);
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure priority value is bounded
|
// Ensure priority value is bounded
|
||||||
TEST (account_sets, saturate_priority)
|
TEST (account_sets, saturate_priority)
|
||||||
{
|
{
|
||||||
nano::test::system system;
|
nano::test::system system;
|
||||||
|
|
||||||
nano::account account{ 1 };
|
nano::account account{ 1 };
|
||||||
auto store = nano::make_store (system.logger, nano::unique_path (), nano::dev::constants);
|
|
||||||
ASSERT_FALSE (store->init_error ());
|
|
||||||
nano::account_sets_config config;
|
nano::account_sets_config config;
|
||||||
nano::bootstrap::account_sets sets{ config, system.stats };
|
nano::bootstrap::account_sets sets{ config, system.stats };
|
||||||
for (int n = 0; n < 1000; ++n)
|
for (int n = 0; n < 1000; ++n)
|
||||||
|
|
@ -166,6 +177,10 @@ TEST (account_sets, saturate_priority)
|
||||||
ASSERT_EQ (sets.priority (account), nano::bootstrap::account_sets::priority_max);
|
ASSERT_EQ (sets.priority (account), nano::bootstrap::account_sets::priority_max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bootstrap
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the base case for returning
|
* Tests the base case for returning
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,11 @@ void nano::bootstrap::account_sets::priority_up (nano::account const & account)
|
||||||
{
|
{
|
||||||
stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::prioritize);
|
stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::prioritize);
|
||||||
|
|
||||||
auto iter = priorities.get<tag_account> ().find (account);
|
if (auto it = priorities.get<tag_account> ().find (account); it != priorities.get<tag_account> ().end ())
|
||||||
if (iter != priorities.get<tag_account> ().end ())
|
|
||||||
{
|
{
|
||||||
priorities.get<tag_account> ().modify (iter, [] (auto & val) {
|
priorities.get<tag_account> ().modify (it, [] (auto & val) {
|
||||||
val.priority = std::min ((val.priority + account_sets::priority_increase), account_sets::priority_max);
|
val.priority = std::min ((val.priority + account_sets::priority_increase), account_sets::priority_max);
|
||||||
|
val.fails = 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -57,21 +57,19 @@ void nano::bootstrap::account_sets::priority_down (nano::account const & account
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto iter = priorities.get<tag_account> ().find (account);
|
if (auto it = priorities.get<tag_account> ().find (account); it != priorities.get<tag_account> ().end ())
|
||||||
if (iter != priorities.get<tag_account> ().end ())
|
|
||||||
{
|
{
|
||||||
stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::deprioritize);
|
stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::deprioritize);
|
||||||
|
|
||||||
auto priority_new = iter->priority / account_sets::priority_divide;
|
if (it->fails >= account_sets::max_fails || it->fails >= it->priority)
|
||||||
if (priority_new <= account_sets::priority_cutoff)
|
|
||||||
{
|
{
|
||||||
stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::erase_by_threshold);
|
stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::erase_by_threshold);
|
||||||
priorities.get<tag_account> ().erase (iter);
|
priorities.get<tag_account> ().erase (it);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
priorities.get<tag_account> ().modify (iter, [priority_new] (auto & val) {
|
priorities.get<tag_account> ().modify (it, [] (auto & val) {
|
||||||
val.priority = priority_new;
|
val.fails += 1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -90,8 +88,7 @@ void nano::bootstrap::account_sets::priority_set (nano::account const & account,
|
||||||
|
|
||||||
if (!blocked (account))
|
if (!blocked (account))
|
||||||
{
|
{
|
||||||
auto iter = priorities.get<tag_account> ().find (account);
|
if (!priorities.get<tag_account> ().contains (account))
|
||||||
if (iter == priorities.get<tag_account> ().end ())
|
|
||||||
{
|
{
|
||||||
stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::priority_set);
|
stats.inc (nano::stat::type::bootstrap_account_sets, nano::stat::detail::priority_set);
|
||||||
priorities.get<tag_account> ().insert ({ account, priority });
|
priorities.get<tag_account> ().insert ({ account, priority });
|
||||||
|
|
@ -332,8 +329,7 @@ double nano::bootstrap::account_sets::priority (nano::account const & account) c
|
||||||
{
|
{
|
||||||
if (!blocked (account))
|
if (!blocked (account))
|
||||||
{
|
{
|
||||||
auto existing = priorities.get<tag_account> ().find (account);
|
if (auto existing = priorities.get<tag_account> ().find (account); existing != priorities.get<tag_account> ().end ())
|
||||||
if (existing != priorities.get<tag_account> ().end ())
|
|
||||||
{
|
{
|
||||||
return existing->priority;
|
return existing->priority;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ namespace bootstrap
|
||||||
static double constexpr priority_divide = 2.0;
|
static double constexpr priority_divide = 2.0;
|
||||||
static double constexpr priority_max = 128.0;
|
static double constexpr priority_max = 128.0;
|
||||||
static double constexpr priority_cutoff = 0.15;
|
static double constexpr priority_cutoff = 0.15;
|
||||||
|
static unsigned constexpr max_fails = 2;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
account_sets (account_sets_config const &, nano::stats &);
|
account_sets (account_sets_config const &, nano::stats &);
|
||||||
|
|
@ -93,7 +94,7 @@ namespace bootstrap
|
||||||
{
|
{
|
||||||
nano::account account;
|
nano::account account;
|
||||||
double priority;
|
double priority;
|
||||||
|
unsigned fails{ 0 };
|
||||||
id_t id{ generate_id () }; // Uniformly distributed, used for random querying
|
id_t id{ generate_id () }; // Uniformly distributed, used for random querying
|
||||||
std::chrono::steady_clock::time_point timestamp{};
|
std::chrono::steady_clock::time_point timestamp{};
|
||||||
};
|
};
|
||||||
|
|
@ -103,7 +104,6 @@ namespace bootstrap
|
||||||
priority_entry original_entry;
|
priority_entry original_entry;
|
||||||
nano::block_hash dependency;
|
nano::block_hash dependency;
|
||||||
nano::account dependency_account{ 0 };
|
nano::account dependency_account{ 0 };
|
||||||
|
|
||||||
id_t id{ generate_id () }; // Uniformly distributed, used for random querying
|
id_t id{ generate_id () }; // Uniformly distributed, used for random querying
|
||||||
|
|
||||||
nano::account account () const
|
nano::account account () const
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue