From d478d31f1fe854f4eff0b82b456317254c8714a3 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Fri, 16 Aug 2019 14:23:31 -0500 Subject: [PATCH] Produce block immediately when exhausted without going through timer --- plugins/producer_plugin/producer_plugin.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index f115fcad3e1..a09b20c083a 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -1330,8 +1330,6 @@ 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(); @@ -1339,8 +1337,11 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() { _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; @@ -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}",