Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Produce block immediately when exhausted without going through timer
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Aug 22, 2019
1 parent 09fbc9f commit d478d31
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1330,17 +1330,18 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() {

const auto& hbs = chain.head_block_state();

fc_dlog(_log, "Starting block ${n} at ${time}", ("n", hbs->block_num + 1)("time", fc::time_point::now()));

//Schedule for the next second's tick regardless of chain state
// If we would wait less than 50ms (1/10 of block_interval), wait for the whole block interval.
const fc::time_point now = fc::time_point::now();
const fc::time_point block_time = calculate_pending_block_time();

_pending_block_mode = pending_block_mode::producing;

// Not our turn
const auto& scheduled_producer = hbs->get_scheduled_producer(block_time);

fc_dlog(_log, "Starting block ${n} at ${time} producer ${p}",
("n", hbs->block_num + 1)("time", now)("p", scheduled_producer.producer_name));

auto current_watermark = get_watermark(scheduled_producer.producer_name);

size_t num_relevant_signatures = 0;
Expand Down Expand Up @@ -1745,9 +1746,13 @@ void producer_plugin_impl::schedule_production_loop() {
auto expect_time = chain.pending_block_time() - fc::microseconds(config::block_interval_us);
// ship this block off up to 1 block time earlier or immediately
if (fc::time_point::now() >= expect_time) {
_timer.expires_from_now( boost::posix_time::microseconds( 0 ));
fc_dlog(_log, "Scheduling Block Production on Exhausted Block #${num} immediately",
// produce block immediately
fc_dlog(_log, "Completing Block Production on Exhausted Block #${num} immediately",
("num", chain.head_block_num()+1));
fc_dlog( _log, "Produce block for ${num} running at ${time}", ("num", chain.head_block_num()+1)("time", fc::time_point::now()) );
auto res = maybe_produce_block();
fc_dlog( _log, "Producing Block #${num} returned: ${res}", ("num", chain.head_block_num()+1)( "res", res ) );
return;
} else {
_timer.expires_at(epoch + boost::posix_time::microseconds(expect_time.time_since_epoch().count()));
fc_dlog(_log, "Scheduling Block Production on Exhausted Block #${num} at ${time}",
Expand Down

0 comments on commit d478d31

Please sign in to comment.