From 1cf1cd7e02b509f496adf1289840d825667a3575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Sun, 5 May 2024 15:34:15 +0200 Subject: [PATCH] Conversion --- nano/lib/observer_set.hpp | 18 ++-- nano/lib/processing_queue.hpp | 10 +- nano/lib/thread_pool.cpp | 8 +- nano/lib/thread_pool.hpp | 2 +- nano/lib/uniquer.hpp | 8 +- nano/lib/work.cpp | 20 ++-- nano/lib/work.hpp | 6 +- nano/node/active_elections.cpp | 22 ++--- nano/node/active_elections.hpp | 28 +----- nano/node/blockprocessor.cpp | 36 +++---- nano/node/blockprocessor.hpp | 14 +-- nano/node/bootstrap/bootstrap.cpp | 21 ++-- nano/node/bootstrap/bootstrap.hpp | 11 +-- .../node/bootstrap_ascending/account_sets.cpp | 14 +-- .../node/bootstrap_ascending/account_sets.hpp | 3 +- nano/node/bootstrap_ascending/service.cpp | 14 +-- nano/node/bootstrap_ascending/service.hpp | 5 +- nano/node/confirming_set.cpp | 10 +- nano/node/confirming_set.hpp | 2 +- nano/node/distributed_work_factory.cpp | 12 +-- nano/node/distributed_work_factory.hpp | 5 +- nano/node/fair_queue.hpp | 10 +- nano/node/fwd.hpp | 22 ++++- nano/node/json_handler.cpp | 2 +- nano/node/local_block_broadcaster.cpp | 8 +- nano/node/local_block_broadcaster.hpp | 2 +- nano/node/local_vote_history.cpp | 15 ++- nano/node/local_vote_history.hpp | 5 +- nano/node/message_processor.cpp | 8 +- nano/node/message_processor.hpp | 4 +- nano/node/network.cpp | 39 ++++---- nano/node/network.hpp | 9 +- nano/node/node.cpp | 95 +++++++++++-------- nano/node/node.hpp | 3 +- nano/node/node_observers.cpp | 26 ++--- nano/node/node_observers.hpp | 4 +- nano/node/online_reps.cpp | 15 +-- nano/node/online_reps.hpp | 6 +- nano/node/peer_exclusion.cpp | 10 +- nano/node/peer_exclusion.hpp | 4 +- nano/node/recently_cemented_cache.cpp | 10 +- nano/node/recently_cemented_cache.hpp | 5 +- nano/node/recently_confirmed_cache.cpp | 10 +- nano/node/recently_confirmed_cache.hpp | 5 +- nano/node/rep_tiers.cpp | 14 +-- nano/node/rep_tiers.hpp | 2 +- nano/node/repcrawler.cpp | 28 +++--- nano/node/repcrawler.hpp | 8 +- nano/node/request_aggregator.cpp | 8 +- nano/node/request_aggregator.hpp | 3 +- nano/node/scheduler/component.cpp | 14 +-- nano/node/scheduler/component.hpp | 26 ++--- nano/node/scheduler/hinted.cpp | 8 +- nano/node/scheduler/hinted.hpp | 17 +--- nano/node/scheduler/manual.cpp | 12 +-- nano/node/scheduler/manual.hpp | 18 ++-- nano/node/scheduler/optimistic.cpp | 8 +- nano/node/scheduler/optimistic.hpp | 11 +-- nano/node/scheduler/priority.cpp | 24 ++--- nano/node/scheduler/priority.hpp | 20 +--- nano/node/telemetry.cpp | 8 +- nano/node/telemetry.hpp | 16 +--- nano/node/transport/fwd.hpp | 1 + nano/node/transport/tcp_channels.cpp | 27 ++---- nano/node/transport/tcp_channels.hpp | 3 +- nano/node/transport/tcp_listener.cpp | 12 ++- nano/node/transport/tcp_listener.hpp | 5 +- nano/node/unchecked_map.cpp | 29 +++--- nano/node/unchecked_map.hpp | 14 +-- nano/node/vote_cache.cpp | 8 +- nano/node/vote_cache.hpp | 4 +- nano/node/vote_generator.cpp | 23 ++--- nano/node/vote_generator.hpp | 28 +----- nano/node/vote_processor.cpp | 19 ++-- nano/node/vote_processor.hpp | 4 +- nano/node/vote_router.cpp | 18 ++-- nano/node/vote_router.hpp | 13 +-- nano/node/wallet.cpp | 20 ++-- nano/node/wallet.hpp | 8 +- nano/secure/fwd.hpp | 8 ++ nano/secure/ledger.cpp | 14 ++- nano/secure/ledger.hpp | 2 +- nano/secure/rep_weights.cpp | 15 +-- nano/secure/rep_weights.hpp | 2 +- 84 files changed, 496 insertions(+), 612 deletions(-) diff --git a/nano/lib/observer_set.hpp b/nano/lib/observer_set.hpp index 9d10ad0a3a..cc4e02e9ca 100644 --- a/nano/lib/observer_set.hpp +++ b/nano/lib/observer_set.hpp @@ -36,15 +36,19 @@ class observer_set final return observers.empty (); } - std::unique_ptr collect_container_info (std::string const & name) const + size_t size () const + { + nano::lock_guard lock{ mutex }; + return observers.size (); + } + + nano::container_info container_info () const { nano::unique_lock lock{ mutex }; - auto count = observers.size (); - lock.unlock (); - auto sizeof_element = sizeof (typename decltype (observers)::value_type); - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "observers", count, sizeof_element })); - return composite; + + nano::container_info info; + info.put ("observers", observers); + return info; } private: diff --git a/nano/lib/processing_queue.hpp b/nano/lib/processing_queue.hpp index d13b9c8275..3202005918 100644 --- a/nano/lib/processing_queue.hpp +++ b/nano/lib/processing_queue.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -107,14 +108,13 @@ class processing_queue final return queue.size (); } -public: // Container info - std::unique_ptr collect_container_info (std::string const & name) const + nano::container_info container_info () const { nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (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: diff --git a/nano/lib/thread_pool.cpp b/nano/lib/thread_pool.cpp index 6f77009018..c5f0108ee0 100644 --- a/nano/lib/thread_pool.cpp +++ b/nano/lib/thread_pool.cpp @@ -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::thread_pool::collect_container_info (std::string const & name) const +nano::container_info nano::thread_pool::container_info () const { - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "count", num_queued_tasks (), sizeof (std::function) })); - return composite; + nano::container_info info; + info.put ("count", num_queued_tasks ()); + return info; } diff --git a/nano/lib/thread_pool.hpp b/nano/lib/thread_pool.hpp index b8eb29f9c0..2b32e60f59 100644 --- a/nano/lib/thread_pool.hpp +++ b/nano/lib/thread_pool.hpp @@ -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 collect_container_info (std::string const & name) const; + nano::container_info container_info () const; private: nano::mutex mutex; diff --git a/nano/lib/uniquer.hpp b/nano/lib/uniquer.hpp index 4b3dabf205..0a3a160e4c 100644 --- a/nano/lib/uniquer.hpp +++ b/nano/lib/uniquer.hpp @@ -51,13 +51,13 @@ class uniquer final return values.size (); } - std::unique_ptr collect_container_info (std::string const & name) const + nano::container_info container_info () const { nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (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 }; diff --git a/nano/lib/work.cpp b/nano/lib/work.cpp index 797f945e34..7ee17cd1f9 100644 --- a/nano/lib/work.cpp +++ b/nano/lib/work.cpp @@ -232,16 +232,12 @@ size_t nano::work_pool::size () return pending.size (); } -std::unique_ptr 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 guard{ work_pool.mutex }; - count = work_pool.pending.size (); - } - auto sizeof_element = sizeof (decltype (work_pool.pending)::value_type); - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "pending", count, sizeof_element })); - composite->add_component (work_pool.work_observers.collect_container_info ("work_observers")); - return composite; -} + nano::lock_guard guard{ mutex }; + + nano::container_info info; + info.put ("pending", pending); + info.add ("work_observers", work_observers.container_info ()); + return info; +} \ No newline at end of file diff --git a/nano/lib/work.hpp b/nano/lib/work.hpp index 60f84987ec..1640648934 100644 --- a/nano/lib/work.hpp +++ b/nano/lib/work.hpp @@ -56,12 +56,12 @@ class work_pool final bool done; std::vector threads; std::list 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 work_observers; -}; -std::unique_ptr collect_container_info (work_pool & work_pool, std::string const & name); + nano::container_info container_info () const; +}; } diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index f9997a4dab..1ebd75458b 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -589,21 +589,21 @@ void nano::active_elections::clear () vacancy_update (); } -std::unique_ptr nano::collect_container_info (active_elections & active_elections, std::string const & name) +nano::container_info nano::active_elections::container_info () const { - nano::lock_guard guard{ active_elections.mutex }; + nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "roots", active_elections.roots.size (), sizeof (decltype (active_elections.roots)::value_type) })); - composite->add_component (std::make_unique (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_entry{ "normal", static_cast (active_elections.count_by_behavior[nano::election_behavior::priority]), 0 })); - composite->add_component (std::make_unique (container_info_entry{ "hinted", static_cast (active_elections.count_by_behavior[nano::election_behavior::hinted]), 0 })); - composite->add_component (std::make_unique (container_info_entry{ "optimistic", static_cast (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 (count_by_behavior[nano::election_behavior::priority])); + info.put ("hinted", static_cast (count_by_behavior[nano::election_behavior::hinted])); + info.put ("optimistic", static_cast (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; } /* diff --git a/nano/node/active_elections.hpp b/nano/node/active_elections.hpp index c74df00332..222d5d278d 100644 --- a/nano/node/active_elections.hpp +++ b/nano/node/active_elections.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -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 @@ -144,6 +127,8 @@ class active_elections final void add_election_winner_details (nano::block_hash const &, std::shared_ptr const &); std::shared_ptr remove_election_winner_details (nano::block_hash const &); + nano::container_info container_info () const; + private: void request_loop (); void request_confirm (nano::unique_lock &); @@ -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 @@ -186,7 +171,6 @@ class active_elections final std::thread thread; friend class election; - friend std::unique_ptr collect_container_info (active_elections &, std::string const &); public: // Tests void clear (); @@ -204,8 +188,6 @@ class active_elections final friend class frontiers_confirmation_expired_optimistic_elections_removal_Test; }; -std::unique_ptr 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); } diff --git a/nano/node/blockprocessor.cpp b/nano/node/blockprocessor.cpp index b199427301..82eff27734 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -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::block_processor::collect_container_info (std::string const & name) +nano::container_info nano::block_processor::container_info () const { nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "blocks", queue.size (), 0 })); - composite->add_component (std::make_unique (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 (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; } /* @@ -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 (type); +} \ No newline at end of file diff --git a/nano/node/blockprocessor.hpp b/nano/node/blockprocessor.hpp index b6a6f2ec87..837631b0ba 100644 --- a/nano/node/blockprocessor.hpp +++ b/nano/node/blockprocessor.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -10,17 +11,6 @@ #include #include -namespace nano -{ -class block; -class node; -} - -namespace nano::secure -{ -class write_transaction; -} - namespace nano { enum class block_source @@ -101,7 +91,7 @@ class block_processor final void force (std::shared_ptr const &); bool should_log (); - std::unique_ptr collect_container_info (std::string const & name); + nano::container_info container_info () const; std::atomic flushing{ false }; diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 823becd76f..3db711dfce 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -288,25 +288,18 @@ void nano::bootstrap_initiator::notify_listeners (bool in_progress_a) } } -std::unique_ptr 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 guard{ bootstrap_initiator.observers_mutex }; - count = bootstrap_initiator.observers.size (); + nano::lock_guard guard{ observers_mutex }; + info.put ("observers", observers.size ()); } { - nano::lock_guard guard{ bootstrap_initiator.cache.pulls_cache_mutex }; - cache_count = bootstrap_initiator.cache.cache.size (); + nano::lock_guard 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 (name); - composite->add_component (std::make_unique (container_info_entry{ "observers", count, sizeof_element })); - composite->add_component (std::make_unique (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) diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index 252b4b5660..f06f83196b 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -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 { }; @@ -116,6 +116,7 @@ class bootstrap_initiator final nano::pulls_cache cache; nano::bootstrap_attempts attempts; void stop (); + nano::container_info container_info () const; private: nano::node & node; @@ -123,17 +124,13 @@ class bootstrap_initiator final void stop_attempts (); std::vector> attempts_list; std::atomic stopped{ false }; - nano::mutex mutex; + mutable nano::mutex mutex; nano::condition_variable condition; - nano::mutex observers_mutex; + mutable nano::mutex observers_mutex; std::vector> observers; std::vector bootstrap_initiator_threads; - - friend std::unique_ptr collect_container_info (bootstrap_initiator & bootstrap_initiator, std::string const & name); }; -std::unique_ptr collect_container_info (bootstrap_initiator & bootstrap_initiator, std::string const & name); - /** * Defines the numeric values for the bootstrap feature. */ diff --git a/nano/node/bootstrap_ascending/account_sets.cpp b/nano/node/bootstrap_ascending/account_sets.cpp index e0db837fdb..4d0a276dfc 100644 --- a/nano/node/bootstrap_ascending/account_sets.cpp +++ b/nano/node/bootstrap_ascending/account_sets.cpp @@ -344,14 +344,14 @@ auto nano::bootstrap_ascending::account_sets::info () const -> nano::bootstrap_a return { blocking, priorities }; } -std::unique_ptr nano::bootstrap_ascending::account_sets::collect_container_info (const std::string & name) +nano::container_info nano::bootstrap_ascending::account_sets::container_info () const { // Count blocking entries with their dependency account unknown auto blocking_unknown = blocking.get ().count (nano::account{ 0 }); - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "priorities", priorities.size (), sizeof (decltype (priorities)::value_type) })); - composite->add_component (std::make_unique (container_info_entry{ "blocking", blocking.size (), sizeof (decltype (blocking)::value_type) })); - composite->add_component (std::make_unique (container_info_entry{ "blocking_unknown", blocking_unknown, 0 })); - return composite; -} + nano::container_info info; + info.put ("priorities", priorities); + info.put ("blocking", blocking); + info.put ("blocking_unknown", blocking_unknown); + return info; +} \ No newline at end of file diff --git a/nano/node/bootstrap_ascending/account_sets.hpp b/nano/node/bootstrap_ascending/account_sets.hpp index 4b2d0cedb9..d83d3a8898 100644 --- a/nano/node/bootstrap_ascending/account_sets.hpp +++ b/nano/node/bootstrap_ascending/account_sets.hpp @@ -62,7 +62,6 @@ namespace bootstrap_ascending nano::account next_priority (std::function const & filter); nano::block_hash next_blocking (std::function const & filter); - public: bool blocked (nano::account const & account) const; bool prioritized (nano::account const & account) const; // Accounts in the ledger but not in priority list are assumed priority 1.0f @@ -74,7 +73,7 @@ namespace bootstrap_ascending bool priority_half_full () const; bool blocked_half_full () const; - std::unique_ptr collect_container_info (std::string const & name); + nano::container_info container_info () const; private: // Dependencies account_sets_config const & config; diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index afbfd9f3c1..8fb6834daa 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -830,16 +830,16 @@ std::size_t nano::bootstrap_ascending::service::compute_throttle_size () const return std::max (target, min_size); } -std::unique_ptr nano::bootstrap_ascending::service::collect_container_info (std::string const & name) +nano::container_info nano::bootstrap_ascending::service::container_info () const { nano::lock_guard lock{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "tags", tags.size (), sizeof (decltype (tags)::value_type) })); - composite->add_component (std::make_unique (container_info_entry{ "throttle", throttle.size (), 0 })); - composite->add_component (std::make_unique (container_info_entry{ "throttle_successes", throttle.successes (), 0 })); - composite->add_component (accounts.collect_container_info ("accounts")); - return composite; + nano::container_info info; + info.put ("tags", tags); + info.put ("throttle", throttle.size ()); + info.put ("throttle_successes", throttle.successes ()); + info.add ("accounts", accounts.container_info ()); + return info; } /* diff --git a/nano/node/bootstrap_ascending/service.hpp b/nano/node/bootstrap_ascending/service.hpp index a31461a7f1..f462bb3fc2 100644 --- a/nano/node/bootstrap_ascending/service.hpp +++ b/nano/node/bootstrap_ascending/service.hpp @@ -40,11 +40,12 @@ namespace bootstrap_ascending */ void process (nano::asc_pull_ack const & message, std::shared_ptr const &); - public: // Container info - std::unique_ptr collect_container_info (std::string const & name); std::size_t blocked_size () const; std::size_t priority_size () const; std::size_t score_size () const; + + nano::container_info container_info () const; + nano::bootstrap_ascending::account_sets::info_t info () const; private: // Dependencies diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index bd51ff6eea..e3a741ed9d 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -208,12 +208,12 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) release_assert (already.empty ()); } -std::unique_ptr nano::confirming_set::collect_container_info (std::string const & name) const +nano::container_info nano::confirming_set::container_info () const { std::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "set", set.size (), sizeof (typename decltype (set)::value_type) })); - composite->add_component (notification_workers.collect_container_info ("notification_workers")); - return composite; + nano::container_info info; + info.put ("set", set); + info.add ("notification_workers", notification_workers.container_info ()); + return info; } diff --git a/nano/node/confirming_set.hpp b/nano/node/confirming_set.hpp index 2f363b51e6..e5ef4857f1 100644 --- a/nano/node/confirming_set.hpp +++ b/nano/node/confirming_set.hpp @@ -45,7 +45,7 @@ class confirming_set final bool exists (nano::block_hash const & hash) const; std::size_t size () const; - std::unique_ptr collect_container_info (std::string const & name) const; + nano::container_info container_info () const; public: // Events // Observers will be called once ledger has blocks marked as confirmed diff --git a/nano/node/distributed_work_factory.cpp b/nano/node/distributed_work_factory.cpp index b00f2bc549..92a72affda 100644 --- a/nano/node/distributed_work_factory.cpp +++ b/nano/node/distributed_work_factory.cpp @@ -80,11 +80,9 @@ std::size_t nano::distributed_work_factory::size () const return items.size (); } -std::unique_ptr nano::collect_container_info (distributed_work_factory & distributed_work, std::string const & name) +nano::container_info nano::distributed_work_factory::container_info () const { - auto item_count = distributed_work.size (); - auto sizeof_item_element = sizeof (decltype (nano::distributed_work_factory::items)::value_type); - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "items", item_count, sizeof_item_element })); - return composite; -} + nano::container_info info; + info.put ("items", size ()); + return info; +} \ No newline at end of file diff --git a/nano/node/distributed_work_factory.hpp b/nano/node/distributed_work_factory.hpp index 97c697aa9e..8024bb1841 100644 --- a/nano/node/distributed_work_factory.hpp +++ b/nano/node/distributed_work_factory.hpp @@ -27,6 +27,7 @@ class distributed_work_factory final void cleanup_finished (); void stop (); std::size_t size () const; + nano::container_info container_info () const; private: std::unordered_multimap> items; @@ -34,9 +35,5 @@ class distributed_work_factory final nano::node & node; mutable nano::mutex mutex; std::atomic stopped{ false }; - - friend std::unique_ptr collect_container_info (distributed_work_factory &, std::string const &); }; - -std::unique_ptr collect_container_info (distributed_work_factory & distributed_work, std::string const & name); } diff --git a/nano/node/fair_queue.hpp b/nano/node/fair_queue.hpp index aa940056cb..5b045a71da 100644 --- a/nano/node/fair_queue.hpp +++ b/nano/node/fair_queue.hpp @@ -302,12 +302,12 @@ class fair_queue final std::chrono::steady_clock::time_point last_update{ std::chrono::steady_clock::now () }; public: - std::unique_ptr collect_container_info (std::string const & name) const + nano::container_info container_info () const { - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "queues", queues_size (), sizeof (typename decltype (queues)::value_type) })); - composite->add_component (std::make_unique (container_info_entry{ "total_size", size (), sizeof (typename decltype (queues)::value_type) })); - return composite; + nano::container_info info; + info.put ("queues", queues); + info.put ("total_size", size ()); + return info; } }; } diff --git a/nano/node/fwd.hpp b/nano/node/fwd.hpp index d79581378d..57b2169655 100644 --- a/nano/node/fwd.hpp +++ b/nano/node/fwd.hpp @@ -4,12 +4,19 @@ #include #include +// TODO: Move to lib/fwd.hpp namespace nano { -class active_elections; class block; +class container_info; +} + +namespace nano +{ +class active_elections; class block_processor; class confirming_set; +class election; class ledger; class local_block_broadcaster; class local_vote_history; @@ -21,6 +28,8 @@ class node_config; class node_flags; class node_observers; class online_reps; +class recently_cemented_cache; +class recently_confirmed_cache; class rep_crawler; class rep_tiers; class stats; @@ -28,8 +37,19 @@ class vote_cache; class vote_generator; class vote_processor; class vote_router; +class vote_spacing; class wallets; enum class block_source; +enum class election_behavior; +enum class election_state; enum class vote_code; +} + +namespace nano::scheduler +{ +class hinted; +class manual; +class optimistic; +class priority; } \ No newline at end of file diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index e426f5fc66..000b6e5a21 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -3999,7 +3999,7 @@ void nano::json_handler::stats () } else if (type == "objects") { - construct_json (collect_container_info (node, "node").get (), response_l); + construct_json (node.container_info ().to_legacy ("node").get (), response_l); } else if (type == "database") { diff --git a/nano/node/local_block_broadcaster.cpp b/nano/node/local_block_broadcaster.cpp index 9bdd2ea668..ad1a2201fe 100644 --- a/nano/node/local_block_broadcaster.cpp +++ b/nano/node/local_block_broadcaster.cpp @@ -223,11 +223,11 @@ void nano::local_block_broadcaster::cleanup (nano::unique_lock & lo }); } -std::unique_ptr nano::local_block_broadcaster::collect_container_info (const std::string & name) const +nano::container_info nano::local_block_broadcaster::container_info () const { nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "local", local_blocks.size (), sizeof (decltype (local_blocks)::value_type) })); - return composite; + nano::container_info info; + info.put ("local", local_blocks); + return info; } \ No newline at end of file diff --git a/nano/node/local_block_broadcaster.hpp b/nano/node/local_block_broadcaster.hpp index 1583e7d382..d2bed33ce3 100644 --- a/nano/node/local_block_broadcaster.hpp +++ b/nano/node/local_block_broadcaster.hpp @@ -60,7 +60,7 @@ class local_block_broadcaster final size_t size () const; - std::unique_ptr collect_container_info (std::string const & name) const; + nano::container_info container_info () const; private: void run (); diff --git a/nano/node/local_vote_history.cpp b/nano/node/local_vote_history.cpp index 8051fd2572..67acdd68a6 100644 --- a/nano/node/local_vote_history.cpp +++ b/nano/node/local_vote_history.cpp @@ -104,12 +104,11 @@ std::size_t nano::local_vote_history::size () const return history.size (); } -std::unique_ptr nano::local_vote_history::collect_container_info (std::string const & name) const +nano::container_info nano::local_vote_history::container_info () const { - std::size_t history_count = size (); - auto sizeof_element = sizeof (decltype (history)::value_type); - auto composite = std::make_unique (name); - /* This does not currently loop over each element inside the cache to get the sizes of the votes inside history*/ - composite->add_component (std::make_unique (container_info_entry{ "history", history_count, sizeof_element })); - return composite; -} + nano::lock_guard guard{ mutex }; + + nano::container_info info; + info.put ("history", history); + return info; +} \ No newline at end of file diff --git a/nano/node/local_vote_history.hpp b/nano/node/local_vote_history.hpp index 2cf603ec4c..311867e21a 100644 --- a/nano/node/local_vote_history.hpp +++ b/nano/node/local_vote_history.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -15,8 +16,6 @@ namespace mi = boost::multi_index; namespace nano { -class container_info_component; -class vote; class voting_constants; } @@ -50,7 +49,7 @@ class local_vote_history final bool exists (nano::root const &) const; std::size_t size () const; - std::unique_ptr collect_container_info (std::string const & name) const; + nano::container_info container_info () const; private: // clang-format off diff --git a/nano/node/message_processor.cpp b/nano/node/message_processor.cpp index 6ed8cd1185..3473a33cdd 100644 --- a/nano/node/message_processor.cpp +++ b/nano/node/message_processor.cpp @@ -281,13 +281,13 @@ void nano::message_processor::process (nano::message const & message, std::share message.visit (visitor); } -std::unique_ptr nano::message_processor::collect_container_info (std::string const & name) +nano::container_info nano::message_processor::container_info () const { nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (queue.collect_container_info ("queue")); - return composite; + nano::container_info info; + info.add ("queue", queue.container_info ()); + return info; } /* diff --git a/nano/node/message_processor.hpp b/nano/node/message_processor.hpp index 5481dc6887..f0bfa8d8c1 100644 --- a/nano/node/message_processor.hpp +++ b/nano/node/message_processor.hpp @@ -36,7 +36,7 @@ class message_processor final bool put (std::unique_ptr, std::shared_ptr const &); void process (nano::message const &, std::shared_ptr const &); - std::unique_ptr collect_container_info (std::string const & name); + nano::container_info container_info () const; private: void run (); @@ -53,7 +53,7 @@ class message_processor final nano::fair_queue queue; std::atomic stopped{ false }; - nano::mutex mutex; + mutable nano::mutex mutex; nano::condition_variable condition; std::vector threads; }; diff --git a/nano/node/network.cpp b/nano/node/network.cpp index 8eb599f002..00adac220c 100644 --- a/nano/node/network.cpp +++ b/nano/node/network.cpp @@ -571,6 +571,15 @@ nano::node_id_handshake::response_payload nano::network::prepare_handshake_respo return response; } +nano::container_info nano::network::container_info () const +{ + nano::container_info info; + info.add ("tcp_channels", tcp_channels.container_info ()); + info.add ("syn_cookies", syn_cookies.container_info ()); + info.add ("excluded_peers", excluded_peers.container_info ()); + return info; +} + /* * syn_cookies */ @@ -678,32 +687,18 @@ std::optional nano::syn_cookies::cookie (const nano::endpoi return std::nullopt; } -std::size_t nano::syn_cookies::cookies_size () +std::size_t nano::syn_cookies::cookies_size () const { nano::lock_guard lock{ syn_cookie_mutex }; return cookies.size (); } -std::unique_ptr nano::collect_container_info (network & network, std::string const & name) +nano::container_info nano::syn_cookies::container_info () const { - auto composite = std::make_unique (name); - composite->add_component (network.tcp_channels.collect_container_info ("tcp_channels")); - composite->add_component (network.syn_cookies.collect_container_info ("syn_cookies")); - composite->add_component (network.excluded_peers.collect_container_info ("excluded_peers")); - return composite; -} + nano::lock_guard syn_cookie_guard{ syn_cookie_mutex }; -std::unique_ptr nano::syn_cookies::collect_container_info (std::string const & name) -{ - std::size_t syn_cookies_count; - std::size_t syn_cookies_per_ip_count; - { - nano::lock_guard syn_cookie_guard{ syn_cookie_mutex }; - syn_cookies_count = cookies.size (); - syn_cookies_per_ip_count = cookies_per_ip.size (); - } - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "syn_cookies", syn_cookies_count, sizeof (decltype (cookies)::value_type) })); - composite->add_component (std::make_unique (container_info_entry{ "syn_cookies_per_ip", syn_cookies_per_ip_count, sizeof (decltype (cookies_per_ip)::value_type) })); - return composite; -} + nano::container_info info; + info.put ("syn_cookies", cookies.size ()); + info.put ("syn_cookies_per_ip", cookies_per_ip.size ()); + return info; +} \ No newline at end of file diff --git a/nano/node/network.hpp b/nano/node/network.hpp index 31ebeee2b3..b3a9361bf1 100644 --- a/nano/node/network.hpp +++ b/nano/node/network.hpp @@ -34,9 +34,8 @@ class syn_cookies final bool validate (nano::endpoint const &, nano::account const &, nano::signature const &); /** Get cookie associated with endpoint and erases that cookie from this container */ std::optional cookie (nano::endpoint const &); - - std::unique_ptr collect_container_info (std::string const &); - std::size_t cookies_size (); + std::size_t cookies_size () const; + nano::container_info container_info () const; private: // Dependencies nano::logger & logger; @@ -127,6 +126,8 @@ class network final void exclude (std::shared_ptr const & channel); void inbound (nano::message const &, std::shared_ptr const &); + nano::container_info container_info () const; + public: // Handshake /** Verifies that handshake response matches our query. @returns true if OK */ bool verify_handshake_response (nano::node_id_handshake::response_payload const & response, nano::endpoint const & remote_endpoint); @@ -173,6 +174,4 @@ class network final static std::size_t confirm_req_hashes_max; static std::size_t confirm_ack_hashes_max; }; - -std::unique_ptr collect_container_info (network & network, std::string const & name); } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 182d1cd5ef..587f95f622 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -525,46 +525,6 @@ void nano::node::keepalive (std::string const & address_a, uint16_t port_a) }); } -std::unique_ptr nano::collect_container_info (node & node, std::string const & name) -{ - auto composite = std::make_unique (name); - composite->add_component (collect_container_info (node.work, "work")); - composite->add_component (node.ledger.collect_container_info ("ledger")); - composite->add_component (collect_container_info (node.active, "active")); - composite->add_component (collect_container_info (node.bootstrap_initiator, "bootstrap_initiator")); - composite->add_component (node.tcp_listener.collect_container_info ("tcp_listener")); - composite->add_component (collect_container_info (node.network, "network")); - composite->add_component (node.telemetry.collect_container_info ("telemetry")); - composite->add_component (node.workers.collect_container_info ("workers")); - composite->add_component (node.bootstrap_workers.collect_container_info ("bootstrap_workers")); - composite->add_component (node.wallet_workers.collect_container_info ("wallet_workers")); - composite->add_component (node.election_workers.collect_container_info ("election_workers")); - composite->add_component (collect_container_info (node.observers, "observers")); - composite->add_component (collect_container_info (node.wallets, "wallets")); - composite->add_component (node.vote_processor.collect_container_info ("vote_processor")); - composite->add_component (node.vote_cache_processor.collect_container_info ("vote_cache_processor")); - composite->add_component (node.rep_crawler.collect_container_info ("rep_crawler")); - composite->add_component (node.block_processor.collect_container_info ("block_processor")); - composite->add_component (collect_container_info (node.online_reps, "online_reps")); - composite->add_component (node.history.collect_container_info ("history")); - composite->add_component (node.block_uniquer.collect_container_info ("block_uniquer")); - composite->add_component (node.vote_uniquer.collect_container_info ("vote_uniquer")); - composite->add_component (node.confirming_set.collect_container_info ("confirming_set")); - composite->add_component (collect_container_info (node.distributed_work, "distributed_work")); - composite->add_component (node.aggregator.collect_container_info ("request_aggregator")); - composite->add_component (node.scheduler.collect_container_info ("election_scheduler")); - composite->add_component (node.vote_cache.collect_container_info ("vote_cache")); - composite->add_component (node.vote_router.collect_container_info ("vote_router")); - composite->add_component (node.generator.collect_container_info ("vote_generator")); - composite->add_component (node.final_generator.collect_container_info ("vote_generator_final")); - composite->add_component (node.ascendboot.collect_container_info ("bootstrap_ascending")); - composite->add_component (node.unchecked.collect_container_info ("unchecked")); - composite->add_component (node.local_block_broadcaster.collect_container_info ("local_block_broadcaster")); - composite->add_component (node.rep_tiers.collect_container_info ("rep_tiers")); - composite->add_component (node.message_processor.collect_container_info ("message_processor")); - return composite; -} - void nano::node::process_active (std::shared_ptr const & incoming) { block_processor.add (incoming); @@ -1328,6 +1288,59 @@ std::string nano::node::make_logger_identifier (const nano::keypair & node_id) return node_id.pub.to_node_id ().substr (0, 10); } +nano::container_info nano::node::container_info () const +{ + /* + * TODO: Add container infos for: + * - bootstrap_server + * - peer_history + * - port_mapping + * - epoch_upgrader + * - websocket + */ + + nano::container_info info; + info.add ("work", work.container_info ()); + info.add ("ledger", ledger.container_info ()); + info.add ("active", active.container_info ()); + info.add ("bootstrap_initiator", bootstrap_initiator.container_info ()); + info.add ("tcp_listener", tcp_listener.container_info ()); + info.add ("network", network.container_info ()); + info.add ("telemetry", telemetry.container_info ()); + info.add ("workers", workers.container_info ()); + info.add ("bootstrap_workers", bootstrap_workers.container_info ()); + info.add ("wallet_workers", wallet_workers.container_info ()); + info.add ("election_workers", election_workers.container_info ()); + info.add ("observers", observers.container_info ()); + info.add ("wallets", wallets.container_info ()); + info.add ("vote_processor", vote_processor.container_info ()); + info.add ("vote_cache_processor", vote_cache_processor.container_info ()); + info.add ("rep_crawler", rep_crawler.container_info ()); + info.add ("block_processor", block_processor.container_info ()); + info.add ("online_reps", online_reps.container_info ()); + info.add ("history", history.container_info ()); + info.add ("block_uniquer", block_uniquer.container_info ()); + info.add ("vote_uniquer", vote_uniquer.container_info ()); + info.add ("confirming_set", confirming_set.container_info ()); + info.add ("distributed_work", distributed_work.container_info ()); + info.add ("aggregator", aggregator.container_info ()); + info.add ("scheduler", scheduler.container_info ()); + info.add ("vote_cache", vote_cache.container_info ()); + info.add ("vote_router", vote_router.container_info ()); + info.add ("generator", generator.container_info ()); + info.add ("final_generator", final_generator.container_info ()); + info.add ("bootstrap_ascending", ascendboot.container_info ()); + info.add ("unchecked", unchecked.container_info ()); + info.add ("local_block_broadcaster", local_block_broadcaster.container_info ()); + info.add ("rep_tiers", rep_tiers.container_info ()); + info.add ("message_processor", message_processor.container_info ()); + return info; +} + +/* + * + */ + nano::keypair nano::load_or_create_node_id (std::filesystem::path const & application_path) { auto node_private_key_path = application_path / "node_id_private.key"; @@ -1355,4 +1368,4 @@ nano::keypair nano::load_or_create_node_id (std::filesystem::path const & applic release_assert (!ofs.fail ()); return kp; } -} \ No newline at end of file +} diff --git a/nano/node/node.hpp b/nano/node/node.hpp index b31578a190..892468caec 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -143,6 +143,7 @@ class node final : public std::enable_shared_from_this nano::account get_node_id () const; nano::telemetry_data local_telemetry () const; std::string identifier () const; + nano::container_info container_info () const; public: const nano::keypair node_id; @@ -261,8 +262,6 @@ class node final : public std::enable_shared_from_this nano::keypair load_or_create_node_id (std::filesystem::path const & application_path); -std::unique_ptr collect_container_info (node & node, std::string const & name); - nano::node_flags const & inactive_node_flag_defaults (); } diff --git a/nano/node/node_observers.cpp b/nano/node/node_observers.cpp index e179a53d13..a0bbd03cd7 100644 --- a/nano/node/node_observers.cpp +++ b/nano/node/node_observers.cpp @@ -1,16 +1,18 @@ #include -std::unique_ptr nano::collect_container_info (nano::node_observers & node_observers, std::string const & name) +nano::container_info nano::node_observers::container_info () const { - auto composite = std::make_unique (name); - composite->add_component (node_observers.blocks.collect_container_info ("blocks")); - composite->add_component (node_observers.wallet.collect_container_info ("wallet")); - composite->add_component (node_observers.vote.collect_container_info ("vote")); - composite->add_component (node_observers.active_started.collect_container_info ("active_started")); - composite->add_component (node_observers.active_stopped.collect_container_info ("active_stopped")); - composite->add_component (node_observers.account_balance.collect_container_info ("account_balance")); - composite->add_component (node_observers.endpoint.collect_container_info ("endpoint")); - composite->add_component (node_observers.disconnect.collect_container_info ("disconnect")); - composite->add_component (node_observers.work_cancel.collect_container_info ("work_cancel")); - return composite; + nano::container_info info; + info.put ("blocks", blocks.size ()); + info.put ("wallet", wallet.size ()); + info.put ("vote", vote.size ()); + info.put ("active_started", active_started.size ()); + info.put ("active_stopped", active_stopped.size ()); + info.put ("account_balance", account_balance.size ()); + info.put ("endpoint", endpoint.size ()); + info.put ("disconnect", disconnect.size ()); + info.put ("work_cancel", work_cancel.size ()); + info.put ("telemetry", telemetry.size ()); + info.put ("socket_connected", socket_connected.size ()); + return info; } diff --git a/nano/node/node_observers.hpp b/nano/node/node_observers.hpp index db09a45c66..1c6d36ed40 100644 --- a/nano/node/node_observers.hpp +++ b/nano/node/node_observers.hpp @@ -34,7 +34,7 @@ class node_observers final nano::observer_set work_cancel; nano::observer_set const &> telemetry; nano::observer_set socket_connected; -}; -std::unique_ptr collect_container_info (node_observers & node_observers, std::string const & name); + nano::container_info container_info () const; +}; } diff --git a/nano/node/online_reps.cpp b/nano/node/online_reps.cpp index c5c259749a..805796560e 100644 --- a/nano/node/online_reps.cpp +++ b/nano/node/online_reps.cpp @@ -117,16 +117,11 @@ void nano::online_reps::clear () online_m = 0; } -std::unique_ptr nano::collect_container_info (online_reps & online_reps, std::string const & name) +nano::container_info nano::online_reps::container_info () const { - std::size_t count; - { - nano::lock_guard guard{ online_reps.mutex }; - count = online_reps.reps.size (); - } + nano::lock_guard guard{ mutex }; - auto sizeof_element = sizeof (decltype (online_reps.reps)::value_type); - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "reps", count, sizeof_element })); - return composite; + nano::container_info info; + info.put ("reps", reps); + return info; } diff --git a/nano/node/online_reps.hpp b/nano/node/online_reps.hpp index f01fec91e0..2838346f3b 100644 --- a/nano/node/online_reps.hpp +++ b/nano/node/online_reps.hpp @@ -39,6 +39,9 @@ class online_reps final /** List of online representatives, both the currently sampling ones and the ones observed in the previous sampling period */ std::vector list (); void clear (); + nano::container_info container_info () const; + +public: static unsigned constexpr online_weight_quorum = 67; private: @@ -71,8 +74,5 @@ class online_reps final nano::uint128_t minimum; friend class election_quorum_minimum_update_weight_before_quorum_checks_Test; - friend std::unique_ptr collect_container_info (online_reps & online_reps, std::string const & name); }; - -std::unique_ptr collect_container_info (online_reps & online_reps, std::string const & name); } diff --git a/nano/node/peer_exclusion.cpp b/nano/node/peer_exclusion.cpp index 6c660de0db..b2117f14e0 100644 --- a/nano/node/peer_exclusion.cpp +++ b/nano/node/peer_exclusion.cpp @@ -97,11 +97,11 @@ std::size_t nano::peer_exclusion::size () const return peers.size (); } -std::unique_ptr nano::peer_exclusion::collect_container_info (std::string const & name) +nano::container_info nano::peer_exclusion::container_info () const { nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "peers", peers.size (), sizeof (decltype (peers)::value_type) })); - return composite; -} + nano::container_info info; + info.put ("peers", peers.size ()); + return info; +} \ No newline at end of file diff --git a/nano/node/peer_exclusion.hpp b/nano/node/peer_exclusion.hpp index 4ca738d9b9..3100bfe09c 100644 --- a/nano/node/peer_exclusion.hpp +++ b/nano/node/peer_exclusion.hpp @@ -1,3 +1,5 @@ +#pragma once + #include #include @@ -54,6 +56,6 @@ class peer_exclusion final void remove (nano::tcp_endpoint const &); std::size_t size () const; - std::unique_ptr collect_container_info (std::string const & name); + nano::container_info container_info () const; }; } diff --git a/nano/node/recently_cemented_cache.cpp b/nano/node/recently_cemented_cache.cpp index 12ef60d2ec..13d84ac23a 100644 --- a/nano/node/recently_cemented_cache.cpp +++ b/nano/node/recently_cemented_cache.cpp @@ -32,11 +32,11 @@ std::size_t nano::recently_cemented_cache::size () const return cemented.size (); } -std::unique_ptr nano::recently_cemented_cache::collect_container_info (const std::string & name) +nano::container_info nano::recently_cemented_cache::container_info () const { - nano::unique_lock lock{ mutex }; + nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "cemented", cemented.size (), sizeof (decltype (cemented)::value_type) })); - return composite; + nano::container_info info; + info.put ("cemented", cemented); + return info; } diff --git a/nano/node/recently_cemented_cache.hpp b/nano/node/recently_cemented_cache.hpp index c2f382d673..b18a645e7c 100644 --- a/nano/node/recently_cemented_cache.hpp +++ b/nano/node/recently_cemented_cache.hpp @@ -26,13 +26,12 @@ class recently_cemented_cache final queue_t list () const; std::size_t size () const; + nano::container_info container_info () const; + private: queue_t cemented; std::size_t const max_size; mutable nano::mutex mutex; - -public: // Container info - std::unique_ptr collect_container_info (std::string const &); }; } diff --git a/nano/node/recently_confirmed_cache.cpp b/nano/node/recently_confirmed_cache.cpp index e2ec7a9acd..6f1205b52b 100644 --- a/nano/node/recently_confirmed_cache.cpp +++ b/nano/node/recently_confirmed_cache.cpp @@ -56,11 +56,11 @@ nano::recently_confirmed_cache::entry_t nano::recently_confirmed_cache::back () return confirmed.back (); } -std::unique_ptr nano::recently_confirmed_cache::collect_container_info (const std::string & name) +nano::container_info nano::recently_confirmed_cache::container_info () const { - nano::unique_lock lock{ mutex }; + nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "confirmed", confirmed.size (), sizeof (decltype (confirmed)::value_type) })); - return composite; + nano::container_info info; + info.put ("confirmed", confirmed); + return info; } diff --git a/nano/node/recently_confirmed_cache.hpp b/nano/node/recently_confirmed_cache.hpp index 5b8249d906..803039275e 100644 --- a/nano/node/recently_confirmed_cache.hpp +++ b/nano/node/recently_confirmed_cache.hpp @@ -34,6 +34,8 @@ class recently_confirmed_cache final bool exists (nano::qualified_root const &) const; bool exists (nano::block_hash const &) const; + nano::container_info container_info () const; + public: // Tests entry_t back () const; @@ -56,8 +58,5 @@ class recently_confirmed_cache final std::size_t const max_size; mutable nano::mutex mutex; - -public: // Container info - std::unique_ptr collect_container_info (std::string const &); }; } diff --git a/nano/node/rep_tiers.cpp b/nano/node/rep_tiers.cpp index f789dbf0ae..6bc532787e 100644 --- a/nano/node/rep_tiers.cpp +++ b/nano/node/rep_tiers.cpp @@ -118,6 +118,7 @@ void nano::rep_tiers::calculate_tiers () stats.add (nano::stat::type::rep_tiers, nano::stat::detail::processed, nano::stat::dir::in, rep_amounts.size ()); stats.add (nano::stat::type::rep_tiers, nano::stat::detail::ignored, nano::stat::dir::in, ignored); + logger.debug (nano::log::type::rep_tiers, "Representative tiers updated, tier 1: {}, tier 2: {}, tier 3: {} ({} ignored)", representatives_1_l.size (), representatives_2_l.size (), @@ -134,14 +135,15 @@ void nano::rep_tiers::calculate_tiers () stats.inc (nano::stat::type::rep_tiers, nano::stat::detail::updated); } -std::unique_ptr nano::rep_tiers::collect_container_info (const std::string & name) +nano::container_info nano::rep_tiers::container_info () const { nano::lock_guard lock{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "representatives_1", representatives_1.size (), sizeof (decltype (representatives_1)::value_type) })); - composite->add_component (std::make_unique (container_info_entry{ "representatives_2", representatives_2.size (), sizeof (decltype (representatives_2)::value_type) })); - composite->add_component (std::make_unique (container_info_entry{ "representatives_3", representatives_3.size (), sizeof (decltype (representatives_3)::value_type) })); - return composite; + + nano::container_info info; + info.put ("tier_1", representatives_1); + info.put ("tier_2", representatives_2); + info.put ("tier_3", representatives_3); + return info; } nano::stat::detail nano::to_stat_detail (nano::rep_tier tier) diff --git a/nano/node/rep_tiers.hpp b/nano/node/rep_tiers.hpp index e9134a46e9..71c63ab0df 100644 --- a/nano/node/rep_tiers.hpp +++ b/nano/node/rep_tiers.hpp @@ -40,7 +40,7 @@ class rep_tiers final /** Returns the representative tier for the account */ nano::rep_tier tier (nano::account const & representative) const; - std::unique_ptr collect_container_info (std::string const & name); + nano::container_info container_info () const; private: // Dependencies nano::ledger & ledger; diff --git a/nano/node/repcrawler.cpp b/nano/node/repcrawler.cpp index 1db2ab70c9..16d72b17a1 100644 --- a/nano/node/repcrawler.cpp +++ b/nano/node/repcrawler.cpp @@ -435,7 +435,7 @@ nano::uint128_t nano::rep_crawler::total_weight () const return result; } -std::vector nano::rep_crawler::representatives (std::size_t count, nano::uint128_t const minimum_weight, std::optional const & minimum_protocol_version) +std::vector nano::rep_crawler::representatives (std::size_t count, nano::uint128_t const minimum_weight, std::optional const & minimum_protocol_version) const { auto const version_min = minimum_protocol_version.value_or (node.network_params.network.protocol_version_min); @@ -460,28 +460,17 @@ std::vector nano::rep_crawler::representatives (std::size_ return result; } -std::vector nano::rep_crawler::principal_representatives (std::size_t count, std::optional const & minimum_protocol_version) +std::vector nano::rep_crawler::principal_representatives (std::size_t count, std::optional const & minimum_protocol_version) const { return representatives (count, node.minimum_principal_weight (), minimum_protocol_version); } -std::size_t nano::rep_crawler::representative_count () +std::size_t nano::rep_crawler::representative_count () const { nano::lock_guard lock{ mutex }; return reps.size (); } -std::unique_ptr nano::rep_crawler::collect_container_info (const std::string & name) -{ - nano::lock_guard guard{ mutex }; - - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "reps", reps.size (), sizeof (decltype (reps)::value_type) })); - composite->add_component (std::make_unique (container_info_entry{ "queries", queries.size (), sizeof (decltype (queries)::value_type) })); - composite->add_component (std::make_unique (container_info_entry{ "responses", responses.size (), sizeof (decltype (responses)::value_type) })); - return composite; -} - // Only for tests void nano::rep_crawler::force_add_rep (const nano::account & account, const std::shared_ptr & channel) { @@ -506,6 +495,17 @@ void nano::rep_crawler::force_query (const nano::block_hash & hash, const std::s queries.emplace (query_entry{ hash, channel }); } +nano::container_info nano::rep_crawler::container_info () const +{ + nano::lock_guard guard{ mutex }; + + nano::container_info info; + info.put ("reps", reps); + info.put ("queries", queries); + info.put ("responses", responses); + return info; +} + /* * rep_crawler_config */ diff --git a/nano/node/repcrawler.hpp b/nano/node/repcrawler.hpp index 5f9bbf7f7f..c7892399e1 100644 --- a/nano/node/repcrawler.hpp +++ b/nano/node/repcrawler.hpp @@ -76,16 +76,16 @@ class rep_crawler final /** Request a list of the top \p count known representatives in descending order of weight, with at least \p weight_a voting weight, and optionally with a minimum version \p minimum_protocol_version */ - std::vector representatives (std::size_t count = std::numeric_limits::max (), nano::uint128_t minimum_weight = 0, std::optional const & minimum_protocol_version = {}); + std::vector representatives (std::size_t count = std::numeric_limits::max (), nano::uint128_t minimum_weight = 0, std::optional const & minimum_protocol_version = {}) const; /** Request a list of the top \p count known principal representatives in descending order of weight, optionally with a minimum version \p minimum_protocol_version */ - std::vector principal_representatives (std::size_t count = std::numeric_limits::max (), std::optional const & minimum_protocol_version = {}); + std::vector principal_representatives (std::size_t count = std::numeric_limits::max (), std::optional const & minimum_protocol_version = {}) const; /** Total number of representatives */ - std::size_t representative_count (); + std::size_t representative_count () const; - std::unique_ptr collect_container_info (std::string const & name); + nano::container_info container_info () const; private: // Dependencies rep_crawler_config const & config; diff --git a/nano/node/request_aggregator.cpp b/nano/node/request_aggregator.cpp index e846950bc8..8465b7d2b0 100644 --- a/nano/node/request_aggregator.cpp +++ b/nano/node/request_aggregator.cpp @@ -291,13 +291,13 @@ auto nano::request_aggregator::aggregate (nano::secure::transaction const & tran }; } -std::unique_ptr nano::request_aggregator::collect_container_info (std::string const & name) const +nano::container_info nano::request_aggregator::container_info () const { nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (queue.collect_container_info ("queue")); - return composite; + nano::container_info info; + info.add ("queue", queue.container_info ()); + return info; } /* diff --git a/nano/node/request_aggregator.hpp b/nano/node/request_aggregator.hpp index d0a72074af..c910720e13 100644 --- a/nano/node/request_aggregator.hpp +++ b/nano/node/request_aggregator.hpp @@ -51,7 +51,6 @@ class request_aggregator final void start (); void stop (); -public: using request_type = std::vector>; /** Add a new request by \p channel_a for hashes \p hashes_roots_a */ @@ -61,7 +60,7 @@ class request_aggregator final std::size_t size () const; bool empty () const; - std::unique_ptr collect_container_info (std::string const & name) const; + nano::container_info container_info () const; private: void run (); diff --git a/nano/node/scheduler/component.cpp b/nano/node/scheduler/component.cpp index 0d44042448..de3f7469cb 100644 --- a/nano/node/scheduler/component.cpp +++ b/nano/node/scheduler/component.cpp @@ -37,12 +37,12 @@ void nano::scheduler::component::stop () priority.stop (); } -std::unique_ptr nano::scheduler::component::collect_container_info (std::string const & name) +nano::container_info nano::scheduler::component::container_info () const { - auto composite = std::make_unique (name); - composite->add_component (hinted.collect_container_info ("hinted")); - composite->add_component (manual.collect_container_info ("manual")); - composite->add_component (optimistic.collect_container_info ("optimistic")); - composite->add_component (priority.collect_container_info ("priority")); - return composite; + nano::container_info info; + info.add ("hinted", hinted.container_info ()); + info.add ("manual", manual.container_info ()); + info.add ("optimistic", optimistic.container_info ()); + info.add ("priority", priority.container_info ()); + return info; } diff --git a/nano/node/scheduler/component.hpp b/nano/node/scheduler/component.hpp index 8f9e5af075..090b4f6985 100644 --- a/nano/node/scheduler/component.hpp +++ b/nano/node/scheduler/component.hpp @@ -1,27 +1,14 @@ #pragma once +#include + #include #include -namespace nano -{ -class container_info_component; -class node; -} namespace nano::scheduler { -class hinted; -class manual; -class optimistic; -class priority; - class component final { - std::unique_ptr hinted_impl; - std::unique_ptr manual_impl; - std::unique_ptr optimistic_impl; - std::unique_ptr priority_impl; - public: explicit component (nano::node & node); ~component (); @@ -31,8 +18,15 @@ class component final // Stops all schedulers void stop (); - std::unique_ptr collect_container_info (std::string const & name); + nano::container_info container_info () const; + +private: + std::unique_ptr hinted_impl; + std::unique_ptr manual_impl; + std::unique_ptr optimistic_impl; + std::unique_ptr priority_impl; +public: // Schedulers nano::scheduler::hinted & hinted; nano::scheduler::manual & manual; nano::scheduler::optimistic & optimistic; diff --git a/nano/node/scheduler/hinted.cpp b/nano/node/scheduler/hinted.cpp index 50711be90e..47e1ff5ae8 100644 --- a/nano/node/scheduler/hinted.cpp +++ b/nano/node/scheduler/hinted.cpp @@ -236,13 +236,13 @@ bool nano::scheduler::hinted::cooldown (const nano::block_hash & hash) return false; // No need to cooldown } -std::unique_ptr nano::scheduler::hinted::collect_container_info (const std::string & name) const +nano::container_info nano::scheduler::hinted::container_info () const { nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "cooldowns", cooldowns_m.size (), sizeof (decltype (cooldowns_m)::value_type) })); - return composite; + nano::container_info info; + info.put ("cooldowns", cooldowns_m); + return info; } /* diff --git a/nano/node/scheduler/hinted.hpp b/nano/node/scheduler/hinted.hpp index 12eea04698..7cae2f999e 100644 --- a/nano/node/scheduler/hinted.hpp +++ b/nano/node/scheduler/hinted.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -16,20 +17,6 @@ namespace mi = boost::multi_index; -namespace nano -{ -class node; -class node_config; -class active_elections; -class vote_cache; -class online_reps; -} -namespace nano::secure -{ -class transaction; -class read_transaction; -} - namespace nano::scheduler { class hinted_config final @@ -65,7 +52,7 @@ class hinted final */ void notify (); - std::unique_ptr collect_container_info (std::string const & name) const; + nano::container_info container_info () const; private: bool predicate () const; diff --git a/nano/node/scheduler/manual.cpp b/nano/node/scheduler/manual.cpp index 6c1b967444..5b1bec4f03 100644 --- a/nano/node/scheduler/manual.cpp +++ b/nano/node/scheduler/manual.cpp @@ -86,11 +86,11 @@ void nano::scheduler::manual::run () } } -std::unique_ptr nano::scheduler::manual::collect_container_info (std::string const & name) const +nano::container_info nano::scheduler::manual::container_info () const { - nano::unique_lock lock{ mutex }; + nano::lock_guard lock{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "queue", queue.size (), sizeof (decltype (queue)::value_type) })); - return composite; -} + nano::container_info info; + info.put ("queue", queue); + return info; +} \ No newline at end of file diff --git a/nano/node/scheduler/manual.hpp b/nano/node/scheduler/manual.hpp index 3e059b3447..9fe527e50f 100644 --- a/nano/node/scheduler/manual.hpp +++ b/nano/node/scheduler/manual.hpp @@ -1,6 +1,8 @@ #pragma once + #include #include +#include #include @@ -8,16 +10,10 @@ #include #include -namespace nano -{ -class block; -enum class election_behavior; -class node; -} - namespace nano::scheduler { class buckets; + class manual final { std::deque, boost::optional, nano::election_behavior>> queue; @@ -31,7 +27,7 @@ class manual final void run (); public: - manual (nano::node & node); + explicit manual (nano::node & node); ~manual (); void start (); @@ -41,6 +37,6 @@ class manual final // Call action with confirmed block, may be different than what we started with void push (std::shared_ptr const &, boost::optional const & = boost::none); - std::unique_ptr collect_container_info (std::string const & name) const; -}; // class manual -} // nano::scheduler + nano::container_info container_info () const; +}; +} diff --git a/nano/node/scheduler/optimistic.cpp b/nano/node/scheduler/optimistic.cpp index c9f6055336..e2d95b0211 100644 --- a/nano/node/scheduler/optimistic.cpp +++ b/nano/node/scheduler/optimistic.cpp @@ -168,13 +168,13 @@ void nano::scheduler::optimistic::run_one (secure::transaction const & transacti } } -std::unique_ptr nano::scheduler::optimistic::collect_container_info (const std::string & name) const +nano::container_info nano::scheduler::optimistic::container_info () const { nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "candidates", candidates.size (), sizeof (decltype (candidates)::value_type) })); - return composite; + nano::container_info info; + info.put ("candidates", candidates); + return info; } /* diff --git a/nano/node/scheduler/optimistic.hpp b/nano/node/scheduler/optimistic.hpp index a89ce0290b..bcf3e3ca67 100644 --- a/nano/node/scheduler/optimistic.hpp +++ b/nano/node/scheduler/optimistic.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -20,14 +21,6 @@ namespace mi = boost::multi_index; -namespace nano -{ -class account_info; -class active_elections; -class ledger; -class node; -} - namespace nano::scheduler { class optimistic_config final @@ -67,7 +60,7 @@ class optimistic final */ void notify (); - std::unique_ptr collect_container_info (std::string const & name) const; + nano::container_info container_info () const; private: bool activate_predicate (nano::account_info const &, nano::confirmation_height_info const &) const; diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index 39ea1fc90d..b209a2c59c 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -229,30 +229,30 @@ auto nano::scheduler::priority::find_bucket (nano::uint128_t priority) -> bucket return **it; } -std::unique_ptr nano::scheduler::priority::collect_container_info (std::string const & name) const +nano::container_info nano::scheduler::priority::container_info () const { auto collect_blocks = [&] () { - auto composite = std::make_unique ("blocks"); + nano::container_info info; for (auto i = 0; i < buckets.size (); ++i) { auto const & bucket = buckets[i]; - composite->add_component (std::make_unique (container_info_entry{ std::to_string (i), bucket->size (), 0 })); + info.put (std::to_string (i), bucket->size ()); } - return composite; + return info; }; auto collect_elections = [&] () { - auto composite = std::make_unique ("elections"); + nano::container_info info; for (auto i = 0; i < buckets.size (); ++i) { auto const & bucket = buckets[i]; - composite->add_component (std::make_unique (container_info_entry{ std::to_string (i), bucket->election_count (), 0 })); + info.put (std::to_string (i), bucket->election_count ()); } - return composite; + return info; }; - auto composite = std::make_unique (name); - composite->add_component (collect_blocks ()); - composite->add_component (collect_elections ()); - return composite; -} + nano::container_info info; + info.add ("blocks", collect_blocks ()); + info.add ("elections", collect_elections ()); + return info; +} \ No newline at end of file diff --git a/nano/node/scheduler/priority.hpp b/nano/node/scheduler/priority.hpp index e80d6b74b3..727598184c 100644 --- a/nano/node/scheduler/priority.hpp +++ b/nano/node/scheduler/priority.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -9,22 +10,10 @@ #include #include -namespace nano -{ -class account_info; -class confirmation_height_info; -class block; -class container_info_component; -class node; -class stats; -} -namespace nano::secure -{ -class transaction; -} - namespace nano::scheduler { +class buckets; + class priority_config { public: @@ -34,7 +23,6 @@ class priority_config bool enabled{ true }; }; -class buckets; class priority final { public: @@ -55,7 +43,7 @@ class priority final std::size_t size () const; bool empty () const; - std::unique_ptr collect_container_info (std::string const & name) const; + nano::container_info container_info () const; private: // Dependencies priority_config const & config; diff --git a/nano/node/telemetry.cpp b/nano/node/telemetry.cpp index 51864db34a..1ae2a59be0 100644 --- a/nano/node/telemetry.cpp +++ b/nano/node/telemetry.cpp @@ -289,11 +289,11 @@ std::unordered_map nano::telemetry::get_al return result; } -std::unique_ptr nano::telemetry::collect_container_info (const std::string & name) +nano::container_info nano::telemetry::container_info () const { nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "telemetries", telemetries.size (), sizeof (decltype (telemetries)::value_type) })); - return composite; + nano::container_info info; + info.put ("telemetries", telemetries.size ()); + return info; } \ No newline at end of file diff --git a/nano/node/telemetry.hpp b/nano/node/telemetry.hpp index be3542fa65..6262cb25e2 100644 --- a/nano/node/telemetry.hpp +++ b/nano/node/telemetry.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -20,18 +21,6 @@ namespace mi = boost::multi_index; namespace nano { -class node; -class network; -class node_observers; -class stats; -class ledger; -class thread_pool; -class unchecked_map; -namespace transport -{ - class channel; -} - class telemetry_config final { public: @@ -84,8 +73,7 @@ class telemetry */ std::unordered_map get_all_telemetries () const; -public: // Container info - std::unique_ptr collect_container_info (std::string const & name); + nano::container_info container_info () const; private: // Dependencies telemetry_config const config; diff --git a/nano/node/transport/fwd.hpp b/nano/node/transport/fwd.hpp index 1300b13cd6..c62c470304 100644 --- a/nano/node/transport/fwd.hpp +++ b/nano/node/transport/fwd.hpp @@ -5,5 +5,6 @@ namespace nano::transport class channel; class tcp_channel; class tcp_channels; +class tcp_server; class tcp_socket; } \ No newline at end of file diff --git a/nano/node/transport/tcp_channels.cpp b/nano/node/transport/tcp_channels.cpp index 329d77842a..7a41280563 100644 --- a/nano/node/transport/tcp_channels.cpp +++ b/nano/node/transport/tcp_channels.cpp @@ -312,23 +312,6 @@ bool nano::transport::tcp_channels::track_reachout (nano::endpoint const & endpo return inserted; } -std::unique_ptr nano::transport::tcp_channels::collect_container_info (std::string const & name) -{ - std::size_t channels_count; - std::size_t attemps_count; - { - nano::lock_guard guard{ mutex }; - channels_count = channels.size (); - attemps_count = attempts.size (); - } - - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "channels", channels_count, sizeof (decltype (channels)::value_type) })); - composite->add_component (std::make_unique (container_info_entry{ "attempts", attemps_count, sizeof (decltype (attempts)::value_type) })); - - return composite; -} - void nano::transport::tcp_channels::purge (std::chrono::steady_clock::time_point cutoff_deadline) { nano::lock_guard lock{ mutex }; @@ -449,4 +432,14 @@ void nano::transport::tcp_channels::modify (std::shared_ptr guard{ mutex }; + + nano::container_info info; + info.put ("channels", channels.size ()); + info.put ("attempts", attempts.size ()); + return info; } \ No newline at end of file diff --git a/nano/node/transport/tcp_channels.hpp b/nano/node/transport/tcp_channels.hpp index 913550887c..7afd89fc79 100644 --- a/nano/node/transport/tcp_channels.hpp +++ b/nano/node/transport/tcp_channels.hpp @@ -48,7 +48,6 @@ class tcp_channels final bool max_ip_or_subnetwork_connections (nano::tcp_endpoint const & endpoint_a); // Should we reach out to this endpoint with a keepalive message? If yes, register a new reachout attempt bool track_reachout (nano::endpoint const &); - std::unique_ptr collect_container_info (std::string const &); void purge (std::chrono::steady_clock::time_point cutoff_deadline); void list (std::deque> &, uint8_t = 0, bool = true); void modify (std::shared_ptr const &, std::function const &)>); @@ -58,6 +57,8 @@ class tcp_channels final // Connection start void start_tcp (nano::endpoint const &); + nano::container_info container_info () const; + private: // Dependencies nano::node & node; diff --git a/nano/node/transport/tcp_listener.cpp b/nano/node/transport/tcp_listener.cpp index 1c3e44400d..ad3fc63329 100644 --- a/nano/node/transport/tcp_listener.cpp +++ b/nano/node/transport/tcp_listener.cpp @@ -601,12 +601,14 @@ auto nano::transport::tcp_listener::servers () const -> std::vector nano::transport::tcp_listener::collect_container_info (std::string const & name) +nano::container_info nano::transport::tcp_listener::container_info () const { - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "connections", connection_count (), sizeof (decltype (connections)::value_type) })); - composite->add_component (std::make_unique (container_info_entry{ "attempts", attempt_count (), sizeof (decltype (attempts)::value_type) })); - return composite; + nano::lock_guard lock{ mutex }; + + nano::container_info info; + info.put ("connections", connections.size ()); + info.put ("attempts", attempts.size ()); + return info; } /* diff --git a/nano/node/transport/tcp_listener.hpp b/nano/node/transport/tcp_listener.hpp index 55d0603d88..55c63da64a 100644 --- a/nano/node/transport/tcp_listener.hpp +++ b/nano/node/transport/tcp_listener.hpp @@ -22,9 +22,6 @@ namespace asio = boost::asio; namespace nano::transport { -class socket; -class tcp_server; - class tcp_config { public: @@ -84,7 +81,7 @@ class tcp_listener final std::vector> sockets () const; std::vector> servers () const; - std::unique_ptr collect_container_info (std::string const & name); + nano::container_info container_info () const; public: // Events using connection_accepted_event_t = nano::observer_set const &, std::shared_ptr>; diff --git a/nano/node/unchecked_map.cpp b/nano/node/unchecked_map.cpp index 08386cc2d8..8124481b01 100644 --- a/nano/node/unchecked_map.cpp +++ b/nano/node/unchecked_map.cpp @@ -102,12 +102,23 @@ void nano::unchecked_map::clear () entries.clear (); } -std::size_t nano::unchecked_map::count () const +size_t nano::unchecked_map::entries_size () const { nano::lock_guard lock{ entries_mutex }; return entries.size (); } +size_t nano::unchecked_map::queries_size () const +{ + nano::lock_guard lock{ mutex }; + return buffer.size (); +} + +size_t nano::unchecked_map::count () const +{ + return entries_size (); +} + void nano::unchecked_map::trigger (nano::hash_or_account const & dependency) { nano::unique_lock lock{ mutex }; @@ -166,16 +177,10 @@ void nano::unchecked_map::query_impl (nano::block_hash const & hash) } } -std::unique_ptr nano::unchecked_map::collect_container_info (const std::string & name) +nano::container_info nano::unchecked_map::container_info () const { - auto composite = std::make_unique (name); - { - std::lock_guard guard{ entries_mutex }; - composite->add_component (std::make_unique (container_info_entry{ "entries", entries.size (), sizeof (decltype (entries)::value_type) })); - } - { - nano::lock_guard lock{ mutex }; - composite->add_component (std::make_unique (container_info_entry{ "queries", buffer.size (), sizeof (decltype (buffer)::value_type) })); - } - return composite; + nano::container_info info; + info.put ("entries", entries_size ()); + info.put ("queries", queries_size ()); + return info; } diff --git a/nano/node/unchecked_map.hpp b/nano/node/unchecked_map.hpp index b6c904d4be..f8fd0740b7 100644 --- a/nano/node/unchecked_map.hpp +++ b/nano/node/unchecked_map.hpp @@ -37,13 +37,18 @@ class unchecked_map bool exists (nano::unchecked_key const & key) const; void del (nano::unchecked_key const & key); void clear (); - std::size_t count () const; /** * Trigger requested dependencies */ void trigger (nano::hash_or_account const & dependency); + size_t count () const; // Same as `entries_size ()` + size_t entries_size () const; + size_t queries_size () const; + + nano::container_info container_info () const; + public: // Events nano::observer_set satisfied; @@ -62,7 +67,7 @@ class unchecked_map bool stopped{ false }; nano::condition_variable condition; - nano::mutex mutex; + mutable nano::mutex mutex; // Protects queries std::thread thread; unsigned const max_unchecked_blocks; @@ -88,9 +93,6 @@ class unchecked_map // clang-format on ordered_unchecked entries; - mutable std::recursive_mutex entries_mutex; - -public: // Container info - std::unique_ptr collect_container_info (std::string const & name); + mutable std::recursive_mutex entries_mutex; // Protects entries }; } diff --git a/nano/node/vote_cache.cpp b/nano/node/vote_cache.cpp index 99aab149b1..36f9c4adf9 100644 --- a/nano/node/vote_cache.cpp +++ b/nano/node/vote_cache.cpp @@ -272,13 +272,13 @@ void nano::vote_cache::cleanup () }); } -std::unique_ptr nano::vote_cache::collect_container_info (const std::string & name) const +nano::container_info nano::vote_cache::container_info () const { nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "cache", cache.size (), sizeof (ordered_cache::value_type) })); - return composite; + nano::container_info info; + info.put ("cache", cache); + return info; } /* diff --git a/nano/node/vote_cache.hpp b/nano/node/vote_cache.hpp index 2040482948..c70bae9d37 100644 --- a/nano/node/vote_cache.hpp +++ b/nano/node/vote_cache.hpp @@ -144,7 +144,6 @@ class vote_cache final std::size_t size () const; bool empty () const; -public: struct top_entry { nano::block_hash hash; @@ -159,8 +158,7 @@ class vote_cache final */ std::deque top (nano::uint128_t const & min_tally); -public: // Container info - std::unique_ptr collect_container_info (std::string const & name) const; + nano::container_info container_info () const; public: /** diff --git a/nano/node/vote_generator.cpp b/nano/node/vote_generator.cpp index 028e268cbd..a9ffaa785f 100644 --- a/nano/node/vote_generator.cpp +++ b/nano/node/vote_generator.cpp @@ -314,20 +314,11 @@ void nano::vote_generator::run () } } -std::unique_ptr nano::vote_generator::collect_container_info (std::string const & name) const +nano::container_info nano::vote_generator::container_info () const { - std::size_t candidates_count = 0; - std::size_t requests_count = 0; - { - nano::lock_guard guard{ mutex }; - candidates_count = candidates.size (); - requests_count = requests.size (); - } - auto sizeof_candidate_element = sizeof (decltype (candidates)::value_type); - auto sizeof_request_element = sizeof (decltype (requests)::value_type); - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "candidates", candidates_count, sizeof_candidate_element })); - composite->add_component (std::make_unique (container_info_entry{ "requests", requests_count, sizeof_request_element })); - composite->add_component (vote_generation_queue.collect_container_info ("vote_generation_queue")); - return composite; -} + nano::container_info info; + info.put ("candidates", candidates.size ()); + info.put ("requests", requests.size ()); + info.add ("queue", vote_generation_queue.container_info ()); + return info; +} \ No newline at end of file diff --git a/nano/node/vote_generator.hpp b/nano/node/vote_generator.hpp index 6557274a39..c93317bcc3 100644 --- a/nano/node/vote_generator.hpp +++ b/nano/node/vote_generator.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -21,29 +22,6 @@ namespace mi = boost::multi_index; -namespace nano -{ -class ledger; -class local_vote_history; -class network; -class node; -class node_config; -class stats; -class vote_processor; -class vote_spacing; -class wallets; -} -namespace nano::secure -{ -class transaction; -class write_transaction; -class read_transaction; -} -namespace nano::transport -{ -class channel; -} - namespace nano { class vote_generator final @@ -66,7 +44,7 @@ class vote_generator final void start (); void stop (); - std::unique_ptr collect_container_info (std::string const & name) const; + nano::container_info container_info () const; private: using transaction_variant_t = std::variant; @@ -96,7 +74,7 @@ class vote_generator final nano::logger & logger; private: - processing_queue vote_generation_queue; + nano::processing_queue vote_generation_queue; private: const bool is_final; diff --git a/nano/node/vote_processor.cpp b/nano/node/vote_processor.cpp index dd75e61aaf..b4321c8cfb 100644 --- a/nano/node/vote_processor.cpp +++ b/nano/node/vote_processor.cpp @@ -213,14 +213,14 @@ bool nano::vote_processor::empty () const return queue.empty (); } -std::unique_ptr nano::vote_processor::collect_container_info (std::string const & name) const +nano::container_info nano::vote_processor::container_info () const { nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "votes", queue.size (), sizeof (decltype (queue)::value_type) })); - composite->add_component (queue.collect_container_info ("queue")); - return composite; + nano::container_info info; + info.put ("votes", queue.size ()); + info.add ("queue", queue.container_info ()); + return info; } /* @@ -338,12 +338,13 @@ bool nano::vote_cache_processor::empty () const return size () == 0; } -std::unique_ptr nano::vote_cache_processor::collect_container_info (std::string const & name) const +nano::container_info nano::vote_cache_processor::container_info () const { nano::lock_guard guard{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "triggered", triggered.size (), sizeof (decltype (triggered)::value_type) })); - return composite; + + nano::container_info info; + info.put ("triggered", triggered.size ()); + return info; } /* diff --git a/nano/node/vote_processor.hpp b/nano/node/vote_processor.hpp index 2a22f65eea..e204d47b70 100644 --- a/nano/node/vote_processor.hpp +++ b/nano/node/vote_processor.hpp @@ -50,7 +50,7 @@ class vote_processor final std::size_t size () const; bool empty () const; - std::unique_ptr collect_container_info (std::string const & name) const; + nano::container_info container_info () const; std::atomic total_processed{ 0 }; @@ -96,7 +96,7 @@ class vote_cache_processor final std::size_t size () const; bool empty () const; - std::unique_ptr collect_container_info (std::string const & name) const; + nano::container_info container_info () const; private: void run (); diff --git a/nano/node/vote_router.cpp b/nano/node/vote_router.cpp index c5117f2f7e..39710df132 100644 --- a/nano/node/vote_router.cpp +++ b/nano/node/vote_router.cpp @@ -169,15 +169,6 @@ void nano::vote_router::stop () } } -std::unique_ptr nano::vote_router::collect_container_info (std::string const & name) const -{ - std::shared_lock lock{ mutex }; - - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "elections", elections.size (), sizeof (decltype (elections)::value_type) })); - return composite; -} - void nano::vote_router::run () { std::unique_lock lock{ mutex }; @@ -187,3 +178,12 @@ void nano::vote_router::run () condition.wait_for (lock, 15s, [&] () { return stopped; }); } } + +nano::container_info nano::vote_router::container_info () const +{ + std::shared_lock lock{ mutex }; + + nano::container_info info; + info.put ("elections", elections); + return info; +} \ No newline at end of file diff --git a/nano/node/vote_router.hpp b/nano/node/vote_router.hpp index 0468bf3d3c..1dcb80da7e 100644 --- a/nano/node/vote_router.hpp +++ b/nano/node/vote_router.hpp @@ -1,21 +1,13 @@ #pragma once #include +#include #include #include #include #include -namespace nano -{ -class container_info_component; -class election; -class recently_confirmed_cache; -class vote; -class vote_cache; -} - namespace nano { enum class vote_code @@ -46,6 +38,7 @@ class vote_router final public: vote_router (nano::vote_cache & cache, nano::recently_confirmed_cache & recently_confirmed); ~vote_router (); + // Add a route for 'hash' to 'election' // Existing routes will be replaced // Election must hold the block for the hash being passed in @@ -68,7 +61,7 @@ class vote_router final using vote_processed_event_t = nano::observer_set const &, nano::vote_source, std::unordered_map const &>; vote_processed_event_t vote_processed; - std::unique_ptr collect_container_info (std::string const & name) const; + nano::container_info container_info () const; private: void run (); diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index a05d67f9da..837a2ca417 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -1801,20 +1801,12 @@ bool nano::mdb_wallets_store::init_error () const return error; } -std::unique_ptr nano::collect_container_info (wallets & wallets, std::string const & name) +nano::container_info nano::wallets::container_info () const { - std::size_t items_count; - std::size_t actions_count; - { - nano::lock_guard guard{ wallets.mutex }; - items_count = wallets.items.size (); - actions_count = wallets.actions.size (); - } + nano::lock_guard guard{ mutex }; - auto sizeof_item_element = sizeof (decltype (wallets.items)::value_type); - auto sizeof_actions_element = sizeof (decltype (wallets.actions)::value_type); - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "items", items_count, sizeof_item_element })); - composite->add_component (std::make_unique (container_info_entry{ "actions", actions_count, sizeof_actions_element })); - return composite; + nano::container_info info; + info.put ("items", items.size ()); + info.put ("actions", actions.size ()); + return info; } diff --git a/nano/node/wallet.hpp b/nano/node/wallet.hpp index 7366ec4702..7ef86efba8 100644 --- a/nano/node/wallet.hpp +++ b/nano/node/wallet.hpp @@ -222,13 +222,15 @@ class wallets final void ongoing_compute_reps (); void receive_confirmed (nano::block_hash const & hash_a, nano::account const & destination_a); std::unordered_map> get_wallets (); + nano::container_info container_info () const; + nano::network_params & network_params; std::function observer; std::unordered_map> items; std::multimap, std::function>, std::greater> actions; nano::locked> delayed_work; - nano::mutex mutex; - nano::mutex action_mutex; + mutable nano::mutex mutex; + mutable nano::mutex action_mutex; nano::condition_variable condition; nano::kdf kdf; MDB_dbi handle; @@ -250,8 +252,6 @@ class wallets final nano::wallet_representatives representatives; }; -std::unique_ptr collect_container_info (wallets & wallets, std::string const & name); - class wallets_store { public: diff --git a/nano/secure/fwd.hpp b/nano/secure/fwd.hpp index e2651e328e..1d57ae0cfc 100644 --- a/nano/secure/fwd.hpp +++ b/nano/secure/fwd.hpp @@ -1,6 +1,14 @@ +#pragma once + namespace nano::secure { class transaction; class write_transaction; class read_transaction; +} + +namespace nano +{ +class account_info; +class vote; } \ No newline at end of file diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 5c149149c2..6eee30bf4b 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -1513,12 +1513,10 @@ uint64_t nano::ledger::pruned_count () const return cache.pruned_count; } -std::unique_ptr nano::ledger::collect_container_info (std::string const & name) const +nano::container_info nano::ledger::container_info () const { - auto count = bootstrap_weights.size (); - auto sizeof_element = sizeof (decltype (bootstrap_weights)::value_type); - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "bootstrap_weights", count, sizeof_element })); - composite->add_component (cache.rep_weights.collect_container_info ("rep_weights")); - return composite; -} + nano::container_info info; + info.put ("bootstrap_weights", bootstrap_weights); + info.add ("rep_weights", cache.rep_weights.container_info ()); + return info; +} \ No newline at end of file diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index 3419731e11..025d56bcc5 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -82,7 +82,7 @@ class ledger final uint64_t account_count () const; uint64_t pruned_count () const; - std::unique_ptr collect_container_info (std::string const & name) const; + nano::container_info container_info () const; public: static nano::uint128_t const unit; diff --git a/nano/secure/rep_weights.cpp b/nano/secure/rep_weights.cpp index 749b8f8751..7556ec4b97 100644 --- a/nano/secure/rep_weights.cpp +++ b/nano/secure/rep_weights.cpp @@ -126,16 +126,11 @@ std::size_t nano::rep_weights::size () const return rep_amounts.size (); } -std::unique_ptr nano::rep_weights::collect_container_info (std::string const & name) const +nano::container_info nano::rep_weights::container_info () const { - size_t rep_amounts_count; + std::shared_lock guard{ mutex }; - { - std::shared_lock guard{ mutex }; - rep_amounts_count = rep_amounts.size (); - } - auto sizeof_element = sizeof (decltype (rep_amounts)::value_type); - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info_entry{ "rep_amounts", rep_amounts_count, sizeof_element })); - return composite; + nano::container_info info; + info.put ("rep_amounts", rep_amounts); + return info; } diff --git a/nano/secure/rep_weights.hpp b/nano/secure/rep_weights.hpp index 92ea5a9592..9209bbf255 100644 --- a/nano/secure/rep_weights.hpp +++ b/nano/secure/rep_weights.hpp @@ -29,7 +29,7 @@ class rep_weights /* Only use this method when loading rep weights from the database table */ void copy_from (rep_weights & other_a); size_t size () const; - std::unique_ptr collect_container_info (std::string const &) const; + nano::container_info container_info () const; private: mutable std::shared_mutex mutex;