From 4446c6529ff9ebe146b67d4c18d6efe6a013ddb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Sun, 5 Jan 2025 15:17:28 +0100 Subject: [PATCH] Namespace indentation --- nano/node/bootstrap/account_sets.hpp | 272 +++++++++++++-------------- nano/node/bootstrap/peer_scoring.hpp | 133 +++++++------ 2 files changed, 200 insertions(+), 205 deletions(-) diff --git a/nano/node/bootstrap/account_sets.hpp b/nano/node/bootstrap/account_sets.hpp index 59bdbf95af..992c843ba6 100644 --- a/nano/node/bootstrap/account_sets.hpp +++ b/nano/node/bootstrap/account_sets.hpp @@ -17,145 +17,143 @@ namespace mi = boost::multi_index; -namespace nano +namespace nano::bootstrap { -namespace bootstrap +/** This class tracks accounts various account sets which are shared among the multiple bootstrap threads */ +class account_sets { - /** This class tracks accounts various account sets which are shared among the multiple bootstrap threads */ - class account_sets +public: // Constants + static double constexpr priority_initial = 2.0; + static double constexpr priority_increase = 2.0; + static double constexpr priority_divide = 2.0; + static double constexpr priority_max = 128.0; + static double constexpr priority_cutoff = 0.15; + static unsigned constexpr max_fails = 3; + +public: + account_sets (account_sets_config const &, nano::stats &); + + /** + * If an account is not blocked, increase its priority. + * If the account does not exist in priority set and is not blocked, inserts a new entry. + * Current implementation increases priority by 1.0f each increment + */ + void priority_up (nano::account const & account); + /** + * Decreases account priority + * Current implementation divides priority by 2.0f and saturates down to 1.0f. + */ + void priority_down (nano::account const & account); + void priority_set (nano::account const & account, double priority = priority_initial); + + void block (nano::account const & account, nano::block_hash const & dependency); + void unblock (nano::account const & account, std::optional const & hash = std::nullopt); + + void timestamp_set (nano::account const & account); + void timestamp_reset (nano::account const & account); + + /** + * Sets information about the account chain that contains the block hash + */ + void dependency_update (nano::block_hash const & hash, nano::account const & dependency_account); + + /** + * Should be called periodically to reinsert missing dependencies into the priority set + */ + void sync_dependencies (); + + struct priority_result { - public: // Constants - static double constexpr priority_initial = 2.0; - static double constexpr priority_increase = 2.0; - static double constexpr priority_divide = 2.0; - static double constexpr priority_max = 128.0; - static double constexpr priority_cutoff = 0.15; - static unsigned constexpr max_fails = 3; - - public: - account_sets (account_sets_config const &, nano::stats &); - - /** - * If an account is not blocked, increase its priority. - * If the account does not exist in priority set and is not blocked, inserts a new entry. - * Current implementation increases priority by 1.0f each increment - */ - void priority_up (nano::account const & account); - /** - * Decreases account priority - * Current implementation divides priority by 2.0f and saturates down to 1.0f. - */ - void priority_down (nano::account const & account); - void priority_set (nano::account const & account, double priority = priority_initial); - - void block (nano::account const & account, nano::block_hash const & dependency); - void unblock (nano::account const & account, std::optional const & hash = std::nullopt); - - void timestamp_set (nano::account const & account); - void timestamp_reset (nano::account const & account); - - /** - * Sets information about the account chain that contains the block hash - */ - void dependency_update (nano::block_hash const & hash, nano::account const & dependency_account); - /** - * Should be called periodically to reinsert missing dependencies into the priority set - */ - void sync_dependencies (); - - struct priority_result - { - nano::account account; - double priority; - unsigned fails; - }; - - /** - * Sampling - */ - priority_result next_priority (std::function const & filter); - nano::block_hash next_blocking (std::function const & filter); - - 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 - // Blocked accounts are assumed priority 0.0f - double priority (nano::account const & account) const; - - std::size_t priority_size () const; - std::size_t blocked_size () const; - bool priority_half_full () const; - bool blocked_half_full () const; - - nano::container_info container_info () const; - - private: // Dependencies - account_sets_config const & config; - nano::stats & stats; - - private: - void trim_overflow (); - - private: - struct priority_entry - { - nano::account account; - double priority; - unsigned fails{ 0 }; - std::chrono::steady_clock::time_point timestamp{}; - id_t id{ generate_id () }; // Uniformly distributed, used for random querying - }; - - struct blocking_entry - { - nano::account account; - nano::block_hash dependency; - nano::account dependency_account{ 0 }; - id_t id{ generate_id () }; // Uniformly distributed, used for random querying - }; - - // clang-format off - class tag_sequenced {}; - class tag_account {}; - class tag_id {}; - class tag_dependency {}; - class tag_dependency_account {}; - class tag_priority {}; - - // Tracks the ongoing account priorities - using ordered_priorities = boost::multi_index_container>, - mi::ordered_unique, - mi::member>, - mi::ordered_non_unique, - mi::member, std::greater<>>, // Descending - mi::ordered_unique, - mi::member> - >>; - - // A blocked account is an account that has failed to insert a new block because the source block is not currently present in the ledger - // An account is unblocked once it has a block successfully inserted - using ordered_blocking = boost::multi_index_container>, - mi::ordered_unique, - mi::member>, - mi::ordered_non_unique, - mi::member>, - mi::ordered_non_unique, - mi::member>, - mi::ordered_unique, - mi::member> - >>; - // clang-format on - - ordered_priorities priorities; - ordered_blocking blocking; - - public: - using info_t = std::tuple; // - info_t info () const; + nano::account account; + double priority; + unsigned fails; }; -} + + /** + * Sampling + */ + priority_result next_priority (std::function const & filter); + nano::block_hash next_blocking (std::function const & filter); + + 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 + // Blocked accounts are assumed priority 0.0f + double priority (nano::account const & account) const; + + std::size_t priority_size () const; + std::size_t blocked_size () const; + bool priority_half_full () const; + bool blocked_half_full () const; + + nano::container_info container_info () const; + +private: // Dependencies + account_sets_config const & config; + nano::stats & stats; + +private: + void trim_overflow (); + +private: + struct priority_entry + { + nano::account account; + double priority; + unsigned fails{ 0 }; + std::chrono::steady_clock::time_point timestamp{}; + id_t id{ generate_id () }; // Uniformly distributed, used for random querying + }; + + struct blocking_entry + { + nano::account account; + nano::block_hash dependency; + nano::account dependency_account{ 0 }; + id_t id{ generate_id () }; // Uniformly distributed, used for random querying + }; + + // clang-format off + class tag_sequenced {}; + class tag_account {}; + class tag_id {}; + class tag_dependency {}; + class tag_dependency_account {}; + class tag_priority {}; + + // Tracks the ongoing account priorities + using ordered_priorities = boost::multi_index_container>, + mi::ordered_unique, + mi::member>, + mi::ordered_non_unique, + mi::member, std::greater<>>, // Descending + mi::ordered_unique, + mi::member> + >>; + + // A blocked account is an account that has failed to insert a new block because the source block is not currently present in the ledger + // An account is unblocked once it has a block successfully inserted + using ordered_blocking = boost::multi_index_container>, + mi::ordered_unique, + mi::member>, + mi::ordered_non_unique, + mi::member>, + mi::ordered_non_unique, + mi::member>, + mi::ordered_unique, + mi::member> + >>; + // clang-format on + + ordered_priorities priorities; + ordered_blocking blocking; + +public: + using info_t = std::tuple; // + info_t info () const; +}; } diff --git a/nano/node/bootstrap/peer_scoring.hpp b/nano/node/bootstrap/peer_scoring.hpp index 0bae9255c3..798015c543 100644 --- a/nano/node/bootstrap/peer_scoring.hpp +++ b/nano/node/bootstrap/peer_scoring.hpp @@ -13,87 +13,84 @@ namespace mi = boost::multi_index; -namespace nano +namespace nano::bootstrap { -namespace bootstrap +// Container for tracking and scoring peers with respect to bootstrapping +class peer_scoring { - // Container for tracking and scoring peers with respect to bootstrapping - class peer_scoring - { - public: - static nano::transport::traffic_type constexpr traffic_type = nano::transport::traffic_type::bootstrap_requests; +public: + static nano::transport::traffic_type constexpr traffic_type = nano::transport::traffic_type::bootstrap_requests; - public: - peer_scoring (bootstrap_config const &, nano::network_constants const &); +public: + peer_scoring (bootstrap_config const &, nano::network_constants const &); - // Returns true if channel limit has been exceeded - bool limit_exceeded (std::shared_ptr const & channel) const; - bool try_send_message (std::shared_ptr const & channel); - void received_message (std::shared_ptr const & channel); + // Returns true if channel limit has been exceeded + bool limit_exceeded (std::shared_ptr const & channel) const; + bool try_send_message (std::shared_ptr const & channel); + void received_message (std::shared_ptr const & channel); - std::shared_ptr channel (); + std::shared_ptr channel (); - // Synchronize channels with the network, passed channels should be shuffled - void sync (std::deque> const & list); + // Synchronize channels with the network, passed channels should be shuffled + void sync (std::deque> const & list); - // Cleans up scores for closed channels - // Decays scores which become inaccurate over time due to message drops - void timeout (); + // Cleans up scores for closed channels + // Decays scores which become inaccurate over time due to message drops + void timeout (); - std::size_t size () const; - std::size_t available () const; + std::size_t size () const; + std::size_t available () const; - nano::container_info container_info () const; + nano::container_info container_info () const; - private: - bootstrap_config const & config; - nano::network_constants const & network_constants; +private: + bootstrap_config const & config; + nano::network_constants const & network_constants; - private: - class peer_score +private: + class peer_score + { + public: + explicit peer_score (std::shared_ptr const &, uint64_t, uint64_t, uint64_t); + std::weak_ptr channel; + // std::weak_ptr does not provide ordering so the naked pointer is also tracked and used for ordering channels + // This pointer may be invalid if the channel has been destroyed + nano::transport::channel * channel_ptr; + // Acquire reference to the shared channel object if it is still valid + [[nodiscard]] std::shared_ptr shared () const { - public: - explicit peer_score (std::shared_ptr const &, uint64_t, uint64_t, uint64_t); - std::weak_ptr channel; - // std::weak_ptr does not provide ordering so the naked pointer is also tracked and used for ordering channels - // This pointer may be invalid if the channel has been destroyed - nano::transport::channel * channel_ptr; - // Acquire reference to the shared channel object if it is still valid - [[nodiscard]] std::shared_ptr shared () const + auto result = channel.lock (); + if (result) { - auto result = channel.lock (); - if (result) - { - debug_assert (result.get () == channel_ptr); - } - return result; + debug_assert (result.get () == channel_ptr); } - void decay () - { - outstanding = outstanding > 0 ? outstanding - 1 : 0; - } - // Number of outstanding requests to a peer - uint64_t outstanding{ 0 }; - uint64_t request_count_total{ 0 }; - uint64_t response_count_total{ 0 }; - }; - - // clang-format off - // Indexes scores by their shared channel pointer - class tag_channel {}; - // Indexes scores by the number of outstanding requests in ascending order - class tag_outstanding {}; - - using ordered_scoring = boost::multi_index_container, - mi::member>, - mi::ordered_non_unique, - mi::member>>>; - // clang-format on - ordered_scoring scoring; - - std::deque> channels; + return result; + } + void decay () + { + outstanding = outstanding > 0 ? outstanding - 1 : 0; + } + // Number of outstanding requests to a peer + uint64_t outstanding{ 0 }; + uint64_t request_count_total{ 0 }; + uint64_t response_count_total{ 0 }; }; -} + + // clang-format off + // Indexes scores by their shared channel pointer + class tag_channel {}; + // Indexes scores by the number of outstanding requests in ascending order + class tag_outstanding {}; + + using ordered_scoring = boost::multi_index_container, + mi::member>, + mi::ordered_non_unique, + mi::member>>>; + // clang-format on + ordered_scoring scoring; + + std::deque> channels; +}; }