Skip to content

Commit

Permalink
Overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Dec 20, 2024
1 parent 9906b0a commit 0eb9364
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 76 deletions.
4 changes: 2 additions & 2 deletions nano/core_test/online_reps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ TEST (online_reps, basic)
ASSERT_EQ (nano::dev::constants.genesis_amount, node1.online_reps.online ());
// 1 minimum, 1 maximum
ASSERT_EQ (node1.config.online_weight_minimum, node1.online_reps.trended ());
node1.online_reps.sample ();
node1.online_reps.force_sample ();
ASSERT_EQ (nano::dev::constants.genesis_amount, node1.online_reps.trended ());
node1.online_reps.clear ();
// 2 minimum, 1 maximum
node1.online_reps.sample ();
node1.online_reps.force_sample ();
ASSERT_EQ (node1.config.online_weight_minimum, node1.online_reps.trended ());
}

Expand Down
1 change: 1 addition & 0 deletions nano/lib/logging_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ enum class type
signal_manager,
peer_history,
message_processor,
online_reps,
local_block_broadcaster,
monitor,
confirming_set,
Expand Down
10 changes: 10 additions & 0 deletions nano/lib/stats_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ enum class type
message_processor_overfill,
message_processor_type,
process_confirmed,
online_reps,

_last // Must be the last enum
};
Expand Down Expand Up @@ -582,6 +583,15 @@ enum class detail
rollback_skipped,
loop_scan,

// online_reps
trim_trend,
sanitize_old,
sanitize_future,
sample,
rep_new,
rep_update,
update_online,

_last // Must be the last enum
};

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 @@ -184,6 +184,9 @@ std::string nano::thread_role::get_string (nano::thread_role::name role)
case nano::thread_role::name::vote_router:
thread_role_name_string = "Vote router";
break;
case nano::thread_role::name::online_reps:
thread_role_name_string = "Online reps";
break;
case nano::thread_role::name::monitor:
thread_role_name_string = "Monitor";
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 @@ -66,6 +66,7 @@ enum class name
port_mapping,
stats,
vote_router,
online_reps,
monitor,
};

Expand Down
24 changes: 3 additions & 21 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
rep_crawler (config.rep_crawler, *this),
rep_tiers{ ledger, network_params, online_reps, stats, logger },
warmed_up (0),
online_reps_impl{ std::make_unique<nano::online_reps> (config, ledger) },
online_reps_impl{ std::make_unique<nano::online_reps> (config, ledger, stats, logger) },
online_reps{ *online_reps_impl },
history_impl{ std::make_unique<nano::local_vote_history> (config.network_params.voting) },
history{ *history_impl },
Expand Down Expand Up @@ -610,8 +610,6 @@ void nano::node::start ()
rep_crawler.start ();
}

ongoing_online_weight_calculation_queue ();

bool tcp_enabled = false;
if (config.tcp_incoming_connections_max > 0 && !(flags.disable_bootstrap_listener && flags.disable_tcp_realtime))
{
Expand Down Expand Up @@ -665,6 +663,7 @@ void nano::node::start ()
local_block_broadcaster.start ();
peer_history.start ();
vote_router.start ();
online_reps.start ();
monitor.start ();

add_initial_peers ();
Expand All @@ -681,7 +680,7 @@ void nano::node::stop ()
logger.info (nano::log::type::node, "Node stopping...");

tcp_listener.stop ();

online_reps.stop ();
vote_router.stop ();
peer_history.stop ();
// Cancels ongoing work generation tasks, which may be blocking other threads
Expand Down Expand Up @@ -1066,28 +1065,11 @@ bool nano::node::block_confirmed_or_being_confirmed (nano::block_hash const & ha
return block_confirmed_or_being_confirmed (ledger.tx_begin_read (), hash_a);
}

void nano::node::ongoing_online_weight_calculation_queue ()
{
std::weak_ptr<nano::node> node_w (shared_from_this ());
workers.post_delayed ((std::chrono::seconds (network_params.node.weight_period)), [node_w] () {
if (auto node_l = node_w.lock ())
{
node_l->ongoing_online_weight_calculation ();
}
});
}

bool nano::node::online () const
{
return rep_crawler.total_weight () > online_reps.delta ();
}

void nano::node::ongoing_online_weight_calculation ()
{
online_reps.sample ();
ongoing_online_weight_calculation_queue ();
}

std::shared_ptr<nano::node> nano::node::shared ()
{
return shared_from_this ();
Expand Down
2 changes: 0 additions & 2 deletions nano/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ class node final : public std::enable_shared_from_this<node>
bool block_confirmed_or_being_confirmed (nano::block_hash const &);

void do_rpc_callback (boost::asio::ip::tcp::resolver::iterator i_a, std::string const &, uint16_t, std::shared_ptr<std::string> const &, std::shared_ptr<std::string> const &, std::shared_ptr<boost::asio::ip::tcp::resolver> const &);
void ongoing_online_weight_calculation ();
void ongoing_online_weight_calculation_queue ();
bool online () const;
bool init_error () const;
std::pair<uint64_t, std::unordered_map<nano::account, nano::uint128_t>> get_bootstrap_weights () const;
Expand Down
Loading

0 comments on commit 0eb9364

Please sign in to comment.