Skip to content

Commit

Permalink
Erase confirmed blocks from block broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Nov 13, 2023
1 parent 4a2fb93 commit c540ef5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions nano/lib/stats_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ enum class detail : uint8_t
// block_broadcaster
broadcast_normal,
broadcast_aggressive,
erase_old,
erase_confirmed,

_last // Must be the last enum
};
Expand Down
19 changes: 15 additions & 4 deletions nano/node/block_broadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#include <nano/node/block_broadcast.hpp>
#include <nano/node/blockprocessor.hpp>
#include <nano/node/network.hpp>
#include <nano/node/node.hpp>

nano::block_broadcast::block_broadcast (nano::block_processor & block_processor_a, nano::network & network_a, nano::stats & stats_a, bool enabled_a) :
nano::block_broadcast::block_broadcast (nano::node & node_a, nano::block_processor & block_processor_a, nano::network & network_a, nano::stats & stats_a, bool enabled_a) :
node{ node_a },
block_processor{ block_processor_a },
network{ network_a },
stats{ stats_a },
Expand Down Expand Up @@ -92,9 +94,9 @@ void nano::block_broadcast::run ()

if (!stopped)
{
cleanup ();
run_once (lock);
debug_assert (lock.owns_lock ());
cleanup ();
}
}
}
Expand Down Expand Up @@ -130,12 +132,21 @@ void nano::block_broadcast::cleanup ()
{
debug_assert (!mutex.try_lock ());

erase_if (local_blocks, [this] (auto const & entry) {
auto transaction = node.store.tx_begin_read ();
erase_if (local_blocks, [this, &transaction] (auto const & entry) {
transaction.refresh_if_needed ();

if (entry.arrival + local_age_cutoff < std::chrono::steady_clock::now ())
{
stats.inc (nano::stat::type::block_broadcaster, nano::stat::detail::erase);
stats.inc (nano::stat::type::block_broadcaster, nano::stat::detail::erase_old);
return true;
}
if (node.block_confirmed_or_being_confirmed (transaction, entry.block->hash ()))
{
stats.inc (nano::stat::type::block_broadcaster, nano::stat::detail::erase_confirmed);
return true;
}

return false;
});
}
Expand Down
4 changes: 3 additions & 1 deletion nano/node/block_broadcast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace mi = boost::multi_index;

namespace nano
{
class node;
class network;
}

Expand All @@ -38,7 +39,7 @@ class block_broadcast
};

public:
block_broadcast (nano::block_processor &, nano::network &, nano::stats &, bool enabled = false);
block_broadcast (nano::node &, nano::block_processor &, nano::network &, nano::stats &, bool enabled = false);
~block_broadcast ();

void start ();
Expand All @@ -47,6 +48,7 @@ class block_broadcast
std::unique_ptr<container_info_component> collect_container_info (std::string const & name) const;

private: // Dependencies
nano::node & node;
nano::block_processor & block_processor;
nano::network & network;
nano::stats & stats;
Expand Down

0 comments on commit c540ef5

Please sign in to comment.