Skip to content

Commit

Permalink
Remove lazy destinations check (#3117)
Browse files Browse the repository at this point in the history
* Remove lazy destinations check
as not effective and duplicating legacy bootstrap
  • Loading branch information
SergiySW committed Mar 8, 2021
1 parent 4a45048 commit 702fa2e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 100 deletions.
6 changes: 3 additions & 3 deletions nano/core_test/bootstrap.cpp
Expand Up @@ -845,7 +845,7 @@ TEST (bootstrap_processor, lazy_unclear_state_link_not_existing)
ASSERT_EQ (1, node2->stats.count (nano::stat::type::bootstrap, nano::stat::detail::bulk_pull_failed_account, nano::stat::dir::in));
}

TEST (bootstrap_processor, lazy_destinations)
TEST (bootstrap_processor, DISABLED_lazy_destinations)
{
nano::system system;
nano::node_config config (nano::get_available_port (), system.logging);
Expand Down Expand Up @@ -961,11 +961,11 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
node2->block_processor.flush ();
ASSERT_TIMELY (10s, !node2->bootstrap_initiator.in_progress ());
node2->block_processor.flush ();
ASSERT_EQ (4, node2->ledger.cache.block_count);
ASSERT_EQ (3, node2->ledger.cache.block_count);
ASSERT_TRUE (node2->ledger.block_exists (send1->hash ()));
ASSERT_TRUE (node2->ledger.block_exists (send2->hash ()));
ASSERT_FALSE (node2->ledger.block_exists (open->hash ()));
ASSERT_TRUE (node2->ledger.block_exists (state_open->hash ()));
ASSERT_FALSE (node2->ledger.block_exists (state_open->hash ()));
node2->stop ();
}

Expand Down
1 change: 0 additions & 1 deletion nano/node/bootstrap/bootstrap.hpp
Expand Up @@ -135,7 +135,6 @@ class bootstrap_limits final
static constexpr unsigned requeued_pulls_processed_blocks_factor = 4096;
static constexpr unsigned bulk_push_cost_limit = 200;
static constexpr std::chrono::seconds lazy_flush_delay_sec = std::chrono::seconds (5);
static constexpr unsigned lazy_destinations_request_limit = 256 * 1024;
static constexpr uint64_t lazy_batch_pull_count_resize_blocks_limit = 4 * 1024 * 1024;
static constexpr double lazy_batch_pull_count_resize_ratio = 2.0;
static constexpr size_t lazy_blocks_restart_limit = 1024 * 1024;
Expand Down
71 changes: 0 additions & 71 deletions nano/node/bootstrap/bootstrap_lazy.cpp
Expand Up @@ -9,7 +9,6 @@
#include <algorithm>

constexpr std::chrono::seconds nano::bootstrap_limits::lazy_flush_delay_sec;
constexpr unsigned nano::bootstrap_limits::lazy_destinations_request_limit;
constexpr uint64_t nano::bootstrap_limits::lazy_batch_pull_count_resize_blocks_limit;
constexpr double nano::bootstrap_limits::lazy_batch_pull_count_resize_ratio;
constexpr size_t nano::bootstrap_limits::lazy_blocks_restart_limit;
Expand Down Expand Up @@ -157,11 +156,6 @@ bool nano::bootstrap_attempt_lazy::lazy_finished ()
{
result = true;
}
// Don't close lazy bootstrap until all destinations are processed
if (result && !lazy_destinations.empty ())
{
result = false;
}
return result;
}

Expand Down Expand Up @@ -203,20 +197,13 @@ void nano::bootstrap_attempt_lazy::run ()
{
lazy_backlog_cleanup ();
}
// Destinations check
if (pulling == 0 && lazy_destinations_flushed)
{
lazy_destinations_flush ();
lazy_pull_flush (lock);
}
}
// Flushing lazy pulls
lazy_pull_flush (lock);
// Check if some blocks required for backlog were processed. Start destinations check
if (pulling == 0)
{
lazy_backlog_cleanup ();
lazy_destinations_flush ();
lazy_pull_flush (lock);
}
}
Expand Down Expand Up @@ -261,14 +248,6 @@ bool nano::bootstrap_attempt_lazy::process_block_lazy (std::shared_ptr<nano::blo
{
lazy_block_state (block_a, retry_limit);
}
else if (block_a->type () == nano::block_type::send)
{
std::shared_ptr<nano::send_block> block_l (std::static_pointer_cast<nano::send_block> (block_a));
if (block_l != nullptr && !block_l->hashables.destination.is_zero ())
{
lazy_destinations_increment (block_l->hashables.destination);
}
}
lazy_blocks_insert (hash);
// Adding lazy balances for first processed block in pull
if (pull_blocks == 0 && (block_a->type () == nano::block_type::state || block_a->type () == nano::block_type::send))
Expand Down Expand Up @@ -321,10 +300,6 @@ void nano::bootstrap_attempt_lazy::lazy_block_state (std::shared_ptr<nano::block
{
lazy_add (link, retry_limit);
}
else
{
lazy_destinations_increment (link.as_account ());
}
}
// Else ignore pruned blocks
}
Expand All @@ -338,10 +313,6 @@ void nano::bootstrap_attempt_lazy::lazy_block_state (std::shared_ptr<nano::block
{
lazy_add (link, retry_limit);
}
else
{
lazy_destinations_increment (link.as_account ());
}
lazy_balances.erase (previous_balance);
}
}
Expand All @@ -368,10 +339,6 @@ void nano::bootstrap_attempt_lazy::lazy_block_state_backlog_check (std::shared_p
{
lazy_add (next_block.link, next_block.retry_limit); // link
}
else
{
lazy_destinations_increment (next_block.link.as_account ());
}
}
// Assumption for other legacy block types
else if (lazy_undefined_links.find (next_block.link.as_block_hash ()) == lazy_undefined_links.end ())
Expand Down Expand Up @@ -400,10 +367,6 @@ void nano::bootstrap_attempt_lazy::lazy_backlog_cleanup ()
{
lazy_add (next_block.link, next_block.retry_limit); // link
}
else
{
lazy_destinations_increment (next_block.link.as_account ());
}
}
else
{
Expand All @@ -425,39 +388,6 @@ void nano::bootstrap_attempt_lazy::lazy_backlog_cleanup ()
}
}

