Skip to content

Commit 67f313d

Browse files
authored
Merge pull request #1332 from cogutvalera/issue_1314
Terminate block production loop when shutting down witness plugin #1314
2 parents 42e2342 + 0a7a6c9 commit 67f313d

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

libraries/plugins/witness/include/graphene/witness/witness.hpp

+5-11
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,14 @@ namespace block_production_condition
4141
no_private_key = 4,
4242
low_participation = 5,
4343
lag = 6,
44-
exception_producing_block = 7
44+
exception_producing_block = 7,
45+
shutdown = 8
4546
};
4647
}
4748

4849
class witness_plugin : public graphene::app::plugin {
4950
public:
50-
~witness_plugin() {
51-
try {
52-
if( _block_production_task.valid() )
53-
_block_production_task.cancel_and_wait(__FUNCTION__);
54-
} catch(fc::canceled_exception&) {
55-
//Expected exception. Move along.
56-
} catch(fc::exception& e) {
57-
edump((e.to_detail_string()));
58-
}
59-
}
51+
~witness_plugin() { stop_block_production(); }
6052

6153
std::string plugin_name()const override;
6254

@@ -66,6 +58,7 @@ class witness_plugin : public graphene::app::plugin {
6658
) override;
6759

6860
void set_block_production(bool allow) { _production_enabled = allow; }
61+
void stop_block_production();
6962

7063
virtual void plugin_initialize( const boost::program_options::variables_map& options ) override;
7164
virtual void plugin_startup() override;
@@ -84,6 +77,7 @@ class witness_plugin : public graphene::app::plugin {
8477

8578
boost::program_options::variables_map _options;
8679
bool _production_enabled = false;
80+
bool _shutting_down = false;
8781
uint32_t _required_witness_participation = 33 * GRAPHENE_1_PERCENT;
8882
uint32_t _production_skip_flags = graphene::chain::database::skip_nothing;
8983

libraries/plugins/witness/witness.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,21 @@ void witness_plugin::plugin_startup()
143143

144144
void witness_plugin::plugin_shutdown()
145145
{
146-
// nothing to do
146+
stop_block_production();
147+
}
148+
149+
void witness_plugin::stop_block_production()
150+
{
151+
_shutting_down = true;
152+
153+
try {
154+
if( _block_production_task.valid() )
155+
_block_production_task.cancel_and_wait(__FUNCTION__);
156+
} catch(fc::canceled_exception&) {
157+
//Expected exception. Move along.
158+
} catch(fc::exception& e) {
159+
edump((e.to_detail_string()));
160+
}
147161
}
148162

149163
void witness_plugin::refresh_witness_key_cache()
@@ -161,6 +175,8 @@ void witness_plugin::refresh_witness_key_cache()
161175

162176
void witness_plugin::schedule_production_loop()
163177
{
178+
if (_shutting_down) return;
179+
164180
//Schedule for the next second's tick regardless of chain state
165181
// If we would wait less than 50ms, wait for the whole second.
166182
fc::time_point now = fc::time_point::now();
@@ -176,6 +192,8 @@ void witness_plugin::schedule_production_loop()
176192

177193
block_production_condition::block_production_condition_enum witness_plugin::block_production_loop()
178194
{
195+
if (_shutting_down) return block_production_condition::block_production_condition_enum::shutdown;
196+
179197
block_production_condition::block_production_condition_enum result;
180198
fc::limited_mutable_variant_object capture( GRAPHENE_MAX_NESTED_OBJECTS );
181199
try

0 commit comments

Comments
 (0)