Skip to content

Commit

Permalink
CONFIG
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 5, 2024
1 parent 526841b commit 209bcf4
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 7 deletions.
43 changes: 36 additions & 7 deletions nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void nano::block_processor::context::set_result (result_t const & result)
*/

nano::block_processor::block_processor (nano::node & node_a, nano::write_database_queue & write_database_queue_a) :
config{ node_a.config.block_processor },
node (node_a),
write_database_queue (write_database_queue_a),
next_log (std::chrono::steady_clock::now ())
Expand All @@ -51,9 +52,9 @@ nano::block_processor::block_processor (nano::node & node_a, nano::write_databas
switch (origin.source)
{
case nano::block_source::live:
return 128;
return config.max_peer_queue;
default:
return 1024 * 16;
return config.max_system_queue;
}
};

Expand All @@ -62,13 +63,15 @@ nano::block_processor::block_processor (nano::node & node_a, nano::write_databas
switch (origin.source)
{
case nano::block_source::live:
return 1;
case nano::block_source::local:
return 16;
return config.priority_live;
case nano::block_source::bootstrap:
return 8;
case nano::block_source::bootstrap_legacy:
case nano::block_source::unchecked:
return config.priority_bootstrap;
case nano::block_source::local:
return config.priority_local;
default:
return 1;
return size_t{ 1 };
}
};
}
Expand Down Expand Up @@ -467,3 +470,29 @@ nano::stat::detail nano::to_stat_detail (nano::block_source type)
debug_assert (value);
return value.value_or (nano::stat::detail{});
}

/*
* block_processor_config
*/

nano::error nano::block_processor_config::serialize (nano::tomlconfig & toml) const
{
toml.put ("max_peer_queue", max_peer_queue, "Maximum number of blocks to queue from network peers. \ntype:uint64");
toml.put ("max_system_queue", max_system_queue, "Maximum number of blocks to queue from system components (local RPC, bootstrap). \ntype:uint64");
toml.put ("priority_live", priority_live, "Priority for live network blocks. Higher priority gets processed more frequently. \ntype:uint64");
toml.put ("priority_bootstrap", priority_bootstrap, "Priority for bootstrap blocks. Higher priority gets processed more frequently. \ntype:uint64");
toml.put ("priority_local", priority_local, "Priority for local RPC blocks. Higher priority gets processed more frequently. \ntype:uint64");

return toml.get_error ();
}

nano::error nano::block_processor_config::deserialize (nano::tomlconfig & toml)
{
toml.get ("max_peer_queue", max_peer_queue);
toml.get ("max_system_queue", max_system_queue);
toml.get ("priority_live", priority_live);
toml.get ("priority_bootstrap", priority_bootstrap);
toml.get ("priority_local", priority_local);

return toml.get_error ();
}
19 changes: 19 additions & 0 deletions nano/node/blockprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ enum class block_source
std::string_view to_string (block_source);
nano::stat::detail to_stat_detail (block_source);

class block_processor_config final
{
public:
nano::error deserialize (nano::tomlconfig & toml);
nano::error serialize (nano::tomlconfig & toml) const;

public:
// Maximum number of blocks to queue from network peers
size_t max_peer_queue{ 128 };
// Maximum number of blocks to queue from system components (local RPC, bootstrap)
size_t max_system_queue{ 16 * 1024 };

// Higher priority gets processed more frequently
size_t priority_live{ 1 };
size_t priority_bootstrap{ 8 };
size_t priority_local{ 16 };
};

/**
* Processing blocks is a potentially long IO operation.
* This class isolates block insertion from other operations like servicing network operations
Expand Down Expand Up @@ -102,6 +120,7 @@ class block_processor final
bool add_impl (context, std::shared_ptr<nano::transport::channel> channel = nullptr);

private: // Dependencies
block_processor_config const & config;
nano::node & node;
nano::write_database_queue & write_database_queue;

Expand Down
10 changes: 10 additions & 0 deletions nano/node/nodeconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ nano::error nano::node_config::serialize_toml (nano::tomlconfig & toml) const
vote_cache.serialize (vote_cache_l);
toml.put_child ("vote_cache", vote_cache_l);

nano::tomlconfig block_processor_l;
block_processor.serialize (block_processor_l);
toml.put_child ("block_processor", block_processor_l);

return toml.get_error ();
}

Expand Down Expand Up @@ -273,6 +277,12 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml)
vote_cache.deserialize (config_l);
}

if (toml.has_key ("block_processor"))
{
auto config_l = toml.get_required_child ("block_processor");
block_processor.deserialize (config_l);
}

if (toml.has_key ("work_peers"))
{
work_peers.clear ();
Expand Down
2 changes: 2 additions & 0 deletions nano/node/nodeconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <nano/lib/numbers.hpp>
#include <nano/lib/rocksdbconfig.hpp>
#include <nano/lib/stats.hpp>
#include <nano/node/blockprocessor.hpp>
#include <nano/node/bootstrap/bootstrap_config.hpp>
#include <nano/node/ipc/ipc_config.hpp>
#include <nano/node/scheduler/hinted.hpp>
Expand Down Expand Up @@ -127,6 +128,7 @@ class node_config
/** Number of times per second to run backlog population batches. Number of accounts per single batch is `backlog_scan_batch_size / backlog_scan_frequency` */
unsigned backlog_scan_frequency{ 10 };
nano::vote_cache_config vote_cache;
nano::block_processor_config block_processor;

public:
std::string serialize_frontiers_confirmation (nano::frontiers_confirmation_mode) const;
Expand Down

0 comments on commit 209bcf4

Please sign in to comment.