Skip to content

Commit

Permalink
Conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Sep 24, 2024
1 parent cd6a62d commit 1cf1cd7
Show file tree
Hide file tree
Showing 84 changed files with 496 additions and 612 deletions.
18 changes: 11 additions & 7 deletions nano/lib/observer_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@ class observer_set final
return observers.empty ();
}

std::unique_ptr<container_info_component> collect_container_info (std::string const & name) const
size_t size () const
{
nano::lock_guard<nano::mutex> lock{ mutex };
return observers.size ();
}

nano::container_info container_info () const
{
nano::unique_lock<nano::mutex> lock{ mutex };
auto count = observers.size ();
lock.unlock ();
auto sizeof_element = sizeof (typename decltype (observers)::value_type);
auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info_entry{ "observers", count, sizeof_element }));
return composite;

nano::container_info info;
info.put ("observers", observers);
return info;
}

private:
Expand Down
10 changes: 5 additions & 5 deletions nano/lib/processing_queue.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <nano/lib/container_info.hpp>
#include <nano/lib/locks.hpp>
#include <nano/lib/numbers.hpp>
#include <nano/lib/stats.hpp>
Expand Down Expand Up @@ -107,14 +108,13 @@ class processing_queue final
return queue.size ();
}

public: // Container info
std::unique_ptr<container_info_component> collect_container_info (std::string const & name) const
nano::container_info container_info () const
{
nano::lock_guard<nano::mutex> guard{ mutex };

auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info_entry{ "queue", queue.size (), sizeof (typename decltype (queue)::value_type) }));
return composite;
nano::container_info info;
info.put ("queue", queue);
return info;
}

private:
Expand Down
8 changes: 4 additions & 4 deletions nano/lib/thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ void nano::thread_pool::set_thread_names (nano::thread_role::name thread_name)
thread_names_latch.wait ();
}

std::unique_ptr<nano::container_info_component> nano::thread_pool::collect_container_info (std::string const & name) const
nano::container_info nano::thread_pool::container_info () const
{
auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info_entry{ "count", num_queued_tasks (), sizeof (std::function<void ()>) }));
return composite;
nano::container_info info;
info.put ("count", num_queued_tasks ());
return info;
}
2 changes: 1 addition & 1 deletion nano/lib/thread_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class thread_pool final
/** Returns the number of tasks which are awaiting execution by the thread pool **/
uint64_t num_queued_tasks () const;

std::unique_ptr<nano::container_info_component> collect_container_info (std::string const & name) const;
nano::container_info container_info () const;

private:
nano::mutex mutex;
Expand Down
8 changes: 4 additions & 4 deletions nano/lib/uniquer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ class uniquer final
return values.size ();
}

std::unique_ptr<container_info_component> collect_container_info (std::string const & name) const
nano::container_info container_info () const
{
nano::lock_guard<nano::mutex> guard{ mutex };

auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info_entry{ "cache", values.size (), sizeof (Value) }));
return composite;
nano::container_info info;
info.put ("cache", values);
return info;
}

static std::chrono::milliseconds constexpr cleanup_cutoff{ 500 };
Expand Down
20 changes: 8 additions & 12 deletions nano/lib/work.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,12 @@ size_t nano::work_pool::size ()
return pending.size ();
}

std::unique_ptr<nano::container_info_component> nano::collect_container_info (work_pool & work_pool, std::string const & name)
nano::container_info nano::work_pool::container_info () const
{
size_t count;
{
nano::lock_guard<nano::mutex> guard{ work_pool.mutex };
count = work_pool.pending.size ();
}
auto sizeof_element = sizeof (decltype (work_pool.pending)::value_type);
auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info_entry{ "pending", count, sizeof_element }));
composite->add_component (work_pool.work_observers.collect_container_info ("work_observers"));
return composite;
}
nano::lock_guard<nano::mutex> guard{ mutex };

nano::container_info info;
info.put ("pending", pending);
info.add ("work_observers", work_observers.container_info ());
return info;
}
6 changes: 3 additions & 3 deletions nano/lib/work.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ class work_pool final
bool done;
std::vector<boost::thread> threads;
std::list<nano::work_item> pending;
nano::mutex mutex{ mutex_identifier (mutexes::work_pool) };
mutable nano::mutex mutex{ mutex_identifier (mutexes::work_pool) };
nano::condition_variable producer_condition;
std::chrono::nanoseconds pow_rate_limiter;
nano::opencl_work_func_t opencl;
nano::observer_set<bool> work_observers;
};

std::unique_ptr<container_info_component> collect_container_info (work_pool & work_pool, std::string const & name);
nano::container_info container_info () const;
};
}
22 changes: 11 additions & 11 deletions nano/node/active_elections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,21 +589,21 @@ void nano::active_elections::clear ()
vacancy_update ();
}

