Skip to content

Commit

Permalink
Rewrite time library as steemit::time, don't use NTP by default steem…
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed Jan 18, 2017
1 parent 97e221b commit c453d4f
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 182 deletions.
2 changes: 1 addition & 1 deletion libraries/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ add_library( steemit_app
${HEADERS}
)

target_link_libraries( steemit_app steemit_chain steemit_protocol steemit_tags steemit_follow steemit_mf_plugins fc graphene_net graphene_time graphene_utilities )
target_link_libraries( steemit_app steemit_chain steemit_protocol steemit_tags steemit_follow steemit_mf_plugins fc graphene_net steemit_time graphene_utilities )
target_include_directories( steemit_app
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

Expand Down
4 changes: 2 additions & 2 deletions libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#include <steemit/chain/database.hpp>
#include <steemit/chain/steem_objects.hpp>
#include <steemit/chain/transaction_object.hpp>
#include <steemit/time/time.hpp>

#include <graphene/time/time.hpp>
#include <graphene/utilities/key_conversion.hpp>

#include <fc/crypto/hex.hpp>
Expand Down Expand Up @@ -143,7 +143,7 @@ namespace steemit { namespace app {
if( max_block_age < 0 )
return false;

fc::time_point_sec now = graphene::time::now();
fc::time_point_sec now = steemit::time::now();
std::shared_ptr< database > db = _app.chain_database();
const dynamic_global_property_object& dgpo = db->get_dynamic_global_properties();

Expand Down
22 changes: 16 additions & 6 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
#include <steemit/chain/steem_object_types.hpp>
#include <steemit/chain/database_exceptions.hpp>

#include <steemit/time/time.hpp>

#include <graphene/net/core_messages.hpp>
#include <graphene/net/exceptions.hpp>

#include <graphene/time/time.hpp>

#include <graphene/utilities/key_conversion.hpp>

#include <fc/smart_ref_impl.hpp>
Expand Down Expand Up @@ -317,7 +317,15 @@ namespace detail {
_force_validate = true;
}

graphene::time::now();
if( _options->at("enable-ntp").as<bool>() )
{
ilog( "Enable NTP" );
steemit::time::set_ntp_enabled(true);
}
else
{
ilog( "Launching with NTP disabled" );
}
}
else
{
Expand Down Expand Up @@ -471,7 +479,7 @@ namespace detail {
("n", blk_msg.block.block_num()) );
}

time_point_sec now = graphene::time::now();
time_point_sec now = steemit::time::now();

uint64_t max_accept_time = now.sec_since_epoch();
max_accept_time += allow_future_time;
Expand Down Expand Up @@ -819,10 +827,10 @@ namespace detail {
return fc::time_point_sec::min();
} FC_CAPTURE_AND_RETHROW( (block_id) ) }

/** returns graphene::time::now() */
/** returns steemit::time::now() */
virtual fc::time_point_sec get_blockchain_now() override
{
return graphene::time::now();
return steemit::time::now();
}

virtual item_hash_t get_head_block_id() const override
Expand Down Expand Up @@ -857,6 +865,7 @@ namespace detail {
}
if( _chain_db )
_chain_db->close();
steemit::time::set_ntp_enabled(false);
}

