Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
coranos committed May 28, 2023
1 parent 1cffe89 commit e8aeb1c
Show file tree
Hide file tree
Showing 37 changed files with 920 additions and 1,161 deletions.
52 changes: 0 additions & 52 deletions nano/node/lmdb/unchecked_store.cpp

This file was deleted.

36 changes: 0 additions & 36 deletions nano/node/lmdb/unchecked_store.hpp

This file was deleted.

17 changes: 0 additions & 17 deletions nano/node/node_pow_server_config.cpp

This file was deleted.

38 changes: 0 additions & 38 deletions nano/node/node_pow_server_config.hpp

This file was deleted.

16 changes: 8 additions & 8 deletions nano/node/online_reps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void nano::online_reps::observe (nano::account const & rep_a)
{
if (ledger.weight (rep_a) > 0)
{
nano::lock_guard<nano::mutex> lock (mutex);
nano::lock_guard<nano::mutex> lock{ mutex };
auto now = std::chrono::steady_clock::now ();
auto new_insert = reps.get<tag_account> ().erase (rep_a) == 0;
reps.insert ({ now, rep_a });
Expand All @@ -34,7 +34,7 @@ void nano::online_reps::observe (nano::account const & rep_a)

void nano::online_reps::sample ()
{
nano::unique_lock<nano::mutex> lock (mutex);
nano::unique_lock<nano::mutex> lock{ mutex };
nano::uint128_t online_l = online_m;
lock.unlock ();
nano::uint128_t trend_l;
Expand Down Expand Up @@ -83,19 +83,19 @@ nano::uint128_t nano::online_reps::calculate_trend (nano::transaction & transact

nano::uint128_t nano::online_reps::trended () const
{
nano::lock_guard<nano::mutex> lock (mutex);
nano::lock_guard<nano::mutex> lock{ mutex };
return trended_m;
}

nano::uint128_t nano::online_reps::online () const
{
nano::lock_guard<nano::mutex> lock (mutex);
nano::lock_guard<nano::mutex> lock{ mutex };
return online_m;
}

nano::uint128_t nano::online_reps::delta () const
{
nano::lock_guard<nano::mutex> lock (mutex);
nano::lock_guard<nano::mutex> lock{ mutex };
// Using a larger container to ensure maximum precision
auto weight = static_cast<nano::uint256_t> (std::max ({ online_m, trended_m, config.online_weight_minimum.number () }));
return ((weight * online_weight_quorum) / 100).convert_to<nano::uint128_t> ();
Expand All @@ -104,14 +104,14 @@ nano::uint128_t nano::online_reps::delta () const
std::vector<nano::account> nano::online_reps::list ()
{
std::vector<nano::account> result;
nano::lock_guard<nano::mutex> lock (mutex);
nano::lock_guard<nano::mutex> lock{ mutex };
std::for_each (reps.begin (), reps.end (), [&result] (rep_info const & info_a) { result.push_back (info_a.account); });
return result;
}

void nano::online_reps::clear ()
{
nano::lock_guard<nano::mutex> lock (mutex);
nano::lock_guard<nano::mutex> lock{ mutex };
reps.clear ();
online_m = 0;
}
Expand All @@ -120,7 +120,7 @@ std::unique_ptr<nano::container_info_component> nano::collect_container_info (on
{
std::size_t count;
{
nano::lock_guard<nano::mutex> guard (online_reps.mutex);
nano::lock_guard<nano::mutex> guard{ online_reps.mutex };
count = online_reps.reps.size ();
}

Expand Down
1 change: 0 additions & 1 deletion nano/node/online_reps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <boost/multi_index_container.hpp>

#include <memory>
#include <unordered_set>
#include <vector>

namespace nano
Expand Down
3 changes: 1 addition & 2 deletions nano/node/openclwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <boost/format.hpp>

#include <array>
#include <iostream>
#include <string>
#include <vector>

Expand Down Expand Up @@ -450,7 +449,7 @@ boost::optional<uint64_t> nano::opencl_work::generate_work (nano::work_version c

boost::optional<uint64_t> nano::opencl_work::generate_work (nano::work_version const version_a, nano::root const & root_a, uint64_t const difficulty_a, std::atomic<int> & ticket_a)
{
nano::lock_guard<nano::mutex> lock (mutex);
nano::lock_guard<nano::mutex> lock{ mutex };
bool error (false);
int ticket_l (ticket_a);
uint64_t result (0);
Expand Down
99 changes: 53 additions & 46 deletions nano/node/peer_exclusion.cpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
#include <nano/node/peer_exclusion.hpp>

constexpr std::chrono::hours nano::peer_exclusion::exclude_time_hours;
constexpr std::chrono::hours nano::peer_exclusion::exclude_remove_hours;
constexpr std::size_t nano::peer_exclusion::size_max;
constexpr double nano::peer_exclusion::peers_percentage_limit;
nano::peer_exclusion::peer_exclusion (std::size_t max_size_a) :
max_size{ max_size_a }
{
}

uint64_t nano::peer_exclusion::add (nano::tcp_endpoint const & endpoint_a, std::size_t const network_peers_count_a)
uint64_t nano::peer_exclusion::add (nano::tcp_endpoint const & endpoint)
{
uint64_t result (0);
nano::lock_guard<nano::mutex> guard (mutex);
// Clean old excluded peers
auto limited = limited_size (network_peers_count_a);
while (peers.size () > 1 && peers.size () > limited)
{
peers.get<tag_exclusion> ().erase (peers.get<tag_exclusion> ().begin ());
}
debug_assert (peers.size () <= size_max);
auto & peers_by_endpoint (peers.get<tag_endpoint> ());
auto address = endpoint_a.address ();
auto existing (peers_by_endpoint.find (address));
if (existing == peers_by_endpoint.end ())
uint64_t result = 0;
nano::lock_guard<nano::mutex> guard{ mutex };

if (auto existing = peers.get<tag_endpoint> ().find (endpoint.address ()); existing == peers.get<tag_endpoint> ().end ())
{
// Clean old excluded peers
while (peers.size () > 1 && peers.size () >= max_size)
{
peers.get<tag_exclusion> ().erase (peers.get<tag_exclusion> ().begin ());
}
debug_assert (peers.size () <= max_size);

// Insert new endpoint
auto inserted (peers.emplace (peer_exclusion::item{ std::chrono::steady_clock::steady_clock::now () + exclude_time_hours, address, 1 }));
auto inserted = peers.insert (peer_exclusion::item{ std::chrono::steady_clock::steady_clock::now () + exclude_time_hours, endpoint.address (), 1 });
(void)inserted;
debug_assert (inserted.second);
result = 1;
}
else
{
// Update existing endpoint
peers_by_endpoint.modify (existing, [&result] (peer_exclusion::item & item_a) {
peers.get<tag_endpoint> ().modify (existing, [&result] (peer_exclusion::item & item_a) {
++item_a.score;
result = item_a.score;
if (item_a.score == peer_exclusion::score_limit)
Expand All @@ -46,50 +44,59 @@ uint64_t nano::peer_exclusion::add (nano::tcp_endpoint const & endpoint_a, std::
return result;
}

bool nano::peer_exclusion::check (nano::tcp_endpoint const & endpoint_a)
uint64_t nano::peer_exclusion::score (const nano::tcp_endpoint & endpoint) const
{
bool excluded (false);
nano::lock_guard<nano::mutex> guard (mutex);
auto & peers_by_endpoint (peers.get<tag_endpoint> ());
auto existing (peers_by_endpoint.find (endpoint_a.address ()));
if (existing != peers_by_endpoint.end () && existing->score >= score_limit)
nano::lock_guard<nano::mutex> guard{ mutex };

if (auto existing = peers.get<tag_endpoint> ().find (endpoint.address ()); existing != peers.get<tag_endpoint> ().end ())
{
if (existing->exclude_until > std::chrono::steady_clock::now ())
{
excluded = true;
}
else if (existing->exclude_until + exclude_remove_hours * existing->score < std::chrono::steady_clock::now ())
return existing->score;
}
return 0;
}

std::chrono::steady_clock::time_point nano::peer_exclusion::until (const nano::tcp_endpoint & endpoint) const
{
nano::lock_guard<nano::mutex> guard{ mutex };

if (auto existing = peers.get<tag_endpoint> ().find (endpoint.address ()); existing != peers.get<tag_endpoint> ().end ())
{
return existing->exclude_until;
}
return {};
}

bool nano::peer_exclusion::check (nano::tcp_endpoint const & endpoint) const
{
nano::lock_guard<nano::mutex> guard{ mutex };

if (auto existing = peers.get<tag_endpoint> ().find (endpoint.address ()); existing != peers.get<tag_endpoint> ().end ())
{
if (existing->score >= score_limit && existing->exclude_until > std::chrono::steady_clock::now ())
{
peers_by_endpoint.erase (existing);
return true;
}
}
return excluded;
return false;
}

void nano::peer_exclusion::remove (nano::tcp_endpoint const & endpoint_a)
{
nano::lock_guard<nano::mutex> guard (mutex);
nano::lock_guard<nano::mutex> guard{ mutex };
peers.get<tag_endpoint> ().erase (endpoint_a.address ());
}

std::size_t nano::peer_exclusion::limited_size (std::size_t const network_peers_count_a) const
{
return std::min (size_max, static_cast<std::size_t> (network_peers_count_a * peers_percentage_limit));
}

std::size_t nano::peer_exclusion::size () const
{
nano::lock_guard<nano::mutex> guard (mutex);
nano::lock_guard<nano::mutex> guard{ mutex };
return peers.size ();
}

std::unique_ptr<nano::container_info_component> nano::collect_container_info (nano::peer_exclusion const & excluded_peers, std::string const & name)
std::unique_ptr<nano::container_info_component> nano::peer_exclusion::collect_container_info (std::string const & name)
{
auto composite = std::make_unique<container_info_composite> (name);

std::size_t excluded_peers_count = excluded_peers.size ();
auto sizeof_excluded_peers_element = sizeof (nano::peer_exclusion::ordered_endpoints::value_type);
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "peers", excluded_peers_count, sizeof_excluded_peers_element }));
nano::lock_guard<nano::mutex> guard{ mutex };

auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "peers", peers.size (), sizeof (decltype (peers)::value_type) }));
return composite;
}
Loading

0 comments on commit e8aeb1c

Please sign in to comment.