time: Make timer use fc::time_point instead of fc::time_point_sec so witness plugin can control quantization
This commit is contained in:
parent
dd9dbca38c
commit
c14494fb68
4 changed files with 11 additions and 8 deletions
|
|
@ -231,7 +231,7 @@ namespace detail {
|
||||||
genesis_state_type genesis = fc::json::from_file(_options->at("genesis-json").as<boost::filesystem::path>()).as<genesis_state_type>();
|
genesis_state_type genesis = fc::json::from_file(_options->at("genesis-json").as<boost::filesystem::path>()).as<genesis_state_type>();
|
||||||
if( _options->count("genesis-timestamp") )
|
if( _options->count("genesis-timestamp") )
|
||||||
{
|
{
|
||||||
genesis.initial_timestamp = graphene::time::now() + genesis.initial_parameters.block_interval + _options->at("genesis-timestamp").as<uint32_t>();
|
genesis.initial_timestamp = fc::time_point_sec( graphene::time::now() ) + genesis.initial_parameters.block_interval + _options->at("genesis-timestamp").as<uint32_t>();
|
||||||
genesis.initial_timestamp -= genesis.initial_timestamp.sec_since_epoch() % genesis.initial_parameters.block_interval;
|
genesis.initial_timestamp -= genesis.initial_timestamp.sec_since_epoch() % genesis.initial_parameters.block_interval;
|
||||||
std::cerr << "Used genesis timestamp: " << genesis.initial_timestamp.to_iso_string() << " (PLEASE RECORD THIS)\n";
|
std::cerr << "Used genesis timestamp: " << genesis.initial_timestamp.to_iso_string() << " (PLEASE RECORD THIS)\n";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -177,8 +177,10 @@ void witness_plugin::plugin_shutdown()
|
||||||
void witness_plugin::schedule_production_loop()
|
void witness_plugin::schedule_production_loop()
|
||||||
{
|
{
|
||||||
//Schedule for the next second's tick regardless of chain state
|
//Schedule for the next second's tick regardless of chain state
|
||||||
fc::time_point_sec next_second( graphene::time::now().sec_since_epoch() + 1 );
|
// If we would wait less than 200ms, wait for the whole second.
|
||||||
wdump( (next_second) );
|
fc::time_point now = graphene::time::now();
|
||||||
|
fc::time_point_sec next_second( now + fc::microseconds( 1200000 ) );
|
||||||
|
wdump( (now.time_since_epoch().count())(next_second) );
|
||||||
_block_production_task = fc::schedule([this]{block_production_loop();},
|
_block_production_task = fc::schedule([this]{block_production_loop();},
|
||||||
next_second, "Witness Block Production");
|
next_second, "Witness Block Production");
|
||||||
}
|
}
|
||||||
|
|
@ -239,7 +241,8 @@ block_production_condition::block_production_condition_enum witness_plugin::bloc
|
||||||
block_production_condition::block_production_condition_enum witness_plugin::maybe_produce_block( fc::mutable_variant_object& capture )
|
block_production_condition::block_production_condition_enum witness_plugin::maybe_produce_block( fc::mutable_variant_object& capture )
|
||||||
{
|
{
|
||||||
chain::database& db = database();
|
chain::database& db = database();
|
||||||
fc::time_point_sec now = graphene::time::now();
|
fc::time_point now_fine = graphene::time::now();
|
||||||
|
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 the next block production opportunity is in the present or future, we're synced.
|
||||||
if( !_production_enabled )
|
if( !_production_enabled )
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ namespace graphene { namespace time {
|
||||||
extern time_discontinuity_signal_type time_discontinuity_signal;
|
extern time_discontinuity_signal_type time_discontinuity_signal;
|
||||||
|
|
||||||
fc::optional<fc::time_point> ntp_time();
|
fc::optional<fc::time_point> ntp_time();
|
||||||
fc::time_point_sec now();
|
fc::time_point now();
|
||||||
fc::time_point_sec nonblocking_now(); // identical to now() but guaranteed not to block
|
fc::time_point nonblocking_now(); // identical to now() but guaranteed not to block
|
||||||
void update_ntp_time();
|
void update_ntp_time();
|
||||||
fc::microseconds ntp_error();
|
fc::microseconds ntp_error();
|
||||||
void shutdown_ntp_time();
|
void shutdown_ntp_time();
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ void shutdown_ntp_time()
|
||||||
delete actual_ntp_service;
|
delete actual_ntp_service;
|
||||||
}
|
}
|
||||||
|
|
||||||
fc::time_point_sec now()
|
fc::time_point now()
|
||||||
{
|
{
|
||||||
if( simulated_time )
|
if( simulated_time )
|
||||||
return fc::time_point() + fc::seconds( simulated_time + adjusted_time_sec );
|
return fc::time_point() + fc::seconds( simulated_time + adjusted_time_sec );
|
||||||
|
|
@ -72,7 +72,7 @@ fc::time_point_sec now()
|
||||||
return fc::time_point::now() + fc::seconds( adjusted_time_sec );
|
return fc::time_point::now() + fc::seconds( adjusted_time_sec );
|
||||||
}
|
}
|
||||||
|
|
||||||
fc::time_point_sec nonblocking_now()
|
fc::time_point nonblocking_now()
|
||||||
{
|
{
|
||||||
if (simulated_time)
|
if (simulated_time)
|
||||||
return fc::time_point() + fc::seconds(simulated_time + adjusted_time_sec);
|
return fc::time_point() + fc::seconds(simulated_time + adjusted_time_sec);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue