From 109c7ce9352f23a147bb70084639c5a1b9eb725c Mon Sep 17 00:00:00 2001 From: Valera Cogut Date: Wed, 3 Oct 2018 14:35:30 +0300 Subject: [PATCH 1/4] Terminate block production loop when shutting down witness plugin #1314 --- libraries/plugins/witness/include/graphene/witness/witness.hpp | 1 + libraries/plugins/witness/witness.cpp | 3 +++ 2 files changed, 4 insertions(+) diff --git a/libraries/plugins/witness/include/graphene/witness/witness.hpp b/libraries/plugins/witness/include/graphene/witness/witness.hpp index d2bfcd1290..9a22dcbd9a 100644 --- a/libraries/plugins/witness/include/graphene/witness/witness.hpp +++ b/libraries/plugins/witness/include/graphene/witness/witness.hpp @@ -84,6 +84,7 @@ class witness_plugin : public graphene::app::plugin { boost::program_options::variables_map _options; bool _production_enabled = false; + bool _shutting_down = false; uint32_t _required_witness_participation = 33 * GRAPHENE_1_PERCENT; uint32_t _production_skip_flags = graphene::chain::database::skip_nothing; diff --git a/libraries/plugins/witness/witness.cpp b/libraries/plugins/witness/witness.cpp index 1d2db30a73..a2066204f6 100644 --- a/libraries/plugins/witness/witness.cpp +++ b/libraries/plugins/witness/witness.cpp @@ -144,6 +144,7 @@ void witness_plugin::plugin_startup() void witness_plugin::plugin_shutdown() { // nothing to do + _shutting_down = true; } void witness_plugin::refresh_witness_key_cache() @@ -161,6 +162,8 @@ void witness_plugin::refresh_witness_key_cache() void witness_plugin::schedule_production_loop() { + if (_shutting_down) return; + //Schedule for the next second's tick regardless of chain state // If we would wait less than 50ms, wait for the whole second. fc::time_point now = fc::time_point::now(); From f5ed56a21f4ae32a098d0e8657d374f0412f5aa6 Mon Sep 17 00:00:00 2001 From: Valera Cogut Date: Wed, 3 Oct 2018 16:27:25 +0300 Subject: [PATCH 2/4] removed comment --- libraries/plugins/witness/witness.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/plugins/witness/witness.cpp b/libraries/plugins/witness/witness.cpp index a2066204f6..f2e559893e 100644 --- a/libraries/plugins/witness/witness.cpp +++ b/libraries/plugins/witness/witness.cpp @@ -143,7 +143,6 @@ void witness_plugin::plugin_startup() void witness_plugin::plugin_shutdown() { - // nothing to do _shutting_down = true; } From b3dea5479d5f727542b316ed5bc93e00e77e7573 Mon Sep 17 00:00:00 2001 From: Valera Cogut Date: Thu, 4 Oct 2018 01:44:30 +0300 Subject: [PATCH 3/4] Added check in block_production_loop() if shutting down --- .../witness/include/graphene/witness/witness.hpp | 15 ++++----------- libraries/plugins/witness/witness.cpp | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/libraries/plugins/witness/include/graphene/witness/witness.hpp b/libraries/plugins/witness/include/graphene/witness/witness.hpp index 9a22dcbd9a..9292b55e9f 100644 --- a/libraries/plugins/witness/include/graphene/witness/witness.hpp +++ b/libraries/plugins/witness/include/graphene/witness/witness.hpp @@ -41,22 +41,14 @@ namespace block_production_condition no_private_key = 4, low_participation = 5, lag = 6, - exception_producing_block = 7 + exception_producing_block = 7, + shutdown = 8 }; } class witness_plugin : public graphene::app::plugin { public: - ~witness_plugin() { - try { - if( _block_production_task.valid() ) - _block_production_task.cancel_and_wait(__FUNCTION__); - } catch(fc::canceled_exception&) { - //Expected exception. Move along. - } catch(fc::exception& e) { - edump((e.to_detail_string())); - } - } + ~witness_plugin() { stop_block_production(); } std::string plugin_name()const override; @@ -66,6 +58,7 @@ class witness_plugin : public graphene::app::plugin { ) override; void set_block_production(bool allow) { _production_enabled = allow; } + void stop_block_production(); virtual void plugin_initialize( const boost::program_options::variables_map& options ) override; virtual void plugin_startup() override; diff --git a/libraries/plugins/witness/witness.cpp b/libraries/plugins/witness/witness.cpp index f2e559893e..27e5f9aeb7 100644 --- a/libraries/plugins/witness/witness.cpp +++ b/libraries/plugins/witness/witness.cpp @@ -144,6 +144,20 @@ void witness_plugin::plugin_startup() void witness_plugin::plugin_shutdown() { _shutting_down = true; + + stop_block_production(); +} + +void witness_plugin::stop_block_production() +{ + try { + if( _block_production_task.valid() ) + _block_production_task.cancel_and_wait(__FUNCTION__); + } catch(fc::canceled_exception&) { + //Expected exception. Move along. + } catch(fc::exception& e) { + edump((e.to_detail_string())); + } } void witness_plugin::refresh_witness_key_cache() @@ -178,6 +192,8 @@ void witness_plugin::schedule_production_loop() block_production_condition::block_production_condition_enum witness_plugin::block_production_loop() { + if (_shutting_down) return block_production_condition::block_production_condition_enum::shutdown; + block_production_condition::block_production_condition_enum result; fc::limited_mutable_variant_object capture( GRAPHENE_MAX_NESTED_OBJECTS ); try From 0a7a6c99361bc715971f3c2d9742484d865650b3 Mon Sep 17 00:00:00 2001 From: Valera Cogut Date: Fri, 5 Oct 2018 15:46:52 +0300 Subject: [PATCH 4/4] Set shutting down flag inside stop_block_production() method --- libraries/plugins/witness/witness.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/plugins/witness/witness.cpp b/libraries/plugins/witness/witness.cpp index 27e5f9aeb7..a9a24a9107 100644 --- a/libraries/plugins/witness/witness.cpp +++ b/libraries/plugins/witness/witness.cpp @@ -143,13 +143,13 @@ void witness_plugin::plugin_startup() void witness_plugin::plugin_shutdown() { - _shutting_down = true; - stop_block_production(); } void witness_plugin::stop_block_production() { + _shutting_down = true; + try { if( _block_production_task.valid() ) _block_production_task.cancel_and_wait(__FUNCTION__);