From fda84dfe8bdafe1b7e35565c1b022548b6f046f6 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Sat, 24 Oct 2015 12:21:48 -0400 Subject: [PATCH] witness: Submit wakeup time for fc::schedule() on local system clock, not NTP --- libraries/plugins/witness/witness.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libraries/plugins/witness/witness.cpp b/libraries/plugins/witness/witness.cpp index fd346342..acdad202 100644 --- a/libraries/plugins/witness/witness.cpp +++ b/libraries/plugins/witness/witness.cpp @@ -146,12 +146,18 @@ void witness_plugin::plugin_shutdown() void witness_plugin::schedule_production_loop() { //Schedule for the next second's tick regardless of chain state - // If we would wait less than 200ms, wait for the whole 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) ); + // If we would wait less than 50ms, wait for the whole second. + fc::time_point ntp_now = graphene::time::now(); + fc::time_point fc_now = fc::time_point::now(); + int64_t time_to_next_second = 1000000 - (ntp_now.time_since_epoch().count() % 1000000); + if( time_to_next_second < 50000 ) // we must sleep for at least 50ms + time_to_next_second += 1000000; + + fc::time_point next_wakeup( fc_now + fc::microseconds( time_to_next_second ) ); + + //wdump( (now.time_since_epoch().count())(next_wakeup.time_since_epoch().count()) ); _block_production_task = fc::schedule([this]{block_production_loop();}, - next_second, "Witness Block Production"); + next_wakeup, "Witness Block Production"); } block_production_condition::block_production_condition_enum witness_plugin::block_production_loop()