Implement vote rebroadcaster config serde (#4886)

This commit is contained in:
Piotr Wójcik 2025-04-18 12:21:21 +02:00 committed by GitHub
commit 3894dbc289
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 1 deletions

View file

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

View file

@ -456,4 +456,32 @@ size_t nano::vote_rebroadcaster_index::total_hashes () const
return std::accumulate (index.begin (), index.end (), size_t{ 0 }, [] (auto total, auto const & entry) {
return total + entry.hashes.size ();
});
}
/*
* vote_rebroadcaster_config
*/
nano::error nano::vote_rebroadcaster_config::deserialize (nano::tomlconfig & toml)
{
toml.get ("enable", enable);
toml.get ("max_queue", max_queue);
toml.get ("max_history", max_history);
toml.get ("max_representatives", max_representatives);
toml.get_duration ("rebroadcast_threshold", rebroadcast_threshold);
toml.get ("priority_coefficient", priority_coefficient);
return toml.get_error ();
}
nano::error nano::vote_rebroadcaster_config::serialize (nano::tomlconfig & toml) const
{
toml.put ("enable", enable, "Enable or disable vote rebroadcasting. Disabling it will reduce bandwidth usage but should be done with understanding that the node will not participate fully in network consensus.\ntype:bool");
toml.put ("max_queue", max_queue, "Maximum number of votes to keep in queue for processing.\ntype:uint64");
toml.put ("max_history", max_history, "Maximum number of recently broadcast hashes to keep per representative.\ntype:uint64");
toml.put ("max_representatives", max_representatives, "Maximum number of representatives to track rebroadcasts for.\ntype:uint64");
toml.put ("rebroadcast_threshold", rebroadcast_threshold.count (), "Minimum amount of time between rebroadcasts for the same hash from the same representative.\ntype:milliseconds");
toml.put ("priority_coefficient", priority_coefficient, "Priority coefficient for prioritizing votes from representative tiers.\ntype:uint64");
return toml.get_error ();
}

View file

@ -28,7 +28,8 @@ namespace nano
class vote_rebroadcaster_config final
{
public:
// TODO: Serde
nano::error deserialize (nano::tomlconfig &);
nano::error serialize (nano::tomlconfig &) const;
public:
bool enable{ true };