Skip to content

Commit

Permalink
FIX TRENDED CALCULATION
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 9, 2024
1 parent e62602c commit 2f8fe82
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
8 changes: 7 additions & 1 deletion nano/core_test/vote_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,15 @@ TEST (vote_processor, weights)
system.wallet (0)->send_sync (nano::dev::genesis_key.pub, key1.pub, level1);
system.wallet (0)->send_sync (nano::dev::genesis_key.pub, key2.pub, level2);

while (true)
{
std::cout << "trended: " << node.online_reps.trended () << std::endl;
WAIT (1s);
}

// Wait for representatives
ASSERT_TIMELY_EQ (10s, node.ledger.cache.rep_weights.get_rep_amounts ().size (), 4);
ASSERT_TIMELY_EQ (5s, node.online_reps.online (), total);
ASSERT_TIMELY_EQ (5s, node.online_reps.trended (), total);

// Wait for rep tiers to be updated
node.stats.clear ();
Expand Down
13 changes: 4 additions & 9 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ void nano::node::start ()
rep_crawler.start ();
}
ongoing_peer_store ();
ongoing_online_weight_calculation_queue ();
ongoing_online_weight_calculation ();

bool tcp_enabled = false;
if (config.tcp_incoming_connections_max > 0 && !(flags.disable_bootstrap_listener && flags.disable_tcp_realtime))
Expand Down Expand Up @@ -1145,12 +1145,13 @@ bool nano::node::block_confirmed_or_being_confirmed (nano::block_hash const & ha
return block_confirmed_or_being_confirmed (store.tx_begin_read (), hash_a);
}

void nano::node::ongoing_online_weight_calculation_queue ()
void nano::node::ongoing_online_weight_calculation ()
{
std::weak_ptr<nano::node> node_w (shared_from_this ());
workers.add_timed_task (std::chrono::steady_clock::now () + (std::chrono::seconds (network_params.node.weight_period)), [node_w] () {
workers.add_timed_task (std::chrono::steady_clock::now () + (network_params.node.weight_period), [node_w] () {
if (auto node_l = node_w.lock ())
{
node_l->online_reps.sample ();
node_l->ongoing_online_weight_calculation ();
}
});
Expand All @@ -1161,12 +1162,6 @@ bool nano::node::online () const
return rep_crawler.total_weight () > online_reps.delta ();
}

void nano::node::ongoing_online_weight_calculation ()
{
online_reps.sample ();
ongoing_online_weight_calculation_queue ();
}

void nano::node::receive_confirmed (store::transaction const & block_transaction_a, nano::block_hash const & hash_a, nano::account const & destination_a)
{
nano::unique_lock<nano::mutex> lk{ wallets.mutex };
Expand Down
1 change: 0 additions & 1 deletion nano/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class node final : public std::enable_shared_from_this<nano::node>
bool block_confirmed_or_being_confirmed (nano::block_hash const &);
void do_rpc_callback (boost::asio::ip::tcp::resolver::iterator i_a, std::string const &, uint16_t, std::shared_ptr<std::string> const &, std::shared_ptr<std::string> const &, std::shared_ptr<boost::asio::ip::tcp::resolver> const &);
void ongoing_online_weight_calculation ();
void ongoing_online_weight_calculation_queue ();
bool online () const;
bool init_error () const;
std::pair<uint64_t, decltype (nano::ledger::bootstrap_weights)> get_bootstrap_weights () const;
Expand Down
2 changes: 1 addition & 1 deletion nano/node/online_reps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void nano::online_reps::observe (nano::account const & rep_a)
auto now = std::chrono::steady_clock::now ();
auto new_insert = reps.get<tag_account> ().erase (rep_a) == 0;
reps.insert ({ now, rep_a });
auto cutoff = reps.get<tag_time> ().lower_bound (now - std::chrono::seconds (config.network_params.node.weight_period));
auto cutoff = reps.get<tag_time> ().lower_bound (now - config.network_params.node.weight_period);
auto trimmed = reps.get<tag_time> ().begin () != cutoff;
reps.get<tag_time> ().erase (reps.get<tag_time> ().begin (), cutoff);
if (new_insert || trimmed)
Expand Down
4 changes: 3 additions & 1 deletion nano/secure/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <cryptopp/words.h>
#include <magic_enum.hpp>

using namespace std::chrono_literals;

nano::networks nano::network_constants::active_network = nano::networks::ACTIVE_NETWORK;

namespace
Expand Down Expand Up @@ -170,7 +172,7 @@ nano::node_constants::node_constants (nano::network_constants & network_constant
unchecked_cleaning_interval = std::chrono::minutes (30);
process_confirmed_interval = network_constants.is_dev_network () ? std::chrono::milliseconds (50) : std::chrono::milliseconds (500);
max_weight_samples = (network_constants.is_live_network () || network_constants.is_test_network ()) ? 4032 : 288;
weight_period = 5 * 60; // 5 minutes
weight_period = network_constants.is_dev_network () ? 1s : 5min;
}

nano::voting_constants::voting_constants (nano::network_constants & network_constants) :
Expand Down
2 changes: 1 addition & 1 deletion nano/secure/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class node_constants

/** The maximum amount of samples for a 2 week period on live or 1 day on beta */
uint64_t max_weight_samples;
uint64_t weight_period;
std::chrono::seconds weight_period;
};

/** Voting related constants whose value depends on the active network */
Expand Down

0 comments on commit 2f8fe82

Please sign in to comment.