Skip to content

Commit

Permalink
Split out votes cache bootstrap start function (#2894)
Browse files Browse the repository at this point in the history
  • Loading branch information
SergiySW authored and guilhermelawless committed Sep 2, 2020
1 parent 4cfd661 commit 951c6fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 40 deletions.
22 changes: 2 additions & 20 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,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 @@ -1152,25 +1152,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

0 comments on commit 951c6fe

Please sign in to comment.