From d682454665268eaddce7a76ed5de102f57f3f769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 4 Apr 2025 16:14:00 +0200 Subject: [PATCH] Fork cache config implementation --- nano/node/bootstrap/bootstrap_server.cpp | 2 ++ nano/node/fork_cache.cpp | 21 +++++++++++++++++++++ nano/node/fork_cache.hpp | 4 ++++ nano/node/nodeconfig.cpp | 10 ++++++++++ 4 files changed, 37 insertions(+) diff --git a/nano/node/bootstrap/bootstrap_server.cpp b/nano/node/bootstrap/bootstrap_server.cpp index aac4e8a2e..f6e6ae037 100644 --- a/nano/node/bootstrap/bootstrap_server.cpp +++ b/nano/node/bootstrap/bootstrap_server.cpp @@ -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); diff --git a/nano/node/fork_cache.cpp b/nano/node/fork_cache.cpp index b223cf905..65e1d5167 100644 --- a/nano/node/fork_cache.cpp +++ b/nano/node/fork_cache.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -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 (); } \ No newline at end of file diff --git a/nano/node/fork_cache.hpp b/nano/node/fork_cache.hpp index 2c149050d..cfa0585d3 100644 --- a/nano/node/fork_cache.hpp +++ b/nano/node/fork_cache.hpp @@ -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 }; diff --git a/nano/node/nodeconfig.cpp b/nano/node/nodeconfig.cpp index fb28b1b6c..677b5d555 100644 --- a/nano/node/nodeconfig.cpp +++ b/nano/node/nodeconfig.cpp @@ -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 */