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

[1.0-beta4 -> main] Watermark violation should create speculative block #473

Merged
merged 3 commits into from
Aug 5, 2024
Merged
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
22 changes: 11 additions & 11 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,17 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() {
_pending_block_mode = pending_block_mode::speculating;
}

if (in_speculating_mode()) {
static fc::time_point last_start_block_time = fc::time_point::maximum(); // always start with speculative block
// Determine if we are syncing: if we have recently started an old block then assume we are syncing
if (last_start_block_time < now + fc::microseconds(config::block_interval_us)) {
auto head_block_age = now - chain.head().block_time();
if (head_block_age > fc::seconds(5))
return start_block_result::waiting_for_block; // if syncing no need to create a block just to immediately abort it
}
last_start_block_time = now;
}

if (in_producing_mode()) {
// determine if our watermark excludes us from producing at this point
if (auto current_watermark = _producer_watermarks.get_watermark(scheduled_producer.producer_name)) {
Expand All @@ -1898,17 +1909,6 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() {
}
}

if (in_speculating_mode()) {
static fc::time_point last_start_block_time = fc::time_point::maximum(); // always start with speculative block
// Determine if we are syncing: if we have recently started an old block then assume we are syncing
if (last_start_block_time < now + fc::microseconds(config::block_interval_us)) {
auto head_block_age = now - chain.head().block_time();
if (head_block_age > fc::seconds(5))
return start_block_result::waiting_for_block; // if syncing no need to create a block just to immediately abort it
}
last_start_block_time = now;
}

if (in_producing_mode()) {
uint32_t production_round_index = block_timestamp_type(block_time).slot % chain::config::producer_repetitions;
if (production_round_index == 0) {
Expand Down