From ec45d3091e87c5e460efd2c024e6dfd40aff703d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:26:26 +0100 Subject: [PATCH] WIP --- nano/lib/stats_enums.hpp | 1 + nano/lib/thread_roles.cpp | 3 ++ nano/lib/thread_roles.hpp | 1 + nano/node/CMakeLists.txt | 2 ++ nano/node/vote_broadcaster.cpp | 2 ++ nano/node/vote_broadcaster.hpp | 61 ++++++++++++++++++++++++++++++++++ 6 files changed, 70 insertions(+) create mode 100644 nano/node/vote_broadcaster.cpp create mode 100644 nano/node/vote_broadcaster.hpp diff --git a/nano/lib/stats_enums.hpp b/nano/lib/stats_enums.hpp index 31d3f248fe..49ade761f7 100644 --- a/nano/lib/stats_enums.hpp +++ b/nano/lib/stats_enums.hpp @@ -34,6 +34,7 @@ enum class type : uint8_t telemetry, vote_generator, vote_cache, + vote_broadcaster, hinting, blockprocessor, blockprocessor_source, diff --git a/nano/lib/thread_roles.cpp b/nano/lib/thread_roles.cpp index 1b703b6191..ca4fef7c3d 100644 --- a/nano/lib/thread_roles.cpp +++ b/nano/lib/thread_roles.cpp @@ -22,6 +22,9 @@ std::string nano::thread_role::get_string (nano::thread_role::name role) case nano::thread_role::name::vote_processing: thread_role_name_string = "Vote processing"; break; + case nano::thread_role::name::vote_broadcasting: + thread_role_name_string = "Vote broadcast"; + break; case nano::thread_role::name::block_processing: thread_role_name_string = "Blck processing"; break; diff --git a/nano/lib/thread_roles.hpp b/nano/lib/thread_roles.hpp index d55db1d9d0..6b3d1a4612 100644 --- a/nano/lib/thread_roles.hpp +++ b/nano/lib/thread_roles.hpp @@ -14,6 +14,7 @@ enum class name work, packet_processing, vote_processing, + vote_broadcasting, block_processing, request_loop, wallet_actions, diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index f8f3b5407e..873cb8f13b 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -164,6 +164,8 @@ add_library( transport/transport.cpp unchecked_map.cpp unchecked_map.hpp + vote_processor.hpp + vote_processor.cpp vote_cache.hpp vote_cache.cpp vote_processor.hpp diff --git a/nano/node/vote_broadcaster.cpp b/nano/node/vote_broadcaster.cpp new file mode 100644 index 0000000000..a1ad1c75d3 --- /dev/null +++ b/nano/node/vote_broadcaster.cpp @@ -0,0 +1,2 @@ +#include + diff --git a/nano/node/vote_broadcaster.hpp b/nano/node/vote_broadcaster.hpp new file mode 100644 index 0000000000..b934ccf480 --- /dev/null +++ b/nano/node/vote_broadcaster.hpp @@ -0,0 +1,61 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace nano +{ +class node; +class stats; +} + +namespace nano +{ +class vote_broadcaster_config final +{ +public: + size_t max_recently_broadcasted{ 1024 * 32 }; +}; + +class vote_broadcaster final +{ +public: + explicit vote_broadcaster (nano::node &); + ~vote_broadcaster (); + + void start (); + void stop (); + + bool rebroadcast (std::shared_ptr const & vote, nano::rep_tier tier); + bool local (std::shared_ptr const & vote); + +private: // Dependencies + nano::vote_broadcaster_config const & config; + nano::node & node; + nano::stats & stats; + +private: + void run (); + +private: + class recently_broadcasted_entry + { + std::map representatives; // + }; + + std::unordered_map recently_broadcasted; + +private: + std::atomic stopped{ false }; + nano::condition_variable condition; + mutable nano::mutex mutex; + std::thread thread; +}; +} \ No newline at end of file