diff --git a/nano/node/confirmation_height_bounded.hpp b/nano/node/confirmation_height_bounded.hpp index ac850600b..338223fba 100644 --- a/nano/node/confirmation_height_bounded.hpp +++ b/nano/node/confirmation_height_bounded.hpp @@ -19,7 +19,7 @@ class write_guard; class confirmation_height_bounded final { public: - confirmation_height_bounded (nano::ledger &, nano::write_database_queue &, std::chrono::milliseconds, nano::logging const &, nano::logger_mt &, std::atomic &, uint64_t &, std::function> const &)> const &, std::function const &, std::function const &); + confirmation_height_bounded (nano::ledger &, nano::write_database_queue &, std::chrono::milliseconds batch_separate_pending_min_time, nano::logging const &, nano::logger_mt &, std::atomic & stopped, uint64_t & batch_write_size, std::function> const &)> const & cemented_callback, std::function const & already_cemented_callback, std::function const & awaiting_processing_size_query); bool pending_empty () const; void clear_process_vars (); void process (std::shared_ptr original_block); diff --git a/nano/node/confirmation_height_processor.cpp b/nano/node/confirmation_height_processor.cpp index 28e10c53e..3f7527bfc 100644 --- a/nano/node/confirmation_height_processor.cpp +++ b/nano/node/confirmation_height_processor.cpp @@ -14,10 +14,16 @@ nano::confirmation_height_processor::confirmation_height_processor (nano::ledger & ledger_a, nano::write_database_queue & write_database_queue_a, std::chrono::milliseconds batch_separate_pending_min_time_a, nano::logging const & logging_a, nano::logger_mt & logger_a, boost::latch & latch, confirmation_height_mode mode_a) : ledger (ledger_a), write_database_queue (write_database_queue_a), - // clang-format off -unbounded_processor (ledger_a, write_database_queue_a, batch_separate_pending_min_time_a, logging_a, logger_a, stopped, batch_write_size, [this](auto & cemented_blocks) { this->notify_observers (cemented_blocks); }, [this](auto const & block_hash_a) { this->notify_observers (block_hash_a); }, [this]() { return this->awaiting_processing_size (); }), -bounded_processor (ledger_a, write_database_queue_a, batch_separate_pending_min_time_a, logging_a, logger_a, stopped, batch_write_size, [this](auto & cemented_blocks) { this->notify_observers (cemented_blocks); }, [this](auto const & block_hash_a) { this->notify_observers (block_hash_a); }, [this]() { return this->awaiting_processing_size (); }), - // clang-format on + unbounded_processor ( + ledger_a, write_database_queue_a, batch_separate_pending_min_time_a, logging_a, logger_a, stopped, batch_write_size, + /* cemented_callback */ [this] (auto & cemented_blocks) { this->notify_cemented (cemented_blocks); }, + /* already cemented_callback */ [this] (auto const & block_hash_a) { this->notify_already_cemented (block_hash_a); }, + /* awaiting_processing_size_query */ [this] () { return this->awaiting_processing_size (); }), + bounded_processor ( + ledger_a, write_database_queue_a, batch_separate_pending_min_time_a, logging_a, logger_a, stopped, batch_write_size, + /* cemented_callback */ [this] (auto & cemented_blocks) { this->notify_cemented (cemented_blocks); }, + /* already cemented_callback */ [this] (auto const & block_hash_a) { this->notify_already_cemented (block_hash_a); }, + /* awaiting_processing_size_query */ [this] () { return this->awaiting_processing_size (); }), thread ([this, &latch, mode_a] () { nano::thread_role::set (nano::thread_role::name::confirmation_height_processing); // Do not start running the processing thread until other threads have finished their operations @@ -181,7 +187,7 @@ void nano::confirmation_height_processor::add_block_already_cemented_observer (s block_already_cemented_observers.push_back (callback_a); } -void nano::confirmation_height_processor::notify_observers (std::vector> const & cemented_blocks) +void nano::confirmation_height_processor::notify_cemented (std::vector> const & cemented_blocks) { for (auto const & block_callback_data : cemented_blocks) { @@ -192,7 +198,7 @@ void nano::confirmation_height_processor::notify_observers (std::vector const &)> const &); + /* + * Called when the block was added to the confirmation height processor but is already confirmed + * Called from confirmation height processor thread + */ void add_block_already_cemented_observer (std::function const &); private: mutable nano::mutex mutex{ mutex_identifier (mutexes::confirmation_height_processor) }; + // Hashes which have been added to the confirmation height processor, but not yet processed - // clang-format off struct block_wrapper { - block_wrapper (std::shared_ptr const & block_a) : - block (block_a) + explicit block_wrapper (std::shared_ptr const & block_a) : + block (block_a) { } @@ -65,6 +73,7 @@ private: std::shared_ptr block; }; + // clang-format off class tag_sequence {}; class tag_hash {}; boost::multi_index_container> const &); - void notify_observers (nano::block_hash const &); + void notify_cemented (std::vector> const &); + void notify_already_cemented (nano::block_hash const &); friend std::unique_ptr collect_container_info (confirmation_height_processor &, std::string const &); + +private: // Tests friend class confirmation_height_pending_observer_callbacks_Test; friend class confirmation_height_dependent_election_Test; friend class confirmation_height_dependent_election_after_already_cemented_Test; diff --git a/nano/node/confirmation_height_unbounded.cpp b/nano/node/confirmation_height_unbounded.cpp index 7f49ff4d0..5d8690c3b 100644 --- a/nano/node/confirmation_height_unbounded.cpp +++ b/nano/node/confirmation_height_unbounded.cpp @@ -361,9 +361,6 @@ void nano::confirmation_height_unbounded::prepare_iterated_blocks_for_cementing } } -/* - * Returns true if there was an error in finding one of the blocks to write a confirmation height for, false otherwise - */ void nano::confirmation_height_unbounded::cement_blocks (nano::write_guard & scoped_write_guard_a) { nano::timer cemented_batch_timer; diff --git a/nano/node/confirmation_height_unbounded.hpp b/nano/node/confirmation_height_unbounded.hpp index 93199c35d..de8f07c08 100644 --- a/nano/node/confirmation_height_unbounded.hpp +++ b/nano/node/confirmation_height_unbounded.hpp @@ -20,7 +20,7 @@ class write_guard; class confirmation_height_unbounded final { public: - confirmation_height_unbounded (nano::ledger &, nano::write_database_queue &, std::chrono::milliseconds, nano::logging const &, nano::logger_mt &, std::atomic &, uint64_t &, std::function> const &)> const &, std::function const &, std::function const &); + confirmation_height_unbounded (nano::ledger &, nano::write_database_queue &, std::chrono::milliseconds batch_separate_pending_min_time, nano::logging const &, nano::logger_mt &, std::atomic & stopped, uint64_t & batch_write_size, std::function> const &)> const & cemented_callback, std::function const & already_cemented_callback, std::function const & awaiting_processing_size_query); bool pending_empty () const; void clear_process_vars (); void process (std::shared_ptr original_block);