From 8ae1f6b3a52c36b0c9c454654a338511c0f4812b Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Thu, 16 Mar 2017 12:46:09 -0500 Subject: [PATCH] Remove NTP time --- libraries/CMakeLists.txt | 1 - libraries/app/CMakeLists.txt | 2 +- libraries/app/application.cpp | 15 +-- libraries/fc | 2 +- libraries/net/include/graphene/net/node.hpp | 3 - libraries/net/node.cpp | 14 +- .../plugins/debug_witness/debug_witness.cpp | 1 - libraries/plugins/witness/CMakeLists.txt | 2 +- libraries/plugins/witness/witness.cpp | 15 +-- libraries/time/CMakeLists.txt | 18 --- libraries/time/include/graphene/time/time.hpp | 46 ------- libraries/time/time.cpp | 126 ------------------ tests/CMakeLists.txt | 4 +- tests/app/main.cpp | 2 - tests/benchmarks/genesis_allocation.cpp | 2 - 15 files changed, 15 insertions(+), 238 deletions(-) delete mode 100644 libraries/time/CMakeLists.txt delete mode 100644 libraries/time/include/graphene/time/time.hpp delete mode 100644 libraries/time/time.cpp diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt index 6af806f9..b3c37f48 100644 --- a/libraries/CMakeLists.txt +++ b/libraries/CMakeLists.txt @@ -4,7 +4,6 @@ add_subdirectory( deterministic_openssl_rand ) add_subdirectory( chain ) add_subdirectory( egenesis ) add_subdirectory( net ) -add_subdirectory( time ) add_subdirectory( utilities ) add_subdirectory( app ) add_subdirectory( plugins ) diff --git a/libraries/app/CMakeLists.txt b/libraries/app/CMakeLists.txt index 29d76fe8..75b9ca52 100644 --- a/libraries/app/CMakeLists.txt +++ b/libraries/app/CMakeLists.txt @@ -12,7 +12,7 @@ add_library( graphene_app ) # need to link graphene_debug_witness because plugins aren't sufficiently isolated #246 -target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities graphene_debug_witness ) +target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_chain fc graphene_db graphene_net graphene_utilities graphene_debug_witness ) target_include_directories( graphene_app PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include" ) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 0b7fc33f..0b42c6b0 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -28,15 +28,12 @@ #include #include -#include #include #include #include -#include - #include #include @@ -336,7 +333,7 @@ namespace detail { bool modified_genesis = false; if( _options->count("genesis-timestamp") ) { - genesis.initial_timestamp = fc::time_point_sec( graphene::time::now() ) + genesis.initial_parameters.block_interval + _options->at("genesis-timestamp").as(); + genesis.initial_timestamp = fc::time_point_sec( fc::time_point::now() ) + genesis.initial_parameters.block_interval + _options->at("genesis-timestamp").as(); genesis.initial_timestamp -= genesis.initial_timestamp.sec_since_epoch() % genesis.initial_parameters.block_interval; modified_genesis = true; std::cerr << "Used genesis timestamp: " << genesis.initial_timestamp.to_iso_string() << " (PLEASE RECORD THIS)\n"; @@ -468,8 +465,6 @@ namespace detail { _force_validate = true; } - graphene::time::now(); - if( _options->count("api-access") ) _apiaccess = fc::json::from_file( _options->at("api-access").as() ) .as(); @@ -538,7 +533,7 @@ namespace detail { std::vector& contained_transaction_message_ids) override { try { - auto latency = graphene::time::now() - blk_msg.block.timestamp; + auto latency = fc::time_point::now() - blk_msg.block.timestamp; FC_ASSERT( (latency.count()/1000) > -5000, "Rejecting block with timestamp in the future" ); if (!sync_mode || blk_msg.block.block_num() % 10000 == 0) { @@ -910,12 +905,6 @@ namespace detail { return fc::time_point_sec::min(); } FC_CAPTURE_AND_RETHROW( (block_id) ) } - /** returns graphene::time::now() */ - virtual fc::time_point_sec get_blockchain_now() override - { - return graphene::time::now(); - } - virtual item_hash_t get_head_block_id() const override { return _chain_db->head_block_id(); diff --git a/libraries/fc b/libraries/fc index e3238628..0d0b485f 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit e3238628fc319fbd9ce8d3b00e771cb806d69f2e +Subproject commit 0d0b485f3ab76d46da1bbe5d85c60a6d95e06bd4 diff --git a/libraries/net/include/graphene/net/node.hpp b/libraries/net/include/graphene/net/node.hpp index 1e01904f..e17af148 100644 --- a/libraries/net/include/graphene/net/node.hpp +++ b/libraries/net/include/graphene/net/node.hpp @@ -158,9 +158,6 @@ namespace graphene { namespace net { */ virtual fc::time_point_sec get_block_time(const item_hash_t& block_id) = 0; - /** returns graphene::blockchain::now() */ - virtual fc::time_point_sec get_blockchain_now() = 0; - virtual item_hash_t get_head_block_id() const = 0; virtual uint32_t estimate_last_known_fork_from_git_revision_timestamp(uint32_t unix_timestamp) const = 0; diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 9e13e599..2b8a877f 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -396,7 +396,6 @@ namespace graphene { namespace net { namespace detail { void connection_count_changed( uint32_t c ) override; uint32_t get_block_number(const item_hash_t& block_id) override; fc::time_point_sec get_block_time(const item_hash_t& block_id) override; - fc::time_point_sec get_blockchain_now() override; item_hash_t get_head_block_id() const override; uint32_t estimate_last_known_fork_from_git_revision_timestamp(uint32_t unix_timestamp) const override; void error_encountered(const std::string& message, const fc::oexception& error) override; @@ -2642,7 +2641,8 @@ namespace graphene { namespace net { namespace detail { fc::time_point_sec minimum_time_of_last_offered_block = originating_peer->last_block_time_delegate_has_seen + // timestamp of the block immediately before the first unfetched block originating_peer->number_of_unfetched_item_ids * GRAPHENE_MIN_BLOCK_INTERVAL; - if (minimum_time_of_last_offered_block > _delegate->get_blockchain_now() + GRAPHENE_NET_FUTURE_SYNC_BLOCKS_GRACE_PERIOD_SEC) + fc::time_point_sec now = fc::time_point::now(); + if (minimum_time_of_last_offered_block > now + GRAPHENE_NET_FUTURE_SYNC_BLOCKS_GRACE_PERIOD_SEC) { wlog("Disconnecting from peer ${peer} who offered us an implausible number of blocks, their last block would be in the future (${timestamp})", ("peer", originating_peer->get_remote_endpoint()) @@ -2650,7 +2650,7 @@ namespace graphene { namespace net { namespace detail { fc::exception error_for_peer(FC_LOG_MESSAGE(error, "You offered me a list of more sync blocks than could possibly exist. Total blocks offered: ${blocks}, Minimum time of the last block you offered: ${minimum_time_of_last_offered_block}, Now: ${now}", ("blocks", originating_peer->number_of_unfetched_item_ids) ("minimum_time_of_last_offered_block", minimum_time_of_last_offered_block) - ("now", _delegate->get_blockchain_now()))); + ("now", now))); disconnect_from_peer(originating_peer, "You offered me a list of more sync blocks than could possibly exist", true, error_for_peer); @@ -5448,14 +5448,6 @@ namespace graphene { namespace net { namespace detail { INVOKE_AND_COLLECT_STATISTICS(get_block_time, block_id); } - /** returns graphene::blockchain::now() */ - fc::time_point_sec statistics_gathering_node_delegate_wrapper::get_blockchain_now() - { - // this function doesn't need to block, - ASSERT_TASK_NOT_PREEMPTED(); - return _node_delegate->get_blockchain_now(); - } - item_hash_t statistics_gathering_node_delegate_wrapper::get_head_block_id() const { INVOKE_AND_COLLECT_STATISTICS(get_head_block_id); diff --git a/libraries/plugins/debug_witness/debug_witness.cpp b/libraries/plugins/debug_witness/debug_witness.cpp index 7bb5562d..751d1e82 100644 --- a/libraries/plugins/debug_witness/debug_witness.cpp +++ b/libraries/plugins/debug_witness/debug_witness.cpp @@ -25,7 +25,6 @@ #include #include -#include #include diff --git a/libraries/plugins/witness/CMakeLists.txt b/libraries/plugins/witness/CMakeLists.txt index c82442ff..95759bbf 100644 --- a/libraries/plugins/witness/CMakeLists.txt +++ b/libraries/plugins/witness/CMakeLists.txt @@ -4,7 +4,7 @@ add_library( graphene_witness witness.cpp ) -target_link_libraries( graphene_witness graphene_chain graphene_app graphene_time ) +target_link_libraries( graphene_witness graphene_chain graphene_app ) target_include_directories( graphene_witness PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) diff --git a/libraries/plugins/witness/witness.cpp b/libraries/plugins/witness/witness.cpp index 01160272..6c661e2d 100644 --- a/libraries/plugins/witness/witness.cpp +++ b/libraries/plugins/witness/witness.cpp @@ -25,7 +25,6 @@ #include #include -#include #include @@ -51,7 +50,7 @@ void new_chain_banner( const graphene::chain::database& db ) "* *\n" "********************************\n" "\n"; - if( db.get_slot_at_time( graphene::time::now() ) > 200 ) + if( db.get_slot_at_time( fc::time_point::now() ) > 200 ) { std::cerr << "Your genesis seems to have an old timestamp\n" "Please consider using the --genesis-timestamp option to give your genesis a recent timestamp\n" @@ -122,8 +121,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() ) { @@ -143,7 +140,6 @@ void witness_plugin::plugin_startup() void witness_plugin::plugin_shutdown() { - graphene::time::shutdown_ntp_time(); return; } @@ -151,13 +147,12 @@ 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 fc_now = fc::time_point::now(); - int64_t time_to_next_second = 1000000 - (ntp_now.time_since_epoch().count() % 1000000); + fc::time_point now = fc::time_point::now(); + int64_t time_to_next_second = 1000000 - (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 ) ); + fc::time_point next_wakeup( 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();}, @@ -221,7 +216,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 = fc::time_point::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. diff --git a/libraries/time/CMakeLists.txt b/libraries/time/CMakeLists.txt deleted file mode 100644 index 4c9b85c1..00000000 --- a/libraries/time/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -file(GLOB HEADERS "include/graphene/time/*.hpp") - -add_library( graphene_time - time.cpp - ) - -target_link_libraries( graphene_time fc ) -target_include_directories( graphene_time - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) - -install( TARGETS - graphene_time - - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib -) -install( FILES ${HEADERS} DESTINATION "include/graphene/time" ) diff --git a/libraries/time/include/graphene/time/time.hpp b/libraries/time/include/graphene/time/time.hpp deleted file mode 100644 index 2979369c..00000000 --- a/libraries/time/include/graphene/time/time.hpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2015 Cryptonomex, Inc., and contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#pragma once - -#include -#include -#include - -namespace graphene { namespace time { - - typedef fc::signal time_discontinuity_signal_type; - extern time_discontinuity_signal_type time_discontinuity_signal; - - fc::optional ntp_time(); - fc::time_point now(); - fc::time_point nonblocking_now(); // identical to now() but guaranteed not to block - void update_ntp_time(); - fc::microseconds ntp_error(); - void shutdown_ntp_time(); - - void start_simulated_time( const fc::time_point sim_time ); - void advance_simulated_time_to( const fc::time_point sim_time ); - void advance_time( int32_t delta_seconds ); - -} } // graphene::time diff --git a/libraries/time/time.cpp b/libraries/time/time.cpp deleted file mode 100644 index 6ba0c126..00000000 --- a/libraries/time/time.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2015 Cryptonomex, Inc., and contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include - -#include -#include -#include -#include - -#include - -namespace graphene { namespace time { - -static int32_t simulated_time = 0; -static int32_t adjusted_time_sec = 0; - -time_discontinuity_signal_type time_discontinuity_signal; - -namespace detail -{ - std::atomic ntp_service(nullptr); - fc::mutex ntp_service_initialization_mutex; -} - -fc::optional ntp_time() -{ - fc::ntp* actual_ntp_service = detail::ntp_service.load(); - if (!actual_ntp_service) - { - fc::scoped_lock lock(detail::ntp_service_initialization_mutex); - actual_ntp_service = detail::ntp_service.load(); - if (!actual_ntp_service) - { - actual_ntp_service = new fc::ntp; - detail::ntp_service.store(actual_ntp_service); - } - } - return actual_ntp_service->get_time(); -} - -void shutdown_ntp_time() -{ - fc::ntp* actual_ntp_service = detail::ntp_service.exchange(nullptr); - delete actual_ntp_service; -} - -fc::time_point now() -{ - if( simulated_time ) - return fc::time_point() + fc::seconds( simulated_time + adjusted_time_sec ); - - fc::optional current_ntp_time = ntp_time(); - if( current_ntp_time.valid() ) - return *current_ntp_time + fc::seconds( adjusted_time_sec ); - else - return fc::time_point::now() + fc::seconds( adjusted_time_sec ); -} - -fc::time_point nonblocking_now() -{ - if (simulated_time) - return fc::time_point() + fc::seconds(simulated_time + adjusted_time_sec); - - fc::ntp* actual_ntp_service = detail::ntp_service.load(); - fc::optional current_ntp_time; - if (actual_ntp_service) - current_ntp_time = actual_ntp_service->get_time(); - - if (current_ntp_time) - return *current_ntp_time + fc::seconds(adjusted_time_sec); - else - return fc::time_point::now() + fc::seconds(adjusted_time_sec); -} - -void update_ntp_time() -{ - detail::ntp_service.load()->request_now(); -} - -fc::microseconds ntp_error() -{ - fc::optional current_ntp_time = ntp_time(); - FC_ASSERT( current_ntp_time, "We don't have NTP time!" ); - return *current_ntp_time - fc::time_point::now(); -} - -void start_simulated_time( const fc::time_point sim_time ) -{ - simulated_time = sim_time.sec_since_epoch(); - adjusted_time_sec = 0; -} -void advance_simulated_time_to( const fc::time_point sim_time ) -{ - simulated_time = sim_time.sec_since_epoch(); - adjusted_time_sec = 0; -} - -void advance_time( int32_t delta_seconds ) -{ - adjusted_time_sec += delta_seconds; - time_discontinuity_signal(); -} - -} } // graphene::time diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 827bdb1b..7edc54bd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,11 +19,11 @@ target_link_libraries( performance_test graphene_chain graphene_app graphene_acc file(GLOB BENCH_MARKS "benchmarks/*.cpp") add_executable( chain_bench ${BENCH_MARKS} ${COMMON_SOURCES} ) -target_link_libraries( chain_bench graphene_chain graphene_app graphene_account_history graphene_time graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) +target_link_libraries( chain_bench graphene_chain graphene_app graphene_account_history graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) file(GLOB APP_SOURCES "app/*.cpp") add_executable( app_test ${APP_SOURCES} ) -target_link_libraries( app_test graphene_app graphene_account_history graphene_net graphene_chain graphene_time graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) +target_link_libraries( app_test graphene_app graphene_account_history graphene_net graphene_chain graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) file(GLOB INTENSE_SOURCES "intense/*.cpp") add_executable( intense_test ${INTENSE_SOURCES} ${COMMON_SOURCES} ) diff --git a/tests/app/main.cpp b/tests/app/main.cpp index 50ed9f07..20f140ee 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -26,8 +26,6 @@ #include -#include - #include #include diff --git a/tests/benchmarks/genesis_allocation.cpp b/tests/benchmarks/genesis_allocation.cpp index 470d586d..61a3b1b8 100644 --- a/tests/benchmarks/genesis_allocation.cpp +++ b/tests/benchmarks/genesis_allocation.cpp @@ -25,8 +25,6 @@ #include #include -#include - #include #include