diff --git a/contracts/eosio.system/voting.cpp b/contracts/eosio.system/voting.cpp index 8eb98731196..4b850c2dbad 100644 --- a/contracts/eosio.system/voting.cpp +++ b/contracts/eosio.system/voting.cpp @@ -122,7 +122,7 @@ namespace eosiosystem { double stake2vote( int64_t staked ) { /// TODO subtract 2080 brings the large numbers closer to this decade - double weight = int64_t( (now() / (seconds_per_day * 7)) ) / double( 52 ); + double weight = int64_t( (now() - (block_timestamp::block_timestamp_epoch / 1000)) / (seconds_per_day * 7) ) / double( 52 ); return double(staked) * std::pow( 2, weight ); } /** diff --git a/contracts/eosiolib/time.hpp b/contracts/eosiolib/time.hpp index 47b4d1f32a1..ff9d0e47757 100644 --- a/contracts/eosiolib/time.hpp +++ b/contracts/eosiolib/time.hpp @@ -156,11 +156,12 @@ namespace eosio { bool operator ==( const block_timestamp& t )const { return slot == t.slot; } bool operator !=( const block_timestamp& t )const { return slot != t.slot; } uint32_t slot; + static constexpr int32_t block_interval_ms = 500; + static constexpr int64_t block_timestamp_epoch = 946684800000ll; // epoch is year 2000 EOSLIB_SERIALIZE( block_timestamp, (slot) ) private: - static constexpr int32_t block_interval_ms = 500; - static constexpr int64_t block_timestamp_epoch = 946684800000ll; // epoch is year 2000 + void set_time_point(const time_point& t) { int64_t micro_since_epoch = t.time_since_epoch().count(); diff --git a/unittests/eosio.system_tests.cpp b/unittests/eosio.system_tests.cpp index db766b8da70..fb061d05275 100644 --- a/unittests/eosio.system_tests.cpp +++ b/unittests/eosio.system_tests.cpp @@ -353,7 +353,7 @@ class eosio_system_tester : public TESTER { double stake2votes( asset stake ) { auto now = control->pending_block_time().time_since_epoch().count() / 1000000; - return stake.amount * pow(2, int64_t(now/ (86400 * 7))/ double(52) ); // 52 week periods (i.e. ~years) + return stake.amount * pow(2, int64_t((now - (config::block_timestamp_epoch / 1000)) / (86400 * 7))/ double(52) ); // 52 week periods (i.e. ~years) } double stake2votes( const string& s ) {