application* _self;
Expand Down Expand Up @@ -940,6 +949,7 @@ void application::set_program_options(boost::program_options::options_descriptio
("max-block-age", bpo::value< int32_t >()->default_value(200), "Maximum age of head block when broadcasting tx via API")
("flush", bpo::value< uint32_t >()->default_value(100000), "Flush shared memory file to disk this many blocks")
("check-locks", bpo::value< bool >()->default_value(false), "Check correctness of chainbase locking")
("enable-ntp", bpo::value< bool >()->default_value(false), "Enable built-in NTP client")
;
command_line_options.add(configuration_file_options);
command_line_options.add_options()
Expand Down
2 changes: 1 addition & 1 deletion libraries/plugins/account_by_key/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_library( steemit_account_by_key
account_by_key_api.cpp
)

target_link_libraries( steemit_account_by_key steemit_chain steemit_protocol steemit_app graphene_time )
target_link_libraries( steemit_account_by_key steemit_chain steemit_protocol steemit_app )
target_include_directories( steemit_account_by_key
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

Expand Down
2 changes: 1 addition & 1 deletion libraries/plugins/account_history/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ add_library( steemit_account_history
account_history_plugin.cpp
)

target_link_libraries( steemit_account_history steemit_chain steemit_protocol steemit_app graphene_time )
target_link_libraries( steemit_account_history steemit_chain steemit_protocol steemit_app )
target_include_directories( steemit_account_history
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

Expand Down
2 changes: 1 addition & 1 deletion libraries/plugins/follow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_library( steemit_follow
follow_evaluators.cpp
)

target_link_libraries( steemit_follow steemit_chain steemit_protocol steemit_app graphene_time )
target_link_libraries( steemit_follow steemit_chain steemit_protocol steemit_app )
target_include_directories( steemit_follow
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

Expand Down
2 changes: 1 addition & 1 deletion libraries/plugins/private_message/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ add_library( steemit_private_message
private_message_plugin.cpp
)

target_link_libraries( steemit_private_message steemit_chain steemit_protocol steemit_app graphene_time )
target_link_libraries( steemit_private_message steemit_chain steemit_protocol steemit_app )
target_include_directories( steemit_private_message
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

Expand Down
2 changes: 1 addition & 1 deletion libraries/plugins/tags/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ file(GLOB HEADERS "include/steemit/tags/*.hpp")
add_library( steemit_tags
tags_plugin.cpp )

target_link_libraries( steemit_tags steemit_chain steemit_protocol steemit_app graphene_time )
target_link_libraries( steemit_tags steemit_chain steemit_protocol steemit_app )
target_include_directories( steemit_tags
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

Expand Down
2 changes: 1 addition & 1 deletion libraries/plugins/witness/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ add_library( steemit_witness
witness.cpp
)

target_link_libraries( steemit_witness steemit_chain steemit_protocol steemit_app graphene_time )
target_link_libraries( steemit_witness steemit_chain steemit_protocol steemit_app steemit_time )
target_include_directories( steemit_witness
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

Expand Down
13 changes: 5 additions & 8 deletions libraries/plugins/witness/witness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <steemit/chain/steem_objects.hpp>
#include <steemit/chain/hardfork.hpp>

#include <graphene/time/time.hpp>
#include <steemit/time/time.hpp>

#include <graphene/utilities/key_conversion.hpp>

Expand Down Expand Up @@ -165,8 +165,6 @@ void witness_plugin::plugin_startup()
{ try {
ilog("witness plugin: plugin_startup() begin");
chain::database& d = database();
//Start NTP time client
graphene::time::now();

if( !_witnesses.empty() )
{
Expand Down Expand Up @@ -195,7 +193,6 @@ void witness_plugin::plugin_startup()

void witness_plugin::plugin_shutdown()
{
graphene::time::shutdown_ntp_time();
if( !_miners.empty() )
{
ilog( "shutting downing mining threads" );
Expand All @@ -208,7 +205,7 @@ void witness_plugin::schedule_production_loop()
{
//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 ntp_now = graphene::time::now();
fc::time_point ntp_now = steemit::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
Expand Down Expand Up @@ -293,7 +290,7 @@ 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 )
{
chain::database& db = database();
fc::time_point now_fine = graphene::time::now();
fc::time_point now_fine = steemit::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.
Expand Down Expand Up @@ -495,7 +492,7 @@ void witness_plugin::start_mining(

while( true )
{
if( graphene::time::nonblocking_now() > stop )
if( steemit::time::now() > stop )
{
// ilog( "stop mining due to time out, nonce: ${n}", ("n",op.nonce) );
return;
Expand Down Expand Up @@ -551,7 +548,7 @@ void witness_plugin::start_mining(
while( true )
{
// if( ((op.nonce/num_threads) % 1000) == 0 ) idump((op.nonce));
if( graphene::time::nonblocking_now() > stop )
if( steemit::time::now() > stop )
{
// ilog( "stop mining due to time out, nonce: ${n}", ("n",op.nonce) );
return;
Expand Down
12 changes: 6 additions & 6 deletions libraries/time/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
file(GLOB HEADERS "include/graphene/time/*.hpp")
file(GLOB HEADERS "include/steemit/time/*.hpp")

add_library( graphene_time
add_library( steemit_time
time.cpp
)

target_link_libraries( graphene_time fc )
target_include_directories( graphene_time
target_link_libraries( steemit_time fc )
target_include_directories( steemit_time
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

install( TARGETS
graphene_time
steemit_time

RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
install( FILES ${HEADERS} DESTINATION "include/graphene/time" )
install( FILES ${HEADERS} DESTINATION "include/steemit/time" )
46 changes: 0 additions & 46 deletions libraries/time/include/graphene/time/time.hpp

This file was deleted.

10 changes: 10 additions & 0 deletions libraries/time/include/steemit/time/time.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <fc/time.hpp>

namespace steemit { namespace time {

void set_ntp_enabled( bool enabled );
fc::time_point now();

} } // steemit::time
Loading

0 comments on commit c453d4f

Please sign in to comment.