Move nano::generate_cache to its own file.

This commit is contained in:
Colin LeMahieu 2024-03-10 15:32:30 +00:00
commit caef5dcabc
No known key found for this signature in database
GPG key ID: 43708520C8DFB938
8 changed files with 39 additions and 30 deletions

View file

@ -16,6 +16,7 @@
#include <nano/node/vote_cache.hpp> #include <nano/node/vote_cache.hpp>
#include <nano/node/websocketconfig.hpp> #include <nano/node/websocketconfig.hpp>
#include <nano/secure/common.hpp> #include <nano/secure/common.hpp>
#include <nano/secure/generate_cache_flags.hpp>
#include <chrono> #include <chrono>
#include <optional> #include <optional>
@ -169,7 +170,7 @@ public:
bool read_only{ false }; bool read_only{ false };
bool disable_connection_cleanup{ false }; bool disable_connection_cleanup{ false };
nano::confirmation_height_mode confirmation_height_processor_mode{ nano::confirmation_height_mode::automatic }; nano::confirmation_height_mode confirmation_height_processor_mode{ nano::confirmation_height_mode::automatic };
nano::generate_cache generate_cache; nano::generate_cache_flags generate_cache;
bool inactive_node{ false }; bool inactive_node{ false };
std::size_t block_processor_batch_size{ 0 }; std::size_t block_processor_batch_size{ 0 };
std::size_t block_processor_full_size{ 65536 }; std::size_t block_processor_full_size{ 65536 };

View file

@ -41,6 +41,8 @@ add_library(
${CMAKE_BINARY_DIR}/bootstrap_weights_beta.cpp ${CMAKE_BINARY_DIR}/bootstrap_weights_beta.cpp
common.hpp common.hpp
common.cpp common.cpp
generate_cache_flags.hpp
generate_cache_flags.cpp
ledger.hpp ledger.hpp
ledger.cpp ledger.cpp
network_filter.hpp network_filter.hpp

View file

@ -484,14 +484,6 @@ nano::block_hash const & nano::unchecked_key::key () const
return previous; return previous;
} }
void nano::generate_cache::enable_all ()
{
reps = true;
cemented_count = true;
unchecked_count = true;
account_count = true;
}
std::string_view nano::to_string (nano::block_status code) std::string_view nano::to_string (nano::block_status code)
{ {
return magic_enum::enum_name (code); return magic_enum::enum_name (code);

View file

@ -405,20 +405,6 @@ enum class confirmation_height_mode
bounded bounded
}; };
/* Holds flags for various cacheable data. For most CLI operations caching is unnecessary
* (e.g getting the cemented block count) so it can be disabled for performance reasons. */
class generate_cache
{
public:
bool reps = true;
bool cemented_count = true;
bool unchecked_count = true;
bool account_count = true;
bool block_count = true;
void enable_all ();
};
/* Holds an in-memory cache of various counts */ /* Holds an in-memory cache of various counts */
class ledger_cache class ledger_cache
{ {

View file

@ -0,0 +1,9 @@
#include <nano/secure/generate_cache_flags.hpp>
void nano::generate_cache_flags::enable_all ()
{
reps = true;
cemented_count = true;
unchecked_count = true;
account_count = true;
}

View file

@ -0,0 +1,18 @@
#pragma once
namespace nano
{
/* Holds flags for various cacheable data. For most CLI operations caching is unnecessary
* (e.g getting the cemented block count) so it can be disabled for performance reasons. */
class generate_cache_flags
{
public:
bool reps = true;
bool cemented_count = true;
bool unchecked_count = true;
bool account_count = true;
bool block_count = true;
void enable_all ();
};
}

View file

@ -750,7 +750,7 @@ void representative_visitor::state_block (nano::state_block const & block_a)
} }
} // namespace } // namespace
nano::ledger::ledger (nano::store::component & store_a, nano::stats & stat_a, nano::ledger_constants & constants, nano::generate_cache const & generate_cache_a) : nano::ledger::ledger (nano::store::component & store_a, nano::stats & stat_a, nano::ledger_constants & constants, nano::generate_cache_flags const & generate_cache_flags_a) :
constants{ constants }, constants{ constants },
store{ store_a }, store{ store_a },
stats{ stat_a }, stats{ stat_a },
@ -758,13 +758,13 @@ nano::ledger::ledger (nano::store::component & store_a, nano::stats & stat_a, na
{ {
if (!store.init_error ()) if (!store.init_error ())
{ {
initialize (generate_cache_a); initialize (generate_cache_flags_a);
} }
} }
void nano::ledger::initialize (nano::generate_cache const & generate_cache_a) void nano::ledger::initialize (nano::generate_cache_flags const & generate_cache_flags_a)
{ {
if (generate_cache_a.reps || generate_cache_a.account_count || generate_cache_a.block_count) if (generate_cache_flags_a.reps || generate_cache_flags_a.account_count || generate_cache_flags_a.block_count)
{ {
store.account.for_each_par ( store.account.for_each_par (
[this] (store::read_transaction const & /*unused*/, store::iterator<nano::account, nano::account_info> i, store::iterator<nano::account, nano::account_info> n) { [this] (store::read_transaction const & /*unused*/, store::iterator<nano::account, nano::account_info> i, store::iterator<nano::account, nano::account_info> n) {
@ -784,7 +784,7 @@ void nano::ledger::initialize (nano::generate_cache const & generate_cache_a)
}); });
} }
if (generate_cache_a.cemented_count) if (generate_cache_flags_a.cemented_count)
{ {
store.confirmation_height.for_each_par ( store.confirmation_height.for_each_par (
[this] (store::read_transaction const & /*unused*/, store::iterator<nano::account, nano::confirmation_height_info> i, store::iterator<nano::account, nano::confirmation_height_info> n) { [this] (store::read_transaction const & /*unused*/, store::iterator<nano::account, nano::confirmation_height_info> i, store::iterator<nano::account, nano::confirmation_height_info> n) {

View file

@ -2,6 +2,7 @@
#include <nano/lib/timer.hpp> #include <nano/lib/timer.hpp>
#include <nano/secure/common.hpp> #include <nano/secure/common.hpp>
#include <nano/secure/generate_cache_flags.hpp>
#include <map> #include <map>
@ -28,7 +29,7 @@ public:
class ledger final class ledger final
{ {
public: public:
ledger (nano::store::component &, nano::stats &, nano::ledger_constants & constants, nano::generate_cache const & = nano::generate_cache ()); ledger (nano::store::component &, nano::stats &, nano::ledger_constants & constants, nano::generate_cache_flags const & = nano::generate_cache_flags{});
/** /**
* Returns the account for a given hash * Returns the account for a given hash
* Returns std::nullopt if the block doesn't exist or has been pruned * Returns std::nullopt if the block doesn't exist or has been pruned
@ -87,7 +88,7 @@ public:
bool pruning{ false }; bool pruning{ false };
private: private:
void initialize (nano::generate_cache const &); void initialize (nano::generate_cache_flags const &);
}; };
std::unique_ptr<container_info_component> collect_container_info (ledger & ledger, std::string const & name); std::unique_ptr<container_info_component> collect_container_info (ledger & ledger, std::string const & name);