Skip to content

Commit

Permalink
Merge pull request EOSIO#3199 from EOSIO/3119
Browse files Browse the repository at this point in the history
Adjust voting weight
  • Loading branch information
bytemaster authored May 18, 2018
2 parents 818fa8c + 49b8961 commit ff478bb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion contracts/eosio.system/voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
/**
Expand Down
5 changes: 3 additions & 2 deletions contracts/eosiolib/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion unittests/eosio.system_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down

0 comments on commit ff478bb

Please sign in to comment.