Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable work watcher period #2222

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,12 @@ TEST (node_config, v17_v18_upgrade)
config.logging.init (path);
// These config options should not be present
ASSERT_FALSE (tree.get_optional_child ("backup_before_upgrade"));
ASSERT_FALSE (tree.get_optional_child ("work_watcher_period"));

config.deserialize_json (upgraded, tree);
// The config options should be added after the upgrade
ASSERT_TRUE (!!tree.get_optional_child ("backup_before_upgrade"));
ASSERT_TRUE (!!tree.get_optional_child ("work_watcher_period"));

ASSERT_TRUE (upgraded);
auto version (tree.get<std::string> ("version"));
Expand All @@ -880,22 +882,26 @@ TEST (node_config, v18_values)
{
tree.put ("vote_generator_delay", 100);
tree.put ("backup_before_upgrade", true);
tree.put ("work_watcher_period", 5);
}

config.deserialize_json (upgraded, tree);
ASSERT_FALSE (upgraded);
ASSERT_EQ (config.vote_generator_delay.count (), 100);
ASSERT_EQ (config.backup_before_upgrade, true);
ASSERT_EQ (config.work_watcher_period.count (), 5);

// Check config is correct with other values
tree.put ("vote_generator_delay", std::numeric_limits<unsigned long>::max () - 100);
tree.put ("backup_before_upgrade", false);
tree.put ("work_watcher_period", 999);

upgraded = false;
config.deserialize_json (upgraded, tree);
ASSERT_FALSE (upgraded);
ASSERT_EQ (config.vote_generator_delay.count (), std::numeric_limits<unsigned long>::max () - 100);
ASSERT_EQ (config.backup_before_upgrade, false);
ASSERT_EQ (config.work_watcher_period.count (), 999);
}

// Regression test to ensure that deserializing includes changes node via get_required_child
Expand Down
10 changes: 10 additions & 0 deletions nano/node/nodeconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ nano::error nano::node_config::serialize_json (nano::jsonconfig & json) const
json.put ("active_elections_size", active_elections_size);
json.put ("bandwidth_limit", bandwidth_limit);
json.put ("backup_before_upgrade", backup_before_upgrade);
json.put ("work_watcher_period", work_watcher_period.count ());

return json.get_error ();
}
Expand Down Expand Up @@ -259,6 +260,7 @@ bool nano::node_config::upgrade_json (unsigned version_a, nano::jsonconfig & jso
{
json.put ("vote_generator_delay", vote_generator_delay.count ()); // Update value
json.put ("backup_before_upgrade", backup_before_upgrade);
json.put ("work_watcher_period", work_watcher_period.count ());
}
case 18:
break;
Expand Down Expand Up @@ -414,6 +416,10 @@ nano::error nano::node_config::deserialize_json (bool & upgraded_a, nano::jsonco
json.get<size_t> ("bandwidth_limit", bandwidth_limit);
json.get<bool> ("backup_before_upgrade", backup_before_upgrade);

auto work_watcher_period_l = work_watcher_period.count ();
json.get ("work_watcher_period", work_watcher_period_l);
work_watcher_period = std::chrono::seconds (work_watcher_period_l);

auto conf_height_processor_batch_min_time_l (conf_height_processor_batch_min_time.count ());
json.get ("conf_height_processor_batch_min_time", conf_height_processor_batch_min_time_l);
conf_height_processor_batch_min_time = std::chrono::milliseconds (conf_height_processor_batch_min_time_l);
Expand Down Expand Up @@ -444,6 +450,10 @@ nano::error nano::node_config::deserialize_json (bool & upgraded_a, nano::jsonco
{
json.get_error ().set ("vote_generator_threshold must be a number between 1 and 11");
}
if (work_watcher_period < std::chrono::seconds (1))
{
json.get_error ().set ("work_watcher_period must be equal or larger than 1");
}
}
catch (std::runtime_error const & ex)
{
Expand Down
1 change: 1 addition & 0 deletions nano/node/nodeconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class node_config
size_t bandwidth_limit{ 5 * 1024 * 1024 }; // 5Mb/s
std::chrono::milliseconds conf_height_processor_batch_min_time{ 50 };
bool backup_before_upgrade{ false };
std::chrono::seconds work_watcher_period{ std::chrono::seconds (5) };
static unsigned json_version ()
{
return 18;
Expand Down
12 changes: 8 additions & 4 deletions nano/node/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1424,10 +1424,7 @@ void nano::work_watcher::run ()
std::chrono::steady_clock::time_point next_attempt;
while (!stopped)
{
condition.wait_until (lock, next_attempt, [this, &next_attempt]() {
return stopped || next_attempt < std::chrono::steady_clock::now ();
});
next_attempt = std::chrono::steady_clock::now () + std::chrono::seconds (5);
next_attempt = std::chrono::steady_clock::now () + node.config.work_watcher_period;
for (auto i (blocks.begin ()), n (blocks.end ()); i != n;)
{
std::unique_lock<std::mutex> active_lock (node.active.mutex);
Expand Down Expand Up @@ -1520,6 +1517,13 @@ void nano::work_watcher::run ()
}
}
}

if (!stopped)
{
condition.wait_until (lock, next_attempt, [this, &next_attempt]() {
return stopped || next_attempt < std::chrono::steady_clock::now ();
});
}
} // !stopped
}

Expand Down