std::unique_ptr<nano::container_info_component> nano::collect_container_info (active_elections & active_elections, std::string const & name)
nano::container_info nano::active_elections::container_info () const
{
nano::lock_guard<nano::mutex> guard{ active_elections.mutex };
nano::lock_guard<nano::mutex> guard{ mutex };

auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info_entry{ "roots", active_elections.roots.size (), sizeof (decltype (active_elections.roots)::value_type) }));
composite->add_component (std::make_unique<container_info_leaf> (container_info_entry{ "election_winner_details", active_elections.election_winner_details_size (), sizeof (decltype (active_elections.election_winner_details)::value_type) }));
composite->add_component (std::make_unique<container_info_leaf> (container_info_entry{ "normal", static_cast<std::size_t> (active_elections.count_by_behavior[nano::election_behavior::priority]), 0 }));
composite->add_component (std::make_unique<container_info_leaf> (container_info_entry{ "hinted", static_cast<std::size_t> (active_elections.count_by_behavior[nano::election_behavior::hinted]), 0 }));
composite->add_component (std::make_unique<container_info_leaf> (container_info_entry{ "optimistic", static_cast<std::size_t> (active_elections.count_by_behavior[nano::election_behavior::optimistic]), 0 }));
nano::container_info info;
info.put ("roots", roots.size ());
info.put ("election_winner_details", election_winner_details_size ());
info.put ("normal", static_cast<std::size_t> (count_by_behavior[nano::election_behavior::priority]));
info.put ("hinted", static_cast<std::size_t> (count_by_behavior[nano::election_behavior::hinted]));
info.put ("optimistic", static_cast<std::size_t> (count_by_behavior[nano::election_behavior::optimistic]));

composite->add_component (active_elections.recently_confirmed.collect_container_info ("recently_confirmed"));
composite->add_component (active_elections.recently_cemented.collect_container_info ("recently_cemented"));
info.add ("recently_confirmed", recently_confirmed.container_info ());
info.add ("recently_cemented", recently_cemented.container_info ());

return composite;
return info;
}

/*
Expand Down
28 changes: 5 additions & 23 deletions nano/node/active_elections.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <nano/node/election_behavior.hpp>
#include <nano/node/election_insertion_result.hpp>
#include <nano/node/election_status.hpp>
#include <nano/node/fwd.hpp>
#include <nano/node/recently_cemented_cache.hpp>
#include <nano/node/recently_confirmed_cache.hpp>
#include <nano/node/vote_router.hpp>
Expand All @@ -25,24 +26,6 @@

namespace mi = boost::multi_index;

namespace nano
{
class node;
class active_elections;
class block;
class block_sideband;
class block_processor;
class confirming_set;
class election;
class vote;
class stats;
enum class election_state;
}
namespace nano::secure
{
class transaction;
}

namespace nano
{
class active_elections_config final
Expand Down Expand Up @@ -144,6 +127,8 @@ class active_elections final
void add_election_winner_details (nano::block_hash const &, std::shared_ptr<nano::election> const &);
std::shared_ptr<nano::election> remove_election_winner_details (nano::block_hash const &);

nano::container_info container_info () const;

private:
void request_loop ();
void request_confirm (nano::unique_lock<nano::mutex> &);
Expand All @@ -164,8 +149,8 @@ class active_elections final
nano::block_processor & block_processor;

public:
recently_confirmed_cache recently_confirmed;
recently_cemented_cache recently_cemented;
nano::recently_confirmed_cache recently_confirmed;
nano::recently_cemented_cache recently_cemented;

// TODO: This mutex is currently public because many tests access it
// TODO: This is bad. Remove the need to explicitly lock this from any code outside of this class
Expand All @@ -186,7 +171,6 @@ class active_elections final
std::thread thread;

friend class election;
friend std::unique_ptr<container_info_component> collect_container_info (active_elections &, std::string const &);

public: // Tests
void clear ();
Expand All @@ -204,8 +188,6 @@ class active_elections final
friend class frontiers_confirmation_expired_optimistic_elections_removal_Test;
};

std::unique_ptr<container_info_component> collect_container_info (active_elections & active_elections, std::string const & name);

nano::stat::type to_stat_type (nano::election_state);
nano::stat::detail to_stat_detail (nano::election_state);
}
36 changes: 20 additions & 16 deletions nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,25 +458,15 @@ void nano::block_processor::queue_unchecked (secure::write_transaction const & t
node.unchecked.trigger (hash_or_account_a);
}

std::unique_ptr<nano::container_info_component> nano::block_processor::collect_container_info (std::string const & name)
nano::container_info nano::block_processor::container_info () const
{
nano::lock_guard<nano::mutex> guard{ mutex };

auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info_entry{ "blocks", queue.size (), 0 }));
composite->add_component (std::make_unique<container_info_leaf> (container_info_entry{ "forced", queue.size ({ nano::block_source::forced }), 0 }));
composite->add_component (queue.collect_container_info ("queue"));
return composite;
}

std::string_view nano::to_string (nano::block_source source)
{
return nano::enum_util::name (source);
}

nano::stat::detail nano::to_stat_detail (nano::block_source type)
{
return nano::enum_util::cast<nano::stat::detail> (type);
nano::container_info info;
info.put ("blocks", queue.size ());
info.put ("forced", queue.size ({ nano::block_source::forced }));
info.add ("queue", queue.container_info ());
return info;
}

/*
Expand Down Expand Up @@ -508,3 +498,17 @@ nano::error nano::block_processor_config::deserialize (nano::tomlconfig & toml)

return toml.get_error ();
}

/*
*
*/

