Skip to content

Commit

Permalink
Merge pull request #269 from AntelopeIO/GH-262-opt
Browse files Browse the repository at this point in the history
Do not post to thread pool while syncing/replaying
  • Loading branch information
heifner authored Jun 11, 2024
2 parents 54b57fc + 58291ca commit 8a4bc54
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
26 changes: 15 additions & 11 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3274,9 +3274,11 @@ struct controller_impl {
if ( s == controller::block_status::incomplete || s == controller::block_status::complete || s == controller::block_status::validated ) {
if (!my_finalizers.empty()) {
apply_s<void>(chain_head, [&](const auto& head) {
boost::asio::post(thread_pool.get_executor(), [this, head=head]() {
create_and_send_vote_msg(head);
});
if (head->is_recent() || my_finalizers.is_active()) {
boost::asio::post(thread_pool.get_executor(), [this, head=head]() {
create_and_send_vote_msg(head);
});
}
});
}
}
Expand Down Expand Up @@ -3978,18 +3980,20 @@ struct controller_impl {
// 3. Otherwise, consider voting for that block according to the decide_vote rules.

if (!my_finalizers.empty() && bsp->core.final_on_strong_qc_block_num > 0) {
if (use_thread_pool == use_thread_pool_t::yes) {
boost::asio::post(thread_pool.get_executor(), [this, bsp=bsp]() {
if (bsp->is_recent() || my_finalizers.is_active()) {
if (use_thread_pool == use_thread_pool_t::yes) {
boost::asio::post(thread_pool.get_executor(), [this, bsp=bsp]() {
const auto& final_on_strong_qc_block_ref = bsp->core.get_block_reference(bsp->core.final_on_strong_qc_block_num);
if (fork_db_validated_block_exists(final_on_strong_qc_block_ref.block_id)) {
create_and_send_vote_msg(bsp);
}
});
} else {
// bsp can be used directly instead of copy needed for post
const auto& final_on_strong_qc_block_ref = bsp->core.get_block_reference(bsp->core.final_on_strong_qc_block_num);
if (fork_db_validated_block_exists(final_on_strong_qc_block_ref.block_id)) {
create_and_send_vote_msg(bsp);
}
});
} else {
// bsp can be used directly instead of copy needed for post
const auto& final_on_strong_qc_block_ref = bsp->core.get_block_reference(bsp->core.final_on_strong_qc_block_num);
if (fork_db_validated_block_exists(final_on_strong_qc_block_ref.block_id)) {
create_and_send_vote_msg(bsp);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions libraries/chain/include/eosio/chain/block_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ struct block_state : public block_header_state { // block_header_state provi
bool valid_qc_is_strong() const { return pending_qc.valid_qc_is_strong(); } // thread safe
void set_valid_qc(const valid_quorum_certificate& qc) { pending_qc.set_valid_qc(qc); }

// heuristic for determination if we are syncing or replaying for optimizations
bool is_recent() const {
return timestamp() > fc::time_point::now() - fc::seconds(30);
}

protocol_feature_activation_set_ptr get_activated_protocol_features() const { return block_header_state::activated_protocol_features; }
uint32_t last_qc_block_num() const { return core.latest_qc_claim().block_num; }
uint32_t final_on_strong_qc_block_num() const { return core.final_on_strong_qc_block_num; }
Expand Down
3 changes: 2 additions & 1 deletion libraries/chain/include/eosio/chain/finality/finalizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace eosio::chain {
return;

if (!enable_voting.load(std::memory_order_relaxed)) { // Avoid extra processing while syncing. Once caught up, consider voting
if (bsp->timestamp() < fc::time_point::now() - fc::seconds(30))
if (!bsp->is_recent())
return;
enable_voting.store(true, std::memory_order_relaxed);
}
Expand Down Expand Up @@ -132,6 +132,7 @@ namespace eosio::chain {

size_t size() const { return finalizers.size(); } // doesn't change, thread safe
bool empty() const { return finalizers.empty(); } // doesn't change, thread safe
bool is_active() const { return !empty() && enable_voting.load(std::memory_order_relaxed); } // thread safe

template<typename F>
bool all_of_public_keys(F&& f) const { // only access keys which do not change, thread safe
Expand Down

0 comments on commit 8a4bc54

Please sign in to comment.