Skip to content

Commit

Permalink
change moment of p2p::set_block_production call in witness plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mkochanowicz committed Apr 27, 2018
1 parent 2340f2a commit 605ea22
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions libraries/plugins/witness/witness_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ namespace detail {
block_production_condition::block_production_condition_enum block_production_loop();
block_production_condition::block_production_condition_enum maybe_produce_block(fc::mutable_variant_object& capture);

bool _production_enabled = false;
bool is_production_enabled() const { return _production_enabled; }

void enable_production()
{
_production_enabled = true;
appbase::app().get_plugin< steem::plugins::p2p::p2p_plugin >().set_block_production( true );
}

uint32_t _required_witness_participation = 33 * STEEM_1_PERCENT;
uint32_t _production_skip_flags = chain::database::skip_nothing;

Expand All @@ -78,6 +85,9 @@ namespace detail {
boost::signals2::connection _pre_apply_operation_conn;
boost::signals2::connection _post_apply_block_conn;
boost::signals2::connection _pre_apply_transaction_conn;

private:
bool _production_enabled = false;
};

struct comment_options_extension_visitor
Expand Down Expand Up @@ -470,10 +480,10 @@ namespace detail {
fc::time_point_sec now = now_fine + fc::microseconds( 500000 );

// If the next block production opportunity is in the present or future, we're synced.
if( !_production_enabled )
if( !is_production_enabled() )
{
if( _db.get_slot_time(1) >= now )
_production_enabled = true;
enable_production();
else
return block_production_condition::not_synced;
}
Expand Down Expand Up @@ -577,7 +587,8 @@ void witness_plugin::plugin_initialize(const boost::program_options::variables_m
}
}

my->_production_enabled = options.at( "enable-stale-production" ).as< bool >();
if ( options.at( "enable-stale-production" ).as< bool >())
my->enable_production();

if( options.count( "required-participation" ) )
{
Expand All @@ -594,8 +605,6 @@ void witness_plugin::plugin_initialize(const boost::program_options::variables_m
add_plugin_index< account_bandwidth_index >( my->_db );
add_plugin_index< reserve_ratio_index >( my->_db );

appbase::app().get_plugin< steem::plugins::p2p::p2p_plugin >().set_block_production( true );

if( my->_witnesses.size() && my->_private_keys.size() )
my->_chain_plugin.set_write_lock_hold_time( -1 );
} FC_LOG_AND_RETHROW() }
Expand All @@ -608,7 +617,7 @@ void witness_plugin::plugin_startup()
if( !my->_witnesses.empty() )
{
ilog( "Launching block production for ${n} witnesses.", ("n", my->_witnesses.size()) );
if( my->_production_enabled )
if( my->is_production_enabled() )
{
if( d.head_block_num() == 0 )
new_chain_banner( d );
Expand Down

0 comments on commit 605ea22

Please sign in to comment.