diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 19bd7f62..69c56b5e 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -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; diff --git a/nano/node/gap_cache.cpp b/nano/node/gap_cache.cpp index e57f2f9c..56aad4c8 100644 --- a/nano/node/gap_cache.cpp +++ b/nano/node/gap_cache.cpp @@ -69,7 +69,7 @@ void nano::gap_cache::vote (std::shared_ptr vote_a) bool nano::gap_cache::bootstrap_check (std::vector 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 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); diff --git a/nano/node/gap_cache.hpp b/nano/node/gap_cache.hpp index f6cf41c7..3bc942cb 100644 --- a/nano/node/gap_cache.hpp +++ b/nano/node/gap_cache.hpp @@ -39,6 +39,7 @@ public: void erase (nano::block_hash const & hash_a); void vote (std::shared_ptr); bool bootstrap_check (std::vector 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