Split out votes cache bootstrap start function (#2894)
This commit is contained in:
parent
518467b0b1
commit
0c1205e90e
3 changed files with 28 additions and 40 deletions
|
@ -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);
|
||||
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
@ -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);
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue