Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not post to thread pool while syncing/replaying #269

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) {
Copy link
Contributor

@greg7mdp greg7mdp Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little annoying that we need || my_finalizers.is_active(), but I guess it is needed to ensure that once we start voting, we don't stop.
Maybe add a short comment to that effect as I don't think it is immediately obvious.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, not really sure we need that restriction, but it is current requirements.

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
Loading