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

Extracting votes cache bootstrap start function #2894

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 2 additions & 20 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ nano::inactive_cache_status nano::active_transactions::inactive_votes_bootstrap_
*/
nano::inactive_cache_status status (previously_a);
constexpr unsigned election_start_voters_min{ 5 };
uint128_t tally;
nano::uint128_t tally;
for (auto const & voter : voters_a)
{
tally += node.ledger.weight (voter);
Expand Down Expand Up @@ -1342,25 +1342,7 @@ nano::inactive_cache_status nano::active_transactions::inactive_votes_bootstrap_
}
else if (!block && status.bootstrap_started && !previously_a.bootstrap_started)
{
auto node_l (node.shared ());
node.alarm.add (std::chrono::steady_clock::now () + node.network_params.bootstrap.gap_cache_bootstrap_start_interval, [node_l, hash_a]() {
auto transaction (node_l->store.tx_begin_read ());
if (!node_l->store.block_exists (transaction, hash_a))
{
if (!node_l->bootstrap_initiator.in_progress ())
{
node_l->logger.try_log (boost::str (boost::format ("Missing block %1% which has enough votes to warrant lazy bootstrapping it") % hash_a.to_string ()));
}
if (!node_l->flags.disable_lazy_bootstrap)
{
node_l->bootstrap_initiator.bootstrap_lazy (hash_a);
}
else if (!node_l->flags.disable_legacy_bootstrap)
{
node_l->bootstrap_initiator.bootstrap ();
}
}
});
node.gap_cache.bootstrap_start (hash_a);
}
}
return status;
Expand Down
45 changes: 25 additions & 20 deletions nano/node/gap_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void nano::gap_cache::vote (std::shared_ptr<nano::vote> vote_a)

bool nano::gap_cache::bootstrap_check (std::vector<nano::account> const & voters_a, nano::block_hash const & hash_a)
{
uint128_t tally;
nano::uint128_t tally;
for (auto const & voter : voters_a)
{
tally += node.ledger.weight (voter);
Expand All @@ -88,29 +88,34 @@ bool nano::gap_cache::bootstrap_check (std::vector<nano::account> const & voters
}
if (start_bootstrap && !node.ledger.block_exists (hash_a))
{
auto node_l (node.shared ());
node.alarm.add (std::chrono::steady_clock::now () + node.network_params.bootstrap.gap_cache_bootstrap_start_interval, [node_l, hash_a]() {
auto transaction (node_l->store.tx_begin_read ());
if (!node_l->store.block_exists (transaction, hash_a))
{
if (!node_l->bootstrap_initiator.in_progress ())
{
node_l->logger.try_log (boost::str (boost::format ("Missing block %1% which has enough votes to warrant lazy bootstrapping it") % hash_a.to_string ()));
}
if (!node_l->flags.disable_lazy_bootstrap)
{
node_l->bootstrap_initiator.bootstrap_lazy (hash_a);
}
else if (!node_l->flags.disable_legacy_bootstrap)
{
node_l->bootstrap_initiator.bootstrap ();
}
}
});
bootstrap_start (hash_a);
}
return start_bootstrap;
}

void nano::gap_cache::bootstrap_start (nano::block_hash const & hash_a)
{
auto node_l (node.shared ());
node.alarm.add (std::chrono::steady_clock::now () + node.network_params.bootstrap.gap_cache_bootstrap_start_interval, [node_l, hash_a]() {
auto transaction (node_l->store.tx_begin_read ());
if (!node_l->store.block_exists (transaction, hash_a))
{
if (!node_l->bootstrap_initiator.in_progress ())
{
node_l->logger.try_log (boost::str (boost::format ("Missing block %1% which has enough votes to warrant lazy bootstrapping it") % hash_a.to_string ()));
}
if (!node_l->flags.disable_lazy_bootstrap)
{
node_l->bootstrap_initiator.bootstrap_lazy (hash_a);
}
else if (!node_l->flags.disable_legacy_bootstrap)
{
node_l->bootstrap_initiator.bootstrap ();
}
}
});
}

nano::uint128_t nano::gap_cache::bootstrap_threshold ()
{
auto result ((node.online_reps.online_stake () / 256) * node.config.bootstrap_fraction_numerator);
Expand Down
1 change: 1 addition & 0 deletions nano/node/gap_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class gap_cache final
void erase (nano::block_hash const & hash_a);
void vote (std::shared_ptr<nano::vote>);
bool bootstrap_check (std::vector<nano::account> const &, nano::block_hash const &);
void bootstrap_start (nano::block_hash const & hash_a);
nano::uint128_t bootstrap_threshold ();
size_t size ();
// clang-format off
Expand Down