Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminate block production loop when shutting down witness plugin #1314 #1332

Merged
merged 4 commits into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions libraries/plugins/witness/include/graphene/witness/witness.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -84,6 +77,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;

Expand Down
20 changes: 19 additions & 1 deletion libraries/plugins/witness/witness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,21 @@ void witness_plugin::plugin_startup()

void witness_plugin::plugin_shutdown()
{
// nothing to do
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__);
} catch(fc::canceled_exception&) {
//Expected exception. Move along.
} catch(fc::exception& e) {
edump((e.to_detail_string()));
}
}

void witness_plugin::refresh_witness_key_cache()
Expand All @@ -161,6 +175,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();
Expand All @@ -176,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
Expand Down