Activate successors of cemented blocks
This commit is contained in:
parent
d22b69c934
commit
f2198c9c0c
8 changed files with 39 additions and 31 deletions
|
|
@ -1232,8 +1232,8 @@ TEST (active_elections, activate_inactive)
|
||||||
ASSERT_TIMELY_EQ (5s, 1, node.stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out));
|
ASSERT_TIMELY_EQ (5s, 1, node.stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out));
|
||||||
ASSERT_ALWAYS_EQ (50ms, 0, node.stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_conf_height, nano::stat::dir::out));
|
ASSERT_ALWAYS_EQ (50ms, 0, node.stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_conf_height, nano::stat::dir::out));
|
||||||
|
|
||||||
// The first block was not active so no activation takes place
|
// Cementing of send should activate open
|
||||||
ASSERT_FALSE (node.active.active (open->qualified_root ()) || node.block_confirmed_or_being_confirmed (open->hash ()));
|
ASSERT_TIMELY (5s, node.active.active (open->qualified_root ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST (active_elections, list_active)
|
TEST (active_elections, list_active)
|
||||||
|
|
|
||||||
|
|
@ -123,15 +123,6 @@ void nano::active_elections::block_cemented (nano::secure::transaction const & t
|
||||||
nano::log::arg{ "source_election", source_election });
|
nano::log::arg{ "source_election", source_election });
|
||||||
|
|
||||||
notify_observers (transaction, status, votes);
|
notify_observers (transaction, status, votes);
|
||||||
|
|
||||||
bool cemented_bootstrap_count_reached = node.ledger.cemented_count () >= node.ledger.bootstrap_weight_max_blocks;
|
|
||||||
bool was_active = status.type == nano::election_status_type::active_confirmed_quorum || status.type == nano::election_status_type::active_confirmation_height;
|
|
||||||
|
|
||||||
// Next-block activations are only done for blocks with previously active elections
|
|
||||||
if (cemented_bootstrap_count_reached && was_active && !node.flags.disable_activate_successors)
|
|
||||||
{
|
|
||||||
activate_successors (transaction, block);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void nano::active_elections::notify_observers (nano::secure::transaction const & transaction, nano::election_status const & status, std::vector<nano::vote_with_weight_info> const & votes) const
|
void nano::active_elections::notify_observers (nano::secure::transaction const & transaction, nano::election_status const & status, std::vector<nano::vote_with_weight_info> const & votes) const
|
||||||
|
|
@ -169,17 +160,6 @@ void nano::active_elections::notify_observers (nano::secure::transaction const &
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void nano::active_elections::activate_successors (nano::secure::transaction const & transaction, std::shared_ptr<nano::block> const & block)
|
|
||||||
{
|
|
||||||
node.scheduler.priority.activate (transaction, block->account ());
|
|
||||||
|
|
||||||
// Start or vote for the next unconfirmed block in the destination account
|
|
||||||
if (block->is_send () && !block->destination ().is_zero () && block->destination () != block->account ())
|
|
||||||
{
|
|
||||||
node.scheduler.priority.activate (transaction, block->destination ());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t nano::active_elections::limit (nano::election_behavior behavior) const
|
int64_t nano::active_elections::limit (nano::election_behavior behavior) const
|
||||||
{
|
{
|
||||||
switch (behavior)
|
switch (behavior)
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,6 @@ private:
|
||||||
nano::stat::type completion_type (nano::election const & election) const;
|
nano::stat::type completion_type (nano::election const & election) const;
|
||||||
// Returns a list of elections sorted by difficulty, mutex must be locked
|
// Returns a list of elections sorted by difficulty, mutex must be locked
|
||||||
std::vector<std::shared_ptr<nano::election>> list_active_impl (std::size_t) const;
|
std::vector<std::shared_ptr<nano::election>> list_active_impl (std::size_t) const;
|
||||||
void activate_successors (nano::secure::transaction const &, std::shared_ptr<nano::block> const & block);
|
|
||||||
void notify_observers (nano::secure::transaction const &, nano::election_status const & status, std::vector<nano::vote_with_weight_info> const & votes) const;
|
void notify_observers (nano::secure::transaction const &, nano::election_status const & status, std::vector<nano::vote_with_weight_info> const & votes) const;
|
||||||
void block_cemented (nano::secure::transaction const &, std::shared_ptr<nano::block> const & block, nano::block_hash const & confirmation_root, std::shared_ptr<nano::election> const & source_election);
|
void block_cemented (nano::secure::transaction const &, std::shared_ptr<nano::block> const & block, nano::block_hash const & confirmation_root, std::shared_ptr<nano::election> const & source_election);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
|
||||||
generator{ *generator_impl },
|
generator{ *generator_impl },
|
||||||
final_generator_impl{ std::make_unique<nano::vote_generator> (config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* final */ true) },
|
final_generator_impl{ std::make_unique<nano::vote_generator> (config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* final */ true) },
|
||||||
final_generator{ *final_generator_impl },
|
final_generator{ *final_generator_impl },
|
||||||
scheduler_impl{ std::make_unique<nano::scheduler::component> (config, *this, ledger, block_processor, active, online_reps, vote_cache, stats, logger) },
|
scheduler_impl{ std::make_unique<nano::scheduler::component> (config, *this, ledger, block_processor, active, online_reps, vote_cache, confirming_set, stats, logger) },
|
||||||
scheduler{ *scheduler_impl },
|
scheduler{ *scheduler_impl },
|
||||||
aggregator_impl{ std::make_unique<nano::request_aggregator> (config.request_aggregator, *this, stats, generator, final_generator, history, ledger, wallets, vote_router) },
|
aggregator_impl{ std::make_unique<nano::request_aggregator> (config.request_aggregator, *this, stats, generator, final_generator, history, ledger, wallets, vote_router) },
|
||||||
aggregator{ *aggregator_impl },
|
aggregator{ *aggregator_impl },
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@
|
||||||
#include <nano/node/scheduler/optimistic.hpp>
|
#include <nano/node/scheduler/optimistic.hpp>
|
||||||
#include <nano/node/scheduler/priority.hpp>
|
#include <nano/node/scheduler/priority.hpp>
|
||||||
|
|
||||||
nano::scheduler::component::component (nano::node_config & node_config, nano::node & node, nano::ledger & ledger, nano::block_processor & block_processor, nano::active_elections & active, nano::online_reps & online_reps, nano::vote_cache & vote_cache, nano::stats & stats, nano::logger & logger) :
|
nano::scheduler::component::component (nano::node_config & node_config, nano::node & node, nano::ledger & ledger, nano::block_processor & block_processor, nano::active_elections & active, nano::online_reps & online_reps, nano::vote_cache & vote_cache, nano::confirming_set & confirming_set, nano::stats & stats, nano::logger & logger) :
|
||||||
hinted_impl{ std::make_unique<nano::scheduler::hinted> (node_config.hinted_scheduler, node, vote_cache, active, online_reps, stats) },
|
hinted_impl{ std::make_unique<nano::scheduler::hinted> (node_config.hinted_scheduler, node, vote_cache, active, online_reps, stats) },
|
||||||
manual_impl{ std::make_unique<nano::scheduler::manual> (node) },
|
manual_impl{ std::make_unique<nano::scheduler::manual> (node) },
|
||||||
optimistic_impl{ std::make_unique<nano::scheduler::optimistic> (node_config.optimistic_scheduler, node, ledger, active, node_config.network_params.network, stats) },
|
optimistic_impl{ std::make_unique<nano::scheduler::optimistic> (node_config.optimistic_scheduler, node, ledger, active, node_config.network_params.network, stats) },
|
||||||
priority_impl{ std::make_unique<nano::scheduler::priority> (node_config, node, ledger, block_processor, active, stats, logger) },
|
priority_impl{ std::make_unique<nano::scheduler::priority> (node_config, node, ledger, block_processor, active, confirming_set, stats, logger) },
|
||||||
hinted{ *hinted_impl },
|
hinted{ *hinted_impl },
|
||||||
manual{ *manual_impl },
|
manual{ *manual_impl },
|
||||||
optimistic{ *optimistic_impl },
|
optimistic{ *optimistic_impl },
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace nano::scheduler
|
||||||
class component final
|
class component final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
component (nano::node_config &, nano::node &, nano::ledger &, nano::block_processor &, nano::active_elections &, nano::online_reps &, nano::vote_cache &, nano::stats &, nano::logger &);
|
component (nano::node_config &, nano::node &, nano::ledger &, nano::block_processor &, nano::active_elections &, nano::online_reps &, nano::vote_cache &, nano::confirming_set &, nano::stats &, nano::logger &);
|
||||||
~component ();
|
~component ();
|
||||||
|
|
||||||
void start ();
|
void start ();
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,13 @@
|
||||||
#include <nano/secure/ledger_set_any.hpp>
|
#include <nano/secure/ledger_set_any.hpp>
|
||||||
#include <nano/secure/ledger_set_confirmed.hpp>
|
#include <nano/secure/ledger_set_confirmed.hpp>
|
||||||
|
|
||||||
nano::scheduler::priority::priority (nano::node_config & node_config, nano::node & node_a, nano::ledger & ledger_a, nano::block_processor & block_processor_a, nano::active_elections & active_a, nano::stats & stats_a, nano::logger & logger_a) :
|
nano::scheduler::priority::priority (nano::node_config & node_config, nano::node & node_a, nano::ledger & ledger_a, nano::block_processor & block_processor_a, nano::active_elections & active_a, nano::confirming_set & confirming_set_a, nano::stats & stats_a, nano::logger & logger_a) :
|
||||||
config{ node_config.priority_scheduler },
|
config{ node_config.priority_scheduler },
|
||||||
node{ node_a },
|
node{ node_a },
|
||||||
ledger{ ledger_a },
|
ledger{ ledger_a },
|
||||||
block_processor{ block_processor_a },
|
block_processor{ block_processor_a },
|
||||||
active{ active_a },
|
active{ active_a },
|
||||||
|
confirming_set{ confirming_set_a },
|
||||||
stats{ stats_a },
|
stats{ stats_a },
|
||||||
logger{ logger_a }
|
logger{ logger_a }
|
||||||
{
|
{
|
||||||
|
|
@ -58,6 +59,21 @@ nano::scheduler::priority::priority (nano::node_config & node_config, nano::node
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Activate successors of cemented blocks
|
||||||
|
confirming_set.batch_cemented.add ([this] (auto const & batch) {
|
||||||
|
if (node.flags.disable_activate_successors)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto transaction = ledger.tx_begin_read ();
|
||||||
|
for (auto const & context : batch)
|
||||||
|
{
|
||||||
|
release_assert (context.block != nullptr);
|
||||||
|
activate_successors (transaction, *context.block);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
nano::scheduler::priority::~priority ()
|
nano::scheduler::priority::~priority ()
|
||||||
|
|
@ -157,6 +173,17 @@ bool nano::scheduler::priority::activate (secure::transaction const & transactio
|
||||||
return false; // Not activated
|
return false; // Not activated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool nano::scheduler::priority::activate_successors (secure::transaction const & transaction, nano::block const & block)
|
||||||
|
{
|
||||||
|
bool result = activate (transaction, block.account ());
|
||||||
|
// Start or vote for the next unconfirmed block in the destination account
|
||||||
|
if (block.is_send () && !block.destination ().is_zero () && block.destination () != block.account ())
|
||||||
|
{
|
||||||
|
result |= activate (transaction, block.destination ());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void nano::scheduler::priority::notify ()
|
void nano::scheduler::priority::notify ()
|
||||||
{
|
{
|
||||||
condition.notify_all ();
|
condition.notify_all ();
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ public:
|
||||||
class priority final
|
class priority final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
priority (nano::node_config &, nano::node &, nano::ledger &, nano::block_processor &, nano::active_elections &, nano::stats &, nano::logger &);
|
priority (nano::node_config &, nano::node &, nano::ledger &, nano::block_processor &, nano::active_elections &, nano::confirming_set &, nano::stats &, nano::logger &);
|
||||||
~priority ();
|
~priority ();
|
||||||
|
|
||||||
void start ();
|
void start ();
|
||||||
|
|
@ -36,8 +36,9 @@ public:
|
||||||
* Activates the first unconfirmed block of \p account_a
|
* Activates the first unconfirmed block of \p account_a
|
||||||
* @return true if account was activated
|
* @return true if account was activated
|
||||||
*/
|
*/
|
||||||
bool activate (secure::transaction const &, nano::account const &);
|
bool activate (nano::secure::transaction const &, nano::account const &);
|
||||||
bool activate (secure::transaction const &, nano::account const &, nano::account_info const &, nano::confirmation_height_info const &);
|
bool activate (nano::secure::transaction const &, nano::account const &, nano::account_info const &, nano::confirmation_height_info const &);
|
||||||
|
bool activate_successors (nano::secure::transaction const &, nano::block const &);
|
||||||
|
|
||||||
void notify ();
|
void notify ();
|
||||||
std::size_t size () const;
|
std::size_t size () const;
|
||||||
|
|
@ -51,6 +52,7 @@ private: // Dependencies
|
||||||
nano::ledger & ledger;
|
nano::ledger & ledger;
|
||||||
nano::block_processor & block_processor;
|
nano::block_processor & block_processor;
|
||||||
nano::active_elections & active;
|
nano::active_elections & active;
|
||||||
|
nano::confirming_set & confirming_set;
|
||||||
nano::stats & stats;
|
nano::stats & stats;
|
||||||
nano::logger & logger;
|
nano::logger & logger;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue