From e1511c365370038bfaf50e710760a14b421378c4 Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Tue, 29 Oct 2024 12:45:40 +0100 Subject: [PATCH 1/2] rework move semantics little bit --- .../include/pillar_chain/pillar_chain_manager.hpp | 2 +- .../consensus/src/pillar_chain/pillar_chain_manager.cpp | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libraries/core_libs/consensus/include/pillar_chain/pillar_chain_manager.hpp b/libraries/core_libs/consensus/include/pillar_chain/pillar_chain_manager.hpp index cfe0d14e76..9ddf0c3a83 100644 --- a/libraries/core_libs/consensus/include/pillar_chain/pillar_chain_manager.hpp +++ b/libraries/core_libs/consensus/include/pillar_chain/pillar_chain_manager.hpp @@ -164,7 +164,7 @@ class PillarChainManager { * @param pillar_block * @param new_vote_counts */ - void saveNewPillarBlock(std::shared_ptr pillar_block, + void saveNewPillarBlock(const std::shared_ptr& pillar_block, std::vector&& new_vote_counts); private: diff --git a/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp b/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp index d582f94050..bd8257b977 100644 --- a/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp +++ b/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp @@ -106,14 +106,13 @@ std::shared_ptr PillarChainManager::createPillarBlock( return pillar_block; } -void PillarChainManager::saveNewPillarBlock(std::shared_ptr pillar_block, +void PillarChainManager::saveNewPillarBlock(const std::shared_ptr& pillar_block, std::vector&& new_vote_counts) { - CurrentPillarBlockDataDb data{std::move(pillar_block), std::move(new_vote_counts)}; - db_->saveCurrentPillarBlockData(data); + db_->saveCurrentPillarBlockData({pillar_block, new_vote_counts}); std::scoped_lock lock(mutex_); - current_pillar_block_ = std::move(data.pillar_block); - current_pillar_block_vote_counts_ = std::move(data.vote_counts); + current_pillar_block_ = pillar_block; + current_pillar_block_vote_counts_ = std::move(new_vote_counts); } std::shared_ptr PillarChainManager::genAndPlacePillarVote(PbftPeriod period, From 1a8277ce6e2566c6104c8cd3c22ea5da2abae96d Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Wed, 30 Oct 2024 08:01:40 +0100 Subject: [PATCH 2/2] fix locks --- .../consensus/src/pillar_chain/pillar_chain_manager.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp b/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp index bd8257b977..932ad31a08 100644 --- a/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp +++ b/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp @@ -108,9 +108,8 @@ std::shared_ptr PillarChainManager::createPillarBlock( void PillarChainManager::saveNewPillarBlock(const std::shared_ptr& pillar_block, std::vector&& new_vote_counts) { - db_->saveCurrentPillarBlockData({pillar_block, new_vote_counts}); - std::scoped_lock lock(mutex_); + db_->saveCurrentPillarBlockData({pillar_block, new_vote_counts}); current_pillar_block_ = pillar_block; current_pillar_block_vote_counts_ = std::move(new_vote_counts); } @@ -332,7 +331,6 @@ bool PillarChainManager::isValidPillarBlock(const std::shared_ptr& } const auto last_finalized_pillar_block = getLastFinalizedPillarBlock(); - std::shared_lock lock(mutex_); assert(last_finalized_pillar_block); // Check if some block was not skipped