Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confirm delta #2884

Merged
merged 12 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ bootstrap_initiator (*this),
bootstrap (config.peering_port, *this),
application_path (application_path_a),
port_mapping (*this),
vote_processor (checker, active, observers, stats, config, flags, logger, online_reps, ledger, network_params),
vote_processor{ *this },
rep_crawler (*this),
warmed_up (0),
block_processor (*this, write_database_queue),
Expand Down
61 changes: 26 additions & 35 deletions nano/node/vote_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,15 @@

#include <boost/format.hpp>

nano::vote_processor::vote_processor (nano::signature_checker & checker_a, nano::active_transactions & active_a, nano::node_observers & observers_a, nano::stat & stats_a, nano::node_config & config_a, nano::node_flags & flags_a, nano::logger_mt & logger_a, nano::online_reps & online_reps_a, nano::ledger & ledger_a, nano::network_params & network_params_a) :
checker (checker_a),
active (active_a),
observers (observers_a),
stats (stats_a),
config (config_a),
logger (logger_a),
online_reps (online_reps_a),
ledger (ledger_a),
network_params (network_params_a),
max_votes (flags_a.vote_processor_capacity),
started (false),
stopped (false),
is_active (false),
thread ([this]() {
nano::vote_processor::vote_processor (nano::node & node_a) :
node{ node_a },
started{ false },
stopped{ false },
is_active{ false },
thread{ [this]() {
nano::thread_role::set (nano::thread_role::name::vote_processing);
process_loop ();
})
} }
{
nano::unique_lock<std::mutex> lock (mutex);
condition.wait (lock, [& started = started] { return started; });
Expand All @@ -58,7 +49,7 @@ void nano::vote_processor::process_loop ()
votes_l.swap (votes);

log_this_iteration = false;
if (config.logging.network_logging () && votes_l.size () > 50)
if (node.config.logging.network_logging () && votes_l.size () > 50)
{
/*
* Only log the timing information for this iteration if
Expand All @@ -79,7 +70,7 @@ void nano::vote_processor::process_loop ()

if (log_this_iteration && elapsed.stop () > std::chrono::milliseconds (100))
{
logger.try_log (boost::str (boost::format ("Processed %1% votes in %2% milliseconds (rate of %3% votes per second)") % votes_l.size () % elapsed.value ().count () % ((votes_l.size () * 1000ULL) / elapsed.value ().count ())));
node.logger.try_log (boost::str (boost::format ("Processed %1% votes in %2% milliseconds (rate of %3% votes per second)") % votes_l.size () % elapsed.value ().count () % ((votes_l.size () * 1000ULL) / elapsed.value ().count ())));
}
}
else
Expand All @@ -96,22 +87,22 @@ bool nano::vote_processor::vote (std::shared_ptr<nano::vote> vote_a, std::shared
if (!stopped)
{
// Level 0 (< 0.1%)
if (votes.size () < 6.0 / 9.0 * max_votes)
if (votes.size () < 6.0 / 9.0 * node.flags.vote_processor_capacity)
{
process = true;
}
// Level 1 (0.1-1%)
else if (votes.size () < 7.0 / 9.0 * max_votes)
else if (votes.size () < 7.0 / 9.0 * node.flags.vote_processor_capacity)
{
process = (representatives_1.find (vote_a->account) != representatives_1.end ());
}
// Level 2 (1-5%)
else if (votes.size () < 8.0 / 9.0 * max_votes)
else if (votes.size () < 8.0 / 9.0 * node.flags.vote_processor_capacity)
{
process = (representatives_2.find (vote_a->account) != representatives_2.end ());
}
// Level 3 (> 5%)
else if (votes.size () < max_votes)
else if (votes.size () < node.flags.vote_processor_capacity)
{
process = (representatives_3.find (vote_a->account) != representatives_3.end ());
}
Expand All @@ -124,7 +115,7 @@ bool nano::vote_processor::vote (std::shared_ptr<nano::vote> vote_a, std::shared
}
else
{
stats.inc (nano::stat::type::vote, nano::stat::detail::vote_overflow);
node.stats.inc (nano::stat::type::vote, nano::stat::detail::vote_overflow);
}
}
return !process;
Expand Down Expand Up @@ -152,7 +143,7 @@ void nano::vote_processor::verify_votes (decltype (votes) const & votes_a)
signatures.push_back (vote.first->signature.bytes.data ());
}
nano::signature_check_set check = { size, messages.data (), lengths.data (), pub_keys.data (), signatures.data (), verifications.data () };
checker.verify (check);
node.checker.verify (check);
auto i (0);
for (auto const & vote : votes_a)
{
Expand All @@ -170,32 +161,32 @@ nano::vote_code nano::vote_processor::vote_blocking (std::shared_ptr<nano::vote>
auto result (nano::vote_code::invalid);
if (validated || !vote_a->validate ())
{
result = active.vote (vote_a);
observers.vote.notify (vote_a, channel_a, result);
result = node.active.vote (vote_a);
node.observers.vote.notify (vote_a, channel_a, result);
}
std::string status;
switch (result)
{
case nano::vote_code::invalid:
status = "Invalid";
stats.inc (nano::stat::type::vote, nano::stat::detail::vote_invalid);
node.stats.inc (nano::stat::type::vote, nano::stat::detail::vote_invalid);
break;
case nano::vote_code::replay:
status = "Replay";
stats.inc (nano::stat::type::vote, nano::stat::detail::vote_replay);
node.stats.inc (nano::stat::type::vote, nano::stat::detail::vote_replay);
break;
case nano::vote_code::vote:
status = "Vote";
stats.inc (nano::stat::type::vote, nano::stat::detail::vote_valid);
node.stats.inc (nano::stat::type::vote, nano::stat::detail::vote_valid);
break;
case nano::vote_code::indeterminate:
status = "Indeterminate";
stats.inc (nano::stat::type::vote, nano::stat::detail::vote_indeterminate);
node.stats.inc (nano::stat::type::vote, nano::stat::detail::vote_indeterminate);
break;
}
if (config.logging.vote_logging ())
if (node.config.logging.vote_logging ())
{
logger.try_log (boost::str (boost::format ("Vote from: %1% sequence: %2% block(s): %3%status: %4%") % vote_a->account.to_account () % std::to_string (vote_a->sequence) % vote_a->hashes_string () % status));
node.logger.try_log (boost::str (boost::format ("Vote from: %1% sequence: %2% block(s): %3%status: %4%") % vote_a->account.to_account () % std::to_string (vote_a->sequence) % vote_a->hashes_string () % status));
}
return result;
}
Expand Down Expand Up @@ -242,12 +233,12 @@ void nano::vote_processor::calculate_weights ()
representatives_1.clear ();
representatives_2.clear ();
representatives_3.clear ();
auto supply (online_reps.online_stake ());
auto rep_amounts = ledger.cache.rep_weights.get_rep_amounts ();
auto supply (node.online_reps.online_stake ());
auto rep_amounts = node.ledger.cache.rep_weights.get_rep_amounts ();
for (auto const & rep_amount : rep_amounts)
{
nano::account const & representative (rep_amount.first);
auto weight (ledger.weight (representative));
auto weight (node.ledger.weight (representative));
if (weight > supply / 1000) // 0.1% or above (level 1)
{
representatives_1.insert (representative);
Expand Down
15 changes: 2 additions & 13 deletions nano/node/vote_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace transport
class vote_processor final
{
public:
explicit vote_processor (nano::signature_checker & checker_a, nano::active_transactions & active_a, nano::node_observers & observers_a, nano::stat & stats_a, nano::node_config & config_a, nano::node_flags & flags_a, nano::logger_mt & logger_a, nano::online_reps & online_reps_a, nano::ledger & ledger_a, nano::network_params & network_params_a);
explicit vote_processor (nano::node & node_a);
clemahieu marked this conversation as resolved.
Show resolved Hide resolved
/** Returns false if the vote was processed */
bool vote (std::shared_ptr<nano::vote>, std::shared_ptr<nano::transport::channel>);
/** Note: node.active.mutex lock is required */
Expand All @@ -48,18 +48,7 @@ class vote_processor final
private:
void process_loop ();

nano::signature_checker & checker;
nano::active_transactions & active;
nano::node_observers & observers;
nano::stat & stats;
nano::node_config & config;
nano::logger_mt & logger;
nano::online_reps & online_reps;
nano::ledger & ledger;
nano::network_params & network_params;

size_t max_votes;

nano::node & node;
std::deque<std::pair<std::shared_ptr<nano::vote>, std::shared_ptr<nano::transport::channel>>> votes;
/** Representatives levels for random early detection */
std::unordered_set<nano::account> representatives_1;
Expand Down