diff --git a/core/common/fd_limit.cpp b/core/common/fd_limit.cpp index 91d6f1fdf8..1b4c53fa11 100644 --- a/core/common/fd_limit.cpp +++ b/core/common/fd_limit.cpp @@ -60,13 +60,13 @@ namespace kagome::common { SL_WARN(log(), "requested limit is lower than system allowed limit"); setFdLimit(r); } else if (!setFdLimit(r)) { - std::upper_bound(boost::counting_iterator{current}, - boost::counting_iterator{rlim_t{limit}}, - nullptr, - [&](std::nullptr_t, rlim_t current) { - r.rlim_cur = current; - return !setFdLimit(r); - }); + std::ignore = std::upper_bound(boost::counting_iterator{current}, + boost::counting_iterator{rlim_t{limit}}, + nullptr, + [&](std::nullptr_t, rlim_t current) { + r.rlim_cur = current; + return !setFdLimit(r); + }); } if (!getFdLimit(r)) { return; diff --git a/core/consensus/babe/impl/babe_impl.cpp b/core/consensus/babe/impl/babe_impl.cpp index 87b0c91dbe..2b38739190 100644 --- a/core/consensus/babe/impl/babe_impl.cpp +++ b/core/consensus/babe/impl/babe_impl.cpp @@ -70,6 +70,7 @@ namespace kagome::consensus::babe { std::shared_ptr lottery, std::shared_ptr babe_config_repo, const ThreadPool &thread_pool, + std::shared_ptr main_thread, std::shared_ptr proposer, std::shared_ptr block_tree, std::shared_ptr @@ -102,6 +103,7 @@ namespace kagome::consensus::babe { lottery_{std::move(lottery)}, babe_config_repo_{std::move(babe_config_repo)}, io_context_{thread_pool.io_context()}, + main_thread_{std::move(main_thread)}, proposer_{std::move(proposer)}, block_tree_{std::move(block_tree)}, block_announce_transmitter_{std::move(block_announce_transmitter)}, @@ -1068,10 +1070,11 @@ namespace kagome::consensus::babe { const auto &babe_pre_digest = babe_pre_digest_res.value(); auto propose = [this, + self{shared_from_this()}, inherent_data{std::move(inherent_data)}, now, proposal_start, - babe_pre_digest{std::move(babe_pre_digest)}] { + babe_pre_digest{std::move(babe_pre_digest)}]() mutable { auto changes_tracker = std::make_shared(); @@ -1086,11 +1089,15 @@ namespace kagome::consensus::babe { SL_ERROR(log_, "Cannot propose a block: {}", res.error()); return; } - - processSlotLeadershipProposed(now, - proposal_start, - std::move(changes_tracker), - std::move(res.value())); + auto proposed = [self, + now, + proposal_start, + changes_tracker{std::move(changes_tracker)}, + res{std::move(res.value())}]() mutable { + self->processSlotLeadershipProposed( + now, proposal_start, std::move(changes_tracker), std::move(res)); + }; + main_thread_->post(std::move(proposed)); }; io_context_->post(std::move(propose)); } diff --git a/core/consensus/babe/impl/babe_impl.hpp b/core/consensus/babe/impl/babe_impl.hpp index 52ce5b7ea4..d76358f451 100644 --- a/core/consensus/babe/impl/babe_impl.hpp +++ b/core/consensus/babe/impl/babe_impl.hpp @@ -113,6 +113,7 @@ namespace kagome::consensus::babe { std::shared_ptr lottery, std::shared_ptr babe_config_repo, const ThreadPool &thread_pool, + std::shared_ptr main_thread, std::shared_ptr proposer, std::shared_ptr block_tree, std::shared_ptr @@ -232,6 +233,7 @@ namespace kagome::consensus::babe { std::shared_ptr lottery_; std::shared_ptr babe_config_repo_; std::shared_ptr io_context_; + std::shared_ptr main_thread_; std::shared_ptr proposer_; std::shared_ptr block_tree_; std::shared_ptr diff --git a/core/consensus/babe/impl/block_executor_impl.cpp b/core/consensus/babe/impl/block_executor_impl.cpp index cab4886fa3..cf78d72989 100644 --- a/core/consensus/babe/impl/block_executor_impl.cpp +++ b/core/consensus/babe/impl/block_executor_impl.cpp @@ -35,6 +35,7 @@ namespace kagome::consensus::babe { BlockExecutorImpl::BlockExecutorImpl( std::shared_ptr block_tree, const ThreadPool &thread_pool, + std::shared_ptr main_thread, std::shared_ptr core, std::shared_ptr tx_pool, std::shared_ptr hasher, @@ -44,6 +45,7 @@ namespace kagome::consensus::babe { std::unique_ptr appender) : block_tree_{std::move(block_tree)}, io_context_{thread_pool.io_context()}, + main_thread_{std::move(main_thread)}, core_{std::move(core)}, tx_pool_{std::move(tx_pool)}, hasher_{std::move(hasher)}, @@ -184,13 +186,23 @@ namespace kagome::consensus::babe { changes_tracker->onBlockAdded( block_info.hash, storage_sub_engine_, chain_subscription_engine_); - applyBlockExecuted(std::move(block), - justification, - std::move(callback), - block_info, - start_time, - *consistency_guard, - previous_best_block); + auto executed = [self, + block{std::move(block)}, + justification{std::move(justification)}, + callback{std::move(callback)}, + block_info, + start_time, + consistency_guard{std::move(consistency_guard)}, + previous_best_block]() mutable { + self->applyBlockExecuted(std::move(block), + justification, + std::move(callback), + block_info, + start_time, + *consistency_guard, + previous_best_block); + }; + main_thread_->post(std::move(executed)); }; io_context_->post(std::move(execute)); } diff --git a/core/consensus/babe/impl/block_executor_impl.hpp b/core/consensus/babe/impl/block_executor_impl.hpp index 11f6ea40df..cface11092 100644 --- a/core/consensus/babe/impl/block_executor_impl.hpp +++ b/core/consensus/babe/impl/block_executor_impl.hpp @@ -53,6 +53,7 @@ namespace kagome::consensus::babe { BlockExecutorImpl( std::shared_ptr block_tree, const ThreadPool &thread_pool, + std::shared_ptr main_thread, std::shared_ptr core, std::shared_ptr tx_pool, std::shared_ptr hasher, @@ -80,6 +81,7 @@ namespace kagome::consensus::babe { std::shared_ptr block_tree_; std::shared_ptr io_context_; + std::shared_ptr main_thread_; std::shared_ptr core_; std::shared_ptr tx_pool_; std::shared_ptr hasher_; diff --git a/test/core/consensus/babe/babe_test.cpp b/test/core/consensus/babe/babe_test.cpp index 0a988017d0..dbfd7ca13e 100644 --- a/test/core/consensus/babe/babe_test.cpp +++ b/test/core/consensus/babe/babe_test.cpp @@ -182,6 +182,7 @@ class BabeTest : public testing::Test { lottery_, babe_config_repo_, thread_pool_, + thread_pool_.io_context(), proposer_, block_tree_, block_announce_transmitter_, diff --git a/test/core/consensus/babe/block_executor_test.cpp b/test/core/consensus/babe/block_executor_test.cpp index 57ae23e3ad..e5ff3132d3 100644 --- a/test/core/consensus/babe/block_executor_test.cpp +++ b/test/core/consensus/babe/block_executor_test.cpp @@ -156,6 +156,7 @@ class BlockExecutorTest : public testing::Test { block_executor_ = std::make_shared(block_tree_, thread_pool_, + thread_pool_.io_context(), core_, tx_pool_, hasher_,