Skip to content

Commit

Permalink
synced with main
Browse files Browse the repository at this point in the history
  • Loading branch information
mschoenebeck committed May 8, 2023
2 parents 247413d + 31ae4cb commit 3268500
Show file tree
Hide file tree
Showing 37 changed files with 204 additions and 297 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ set(Boost_USE_MULTITHREADED ON)
set( Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF" )
# Most boost deps get implictly picked up via fc, as just about everything links to fc. In addition we pick up
# the pthread dependency through fc.
find_package(Boost 1.70 REQUIRED COMPONENTS program_options unit_test_framework system)
find_package(Boost 1.71 REQUIRED COMPONENTS program_options unit_test_framework system)

if( APPLE AND UNIX )
# Apple Specific Options Here
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/apply_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ void apply_context::schedule_deferred_transaction( const uint128_t& sender_id, a
trx.ref_block_num = 0;
trx.ref_block_prefix = 0;
} else {
trx.expiration = control.pending_block_time() + fc::microseconds(999'999); // Rounds up to nearest second (makes expiration check unnecessary)
trx.expiration = time_point_sec{control.pending_block_time() + fc::microseconds(999'999)}; // Rounds up to nearest second (makes expiration check unnecessary)
trx.set_reference_block(control.head_block_id()); // No TaPoS check necessary
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ namespace eosio { namespace chain {

static void write_incomplete_block_data(const std::filesystem::path& blocks_dir, fc::time_point now, uint32_t block_num,
fc::cfile& strm) {
auto tail_path = blocks_dir / std::string("blocks-bad-tail-").append(std::string(now)).append(".log");
auto tail_path = blocks_dir / std::string("blocks-bad-tail-").append(now.to_iso_string()).append(".log");
fc::cfile tail;
tail.set_file_path(tail_path);
tail.open(fc::cfile::create_or_update_rw_mode);
Expand Down Expand Up @@ -1320,7 +1320,7 @@ namespace eosio { namespace chain {
auto blocks_dir = std::filesystem::canonical(
data_dir); // canonical always returns an absolute path that has no symbolic link, dot, or dot-dot elements
auto blocks_dir_name = blocks_dir.filename();
auto backup_dir = blocks_dir.parent_path() / blocks_dir_name.generic_string().append("-").append(now);
auto backup_dir = blocks_dir.parent_path() / blocks_dir_name.generic_string().append("-").append(now.to_iso_string());

EOS_ASSERT(!std::filesystem::exists(backup_dir), block_log_backup_dir_exist,
"Cannot move existing blocks directory to already existing directory '${new_blocks_dir}'",
Expand Down
10 changes: 5 additions & 5 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ struct controller_impl {
etrx.ref_block_num = 0;
etrx.ref_block_prefix = 0;
} else {
etrx.expiration = self.pending_block_time() + fc::microseconds(999'999); // Round up to nearest second to avoid appearing expired
etrx.expiration = time_point_sec{self.pending_block_time() + fc::microseconds(999'999)}; // Round up to nearest second to avoid appearing expired
etrx.set_reference_block( self.head_block_id() );
}

Expand Down Expand Up @@ -2488,7 +2488,7 @@ struct controller_impl {
auto now = self.is_building_block() ? self.pending_block_time() : self.head_block_time();
const auto total = dedupe_index.size();
uint32_t num_removed = 0;
while( (!dedupe_index.empty()) && ( now > fc::time_point(dedupe_index.begin()->expiration) ) ) {
while( (!dedupe_index.empty()) && ( now > dedupe_index.begin()->expiration.to_time_point() ) ) {
transaction_idx.remove(*dedupe_index.begin());
++num_removed;
if( deadline <= fc::time_point::now() ) {
Expand Down Expand Up @@ -2663,7 +2663,7 @@ struct controller_impl {
trx.ref_block_num = 0;
trx.ref_block_prefix = 0;
} else {
trx.expiration = self.pending_block_time() + fc::microseconds(999'999); // Round up to nearest second to avoid appearing expired
trx.expiration = time_point_sec{self.pending_block_time() + fc::microseconds(999'999)}; // Round up to nearest second to avoid appearing expired
trx.set_reference_block( self.head_block_id() );
}

Expand Down Expand Up @@ -3484,12 +3484,12 @@ uint32_t controller::configured_subjective_signature_length_limit()const {
void controller::validate_expiration( const transaction& trx )const { try {
const auto& chain_configuration = get_global_properties().configuration;

EOS_ASSERT( time_point(trx.expiration) >= pending_block_time(),
EOS_ASSERT( trx.expiration.to_time_point() >= pending_block_time(),
expired_tx_exception,
"transaction has expired, "
"expiration is ${trx.expiration} and pending block time is ${pending_block_time}",
("trx.expiration",trx.expiration)("pending_block_time",pending_block_time()));
EOS_ASSERT( time_point(trx.expiration) <= pending_block_time() + fc::seconds(chain_configuration.max_transaction_lifetime),
EOS_ASSERT( trx.expiration.to_time_point() <= pending_block_time() + fc::seconds(chain_configuration.max_transaction_lifetime),
tx_exp_too_far_exception,
"Transaction expiration is too far in the future relative to the reference time of ${reference_time}, "
"expiration is ${trx.expiration} and the maximum transaction lifetime is ${max_til_exp} seconds",
Expand Down
6 changes: 4 additions & 2 deletions libraries/chain/include/eosio/chain/subjective_billing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <eosio/chain/resource_limits_private.hpp>
#include <eosio/chain/config.hpp>

#include <fc/time.hpp>

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/hashed_index.hpp>
Expand Down Expand Up @@ -107,7 +109,7 @@ class subjective_billing {
void disable_account( chain::account_name a ) { _disabled_accounts.emplace( a ); }
bool is_account_disabled(const chain::account_name& a ) const { return _disabled || _disabled_accounts.count( a ); }

void subjective_bill( const chain::transaction_id_type& id, const fc::time_point& expire,
void subjective_bill( const chain::transaction_id_type& id, fc::time_point_sec expire,
const chain::account_name& first_auth, const fc::microseconds& elapsed )
{
if( !_disabled && !_disabled_accounts.count( first_auth ) ) {
Expand All @@ -116,7 +118,7 @@ class subjective_billing {
trx_cache_entry{id,
first_auth,
bill,
expire} );
expire.to_time_point()} );
if( p.second ) {
_account_subjective_bill_cache[first_auth].pending_cpu_us += bill;
}
Expand Down
16 changes: 6 additions & 10 deletions libraries/chain/include/eosio/chain/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,12 @@ namespace eosio::chain {
using bls_gt_type = bls12_381::fp12;
using bls_fp_type = bls12_381::fp;
using bls_fp2_type = bls12_381::fp2;

#if BOOST_VERSION >= 107100
// configurable boost deque performs much better than std::deque in our use cases
using block_1024_option_t = boost::container::deque_options< boost::container::block_size<1024u> >::type;
template<typename T>
using deque = boost::container::deque< T, void, block_1024_option_t >;
#else
template<typename T>
using deque = std::deque<T>;
#endif

// configurable boost deque (for boost >= 1.71) performs much better than std::deque in our use cases
using block_1024_option_t = boost::container::deque_options< boost::container::block_size<1024u> >::type;
template<typename T>
using deque = boost::container::deque< T, void, block_1024_option_t >;

struct void_t{};

using chainbase::allocator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class unapplied_transaction_queue {
auto& persisted_by_expiry = queue.get<by_expiry>();
while( !persisted_by_expiry.empty() ) {
const auto& itr = persisted_by_expiry.begin();
if( itr->expiration() > pending_block_time ) {
if( itr->expiration().to_time_point() > pending_block_time ) {
break;
}
if( yield() ) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/libfc/include/fc/io/raw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace fc {
{ try {
uint32_t sec;
s.read( (char*)&sec, sizeof(sec) );
tp = fc::time_point() + fc::seconds(sec);
tp = fc::time_point_sec{sec};
} FC_RETHROW_EXCEPTIONS( warn, "" ) }

template<typename Stream>
Expand Down
29 changes: 6 additions & 23 deletions libraries/libfc/include/fc/time.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <stdint.h>
#include <fc/string.hpp>
#include <cstdint>
#include <string>

#ifdef _MSC_VER
#pragma warning (push)
Expand Down Expand Up @@ -46,7 +46,7 @@ namespace fc {
static constexpr time_point maximum() { return time_point( microseconds::maximum() ); }
static constexpr time_point min() { return time_point(); }

operator std::string()const;
std::string to_iso_string()const;
static time_point from_iso_string( const std::string& s );

constexpr const microseconds& time_since_epoch()const { return elapsed; }
Expand Down Expand Up @@ -78,42 +78,25 @@ namespace fc {
constexpr explicit time_point_sec(uint32_t seconds )
:utc_seconds(seconds){}

constexpr time_point_sec( const time_point& t )
constexpr explicit time_point_sec( const time_point& t )
:utc_seconds( t.time_since_epoch().count() / 1000000ll ){}

static constexpr time_point_sec maximum() { return time_point_sec(0xffffffff); }
static constexpr time_point_sec min() { return time_point_sec(0); }

constexpr operator time_point()const { return time_point( fc::seconds( utc_seconds) ); }
constexpr time_point to_time_point()const { return time_point( fc::seconds( utc_seconds) ); }
constexpr uint32_t sec_since_epoch()const { return utc_seconds; }

constexpr time_point_sec operator = ( const fc::time_point& t )
{
utc_seconds = t.time_since_epoch().count() / 1000000ll;
return *this;
}
constexpr friend bool operator < ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds < b.utc_seconds; }
constexpr friend bool operator > ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds > b.utc_seconds; }
constexpr friend bool operator <= ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds <= b.utc_seconds; }
constexpr friend bool operator >= ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds >= b.utc_seconds; }
constexpr friend bool operator == ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds == b.utc_seconds; }
constexpr friend bool operator != ( const time_point_sec& a, const time_point_sec& b ) { return a.utc_seconds != b.utc_seconds; }
constexpr time_point_sec& operator += ( uint32_t m ) { utc_seconds+=m; return *this; }
constexpr time_point_sec& operator += ( microseconds m ) { utc_seconds+=m.to_seconds(); return *this; }
constexpr time_point_sec& operator -= ( uint32_t m ) { utc_seconds-=m; return *this; }
constexpr time_point_sec& operator -= ( microseconds m ) { utc_seconds-=m.to_seconds(); return *this; }
constexpr time_point_sec operator +( uint32_t offset )const { return time_point_sec(utc_seconds + offset); }
constexpr time_point_sec operator -( uint32_t offset )const { return time_point_sec(utc_seconds - offset); }

friend constexpr time_point operator + ( const time_point_sec& t, const microseconds& m ) { return time_point(t) + m; }
friend constexpr time_point operator - ( const time_point_sec& t, const microseconds& m ) { return time_point(t) - m; }
friend constexpr microseconds operator - ( const time_point_sec& t, const time_point_sec& m ) { return time_point(t) - time_point(m); }
friend constexpr microseconds operator - ( const time_point& t, const time_point_sec& m ) { return time_point(t) - time_point(m); }

std::string to_non_delimited_iso_string()const;
std::string to_iso_string()const;

operator std::string()const;
static time_point_sec from_iso_string( const std::string& s );

private:
Expand All @@ -124,7 +107,7 @@ namespace fc {
* e.g., "4 hours ago", "2 months ago", etc.
*/
std::string get_approximate_relative_time_string(const time_point_sec& event_time,
const time_point_sec& relative_to_time = fc::time_point::now(),
const time_point_sec& relative_to_time = fc::time_point_sec{fc::time_point::now()},
const std::string& ago = " ago");
std::string get_approximate_relative_time_string(const time_point& event_time,
const time_point& relative_to_time = fc::time_point::now(),
Expand Down
2 changes: 1 addition & 1 deletion libraries/libfc/src/log/console_appender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace fc {
}
line += fixed_size( 5, context.get_log_level().to_string() ); line += ' ';
// use now() instead of context.get_timestamp() because log_message construction can include user provided long running calls
line += std::string( time_point::now() ); line += ' ';
line += time_point::now().to_iso_string(); line += ' ';
line += fixed_size( 9, context.get_thread_name() ); line += ' ';
line += fixed_size( 29, file_line ); line += ' ';

Expand Down
19 changes: 7 additions & 12 deletions libraries/libfc/src/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ namespace fc {
return boost::posix_time::to_iso_extended_string( ptime );
}

time_point_sec::operator std::string()const
{
return this->to_iso_string();
}

time_point_sec time_point_sec::from_iso_string( const std::string& s )
{ try {
static boost::posix_time::ptime epoch = boost::posix_time::from_time_t( 0 );
Expand All @@ -47,18 +42,18 @@ namespace fc {
return fc::time_point_sec( (pt - epoch).total_seconds() );
} FC_RETHROW_EXCEPTIONS( warn, "unable to convert ISO-formatted string to fc::time_point_sec" ) }

time_point::operator std::string()const
std::string time_point::to_iso_string()const
{
auto count = elapsed.count();
if (count >= 0) {
uint64_t secs = (uint64_t)count / 1000000ULL;
uint64_t msec = ((uint64_t)count % 1000000ULL) / 1000ULL;
std::string padded_ms = to_string((uint64_t)(msec + 1000ULL)).substr(1);
std::string padded_ms = fc::to_string((uint64_t)(msec + 1000ULL)).substr(1);
const auto ptime = boost::posix_time::from_time_t(time_t(secs));
return boost::posix_time::to_iso_extended_string(ptime) + "." + padded_ms;
} else {
// negative time_points serialized as "durations" in the ISO form with boost
// this is not very human readable but fits the precedent set by the above
// this is not very human-readable but fits the precedent set by the above
auto as_duration = boost::posix_time::microseconds(count);
return boost::posix_time::to_iso_string(as_duration);
}
Expand All @@ -68,23 +63,23 @@ namespace fc {
{ try {
auto dot = s.find( '.' );
if( dot == std::string::npos )
return time_point( time_point_sec::from_iso_string( s ) );
return time_point_sec::from_iso_string( s ).to_time_point();
else {
auto ms = s.substr( dot );
ms[0] = '1';
while( ms.size() < 4 ) ms.push_back('0');
return time_point( time_point_sec::from_iso_string( s ) ) + milliseconds( to_int64(ms) - 1000 );
return time_point_sec::from_iso_string( s ).to_time_point() + milliseconds( to_int64(ms) - 1000 );
}
} FC_RETHROW_EXCEPTIONS( warn, "unable to convert ISO-formatted string to fc::time_point" ) }

void to_variant( const fc::time_point& t, variant& v ) {
v = std::string( t );
v = t.to_iso_string();
}
void from_variant( const fc::variant& v, fc::time_point& t ) {
t = fc::time_point::from_iso_string( v.as_string() );
}
void to_variant( const fc::time_point_sec& t, variant& v ) {
v = std::string( t );
v = t.to_iso_string();
}
void from_variant( const fc::variant& v, fc::time_point_sec& t ) {
t = fc::time_point_sec::from_iso_string( v.as_string() );
Expand Down
2 changes: 1 addition & 1 deletion libraries/testing/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ namespace eosio { namespace testing {


void base_tester::set_transaction_headers( transaction& trx, uint32_t expiration, uint32_t delay_sec ) const {
trx.expiration = control->head_block_time() + fc::seconds(expiration);
trx.expiration = fc::time_point_sec{control->head_block_time() + fc::seconds(expiration)};
trx.set_reference_block( control->head_block_id() );

trx.max_net_usage_words = 0; // No limit
Expand Down
4 changes: 2 additions & 2 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ void chain_plugin::plugin_startup()

if (my->genesis) {
ilog("Blockchain started; head block is #${num}, genesis timestamp is ${ts}",
("num", my->chain->head_block_num())("ts", (std::string)my->genesis->initial_timestamp));
("num", my->chain->head_block_num())("ts", my->genesis->initial_timestamp));
}
else {
ilog("Blockchain started; head block is #${num}", ("num", my->chain->head_block_num()));
Expand Down Expand Up @@ -1305,7 +1305,7 @@ read_only::get_transaction_status(const read_only::get_transaction_status_params
trx_block_valid ? std::optional<uint32_t>(chain::block_header::num_from_id(trx_st->block_id)) : std::optional<uint32_t>{},
trx_block_valid ? std::optional<chain::block_id_type>(trx_st->block_id) : std::optional<chain::block_id_type>{},
trx_block_valid ? std::optional<fc::time_point>(trx_st->block_timestamp) : std::optional<fc::time_point>{},
trx_st ? std::optional<fc::time_point_sec>(trx_st->expiration) : std::optional<fc::time_point_sec>{},
trx_st ? std::optional<fc::time_point>(trx_st->expiration) : std::optional<fc::time_point>{},
chain::block_header::num_from_id(ch_state.head_id),
ch_state.head_id,
ch_state.head_block_timestamp,
Expand Down
Loading

0 comments on commit 3268500

Please sign in to comment.