void nano::bootstrap_attempt_lazy::lazy_destinations_increment (nano::account const & destination_a)
{
// Enabled only if legacy bootstrap is not available. Legacy bootstrap is a more effective way to receive all existing destinations
if (node->flags.disable_legacy_bootstrap)
{
// Update accounts counter for send blocks
auto existing (lazy_destinations.get<account_tag> ().find (destination_a));
if (existing != lazy_destinations.get<account_tag> ().end ())
{
lazy_destinations.get<account_tag> ().modify (existing, [](nano::lazy_destinations_item & item_a) {
++item_a.count;
});
}
else
{
lazy_destinations.emplace (nano::lazy_destinations_item{ destination_a, 1 });
}
}
}

void nano::bootstrap_attempt_lazy::lazy_destinations_flush ()
{
debug_assert (!mutex.try_lock ());
lazy_destinations_flushed = true;
size_t count (0);
for (auto it (lazy_destinations.get<count_tag> ().begin ()), end (lazy_destinations.get<count_tag> ().end ()); it != end && count < nano::bootstrap_limits::lazy_destinations_request_limit && !stopped;)
{
lazy_add (it->account, node->network_params.bootstrap.lazy_destinations_retry_limit);
it = lazy_destinations.get<count_tag> ().erase (it);
++count;
}
}

void nano::bootstrap_attempt_lazy::lazy_blocks_insert (nano::block_hash const & hash_a)
{
debug_assert (!mutex.try_lock ());
Expand Down Expand Up @@ -522,7 +452,6 @@ void nano::bootstrap_attempt_lazy::get_information (boost::property_tree::ptree
tree_a.put ("lazy_blocks", std::to_string (lazy_blocks.size ()));
tree_a.put ("lazy_state_backlog", std::to_string (lazy_state_backlog.size ()));
tree_a.put ("lazy_balances", std::to_string (lazy_balances.size ()));
tree_a.put ("lazy_destinations", std::to_string (lazy_destinations.size ()));
tree_a.put ("lazy_undefined_links", std::to_string (lazy_undefined_links.size ()));
tree_a.put ("lazy_pulls", std::to_string (lazy_pulls.size ()));
tree_a.put ("lazy_keys", std::to_string (lazy_keys.size ()));
Expand Down
25 changes: 0 additions & 25 deletions nano/node/bootstrap/bootstrap_lazy.hpp
Expand Up @@ -23,12 +23,6 @@ class lazy_state_backlog_item final
nano::uint128_t balance{ 0 };
unsigned retry_limit{ 0 };
};
class lazy_destinations_item final
{
public:
nano::account account{ 0 };
uint64_t count{ 0 };
};
class bootstrap_attempt_lazy final : public bootstrap_attempt
{
public:
Expand All @@ -48,8 +42,6 @@ class bootstrap_attempt_lazy final : public bootstrap_attempt
void lazy_block_state (std::shared_ptr<nano::block> const &, unsigned);
void lazy_block_state_backlog_check (std::shared_ptr<nano::block> const &, nano::block_hash const &);
void lazy_backlog_cleanup ();
void lazy_destinations_increment (nano::account const &);
void lazy_destinations_flush ();
void lazy_blocks_insert (nano::block_hash const &);
void lazy_blocks_erase (nano::block_hash const &);
bool lazy_blocks_processed (nano::block_hash const &);
Expand All @@ -63,25 +55,8 @@ class bootstrap_attempt_lazy final : public bootstrap_attempt
std::unordered_set<nano::block_hash> lazy_keys;
std::deque<std::pair<nano::hash_or_account, unsigned>> lazy_pulls;
std::chrono::steady_clock::time_point lazy_start_time;
class account_tag
{
};
class count_tag
{
};
// clang-format off
boost::multi_index_container<lazy_destinations_item,
mi::indexed_by<
mi::ordered_non_unique<mi::tag<count_tag>,
mi::member<lazy_destinations_item, uint64_t, &lazy_destinations_item::count>,
std::greater<uint64_t>>,
mi::hashed_unique<mi::tag<account_tag>,
mi::member<lazy_destinations_item, nano::account, &lazy_destinations_item::account>>>>
lazy_destinations;
// clang-format on
std::atomic<size_t> lazy_blocks_count{ 0 };
size_t peer_count{ 0 };
std::atomic<bool> lazy_destinations_flushed{ false };
/** The maximum number of records to be read in while iterating over long lazy containers */
static uint64_t constexpr batch_read_size = 256;
};
Expand Down

0 comments on commit 702fa2e

Please sign in to comment.