From c0a786840b028ad9befc1ce93c51033b8c326d91 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 5 Feb 2020 10:57:57 -0500 Subject: [PATCH 1/3] Extend cpu percent effort to include immediate speculative block after the last block of the production round. --- plugins/producer_plugin/producer_plugin.cpp | 30 ++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index 690ed02cba0..8d7a5912e40 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -558,7 +558,9 @@ class producer_plugin_impl : public std::enable_shared_from_this& weak_this, const block_timestamp_type& current_block_time); + void schedule_delayed_production_loop(const std::weak_ptr& weak_this, optional wake_up_time); + optional calculate_producer_wake_up_time( const block_timestamp_type& ref_block_time ) const; + }; void new_chain_banner(const eosio::chain::controller& db) @@ -1358,6 +1360,7 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() { const fc::time_point now = fc::time_point::now(); const fc::time_point block_time = calculate_pending_block_time(); + pending_block_mode previous_pending_mode = _pending_block_mode; _pending_block_mode = pending_block_mode::producing; // Not our turn @@ -1412,10 +1415,14 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() { const auto start_block_time = block_time - fc::microseconds( config::block_interval_us ); if( now < start_block_time ) { fc_dlog(_log, "Not producing block waiting for production window ${n} ${bt}", ("n", hbs->block_num + 1)("bt", block_time) ); - // start_block_time instead of block_time because scheduled_delayed_production_loop calculates next block time from given time - schedule_delayed_production_loop(weak_from_this(), start_block_time); + // start_block_time instead of block_time because schedule_delayed_production_loop calculates next block time from given time + schedule_delayed_production_loop(weak_from_this(), calculate_producer_wake_up_time(start_block_time)); return start_block_result::waiting_for_production; } + } else if (previous_pending_mode == pending_block_mode::producing) { + // just produced our last block of our round + const auto start_block_time = block_time - fc::microseconds( config::block_interval_us ); + schedule_delayed_production_loop( weak_from_this(), start_block_time); } fc_dlog(_log, "Starting block #${n} ${bt} at ${time}", ("n", hbs->block_num + 1)("bt", block_time)("time", now)); @@ -1839,7 +1846,7 @@ void producer_plugin_impl::schedule_production_loop() { } else if (result == start_block_result::waiting_for_block){ if (!_producers.empty() && !production_disabled_by_policy()) { fc_dlog(_log, "Waiting till another block is received and scheduling Speculative/Production Change"); - schedule_delayed_production_loop(weak_this, calculate_pending_block_time()); + schedule_delayed_production_loop(weak_this, calculate_producer_wake_up_time(calculate_pending_block_time())); } else { fc_dlog(_log, "Waiting till another block is received"); // nothing to do until more blocks arrive @@ -1889,13 +1896,13 @@ void producer_plugin_impl::schedule_production_loop() { } else if (_pending_block_mode == pending_block_mode::speculating && !_producers.empty() && !production_disabled_by_policy()){ fc_dlog(_log, "Speculative Block Created; Scheduling Speculative/Production Change"); EOS_ASSERT( chain.is_building_block(), missing_pending_block_state, "speculating without pending_block_state" ); - schedule_delayed_production_loop(weak_this, chain.pending_block_time()); + schedule_delayed_production_loop(weak_this, calculate_producer_wake_up_time(chain.pending_block_time())); } else { fc_dlog(_log, "Speculative Block Created"); } } -void producer_plugin_impl::schedule_delayed_production_loop(const std::weak_ptr& weak_this, const block_timestamp_type& ref_block_time) { +optional producer_plugin_impl::calculate_producer_wake_up_time( const block_timestamp_type& ref_block_time ) const { // if we have any producers then we should at least set a timer for our next available slot optional wake_up_time; chain::account_name producer; @@ -1915,9 +1922,16 @@ void producer_plugin_impl::schedule_delayed_production_loop(const std::weak_ptr< } } } + if( !wake_up_time ) { + fc_dlog(_log, "Not Scheduling Speculative/Production, no local producers had valid wake up times"); + } + return wake_up_time; +} + +void producer_plugin_impl::schedule_delayed_production_loop(const std::weak_ptr& weak_this, optional wake_up_time) { if (wake_up_time) { - fc_dlog(_log, "Scheduling Speculative/Production Change for ${p} at ${time}", ("p", producer)("time", wake_up_time)); + fc_dlog(_log, "Scheduling Speculative/Production Change at ${time}", ("time", wake_up_time)); static const boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1)); _timer.expires_at(epoch + boost::posix_time::microseconds(wake_up_time->time_since_epoch().count())); _timer.async_wait( app().get_priority_queue().wrap( priority::high, @@ -1927,8 +1941,6 @@ void producer_plugin_impl::schedule_delayed_production_loop(const std::weak_ptr< self->schedule_production_loop(); } } ) ); - } else { - fc_dlog(_log, "Not Scheduling Speculative/Production, no local producers had valid wake up times"); } } From 1270593e7c42931411501b88a58e51189ae86d56 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 5 Feb 2020 12:00:47 -0500 Subject: [PATCH 2/3] Add const --- plugins/producer_plugin/producer_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index 8d7a5912e40..886257702a8 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -1360,7 +1360,7 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() { const fc::time_point now = fc::time_point::now(); const fc::time_point block_time = calculate_pending_block_time(); - pending_block_mode previous_pending_mode = _pending_block_mode; + const pending_block_mode previous_pending_mode = _pending_block_mode; _pending_block_mode = pending_block_mode::producing; // Not our turn From 4851c85a67336ebafa6de787b6c23de4bfcff7a6 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 5 Feb 2020 13:40:07 -0500 Subject: [PATCH 3/3] Add needed return after schedule_delayed_production_loop when switching to speculative --- plugins/producer_plugin/producer_plugin.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index 886257702a8..320feb7e6ff 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -1422,7 +1422,9 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() { } else if (previous_pending_mode == pending_block_mode::producing) { // just produced our last block of our round const auto start_block_time = block_time - fc::microseconds( config::block_interval_us ); + fc_dlog(_log, "Not starting speculative block until ${bt}", ("bt", start_block_time) ); schedule_delayed_production_loop( weak_from_this(), start_block_time); + return start_block_result::waiting_for_production; } fc_dlog(_log, "Starting block #${n} ${bt} at ${time}", ("n", hbs->block_num + 1)("bt", block_time)("time", now)); @@ -1905,7 +1907,6 @@ void producer_plugin_impl::schedule_production_loop() { optional producer_plugin_impl::calculate_producer_wake_up_time( const block_timestamp_type& ref_block_time ) const { // if we have any producers then we should at least set a timer for our next available slot optional wake_up_time; - chain::account_name producer; for (const auto& p : _producers) { auto next_producer_block_time = calculate_next_block_time(p, ref_block_time); if (next_producer_block_time) { @@ -1914,11 +1915,9 @@ optional producer_plugin_impl::calculate_producer_wake_up_time( // wake up with a full block interval to the deadline if( producer_wake_up_time < *wake_up_time ) { wake_up_time = producer_wake_up_time; - producer = p; } } else { wake_up_time = producer_wake_up_time; - producer = p; } } }