Fork cache config implementation

This commit is contained in:
Piotr Wójcik 2025-04-04 16:14:00 +02:00
commit d682454665
4 changed files with 37 additions and 0 deletions

View file

@ -439,6 +439,7 @@ nano::stat::detail nano::to_stat_detail (nano::asc_pull_type type)
nano::error nano::bootstrap_server_config::serialize (nano::tomlconfig & toml) const
{
toml.put ("enable", enable, "Enable bootstrap server. \ntype:bool");
toml.put ("max_queue", max_queue, "Maximum number of queued requests per peer. \ntype:uint64");
toml.put ("threads", threads, "Number of threads to process requests. \ntype:uint64");
toml.put ("batch_size", batch_size, "Maximum number of requests to process in a single batch. \ntype:uint64");
@ -449,6 +450,7 @@ nano::error nano::bootstrap_server_config::serialize (nano::tomlconfig & toml) c
nano::error nano::bootstrap_server_config::deserialize (nano::tomlconfig & toml)
{
toml.get ("enable", enable);
toml.get ("max_queue", max_queue);
toml.get ("threads", threads);
toml.get ("batch_size", batch_size);

View file

@ -1,4 +1,5 @@
#include <nano/lib/stats.hpp>
#include <nano/lib/tomlconfig.hpp>
#include <nano/node/fork_cache.hpp>
#include <boost/range/iterator_range.hpp>
@ -81,4 +82,24 @@ nano::container_info nano::fork_cache::container_info () const
nano::container_info result;
result.put ("roots", roots);
return result;
}
/*
* fork_cache_config
*/
nano::error nano::fork_cache_config::deserialize (nano::tomlconfig & toml)
{
toml.get ("max_size", max_size);
toml.get ("max_forks_per_root", max_forks_per_root);
return toml.get_error ();
}
nano::error nano::fork_cache_config::serialize (nano::tomlconfig & toml) const
{
toml.put ("max_size", max_size, "Maximum number of roots in the cache. Each root can have multiple forks. \ntype:uint64");
toml.put ("max_forks_per_root", max_forks_per_root, "Maximum number of forks per root. \ntype:uint64");
return toml.get_error ();
}

View file

@ -20,6 +20,10 @@ namespace nano
{
class fork_cache_config final
{
public:
nano::error deserialize (nano::tomlconfig &);
nano::error serialize (nano::tomlconfig &) const;
public:
size_t max_size{ 1024 * 16 };
size_t max_forks_per_root{ 10 };

View file

@ -274,6 +274,10 @@ nano::error nano::node_config::serialize_toml (nano::tomlconfig & toml) const
bounded_backlog.serialize (bounded_backlog_l);
toml.put_child ("bounded_backlog", bounded_backlog_l);
nano::tomlconfig fork_cache_l;
fork_cache.serialize (fork_cache_l);
toml.put_child ("fork_cache", fork_cache_l);
return toml.get_error ();
}
@ -431,6 +435,12 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml)
bounded_backlog.deserialize (config_l);
}
if (toml.has_key ("fork_cache"))
{
auto config_l = toml.get_required_child ("fork_cache");
fork_cache.deserialize (config_l);
}
/*
* Values
*/