Skip to content

Commit

Permalink
GH-641 Pause production when max-reversible-blocks is reached.
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Aug 27, 2024
1 parent 45162f2 commit 15ae10f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion libraries/chain/include/eosio/chain/block_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ struct block_handle {

bool is_valid() const { return !_bsp.valueless_by_exception() && std::visit([](const auto& bsp) { return !!bsp; }, _bsp); }

uint32_t block_num() const { return std::visit([](const auto& bsp) { return bsp->block_num(); }, _bsp); }
block_num_type block_num() const { return std::visit([](const auto& bsp) { return bsp->block_num(); }, _bsp); }
block_num_type irreversible_blocknum() const { return std::visit([](const auto& bsp) { return bsp->irreversible_blocknum(); }, _bsp); }
block_timestamp_type timestamp() const { return std::visit([](const auto& bsp) { return bsp->timestamp(); }, _bsp); };
time_point block_time() const { return std::visit([](const auto& bsp) { return time_point{bsp->timestamp()}; }, _bsp); };
const block_id_type& id() const { return std::visit<const block_id_type&>([](const auto& bsp) -> const block_id_type& { return bsp->id(); }, _bsp); }
Expand Down
8 changes: 7 additions & 1 deletion plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,8 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() {
return start_block_result::failed;
}

block_num_type head_block_num = chain.head().block_num();
block_handle head = chain.head();
block_num_type head_block_num = head.block_num();
const fc::time_point now = fc::time_point::now();
const block_timestamp_type block_time = calculate_pending_block_time();
const uint32_t pending_block_num = head_block_num + 1;
Expand Down Expand Up @@ -1981,6 +1982,11 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() {
("ov", _last_other_vote_received.load(std::memory_order_relaxed))("bt", _accepted_block_time));
_pending_block_mode = pending_block_mode::speculating;
not_producing_when_time = true;
} else if (head_block_num - head.irreversible_blocknum() >= _max_reversible_blocks) {
fc_elog(_log, "Not producing block because max-reversible-blocks ${m} reached, head ${h}, lib ${l}.",
("m", _max_reversible_blocks)("h", head_block_num)("l", head.irreversible_blocknum()));
_pending_block_mode = pending_block_mode::speculating;
not_producing_when_time = true;
}

// !not_producing_when_time to avoid tight spin because of error or paused production
Expand Down

0 comments on commit 15ae10f

Please sign in to comment.