From 74c98f7b7eadc5afd7e91299ce11428fc1326e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 30 Dec 2024 16:19:29 +0100 Subject: [PATCH 1/6] Use fwd header --- nano/lib/fwd.hpp | 1 + nano/node/fwd.hpp | 1 + nano/node/node.hpp | 31 ------------------------------- 3 files changed, 2 insertions(+), 31 deletions(-) diff --git a/nano/lib/fwd.hpp b/nano/lib/fwd.hpp index ee283f2245..8c7e915c6d 100644 --- a/nano/lib/fwd.hpp +++ b/nano/lib/fwd.hpp @@ -17,6 +17,7 @@ class network_constants; class object_stream; class root; class thread_pool; +class thread_runner; class tomlconfig; template class uniquer; diff --git a/nano/node/fwd.hpp b/nano/node/fwd.hpp index 702a51f2e8..3a8b9a162b 100644 --- a/nano/node/fwd.hpp +++ b/nano/node/fwd.hpp @@ -53,6 +53,7 @@ enum class vote_code; namespace nano::scheduler { +class component; class hinted; class manual; class optimistic; diff --git a/nano/node/node.hpp b/nano/node/node.hpp index b67d3cb0aa..03e967fca5 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -31,37 +31,6 @@ #include #include -namespace nano -{ -class active_elections; -class bandwidth_limiter; -class confirming_set; -class message_processor; -class monitor; -class node; -class telemetry; -class online_reps; -class vote_processor; -class vote_cache_processor; -class vote_router; -class work_pool; -class peer_history; -class port_mapping; -class thread_runner; - -namespace scheduler -{ - class component; -} -namespace transport -{ - class tcp_listener; -} -namespace rocksdb -{ -} // Declare a namespace rocksdb inside nano so all references to the rocksdb library need to be globally scoped e.g. ::rocksdb::Slice -} - namespace nano { class node final : public std::enable_shared_from_this From e6d0bb373e89132313795ce76a758c378801e5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 30 Dec 2024 16:20:55 +0100 Subject: [PATCH 2/6] Remove unused fields --- nano/node/node.cpp | 1 - nano/node/node.hpp | 1 - 2 files changed, 2 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index b1693bc3bb..9b3fcbafe0 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -138,7 +138,6 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy active{ *active_impl }, rep_crawler (config.rep_crawler, *this), rep_tiers{ ledger, network_params, online_reps, stats, logger }, - warmed_up (0), online_reps_impl{ std::make_unique (config, ledger, stats, logger) }, online_reps{ *online_reps_impl }, history_impl{ std::make_unique (config.network_params.voting) }, diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 03e967fca5..ed43db1feb 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -149,7 +149,6 @@ class node final : public std::enable_shared_from_this nano::online_reps & online_reps; nano::rep_crawler rep_crawler; nano::rep_tiers rep_tiers; - unsigned warmed_up; std::unique_ptr history_impl; nano::local_vote_history & history; nano::block_uniquer block_uniquer; From 85b9224ea9151f48d832ad041741f6e4bcbc1450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 30 Dec 2024 16:34:15 +0100 Subject: [PATCH 3/6] Use unique_ptr for all components --- nano/node/node.cpp | 55 +++++++++++++++++++++++++++++----------------- nano/node/node.hpp | 44 ++++++++++++++++++++++++------------- 2 files changed, 64 insertions(+), 35 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 9b3fcbafe0..7f9bfd840b 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -83,12 +83,14 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy flags{ flags_a }, io_ctx_shared{ std::make_shared () }, io_ctx{ *io_ctx_shared }, - logger{ make_logger_identifier (node_id) }, + logger_impl{ std::make_unique (make_logger_identifier (node_id)) }, + logger{ *logger_impl }, + stats_impl{ std::make_unique (logger, config.stats_config) }, + stats{ *stats_impl }, runner_impl{ std::make_unique (io_ctx_shared, logger, config.io_threads) }, runner{ *runner_impl }, node_initialized_latch (1), network_params{ config.network_params }, - stats{ logger, config.stats_config }, workers_impl{ std::make_unique (config.background_threads, nano::thread_role::name::worker, /* start immediately */ true) }, workers{ *workers_impl }, bootstrap_workers_impl{ std::make_unique (config.bootstrap_serving_threads, nano::thread_role::name::bootstrap_worker, /* start immediately */ true) }, @@ -97,13 +99,15 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy wallet_workers{ *wallet_workers_impl }, election_workers_impl{ std::make_unique (1, nano::thread_role::name::election_worker, /* start immediately */ true) }, election_workers{ *election_workers_impl }, - work (work_a), - distributed_work (*this), - store_impl (nano::make_store (logger, application_path_a, network_params.ledger, flags.read_only, true, config_a.rocksdb_config, config_a.diagnostics_config.txn_tracking, config_a.block_processor_batch_max_time, config_a.lmdb_config, config_a.backup_before_upgrade)), - store (*store_impl), - unchecked{ config.max_unchecked_blocks, stats, flags.disable_block_processor_unchecked_deletion }, - wallets_store_impl (std::make_unique (application_path_a / "wallets.ldb", config_a.lmdb_config)), - wallets_store (*wallets_store_impl), + work{ work_a }, + distributed_work_impl{ std::make_unique (*this) }, + distributed_work{ *distributed_work_impl }, + store_impl{ nano::make_store (logger, application_path_a, network_params.ledger, flags.read_only, true, config_a.rocksdb_config, config_a.diagnostics_config.txn_tracking, config_a.block_processor_batch_max_time, config_a.lmdb_config, config_a.backup_before_upgrade) }, + store{ *store_impl }, + unchecked_impl{ std::make_unique (config.max_unchecked_blocks, stats, flags.disable_block_processor_unchecked_deletion) }, + unchecked{ *unchecked_impl }, + wallets_store_impl{ std::make_unique (application_path_a / "wallets.ldb", config_a.lmdb_config) }, + wallets_store{ *wallets_store_impl }, ledger_impl{ std::make_unique (store, stats, network_params.ledger, flags_a.generate_cache, config_a.representative_vote_weight_minimum.number ()) }, ledger{ *ledger_impl }, outbound_limiter_impl{ std::make_unique (config) }, @@ -113,7 +117,8 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy // empty `config.peering_port` means the user made no port choice at all; // otherwise, any value is considered, with `0` having the special meaning of 'let the OS pick a port instead' // - network (*this, config.peering_port.has_value () ? *config.peering_port : 0), + network_impl{ std::make_unique (*this, config.peering_port.has_value () ? *config.peering_port : 0) }, + network{ *network_impl }, telemetry_impl{ std::make_unique (flags, *this, network, observers, network_params, stats) }, telemetry{ *telemetry_impl }, // BEWARE: `bootstrap` takes `network.port` instead of `config.peering_port` because when the user doesn't specify @@ -136,14 +141,20 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy bucketing{ *bucketing_impl }, active_impl{ std::make_unique (*this, confirming_set, block_processor) }, active{ *active_impl }, - rep_crawler (config.rep_crawler, *this), - rep_tiers{ ledger, network_params, online_reps, stats, logger }, + rep_crawler_impl{ std::make_unique (config.rep_crawler, *this) }, + rep_crawler{ *rep_crawler_impl }, + rep_tiers_impl{ std::make_unique (ledger, network_params, online_reps, stats, logger) }, + rep_tiers{ *rep_tiers_impl }, online_reps_impl{ std::make_unique (config, ledger, stats, logger) }, online_reps{ *online_reps_impl }, history_impl{ std::make_unique (config.network_params.voting) }, history{ *history_impl }, - vote_uniquer{}, - vote_cache{ config.vote_cache, stats }, + block_uniquer_impl{ std::make_unique () }, + block_uniquer{ *block_uniquer_impl }, + vote_uniquer_impl{ std::make_unique () }, + vote_uniquer{ *vote_uniquer_impl }, + vote_cache_impl{ std::make_unique (config.vote_cache, stats) }, + vote_cache{ *vote_cache_impl }, vote_router_impl{ std::make_unique (vote_cache, active.recently_confirmed) }, vote_router{ *vote_router_impl }, vote_processor_impl{ std::make_unique (config.vote_processor, vote_router, observers, stats, flags, logger, online_reps, rep_crawler, ledger, network_params, rep_tiers) }, @@ -158,7 +169,8 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy scheduler{ *scheduler_impl }, aggregator_impl{ std::make_unique (config.request_aggregator, *this, stats, generator, final_generator, history, ledger, wallets, vote_router) }, aggregator{ *aggregator_impl }, - wallets (wallets_store.init_error (), *this), + wallets_impl{ std::make_unique (wallets_store.init_error (), *this) }, + wallets{ *wallets_impl }, backlog_scan_impl{ std::make_unique (config.backlog_scan, ledger, stats) }, backlog_scan{ *backlog_scan_impl }, backlog_impl{ std::make_unique (config, *this, ledger, bucketing, backlog_scan, block_processor, confirming_set, stats, logger) }, @@ -167,17 +179,20 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy bootstrap_server{ *bootstrap_server_impl }, bootstrap_impl{ std::make_unique (config, block_processor, ledger, network, stats, logger) }, bootstrap{ *bootstrap_impl }, - websocket{ config.websocket_config, observers, wallets, ledger, io_ctx, logger }, - epoch_upgrader{ *this, ledger, store, network_params, logger }, + websocket_impl{ std::make_unique (config.websocket_config, observers, wallets, ledger, io_ctx, logger) }, + websocket{ *websocket_impl }, + epoch_upgrader_impl{ std::make_unique (*this, ledger, store, network_params, logger) }, + epoch_upgrader{ *epoch_upgrader_impl }, local_block_broadcaster_impl{ std::make_unique (config.local_block_broadcaster, *this, block_processor, network, confirming_set, stats, logger, !flags.disable_block_processor_republishing) }, local_block_broadcaster{ *local_block_broadcaster_impl }, - process_live_dispatcher{ ledger, scheduler.priority, vote_cache, websocket }, + process_live_dispatcher_impl{ std::make_unique (ledger, scheduler.priority, vote_cache, websocket) }, + process_live_dispatcher{ *process_live_dispatcher_impl }, peer_history_impl{ std::make_unique (config.peer_history, store, network, logger, stats) }, peer_history{ *peer_history_impl }, monitor_impl{ std::make_unique (config.monitor, *this) }, monitor{ *monitor_impl }, - startup_time (std::chrono::steady_clock::now ()), - node_seq (seq) + startup_time{ std::chrono::steady_clock::now () }, + node_seq{ seq } { logger.debug (nano::log::type::node, "Constructing node..."); diff --git a/nano/node/node.hpp b/nano/node/node.hpp index ed43db1feb..82cd608e65 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -101,12 +101,14 @@ class node final : public std::enable_shared_from_this nano::node_flags flags; std::shared_ptr io_ctx_shared; boost::asio::io_context & io_ctx; - nano::logger logger; + std::unique_ptr logger_impl; + nano::logger & logger; + std::unique_ptr stats_impl; + nano::stats & stats; std::unique_ptr runner_impl; nano::thread_runner & runner; boost::latch node_initialized_latch; nano::network_params & network_params; - nano::stats stats; nano::node_observers observers; std::unique_ptr workers_impl; nano::thread_pool & workers; @@ -117,10 +119,12 @@ class node final : public std::enable_shared_from_this std::unique_ptr election_workers_impl; nano::thread_pool & election_workers; nano::work_pool & work; - nano::distributed_work_factory distributed_work; + std::unique_ptr distributed_work_impl; + nano::distributed_work_factory & distributed_work; std::unique_ptr store_impl; nano::store::component & store; - nano::unchecked_map unchecked; + std::unique_ptr unchecked_impl; + nano::unchecked_map & unchecked; std::unique_ptr wallets_store_impl; nano::wallets_store & wallets_store; std::unique_ptr ledger_impl; @@ -129,7 +133,8 @@ class node final : public std::enable_shared_from_this nano::bandwidth_limiter & outbound_limiter; std::unique_ptr message_processor_impl; nano::message_processor & message_processor; - nano::network network; + std::unique_ptr network_impl; + nano::network & network; std::unique_ptr telemetry_impl; nano::telemetry & telemetry; std::unique_ptr tcp_listener_impl; @@ -147,13 +152,18 @@ class node final : public std::enable_shared_from_this nano::active_elections & active; std::unique_ptr online_reps_impl; nano::online_reps & online_reps; - nano::rep_crawler rep_crawler; - nano::rep_tiers rep_tiers; + std::unique_ptr rep_crawler_impl; + nano::rep_crawler & rep_crawler; + std::unique_ptr rep_tiers_impl; + nano::rep_tiers & rep_tiers; std::unique_ptr history_impl; nano::local_vote_history & history; - nano::block_uniquer block_uniquer; - nano::vote_uniquer vote_uniquer; - nano::vote_cache vote_cache; + std::unique_ptr block_uniquer_impl; + nano::block_uniquer & block_uniquer; + std::unique_ptr vote_uniquer_impl; + nano::vote_uniquer & vote_uniquer; + std::unique_ptr vote_cache_impl; + nano::vote_cache & vote_cache; std::unique_ptr vote_router_impl; nano::vote_router & vote_router; std::unique_ptr vote_processor_impl; @@ -168,7 +178,8 @@ class node final : public std::enable_shared_from_this nano::scheduler::component & scheduler; std::unique_ptr aggregator_impl; nano::request_aggregator & aggregator; - nano::wallets wallets; + std::unique_ptr wallets_impl; + nano::wallets & wallets; std::unique_ptr backlog_scan_impl; nano::backlog_scan & backlog_scan; std::unique_ptr backlog_impl; @@ -177,11 +188,14 @@ class node final : public std::enable_shared_from_this nano::bootstrap_server & bootstrap_server; std::unique_ptr bootstrap_impl; nano::bootstrap_service & bootstrap; - nano::websocket_server websocket; - nano::epoch_upgrader epoch_upgrader; + std::unique_ptr websocket_impl; + nano::websocket_server & websocket; + std::unique_ptr epoch_upgrader_impl; + nano::epoch_upgrader & epoch_upgrader; std::unique_ptr local_block_broadcaster_impl; nano::local_block_broadcaster & local_block_broadcaster; - nano::process_live_dispatcher process_live_dispatcher; + std::unique_ptr process_live_dispatcher_impl; + nano::process_live_dispatcher & process_live_dispatcher; std::unique_ptr peer_history_impl; nano::peer_history & peer_history; std::unique_ptr monitor_impl; @@ -196,7 +210,7 @@ class node final : public std::enable_shared_from_this static double constexpr free_cutoff = 1024.0; public: // For tests only - unsigned node_seq; + const unsigned node_seq; std::optional work_generate_blocking (nano::block &); std::optional work_generate_blocking (nano::root const &, uint64_t); std::optional work_generate_blocking (nano::root const &); From 6fa0543543e3ccf2e7c3025f944daecde1407376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 30 Dec 2024 17:40:15 +0100 Subject: [PATCH 4/6] Reordering --- nano/node/node.cpp | 14 +++++++------- nano/node/node.hpp | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 7f9bfd840b..0f9be22b2a 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -78,9 +78,12 @@ nano::node::node (std::shared_ptr io_ctx_a, uint16_t pe } nano::node::node (std::shared_ptr io_ctx_a, std::filesystem::path const & application_path_a, nano::node_config const & config_a, nano::work_pool & work_a, nano::node_flags flags_a, unsigned seq) : + application_path{ application_path_a }, node_id{ load_or_create_node_id (application_path_a) }, + node_initialized_latch{ 1 }, config{ config_a }, flags{ flags_a }, + network_params{ config.network_params }, io_ctx_shared{ std::make_shared () }, io_ctx{ *io_ctx_shared }, logger_impl{ std::make_unique (make_logger_identifier (node_id)) }, @@ -89,8 +92,6 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy stats{ *stats_impl }, runner_impl{ std::make_unique (io_ctx_shared, logger, config.io_threads) }, runner{ *runner_impl }, - node_initialized_latch (1), - network_params{ config.network_params }, workers_impl{ std::make_unique (config.background_threads, nano::thread_role::name::worker, /* start immediately */ true) }, workers{ *workers_impl }, bootstrap_workers_impl{ std::make_unique (config.bootstrap_serving_threads, nano::thread_role::name::bootstrap_worker, /* start immediately */ true) }, @@ -108,6 +109,8 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy unchecked{ *unchecked_impl }, wallets_store_impl{ std::make_unique (application_path_a / "wallets.ldb", config_a.lmdb_config) }, wallets_store{ *wallets_store_impl }, + wallets_impl{ std::make_unique (wallets_store.init_error (), *this) }, + wallets{ *wallets_impl }, ledger_impl{ std::make_unique (store, stats, network_params.ledger, flags_a.generate_cache, config_a.representative_vote_weight_minimum.number ()) }, ledger{ *ledger_impl }, outbound_limiter_impl{ std::make_unique (config) }, @@ -130,7 +133,6 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy // tcp_listener_impl{ std::make_unique (network.port, config.tcp, *this) }, tcp_listener{ *tcp_listener_impl }, - application_path (application_path_a), port_mapping_impl{ std::make_unique (*this) }, port_mapping{ *port_mapping_impl }, block_processor_impl{ std::make_unique (config, ledger, unchecked, stats, logger) }, @@ -141,12 +143,12 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy bucketing{ *bucketing_impl }, active_impl{ std::make_unique (*this, confirming_set, block_processor) }, active{ *active_impl }, + online_reps_impl{ std::make_unique (config, ledger, stats, logger) }, + online_reps{ *online_reps_impl }, rep_crawler_impl{ std::make_unique (config.rep_crawler, *this) }, rep_crawler{ *rep_crawler_impl }, rep_tiers_impl{ std::make_unique (ledger, network_params, online_reps, stats, logger) }, rep_tiers{ *rep_tiers_impl }, - online_reps_impl{ std::make_unique (config, ledger, stats, logger) }, - online_reps{ *online_reps_impl }, history_impl{ std::make_unique (config.network_params.voting) }, history{ *history_impl }, block_uniquer_impl{ std::make_unique () }, @@ -169,8 +171,6 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy scheduler{ *scheduler_impl }, aggregator_impl{ std::make_unique (config.request_aggregator, *this, stats, generator, final_generator, history, ledger, wallets, vote_router) }, aggregator{ *aggregator_impl }, - wallets_impl{ std::make_unique (wallets_store.init_error (), *this) }, - wallets{ *wallets_impl }, backlog_scan_impl{ std::make_unique (config.backlog_scan, ledger, stats) }, backlog_scan{ *backlog_scan_impl }, backlog_impl{ std::make_unique (config, *this, ledger, bucketing, backlog_scan, block_processor, confirming_set, stats, logger) }, diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 82cd608e65..79c6432969 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -96,9 +96,12 @@ class node final : public std::enable_shared_from_this nano::container_info container_info () const; public: + const std::filesystem::path application_path; const nano::keypair node_id; + boost::latch node_initialized_latch; nano::node_config config; nano::node_flags flags; + nano::network_params & network_params; std::shared_ptr io_ctx_shared; boost::asio::io_context & io_ctx; std::unique_ptr logger_impl; @@ -107,8 +110,6 @@ class node final : public std::enable_shared_from_this nano::stats & stats; std::unique_ptr runner_impl; nano::thread_runner & runner; - boost::latch node_initialized_latch; - nano::network_params & network_params; nano::node_observers observers; std::unique_ptr workers_impl; nano::thread_pool & workers; @@ -127,6 +128,8 @@ class node final : public std::enable_shared_from_this nano::unchecked_map & unchecked; std::unique_ptr wallets_store_impl; nano::wallets_store & wallets_store; + std::unique_ptr wallets_impl; + nano::wallets & wallets; std::unique_ptr ledger_impl; nano::ledger & ledger; std::unique_ptr outbound_limiter_impl; @@ -139,7 +142,6 @@ class node final : public std::enable_shared_from_this nano::telemetry & telemetry; std::unique_ptr tcp_listener_impl; nano::transport::tcp_listener & tcp_listener; - std::filesystem::path application_path; std::unique_ptr port_mapping_impl; nano::port_mapping & port_mapping; std::unique_ptr block_processor_impl; @@ -178,8 +180,6 @@ class node final : public std::enable_shared_from_this nano::scheduler::component & scheduler; std::unique_ptr aggregator_impl; nano::request_aggregator & aggregator; - std::unique_ptr wallets_impl; - nano::wallets & wallets; std::unique_ptr backlog_scan_impl; nano::backlog_scan & backlog_scan; std::unique_ptr backlog_impl; From 97ee5cab3b71646650ac65c6c5a642fb1ce25368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 30 Dec 2024 17:45:29 +0100 Subject: [PATCH 5/6] Missing component --- nano/node/node.cpp | 2 ++ nano/node/node.hpp | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 0f9be22b2a..72e4c4a4fd 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -92,6 +92,8 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy stats{ *stats_impl }, runner_impl{ std::make_unique (io_ctx_shared, logger, config.io_threads) }, runner{ *runner_impl }, + observers_impl{ std::make_unique () }, + observers{ *observers_impl }, workers_impl{ std::make_unique (config.background_threads, nano::thread_role::name::worker, /* start immediately */ true) }, workers{ *workers_impl }, bootstrap_workers_impl{ std::make_unique (config.bootstrap_serving_threads, nano::thread_role::name::bootstrap_worker, /* start immediately */ true) }, diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 79c6432969..fc6581829a 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -110,7 +110,8 @@ class node final : public std::enable_shared_from_this nano::stats & stats; std::unique_ptr runner_impl; nano::thread_runner & runner; - nano::node_observers observers; + std::unique_ptr observers_impl; + nano::node_observers & observers; std::unique_ptr workers_impl; nano::thread_pool & workers; std::unique_ptr bootstrap_workers_impl; From 7cdc57c087943c9528d413487a62dd4b6505364e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 30 Dec 2024 18:06:04 +0100 Subject: [PATCH 6/6] Fix start for `wallets` class --- nano/node/wallet.cpp | 56 ++++++++++++++++++++++++-------------------- nano/node/wallet.hpp | 8 ++++--- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 9d2fa9d74d..56ddd72601 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -1349,6 +1349,10 @@ void nano::wallets::do_wallet_actions () } } +/* + * wallets + */ + nano::wallets::wallets (bool error_a, nano::node & node_a) : network_params{ node_a.config.network_params }, observer ([] (bool) {}), @@ -1413,16 +1417,38 @@ nano::wallets::wallets (bool error_a, nano::node & node_a) : { item.second->enter_initial_password (); } - if (node_a.config.enable_voting) +} + +nano::wallets::~wallets () +{ + stop (); +} + +void nano::wallets::start () +{ + thread = std::thread{ [this] () { + nano::thread_role::set (nano::thread_role::name::wallet_actions); + do_wallet_actions (); + } }; + + if (node.config.enable_voting) { - lock.unlock (); ongoing_compute_reps (); } } -nano::wallets::~wallets () +void nano::wallets::stop () { - stop (); + { + nano::lock_guard action_lock{ action_mutex }; + stopped = true; + actions.clear (); + } + condition.notify_all (); + if (thread.joinable ()) + { + thread.join (); + } } std::shared_ptr nano::wallets::open (nano::wallet_id const & id_a) @@ -1610,28 +1636,6 @@ bool nano::wallets::exists (store::transaction const & transaction_a, nano::acco return result; } -void nano::wallets::stop () -{ - { - nano::lock_guard action_lock{ action_mutex }; - stopped = true; - actions.clear (); - } - condition.notify_all (); - if (thread.joinable ()) - { - thread.join (); - } -} - -void nano::wallets::start () -{ - thread = std::thread{ [this] () { - nano::thread_role::set (nano::thread_role::name::wallet_actions); - do_wallet_actions (); - } }; -} - nano::store::write_transaction nano::wallets::tx_begin_write () { return env.tx_begin_write (); diff --git a/nano/node/wallet.hpp b/nano/node/wallet.hpp index 9cb7aa50e7..50aae60bbd 100644 --- a/nano/node/wallet.hpp +++ b/nano/node/wallet.hpp @@ -205,8 +205,12 @@ class wallet_representatives class wallets final { public: - wallets (bool, nano::node &); + wallets (bool error, nano::node &); ~wallets (); + + void start (); + void stop (); + std::shared_ptr open (nano::wallet_id const &); std::shared_ptr create (nano::wallet_id const &); bool search_receivable (nano::wallet_id const &); @@ -217,8 +221,6 @@ class wallets final void queue_wallet_action (nano::uint128_t const &, std::shared_ptr const &, std::function); void foreach_representative (std::function const &); bool exists (store::transaction const &, nano::account const &); - void start (); - void stop (); void clear_send_ids (store::transaction const &); nano::wallet_representatives reps () const; bool check_rep (nano::account const &, nano::uint128_t const &, bool const = true);