From 8f1721ae8dfa762beb6fbb663ca933203c1d67ec Mon Sep 17 00:00:00 2001 From: gr0vity-dev Date: Mon, 9 Oct 2023 11:31:09 +0200 Subject: [PATCH] remove the need to hold the lock during notify_observers - make use of `set_status_type ()` returning the updated election status --- nano/node/active_transactions.cpp | 10 ++++------ nano/node/active_transactions.hpp | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index b71b38a74a..2e15791551 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -144,8 +144,9 @@ void nano::active_transactions::handle_confirmation (nano::store::read_transacti handle_block_confirmation (transaction, block, hash, account, amount, is_state_send, is_state_epoch, pending_account); - election->set_status_type (status_type); - notify_observers (election, account, amount, is_state_send, is_state_epoch, pending_account); + auto status = election->set_status_type (status_type); + auto votes = election->votes_with_weight (); + notify_observers (status, votes, account, amount, is_state_send, is_state_epoch, pending_account); } void nano::active_transactions::handle_block_confirmation (nano::store::read_transaction const & transaction, std::shared_ptr const & block, nano::block_hash const & hash, nano::account & account, nano::uint128_t & amount, bool & is_state_send, bool & is_state_epoch, nano::account & pending_account) @@ -155,11 +156,8 @@ void nano::active_transactions::handle_block_confirmation (nano::store::read_tra node.process_confirmed_data (transaction, block, hash, account, amount, is_state_send, is_state_epoch, pending_account); } -void nano::active_transactions::notify_observers (std::shared_ptr const & election, nano::account const & account, nano::uint128_t amount, bool is_state_send, bool is_state_epoch, nano::account const & pending_account) +void nano::active_transactions::notify_observers (nano::election_status const & status, std::vector const & votes, nano::account const & account, nano::uint128_t amount, bool is_state_send, bool is_state_epoch, nano::account const & pending_account) { - auto status = election->get_status (); - auto votes = election->votes_with_weight (); - node.observers.blocks.notify (status, votes, account, amount, is_state_send, is_state_epoch); if (amount > 0) diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index 119d5adb85..36acd179e5 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -204,7 +204,7 @@ class active_transactions final void handle_confirmation (nano::store::read_transaction const & transaction, std::shared_ptr const & block, std::shared_ptr election, nano::election_status_type status); void activate_successors (const nano::account & account, std::shared_ptr const & block, nano::store::read_transaction const & transaction); void handle_block_confirmation (nano::store::read_transaction const & transaction, std::shared_ptr const & block, nano::block_hash const & hash, nano::account & account, nano::uint128_t & amount, bool & is_state_send, bool & is_state_epoch, nano::account & pending_account); - void notify_observers (std::shared_ptr const & election, nano::account const & account, nano::uint128_t amount, bool is_state_send, bool is_state_epoch, nano::account const & pending_account); + void notify_observers (nano::election_status const & status, std::vector const & votes, nano::account const & account, nano::uint128_t amount, bool is_state_send, bool is_state_epoch, nano::account const & pending_account); private: // Dependencies nano::confirmation_height_processor & confirmation_height_processor;