std::string_view nano::to_string (nano::block_source source)
{
return nano::enum_util::name (source);
}

nano::stat::detail nano::to_stat_detail (nano::block_source type)
{
return nano::enum_util::cast<nano::stat::detail> (type);
}
14 changes: 2 additions & 12 deletions nano/node/blockprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <nano/lib/logging.hpp>
#include <nano/node/fair_queue.hpp>
#include <nano/node/fwd.hpp>
#include <nano/secure/common.hpp>

#include <chrono>
Expand All @@ -10,17 +11,6 @@
#include <optional>
#include <thread>

namespace nano
{
class block;
class node;
}

namespace nano::secure
{
class write_transaction;
}

namespace nano
{
enum class block_source
Expand Down Expand Up @@ -101,7 +91,7 @@ class block_processor final
void force (std::shared_ptr<nano::block> const &);
bool should_log ();

std::unique_ptr<container_info_component> collect_container_info (std::string const & name);
nano::container_info container_info () const;

std::atomic<bool> flushing{ false };

Expand Down
21 changes: 7 additions & 14 deletions nano/node/bootstrap/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,25 +288,18 @@ void nano::bootstrap_initiator::notify_listeners (bool in_progress_a)
}
}

std::unique_ptr<nano::container_info_component> nano::collect_container_info (bootstrap_initiator & bootstrap_initiator, std::string const & name)
nano::container_info nano::bootstrap_initiator::container_info () const
{
std::size_t count;
std::size_t cache_count;
nano::container_info info;
{
nano::lock_guard<nano::mutex> guard{ bootstrap_initiator.observers_mutex };
count = bootstrap_initiator.observers.size ();
nano::lock_guard<nano::mutex> guard{ observers_mutex };
info.put ("observers", observers.size ());
}
{
nano::lock_guard<nano::mutex> guard{ bootstrap_initiator.cache.pulls_cache_mutex };
cache_count = bootstrap_initiator.cache.cache.size ();
nano::lock_guard<nano::mutex> guard{ cache.pulls_cache_mutex };
info.put ("pulls_cache", cache.cache.size ());
}

auto sizeof_element = sizeof (decltype (bootstrap_initiator.observers)::value_type);
auto sizeof_cache_element = sizeof (decltype (bootstrap_initiator.cache.cache)::value_type);
auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info_entry{ "observers", count, sizeof_element }));
composite->add_component (std::make_unique<container_info_leaf> (container_info_entry{ "pulls_cache", cache_count, sizeof_cache_element }));
return composite;
return info;
}

void nano::pulls_cache::add (nano::pull_info const & pull_a)
Expand Down
11 changes: 4 additions & 7 deletions nano/node/bootstrap/bootstrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class pulls_cache final
void add (nano::pull_info const &);
void update_pull (nano::pull_info &);
void remove (nano::pull_info const &);
nano::mutex pulls_cache_mutex;
mutable nano::mutex pulls_cache_mutex;
class account_head_tag
{
};
Expand Down Expand Up @@ -116,24 +116,21 @@ class bootstrap_initiator final
nano::pulls_cache cache;
nano::bootstrap_attempts attempts;
void stop ();
nano::container_info container_info () const;

private:
nano::node & node;
std::shared_ptr<nano::bootstrap_attempt> find_attempt (nano::bootstrap_mode);
void stop_attempts ();
std::vector<std::shared_ptr<nano::bootstrap_attempt>> attempts_list;
std::atomic<bool> stopped{ false };
nano::mutex mutex;
mutable nano::mutex mutex;
nano::condition_variable condition;
nano::mutex observers_mutex;
mutable nano::mutex observers_mutex;
std::vector<std::function<void (bool)>> observers;
std::vector<boost::thread> bootstrap_initiator_threads;

friend std::unique_ptr<container_info_component> collect_container_info (bootstrap_initiator & bootstrap_initiator, std::string const & name);
};

std::unique_ptr<container_info_component> collect_container_info (bootstrap_initiator & bootstrap_initiator, std::string const & name);

/**
* Defines the numeric values for the bootstrap feature.
*/
Expand Down
Loading

0 comments on commit 1cf1cd7

Please sign in to comment.