Skip to content

Commit

Permalink
Normalize indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Nov 13, 2023
1 parent f135701 commit be28a37
Show file tree
Hide file tree
Showing 3 changed files with 252 additions and 251 deletions.
162 changes: 81 additions & 81 deletions nano/node/bootstrap_ascending/account_sets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,76 +19,77 @@ namespace mi = boost::multi_index;
namespace nano
{
class stats;
}

namespace bootstrap_ascending
namespace nano::bootstrap_ascending
{
/** 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:
explicit account_sets (nano::stats &, nano::account_sets_config config = {});

/**
* 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 block (nano::account const & account, nano::block_hash const & dependency);
void unblock (nano::account const & account, std::optional<nano::block_hash> const & hash = std::nullopt);
void timestamp (nano::account const & account, bool reset = false);

nano::account next ();

public:
bool blocked (nano::account const & account) const;
std::size_t priority_size () const;
std::size_t blocked_size () const;
/**
* Accounts in the ledger but not in priority list are assumed priority 1.0f
* Blocked accounts are assumed priority 0.0f
*/
float priority (nano::account const & account) const;

public: // Container info
std::unique_ptr<nano::container_info_component> collect_container_info (std::string const & name);

private:
void trim_overflow ();
bool check_timestamp (nano::account const & account) const;

private: // Dependencies
nano::stats & stats;

private:
struct priority_entry
{
public:
explicit account_sets (nano::stats &, nano::account_sets_config config = {});

/**
* 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 block (nano::account const & account, nano::block_hash const & dependency);
void unblock (nano::account const & account, std::optional<nano::block_hash> const & hash = std::nullopt);
void timestamp (nano::account const & account, bool reset = false);

nano::account next ();

public:
bool blocked (nano::account const & account) const;
std::size_t priority_size () const;
std::size_t blocked_size () const;
/**
* Accounts in the ledger but not in priority list are assumed priority 1.0f
* Blocked accounts are assumed priority 0.0f
*/
float priority (nano::account const & account) const;

public: // Container info
std::unique_ptr<nano::container_info_component> collect_container_info (std::string const & name);

private:
void trim_overflow ();
bool check_timestamp (nano::account const & account) const;

private: // Dependencies
nano::stats & stats;

private:
struct priority_entry
{
nano::account account{ 0 };
float priority{ 0 };
nano::millis_t timestamp{ 0 };
nano::bootstrap_ascending::id_t id{ 0 }; // Uniformly distributed, used for random querying
nano::account account{ 0 };
float priority{ 0 };
nano::millis_t timestamp{ 0 };
nano::bootstrap_ascending::id_t id{ 0 }; // Uniformly distributed, used for random querying

priority_entry (nano::account account, float priority);
};
priority_entry (nano::account account, float priority);
};

struct blocking_entry
{
nano::account account{ 0 };
nano::block_hash dependency{ 0 };
priority_entry original_entry{ 0, 0 };
struct blocking_entry
{
nano::account account{ 0 };
nano::block_hash dependency{ 0 };
priority_entry original_entry{ 0, 0 };

float priority () const
{
return original_entry.priority;
}
};
float priority () const
{
return original_entry.priority;
}
};

// clang-format off
// clang-format off
class tag_account {};
class tag_priority {};
class tag_sequenced {};
Expand Down Expand Up @@ -117,26 +118,25 @@ namespace bootstrap_ascending
mi::ordered_non_unique<mi::tag<tag_priority>,
mi::const_mem_fun<blocking_entry, float, &blocking_entry::priority>>
>>;
// clang-format on
// clang-format on

ordered_priorities priorities;
ordered_blocking blocking;
ordered_priorities priorities;
ordered_blocking blocking;

std::default_random_engine rng;
std::default_random_engine rng;

private:
nano::account_sets_config config;
private:
nano::account_sets_config config;

public: // Consts
static float constexpr priority_initial = 8.0f;
static float constexpr priority_increase = 2.0f;
static float constexpr priority_decrease = 0.5f;
static float constexpr priority_max = 32.0f;
static float constexpr priority_cutoff = 1.0f;
public: // Consts
static float constexpr priority_initial = 8.0f;
static float constexpr priority_increase = 2.0f;
static float constexpr priority_decrease = 0.5f;
static float constexpr priority_max = 32.0f;
static float constexpr priority_cutoff = 1.0f;

public:
using info_t = std::tuple<decltype (blocking), decltype (priorities)>; // <blocking, priorities>
info_t info () const;
};
} // bootstrap_ascending
} // nano
public:
using info_t = std::tuple<decltype (blocking), decltype (priorities)>; // <blocking, priorities>
info_t info () const;
};
}
93 changes: 47 additions & 46 deletions nano/node/bootstrap_ascending/peer_scoring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,57 @@ namespace transport
{
class channel;
}
namespace bootstrap_ascending
}

namespace nano::bootstrap_ascending
{
// 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:
peer_scoring (nano::bootstrap_ascending_config & config, nano::network_constants const & network_constants);
// Returns true if channel limit has been exceeded
bool try_send_message (std::shared_ptr<nano::transport::channel> channel);
void received_message (std::shared_ptr<nano::transport::channel> channel);
std::shared_ptr<nano::transport::channel> channel ();
[[nodiscard]] std::size_t size () const;
// Cleans up scores for closed channels
// Decays scores which become inaccurate over time due to message drops
void timeout ();
void sync (std::deque<std::shared_ptr<nano::transport::channel>> const & list);

private:
class peer_score
{
public:
peer_scoring (nano::bootstrap_ascending_config & config, nano::network_constants const & network_constants);
// Returns true if channel limit has been exceeded
bool try_send_message (std::shared_ptr<nano::transport::channel> channel);
void received_message (std::shared_ptr<nano::transport::channel> channel);
std::shared_ptr<nano::transport::channel> channel ();
[[nodiscard]] std::size_t size () const;
// Cleans up scores for closed channels
// Decays scores which become inaccurate over time due to message drops
void timeout ();
void sync (std::deque<std::shared_ptr<nano::transport::channel>> const & list);

private:
class peer_score
explicit peer_score (std::shared_ptr<nano::transport::channel> const &, uint64_t, uint64_t, uint64_t);
std::weak_ptr<nano::transport::channel> 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<nano::transport::channel> shared () const
{
public:
explicit peer_score (std::shared_ptr<nano::transport::channel> const &, uint64_t, uint64_t, uint64_t);
std::weak_ptr<nano::transport::channel> 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<nano::transport::channel> 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 };
};
nano::network_constants const & network_constants;
nano::bootstrap_ascending_config & config;
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 };
};
nano::network_constants const & network_constants;
nano::bootstrap_ascending_config & config;

// clang-format off
// clang-format off
// Indexes scores by their shared channel pointer
class tag_channel {};
// Indexes scores by the number of outstanding requests in ascending order
Expand All @@ -80,8 +82,7 @@ namespace bootstrap_ascending
mi::member<peer_score, nano::transport::channel *, &peer_score::channel_ptr>>,
mi::ordered_non_unique<mi::tag<tag_outstanding>,
mi::member<peer_score, uint64_t, &peer_score::outstanding>>>>;
// clang-format on
scoring_t scoring;
};
}
// clang-format on
scoring_t scoring;
};
}
Loading

0 comments on commit be28a37

Please sign in to comment.