Skip to content

Commit

Permalink
Merge pull request #4784 from pwojcikdev/bootstrap-tuning-3
Browse files Browse the repository at this point in the history
Bootstrap tuning
  • Loading branch information
pwojcikdev authored Nov 22, 2024
2 parents d843dbb + 694d975 commit 22abd71
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 169 deletions.
70 changes: 43 additions & 27 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ nano::block_hash random_hash ()
}
}

/*
* account_sets
*/

TEST (account_sets, construction)
{
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::bootstrap::account_sets sets{ config, system.stats };
}
Expand All @@ -41,8 +43,6 @@ TEST (account_sets, empty_blocked)
nano::test::system system;

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::bootstrap::account_sets sets{ config, system.stats };
ASSERT_FALSE (sets.blocked (account));
Expand All @@ -53,10 +53,9 @@ TEST (account_sets, block)
nano::test::system system;

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::bootstrap::account_sets sets{ config, system.stats };
sets.priority_up (account);
sets.block (account, random_hash ());
ASSERT_TRUE (sets.blocked (account));
}
Expand All @@ -66,12 +65,12 @@ TEST (account_sets, unblock)
nano::test::system system;

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::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 @@ -81,8 +80,6 @@ TEST (account_sets, priority_base)
nano::test::system system;

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::bootstrap::account_sets sets{ config, system.stats };
ASSERT_EQ (0.0, sets.priority (account));
Expand All @@ -93,70 +90,85 @@ TEST (account_sets, priority_blocked)
nano::test::system system;

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::bootstrap::account_sets sets{ config, system.stats };
sets.block (account, random_hash ());
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 };
auto store = nano::make_store (system.logger, nano::unique_path (), nano::dev::constants);
ASSERT_FALSE (store->init_error ());
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)
{
nano::test::system system;

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::bootstrap::account_sets sets{ config, system.stats };
sets.priority_up (account);
ASSERT_EQ (sets.priority (account), nano::bootstrap::account_sets::priority_initial);
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::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::bootstrap::account_sets sets{ config, system.stats };
sets.priority_down (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
TEST (account_sets, saturate_priority)
{
nano::test::system system;

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::bootstrap::account_sets sets{ config, system.stats };
for (int n = 0; n < 1000; ++n)
Expand All @@ -166,6 +178,10 @@ TEST (account_sets, saturate_priority)
ASSERT_EQ (sets.priority (account), nano::bootstrap::account_sets::priority_max);
}

/*
* bootstrap
*/

/**
* Tests the base case for returning
*/
Expand Down
16 changes: 12 additions & 4 deletions nano/lib/stats_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ enum class type
bootstrap_frontiers,
bootstrap_account_sets,
bootstrap_frontier_scan,
bootstrap_timeout,
bootstrap_server,
bootstrap_server_request,
bootstrap_server_overfill,
Expand Down Expand Up @@ -145,6 +146,7 @@ enum class detail
retry,
prioritized,
pending,
sync,

// processing queue
queue,
Expand Down Expand Up @@ -456,13 +458,16 @@ enum class detail
loop_frontiers_processing,
duplicate_request,
invalid_response_type,
invalid_response,
timestamp_reset,
processing_frontiers,
frontiers_dropped,
sync_accounts,

prioritize,
prioritize_failed,
block,
block_failed,
unblock,
unblock_failed,
dependency_update,
Expand All @@ -483,14 +488,17 @@ enum class detail
next_frontier,

blocking_insert,
blocking_erase_overflow,
blocking_overflow,
priority_insert,
priority_erase_by_threshold,
priority_erase_by_blocking,
priority_erase_overflow,
priority_set,
priority_unblocked,
erase_by_threshold,
erase_by_blocking,
priority_overflow,
deprioritize,
deprioritize_failed,
sync_dependencies,
dependency_synced,

request_blocks,
request_account_info,
Expand Down
2 changes: 1 addition & 1 deletion nano/lib/thread_roles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ std::string nano::thread_role::get_string (nano::thread_role::name role)
case nano::thread_role::name::bootstrap_database_scan:
thread_role_name_string = "Bootstrap db";
break;
case nano::thread_role::name::bootstrap_dependendy_walker:
case nano::thread_role::name::bootstrap_dependency_walker:
thread_role_name_string = "Bootstrap walkr";
break;
case nano::thread_role::name::bootstrap_frontier_scan:
Expand Down
2 changes: 1 addition & 1 deletion nano/lib/thread_roles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum class name
telemetry,
bootstrap,
bootstrap_database_scan,
bootstrap_dependendy_walker,
bootstrap_dependency_walker,
bootstrap_frontier_scan,
bootstrap_cleanup,
bootstrap_worker,
Expand Down
Loading

0 comments on commit 22abd71

Please sign in to comment.