Skip to content

Commit

Permalink
fix wasm thread (#1817)
Browse files Browse the repository at this point in the history
Signed-off-by: turuslan <turuslan.devbox@gmail.com>
Co-authored-by: kamilsa <kamilsa16@gmail.com>
  • Loading branch information
turuslan and kamilsa authored Oct 2, 2023
1 parent 069f49f commit eadc7aa
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 20 deletions.
14 changes: 7 additions & 7 deletions core/common/fd_limit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 13 additions & 6 deletions core/consensus/babe/impl/babe_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace kagome::consensus::babe {
std::shared_ptr<BabeLottery> lottery,
std::shared_ptr<BabeConfigRepository> babe_config_repo,
const ThreadPool &thread_pool,
std::shared_ptr<boost::asio::io_context> main_thread,
std::shared_ptr<authorship::Proposer> proposer,
std::shared_ptr<blockchain::BlockTree> block_tree,
std::shared_ptr<network::BlockAnnounceTransmitter>
Expand Down Expand Up @@ -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)},
Expand Down Expand Up @@ -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<storage::changes_trie::StorageChangesTrackerImpl>();

Expand All @@ -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));
}
Expand Down
2 changes: 2 additions & 0 deletions core/consensus/babe/impl/babe_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ namespace kagome::consensus::babe {
std::shared_ptr<BabeLottery> lottery,
std::shared_ptr<BabeConfigRepository> babe_config_repo,
const ThreadPool &thread_pool,
std::shared_ptr<boost::asio::io_context> main_thread,
std::shared_ptr<authorship::Proposer> proposer,
std::shared_ptr<blockchain::BlockTree> block_tree,
std::shared_ptr<network::BlockAnnounceTransmitter>
Expand Down Expand Up @@ -232,6 +233,7 @@ namespace kagome::consensus::babe {
std::shared_ptr<BabeLottery> lottery_;
std::shared_ptr<BabeConfigRepository> babe_config_repo_;
std::shared_ptr<boost::asio::io_context> io_context_;
std::shared_ptr<boost::asio::io_context> main_thread_;
std::shared_ptr<authorship::Proposer> proposer_;
std::shared_ptr<blockchain::BlockTree> block_tree_;
std::shared_ptr<network::BlockAnnounceTransmitter>
Expand Down
26 changes: 19 additions & 7 deletions core/consensus/babe/impl/block_executor_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace kagome::consensus::babe {
BlockExecutorImpl::BlockExecutorImpl(
std::shared_ptr<blockchain::BlockTree> block_tree,
const ThreadPool &thread_pool,
std::shared_ptr<boost::asio::io_context> main_thread,
std::shared_ptr<runtime::Core> core,
std::shared_ptr<transaction_pool::TransactionPool> tx_pool,
std::shared_ptr<crypto::Hasher> hasher,
Expand All @@ -44,6 +45,7 @@ namespace kagome::consensus::babe {
std::unique_ptr<BlockAppenderBase> 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)},
Expand Down Expand Up @@ -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));
}
Expand Down
2 changes: 2 additions & 0 deletions core/consensus/babe/impl/block_executor_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace kagome::consensus::babe {
BlockExecutorImpl(
std::shared_ptr<blockchain::BlockTree> block_tree,
const ThreadPool &thread_pool,
std::shared_ptr<boost::asio::io_context> main_thread,
std::shared_ptr<runtime::Core> core,
std::shared_ptr<transaction_pool::TransactionPool> tx_pool,
std::shared_ptr<crypto::Hasher> hasher,
Expand Down Expand Up @@ -80,6 +81,7 @@ namespace kagome::consensus::babe {

std::shared_ptr<blockchain::BlockTree> block_tree_;
std::shared_ptr<boost::asio::io_context> io_context_;
std::shared_ptr<boost::asio::io_context> main_thread_;
std::shared_ptr<runtime::Core> core_;
std::shared_ptr<transaction_pool::TransactionPool> tx_pool_;
std::shared_ptr<crypto::Hasher> hasher_;
Expand Down
1 change: 1 addition & 0 deletions test/core/consensus/babe/babe_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_,
Expand Down
1 change: 1 addition & 0 deletions test/core/consensus/babe/block_executor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class BlockExecutorTest : public testing::Test {

block_executor_ = std::make_shared<BlockExecutorImpl>(block_tree_,
thread_pool_,
thread_pool_.io_context(),
core_,
tx_pool_,
hasher_,
Expand Down

0 comments on commit eadc7aa

Please sign in to comment.