Skip to content

Commit

Permalink
Config serialization/deseriaization
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Nov 7, 2023
1 parent 2de026d commit 4aa3cf4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions nano/core_test/toml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ TEST (toml, daemon_config_deserialize_defaults)
ASSERT_EQ (conf.node.hinted_scheduler.hinting_threshold_percent, defaults.node.hinted_scheduler.hinting_threshold_percent);
ASSERT_EQ (conf.node.hinted_scheduler.check_interval.count (), defaults.node.hinted_scheduler.check_interval.count ());
ASSERT_EQ (conf.node.hinted_scheduler.block_cooldown.count (), defaults.node.hinted_scheduler.block_cooldown.count ());
ASSERT_EQ (conf.node.hinted_scheduler.vacancy_threshold_percent, defaults.node.hinted_scheduler.vacancy_threshold_percent);

ASSERT_EQ (conf.node.vote_cache.max_size, defaults.node.vote_cache.max_size);
ASSERT_EQ (conf.node.vote_cache.max_voters, defaults.node.vote_cache.max_voters);
Expand Down Expand Up @@ -543,6 +544,7 @@ TEST (toml, daemon_config_deserialize_no_defaults)
hinting_threshold = 99
check_interval = 999
block_cooldown = 999
vacancy_threshold = 99
[node.rocksdb]
enable = true
Expand Down Expand Up @@ -720,6 +722,7 @@ TEST (toml, daemon_config_deserialize_no_defaults)
ASSERT_NE (conf.node.hinted_scheduler.hinting_threshold_percent, defaults.node.hinted_scheduler.hinting_threshold_percent);
ASSERT_NE (conf.node.hinted_scheduler.check_interval.count (), defaults.node.hinted_scheduler.check_interval.count ());
ASSERT_NE (conf.node.hinted_scheduler.block_cooldown.count (), defaults.node.hinted_scheduler.block_cooldown.count ());
ASSERT_NE (conf.node.hinted_scheduler.vacancy_threshold_percent, defaults.node.hinted_scheduler.vacancy_threshold_percent);

ASSERT_NE (conf.node.vote_cache.max_size, defaults.node.vote_cache.max_size);
ASSERT_NE (conf.node.vote_cache.max_voters, defaults.node.vote_cache.max_voters);
Expand Down
9 changes: 8 additions & 1 deletion nano/node/scheduler/hinted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void nano::scheduler::hinted::notify ()
{
// Avoid notifying when there is very little space inside AEC
auto const limit = active.limit (nano::election_behavior::hinted);
if (active.vacancy (nano::election_behavior::hinted) >= (limit * config.vaccancy_threshold_percent / 100))
if (active.vacancy (nano::election_behavior::hinted) >= (limit * config.vacancy_threshold_percent / 100))
{
condition.notify_all ();
}
Expand Down Expand Up @@ -230,6 +230,7 @@ nano::error nano::scheduler::hinted_config::serialize (nano::tomlconfig & toml)
toml.put ("hinting_threshold", hinting_threshold_percent, "Percentage of online weight needed to start a hinted election. \ntype:uint32,[0,100]");
toml.put ("check_interval", check_interval.count (), "Interval between scans of the vote cache for possible hinted elections. \ntype:milliseconds");
toml.put ("block_cooldown", block_cooldown.count (), "Cooldown period for blocks that failed to start an election. \ntype:milliseconds");
toml.put ("vacancy_threshold", vacancy_threshold_percent, "Percentage of available space in the active elections container needed to trigger a scan for hinted elections (before the check interval elapses). \ntype:uint32,[0,100]");

return toml.get_error ();
}
Expand All @@ -246,10 +247,16 @@ nano::error nano::scheduler::hinted_config::deserialize (nano::tomlconfig & toml
toml.get ("block_cooldown", block_cooldown_l);
block_cooldown = std::chrono::milliseconds{ block_cooldown_l };

toml.get ("vacancy_threshold", vacancy_threshold_percent);

if (hinting_threshold_percent > 100)
{
toml.get_error ().set ("hinting_threshold must be a number between 0 and 100");
}
if (vacancy_threshold_percent > 100)
{
toml.get_error ().set ("vacancy_threshold must be a number between 0 and 100");
}

return toml.get_error ();
}
2 changes: 1 addition & 1 deletion nano/node/scheduler/hinted.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class hinted_config final
std::chrono::milliseconds check_interval{ 1000 };
std::chrono::milliseconds block_cooldown{ 10000 };
unsigned hinting_threshold_percent{ 10 };
unsigned vaccancy_threshold_percent{ 20 };
unsigned vacancy_threshold_percent{ 20 };
};

/*
Expand Down
5 changes: 5 additions & 0 deletions nano/node/vote_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ nano::error nano::vote_cache_config::serialize (nano::tomlconfig & toml) const
{
toml.put ("max_size", max_size, "Maximum number of blocks to cache votes for. \ntype:uint64");
toml.put ("max_voters", max_voters, "Maximum number of voters to cache per block. \ntype:uint64");
toml.put ("age_cutoff", age_cutoff.count (), "Maximum age of votes to keep in cache. \ntype:seconds");

return toml.get_error ();
}
Expand All @@ -277,5 +278,9 @@ nano::error nano::vote_cache_config::deserialize (nano::tomlconfig & toml)
toml.get ("max_size", max_size);
toml.get ("max_voters", max_voters);

auto age_cutoff_l = age_cutoff.count ();
toml.get ("age_cutoff", age_cutoff_l);
age_cutoff = std::chrono::seconds{ age_cutoff_l };

return toml.get_error ();
}

0 comments on commit 4aa3cf4

Please sign in to comment.