From 0e3d87eaad6e80eac1062447d8ced2b7d9a7a446 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Thu, 31 Jan 2019 20:32:19 -0300 Subject: [PATCH] refactor calculate_vesting_factor to consider if voted in last periods for coefficient calculation, fix the tests accordingly, change hardfork date --- libraries/chain/db_maint.cpp | 27 +++++-- libraries/chain/hardfork.d/GPOS.hf | 4 +- tests/tests/gpos_tests.cpp | 117 +++++++++++++++++++++-------- 3 files changed, 108 insertions(+), 40 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index fa8bd1b1..57cb421f 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -752,24 +752,35 @@ double calculate_vesting_factor(const database& d, const account_object& stake_a std::iota(period_list.begin(), period_list.end(), 1); std::for_each(period_list.begin(), period_list.end(),[&](uint32_t period) { - if(seconds_since_period_start > vesting_subperiod * (period - 1) && + if(seconds_since_period_start >= vesting_subperiod * (period - 1) && seconds_since_period_start < vesting_subperiod * period) current_subperiod = period; }); if(current_subperiod == 0 || current_subperiod > number_of_subperiods) return 0; + if(last_date_voted < period_start) return 0; - double numerator = number_of_subperiods - current_subperiod + 1; + double numerator = number_of_subperiods; - auto last_period_start = period_start + fc::seconds(vesting_subperiod * (current_subperiod - 1)); - auto last_period_end = period_start + fc::seconds(vesting_subperiod * (current_subperiod)); + if(current_subperiod > 1) { + std::list subperiod_list(current_subperiod - 1); + std::iota(subperiod_list.begin(), subperiod_list.end(), 2); + subperiod_list.reverse(); - // reset n if account voted last period - if (last_date_voted < last_period_start && last_date_voted >= last_period_end) - numerator = number_of_subperiods; + for(auto subperiod: subperiod_list) + { + numerator--; + auto last_period_start = period_start + fc::seconds(vesting_subperiod * (subperiod - 1)); + auto last_period_end = period_start + fc::seconds(vesting_subperiod * (subperiod)); + + if (last_date_voted > last_period_start && last_date_voted <= last_period_end) { + numerator++; + break; + } + } + } vesting_factor = numerator / number_of_subperiods; - return vesting_factor; } diff --git a/libraries/chain/hardfork.d/GPOS.hf b/libraries/chain/hardfork.d/GPOS.hf index 3137123f..ad914bec 100644 --- a/libraries/chain/hardfork.d/GPOS.hf +++ b/libraries/chain/hardfork.d/GPOS.hf @@ -1,4 +1,4 @@ -// GPOS HARDFORK Friday, February 1, 2019 12:00:00 AM +// GPOS HARDFORK Friday, February 15, 2019 5:08:21 PM #ifndef HARDFORK_GPOS_TIME -#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1548979200 )) +#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1550250501 )) #endif \ No newline at end of file diff --git a/tests/tests/gpos_tests.cpp b/tests/tests/gpos_tests.cpp index b283aceb..cf133473 100644 --- a/tests/tests/gpos_tests.cpp +++ b/tests/tests/gpos_tests.cpp @@ -117,6 +117,13 @@ struct gpos_fixture: database_fixture PUSH_TX( db, trx, ~0 ); trx.clear(); } + + void advance_x_maint(int periods) + { + for(int i=0; i