Remove NTP time
This commit is contained in:
parent
974a7fc0c8
commit
8ae1f6b3a5
15 changed files with 15 additions and 238 deletions
|
|
@ -4,7 +4,6 @@ add_subdirectory( deterministic_openssl_rand )
|
||||||
add_subdirectory( chain )
|
add_subdirectory( chain )
|
||||||
add_subdirectory( egenesis )
|
add_subdirectory( egenesis )
|
||||||
add_subdirectory( net )
|
add_subdirectory( net )
|
||||||
add_subdirectory( time )
|
|
||||||
add_subdirectory( utilities )
|
add_subdirectory( utilities )
|
||||||
add_subdirectory( app )
|
add_subdirectory( app )
|
||||||
add_subdirectory( plugins )
|
add_subdirectory( plugins )
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ add_library( graphene_app
|
||||||
)
|
)
|
||||||
|
|
||||||
# need to link graphene_debug_witness because plugins aren't sufficiently isolated #246
|
# 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
|
target_include_directories( graphene_app
|
||||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include"
|
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include" )
|
"${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include" )
|
||||||
|
|
|
||||||
|
|
@ -28,15 +28,12 @@
|
||||||
|
|
||||||
#include <graphene/chain/protocol/fee_schedule.hpp>
|
#include <graphene/chain/protocol/fee_schedule.hpp>
|
||||||
#include <graphene/chain/protocol/types.hpp>
|
#include <graphene/chain/protocol/types.hpp>
|
||||||
#include <graphene/time/time.hpp>
|
|
||||||
|
|
||||||
#include <graphene/egenesis/egenesis.hpp>
|
#include <graphene/egenesis/egenesis.hpp>
|
||||||
|
|
||||||
#include <graphene/net/core_messages.hpp>
|
#include <graphene/net/core_messages.hpp>
|
||||||
#include <graphene/net/exceptions.hpp>
|
#include <graphene/net/exceptions.hpp>
|
||||||
|
|
||||||
#include <graphene/time/time.hpp>
|
|
||||||
|
|
||||||
#include <graphene/utilities/key_conversion.hpp>
|
#include <graphene/utilities/key_conversion.hpp>
|
||||||
#include <graphene/chain/worker_evaluator.hpp>
|
#include <graphene/chain/worker_evaluator.hpp>
|
||||||
|
|
||||||
|
|
@ -336,7 +333,7 @@ namespace detail {
|
||||||
bool modified_genesis = false;
|
bool modified_genesis = false;
|
||||||
if( _options->count("genesis-timestamp") )
|
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<uint32_t>();
|
genesis.initial_timestamp = fc::time_point_sec( fc::time_point::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;
|
||||||
modified_genesis = true;
|
modified_genesis = true;
|
||||||
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";
|
||||||
|
|
@ -468,8 +465,6 @@ namespace detail {
|
||||||
_force_validate = true;
|
_force_validate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
graphene::time::now();
|
|
||||||
|
|
||||||
if( _options->count("api-access") )
|
if( _options->count("api-access") )
|
||||||
_apiaccess = fc::json::from_file( _options->at("api-access").as<boost::filesystem::path>() )
|
_apiaccess = fc::json::from_file( _options->at("api-access").as<boost::filesystem::path>() )
|
||||||
.as<api_access>();
|
.as<api_access>();
|
||||||
|
|
@ -538,7 +533,7 @@ namespace detail {
|
||||||
std::vector<fc::uint160_t>& contained_transaction_message_ids) override
|
std::vector<fc::uint160_t>& contained_transaction_message_ids) override
|
||||||
{ try {
|
{ 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" );
|
FC_ASSERT( (latency.count()/1000) > -5000, "Rejecting block with timestamp in the future" );
|
||||||
if (!sync_mode || blk_msg.block.block_num() % 10000 == 0)
|
if (!sync_mode || blk_msg.block.block_num() % 10000 == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -910,12 +905,6 @@ namespace detail {
|
||||||
return fc::time_point_sec::min();
|
return fc::time_point_sec::min();
|
||||||
} FC_CAPTURE_AND_RETHROW( (block_id) ) }
|
} 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
|
virtual item_hash_t get_head_block_id() const override
|
||||||
{
|
{
|
||||||
return _chain_db->head_block_id();
|
return _chain_db->head_block_id();
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit e3238628fc319fbd9ce8d3b00e771cb806d69f2e
|
Subproject commit 0d0b485f3ab76d46da1bbe5d85c60a6d95e06bd4
|
||||||
|
|
@ -158,9 +158,6 @@ namespace graphene { namespace net {
|
||||||
*/
|
*/
|
||||||
virtual fc::time_point_sec get_block_time(const item_hash_t& block_id) = 0;
|
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 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;
|
virtual uint32_t estimate_last_known_fork_from_git_revision_timestamp(uint32_t unix_timestamp) const = 0;
|
||||||
|
|
|
||||||
|
|
@ -396,7 +396,6 @@ namespace graphene { namespace net { namespace detail {
|
||||||
void connection_count_changed( uint32_t c ) override;
|
void connection_count_changed( uint32_t c ) override;
|
||||||
uint32_t get_block_number(const item_hash_t& block_id) 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_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;
|
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;
|
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;
|
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 =
|
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->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;
|
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})",
|
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())
|
("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}",
|
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)
|
("blocks", originating_peer->number_of_unfetched_item_ids)
|
||||||
("minimum_time_of_last_offered_block", minimum_time_of_last_offered_block)
|
("minimum_time_of_last_offered_block", minimum_time_of_last_offered_block)
|
||||||
("now", _delegate->get_blockchain_now())));
|
("now", now)));
|
||||||
disconnect_from_peer(originating_peer,
|
disconnect_from_peer(originating_peer,
|
||||||
"You offered me a list of more sync blocks than could possibly exist",
|
"You offered me a list of more sync blocks than could possibly exist",
|
||||||
true, error_for_peer);
|
true, error_for_peer);
|
||||||
|
|
@ -5448,14 +5448,6 @@ namespace graphene { namespace net { namespace detail {
|
||||||
INVOKE_AND_COLLECT_STATISTICS(get_block_time, block_id);
|
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
|
item_hash_t statistics_gathering_node_delegate_wrapper::get_head_block_id() const
|
||||||
{
|
{
|
||||||
INVOKE_AND_COLLECT_STATISTICS(get_head_block_id);
|
INVOKE_AND_COLLECT_STATISTICS(get_head_block_id);
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@
|
||||||
|
|
||||||
#include <graphene/chain/database.hpp>
|
#include <graphene/chain/database.hpp>
|
||||||
#include <graphene/chain/witness_object.hpp>
|
#include <graphene/chain/witness_object.hpp>
|
||||||
#include <graphene/time/time.hpp>
|
|
||||||
|
|
||||||
#include <graphene/utilities/key_conversion.hpp>
|
#include <graphene/utilities/key_conversion.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ add_library( graphene_witness
|
||||||
witness.cpp
|
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
|
target_include_directories( graphene_witness
|
||||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
|
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@
|
||||||
|
|
||||||
#include <graphene/chain/database.hpp>
|
#include <graphene/chain/database.hpp>
|
||||||
#include <graphene/chain/witness_object.hpp>
|
#include <graphene/chain/witness_object.hpp>
|
||||||
#include <graphene/time/time.hpp>
|
|
||||||
|
|
||||||
#include <graphene/utilities/key_conversion.hpp>
|
#include <graphene/utilities/key_conversion.hpp>
|
||||||
|
|
||||||
|
|
@ -51,7 +50,7 @@ void new_chain_banner( const graphene::chain::database& db )
|
||||||
"* *\n"
|
"* *\n"
|
||||||
"********************************\n"
|
"********************************\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"
|
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"
|
"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 {
|
{ try {
|
||||||
ilog("witness plugin: plugin_startup() begin");
|
ilog("witness plugin: plugin_startup() begin");
|
||||||
chain::database& d = database();
|
chain::database& d = database();
|
||||||
//Start NTP time client
|
|
||||||
graphene::time::now();
|
|
||||||
|
|
||||||
if( !_witnesses.empty() )
|
if( !_witnesses.empty() )
|
||||||
{
|
{
|
||||||
|
|
@ -143,7 +140,6 @@ void witness_plugin::plugin_startup()
|
||||||
|
|
||||||
void witness_plugin::plugin_shutdown()
|
void witness_plugin::plugin_shutdown()
|
||||||
{
|
{
|
||||||
graphene::time::shutdown_ntp_time();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -151,13 +147,12 @@ 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
|
||||||
// If we would wait less than 50ms, wait for the whole second.
|
// If we would wait less than 50ms, wait for the whole second.
|
||||||
fc::time_point ntp_now = graphene::time::now();
|
fc::time_point now = fc::time_point::now();
|
||||||
fc::time_point fc_now = fc::time_point::now();
|
int64_t time_to_next_second = 1000000 - (now.time_since_epoch().count() % 1000000);
|
||||||
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
|
if( time_to_next_second < 50000 ) // we must sleep for at least 50ms
|
||||||
time_to_next_second += 1000000;
|
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()) );
|
//wdump( (now.time_since_epoch().count())(next_wakeup.time_since_epoch().count()) );
|
||||||
_block_production_task = fc::schedule([this]{block_production_loop();},
|
_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 )
|
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 now_fine = graphene::time::now();
|
fc::time_point now_fine = fc::time_point::now();
|
||||||
fc::time_point_sec now = now_fine + fc::microseconds( 500000 );
|
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.
|
||||||
|
|
|
||||||
|
|
@ -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" )
|
|
||||||
|
|
@ -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 <fc/optional.hpp>
|
|
||||||
#include <fc/signals.hpp>
|
|
||||||
#include <fc/time.hpp>
|
|
||||||
|
|
||||||
namespace graphene { namespace time {
|
|
||||||
|
|
||||||
typedef fc::signal<void()> time_discontinuity_signal_type;
|
|
||||||
extern time_discontinuity_signal_type time_discontinuity_signal;
|
|
||||||
|
|
||||||
fc::optional<fc::time_point> 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
|
|
||||||
|
|
@ -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 <graphene/time/time.hpp>
|
|
||||||
|
|
||||||
#include <fc/exception/exception.hpp>
|
|
||||||
#include <fc/network/ntp.hpp>
|
|
||||||
#include <fc/thread/mutex.hpp>
|
|
||||||
#include <fc/thread/scoped_lock.hpp>
|
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
|
|
||||||
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<fc::ntp*> ntp_service(nullptr);
|
|
||||||
fc::mutex ntp_service_initialization_mutex;
|
|
||||||
}
|
|
||||||
|
|
||||||
fc::optional<fc::time_point> ntp_time()
|
|
||||||
{
|
|
||||||
fc::ntp* actual_ntp_service = detail::ntp_service.load();
|
|
||||||
if (!actual_ntp_service)
|
|
||||||
{
|
|
||||||
fc::scoped_lock<fc::mutex> 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<fc::time_point> 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<fc::time_point> 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<fc::time_point> 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
|
|
||||||
|
|
@ -19,11 +19,11 @@ target_link_libraries( performance_test graphene_chain graphene_app graphene_acc
|
||||||
|
|
||||||
file(GLOB BENCH_MARKS "benchmarks/*.cpp")
|
file(GLOB BENCH_MARKS "benchmarks/*.cpp")
|
||||||
add_executable( chain_bench ${BENCH_MARKS} ${COMMON_SOURCES} )
|
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")
|
file(GLOB APP_SOURCES "app/*.cpp")
|
||||||
add_executable( app_test ${APP_SOURCES} )
|
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")
|
file(GLOB INTENSE_SOURCES "intense/*.cpp")
|
||||||
add_executable( intense_test ${INTENSE_SOURCES} ${COMMON_SOURCES} )
|
add_executable( intense_test ${INTENSE_SOURCES} ${COMMON_SOURCES} )
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,6 @@
|
||||||
|
|
||||||
#include <graphene/chain/balance_object.hpp>
|
#include <graphene/chain/balance_object.hpp>
|
||||||
|
|
||||||
#include <graphene/time/time.hpp>
|
|
||||||
|
|
||||||
#include <graphene/utilities/tempdir.hpp>
|
#include <graphene/utilities/tempdir.hpp>
|
||||||
|
|
||||||
#include <graphene/account_history/account_history_plugin.hpp>
|
#include <graphene/account_history/account_history_plugin.hpp>
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,6 @@
|
||||||
#include <graphene/chain/account_object.hpp>
|
#include <graphene/chain/account_object.hpp>
|
||||||
#include <graphene/utilities/tempdir.hpp>
|
#include <graphene/utilities/tempdir.hpp>
|
||||||
|
|
||||||
#include <graphene/time/time.hpp>
|
|
||||||
|
|
||||||
#include <fc/crypto/digest.hpp>
|
#include <fc/crypto/digest.hpp>
|
||||||
#include <fc/smart_ref_impl.hpp>
|
#include <fc/smart_ref_impl.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue