Skip to content

Commit

Permalink
Move block_source enum
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Feb 8, 2024
1 parent 1cdea1d commit 6fc74c8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions nano/node/block_broadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ void nano::block_broadcast::connect (nano::block_processor & block_processor)

void nano::block_broadcast::observe (std::shared_ptr<nano::block> const & block, nano::block_processor::context const & context)
{
if (context.source == nano::block_processor::block_source::local)
if (context.source == nano::block_source::local)
{
// Block created on this node
// Perform more agressive initial flooding
network.flood_block_initial (block);
}
else
{
if (context.source != nano::block_processor::block_source::bootstrap)
if (context.source != nano::block_source::bootstrap)
{
// Block arrived from realtime traffic, do normal gossip.
network.flood_block (block, nano::transport::buffer_drop_policy::limiter);
Expand Down
14 changes: 7 additions & 7 deletions nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* block_processor::context
*/

nano::block_processor::context::context (nano::block_processor::block_source source_a) :
nano::block_processor::context::context (nano::block_source source_a) :
source{ source_a }
{
debug_assert (source != nano::block_processor::block_source::unknown);
debug_assert (source != nano::block_source::unknown);
}

auto nano::block_processor::context::get_future () -> std::future<result_t>
Expand Down Expand Up @@ -210,7 +210,7 @@ bool nano::block_processor::have_blocks ()

void nano::block_processor::add_impl (std::shared_ptr<nano::block> block, context ctx)
{
release_assert (ctx.source != nano::block_processor::block_source::forced);
release_assert (ctx.source != nano::block_source::forced);
{
nano::lock_guard<nano::mutex> guard{ mutex };
blocks.emplace_back (entry{ block, std::move (ctx) });
Expand All @@ -226,15 +226,15 @@ auto nano::block_processor::next () -> entry
if (!blocks.empty ())
{
entry entry = std::move (blocks.front ());
release_assert (entry.ctx.source != nano::block_processor::block_source::forced);
release_assert (entry.ctx.source != nano::block_source::forced);
blocks.pop_front ();
return entry;
}

if (!forced.empty ())
{
entry entry = std::move (forced.front ());
release_assert (entry.ctx.source == nano::block_processor::block_source::forced);
release_assert (entry.ctx.source == nano::block_source::forced);
forced.pop_front ();
return entry;
}
Expand Down Expand Up @@ -271,7 +271,7 @@ auto nano::block_processor::process_batch (nano::unique_lock<nano::mutex> & lock
context ctx = std::move (entry.ctx);
auto const block = entry.block;
auto const hash = block->hash ();
bool const force = ctx.source == nano::block_processor::block_source::forced;
bool const force = ctx.source == nano::block_source::forced;

lock_a.unlock ();

Expand Down Expand Up @@ -415,7 +415,7 @@ std::unique_ptr<nano::container_info_component> nano::collect_container_info (bl
return composite;
}

nano::stat::detail nano::to_stat_detail (block_processor::block_source type)
nano::stat::detail nano::to_stat_detail (nano::block_source type)
{
auto value = magic_enum::enum_cast<nano::stat::detail> (magic_enum::enum_name (type));
debug_assert (value);
Expand Down
24 changes: 12 additions & 12 deletions nano/node/blockprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ namespace nano
class node;
class write_database_queue;

enum class block_source
{
unknown = 0,
live,
bootstrap,
unchecked,
local,
forced,
};

nano::stat::detail to_stat_detail (block_source);

/**
* Processing blocks is a potentially long IO operation.
* This class isolates block insertion from other operations like servicing network operations
*/
class block_processor final
{
public: // Context
enum class block_source
{
unknown = 0,
live,
bootstrap,
unchecked,
local,
forced,
};

class context
{
public:
Expand Down Expand Up @@ -115,6 +117,4 @@ class block_processor final

friend std::unique_ptr<container_info_component> collect_container_info (block_processor & block_processor, std::string const & name);
};

nano::stat::detail to_stat_detail (block_processor::block_source);
}
6 changes: 3 additions & 3 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path cons
process_live_dispatcher.connect (block_processor);

unchecked.satisfied.add ([this] (nano::unchecked_info const & info) {
block_processor.add (info.block, nano::block_processor::block_source::unchecked);
block_processor.add (info.block, nano::block_source::unchecked);
});

vote_cache.rep_weight_query = [this] (nano::account const & rep) {
Expand Down Expand Up @@ -572,12 +572,12 @@ nano::process_return nano::node::process (nano::block & block)

std::optional<nano::process_return> nano::node::process_local (std::shared_ptr<nano::block> const & block_a)
{
return block_processor.add_blocking (block_a, nano::block_processor::block_source::local);
return block_processor.add_blocking (block_a, nano::block_source::local);
}

void nano::node::process_local_async (std::shared_ptr<nano::block> const & block_a)
{
block_processor.add (block_a, nano::block_processor::block_source::local);
block_processor.add (block_a, nano::block_source::local);
}

void nano::node::start ()
Expand Down

0 comments on commit 6fc74c8

Please sign in to comment.