Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 8, 2024
1 parent 03da746 commit ec45d30
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions nano/lib/stats_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum class type : uint8_t
telemetry,
vote_generator,
vote_cache,
vote_broadcaster,
hinting,
blockprocessor,
blockprocessor_source,
Expand Down
3 changes: 3 additions & 0 deletions nano/lib/thread_roles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions nano/lib/thread_roles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum class name
work,
packet_processing,
vote_processing,
vote_broadcasting,
block_processing,
request_loop,
wallet_actions,
Expand Down
2 changes: 2 additions & 0 deletions nano/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions nano/node/vote_broadcaster.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include <nano/node/vote_broadcaster.hpp>

61 changes: 61 additions & 0 deletions nano/node/vote_broadcaster.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once

#include <nano/lib/locks.hpp>
#include <nano/lib/numbers.hpp>
#include <nano/node/rep_tiers.hpp>
#include <nano/secure/common.hpp>

#include <atomic>
#include <chrono>
#include <condition_variable>
#include <thread>

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<nano::vote> const & vote, nano::rep_tier tier);
bool local (std::shared_ptr<nano::vote> 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<nano::account, uint64_t> representatives; // <representative account, vote timestamp>
};

std::unordered_map<nano::block_hash, recently_broadcasted_entry> recently_broadcasted;

private:
std::atomic<bool> stopped{ false };
nano::condition_variable condition;
mutable nano::mutex mutex;
std::thread thread;
};
}

0 comments on commit ec45d30

Please sign in to comment.