Skip to content

Commit

Permalink
Removing erasing recently_confirmed
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Nov 1, 2023
1 parent 32bd188 commit 298b348
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4090,7 +4090,7 @@ TEST (node, deferred_dependent_elections)
}
}

TEST (rep_crawler, recently_confirmed)
TEST (rep_crawler, DISABLED_recently_confirmed)
{
nano::test::system system (1);
auto & node1 (*system.nodes[0]);
Expand Down
14 changes: 5 additions & 9 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,13 @@ nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path cons
});
observers.vote.add ([this] (std::shared_ptr<nano::vote> vote_a, std::shared_ptr<nano::transport::channel> const & channel_a, nano::vote_code code_a) {
debug_assert (code_a != nano::vote_code::invalid);
// The vote_code::vote is handled inside the election
if (code_a == nano::vote_code::indeterminate)
auto active_in_rep_crawler (!this->rep_crawler.response (channel_a, vote_a));
if (active_in_rep_crawler)
{
auto active_in_rep_crawler (!this->rep_crawler.response (channel_a, vote_a));
if (active_in_rep_crawler)
{
// Representative is defined as online if replying to live votes or rep_crawler queries
this->online_reps.observe (vote_a->account);
}
this->gap_cache.vote (vote_a);
// Representative is defined as online if replying to live votes or rep_crawler queries
this->online_reps.observe (vote_a->account);
}
this->gap_cache.vote (vote_a);
});

// Cancelling local work generation
Expand Down
27 changes: 17 additions & 10 deletions nano/node/repcrawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,34 +155,41 @@ std::vector<std::shared_ptr<nano::transport::channel>> nano::rep_crawler::get_cr
void nano::rep_crawler::query (std::vector<std::shared_ptr<nano::transport::channel>> const & channels_a)
{
auto transaction (node.store.tx_begin_read ());
auto hash_root (node.ledger.hash_root_random (transaction));
std::optional<std::pair<nano::block_hash, nano::block_hash>> hash_root;
for (auto i = 0; i < 4 && !hash_root; ++i)
{
hash_root = node.ledger.hash_root_random (transaction);
if (node.active.recently_confirmed.exists (hash_root->first))
{
hash_root = std::nullopt;
}
}
if (!hash_root)
{
return;
}
{
nano::lock_guard<nano::mutex> lock{ active_mutex };
// Don't send same block multiple times in tests
if (node.network_params.network.is_dev_network ())
{
for (auto i (0); active.count (hash_root.first) != 0 && i < 4; ++i)
for (auto i (0); active.count (hash_root->first) != 0 && i < 4; ++i)
{
hash_root = node.ledger.hash_root_random (transaction);
}
}
active.insert (hash_root.first);
}
if (!channels_a.empty ())
{
// In case our random block is a recently confirmed one, we remove an entry otherwise votes will be marked as replay and not forwarded to repcrawler
node.active.recently_confirmed.erase (hash_root.first);
active.insert (hash_root->first);
}
for (auto i (channels_a.begin ()), n (channels_a.end ()); i != n; ++i)
{
debug_assert (*i != nullptr);
on_rep_request (*i);
node.network.send_confirm_req (*i, hash_root);
node.network.send_confirm_req (*i, *hash_root);
}

// A representative must respond with a vote within the deadline
std::weak_ptr<nano::node> node_w (node.shared ());
node.workers.add_timed_task (std::chrono::steady_clock::now () + std::chrono::seconds (5), [node_w, hash = hash_root.first] () {
node.workers.add_timed_task (std::chrono::steady_clock::now () + std::chrono::seconds (5), [node_w, hash = hash_root->first] () {
if (auto node_l = node_w.lock ())
{
auto target_finished_processed (node_l->vote_processor.total_processed + node_l->vote_processor.size ());
Expand Down

0 comments on commit 298b348

Please sign in to comment.