From 88f18d16a7d971832c7c1435488d1b02d88c202c Mon Sep 17 00:00:00 2001 From: Alfredo Date: Sat, 29 Dec 2018 14:43:41 -0300 Subject: [PATCH 01/31] add gpos hardfork date --- libraries/chain/hardfork.d/GPOS.hf | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 libraries/chain/hardfork.d/GPOS.hf diff --git a/libraries/chain/hardfork.d/GPOS.hf b/libraries/chain/hardfork.d/GPOS.hf new file mode 100644 index 000000000..c9855f5d7 --- /dev/null +++ b/libraries/chain/hardfork.d/GPOS.hf @@ -0,0 +1,4 @@ +// GPOS HARDFORK Saturday, January 5, 2019 4:39:39 PM +#ifndef HARDFORK_GPOS_TIME +#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1546706379 )) +#endif \ No newline at end of file From 62d2c1c63b4d6689e3a80884463d894b6e190dc5 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Sat, 29 Dec 2018 21:19:42 -0300 Subject: [PATCH 02/31] add global gpos parameters --- libraries/chain/include/graphene/chain/config.hpp | 2 ++ .../include/graphene/chain/protocol/chain_parameters.hpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index d85cc093e..d5570397b 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -226,3 +226,5 @@ #define TOURNAMENT_MAX_WHITELIST_LENGTH 1000 #define TOURNAMENT_MAX_START_TIME_IN_FUTURE (60*60*24*7*4) // 1 month #define TOURNAMENT_MAX_START_DELAY (60*60*24*7) // 1 week +#define GPOS_PERIOD (60*60*24*30*6) // 6 months +#define GPOS_SUBPERIOD (60*60*24*30) // 1 month diff --git a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp index b2551e447..ef12e65e8 100644 --- a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp +++ b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp @@ -27,6 +27,8 @@ #include #include +#include + namespace graphene { namespace chain { struct fee_schedule; } } namespace graphene { namespace chain { @@ -86,6 +88,10 @@ namespace graphene { namespace chain { uint32_t maximum_tournament_start_time_in_future = TOURNAMENT_MAX_START_TIME_IN_FUTURE; uint32_t maximum_tournament_start_delay = TOURNAMENT_MAX_START_DELAY; uint16_t maximum_tournament_number_of_wins = TOURNAMENT_MAX_NUMBER_OF_WINS; + /* gpos parameters constraints */ + uint32_t gpos_period = GPOS_PERIOD; /// toal seconds of current gpos period + uint32_t gpos_subperiod = GPOS_SUBPERIOD; /// gpos_period % gpos_subperiod = 0 + time_point_sec gpos_period_start = HARDFORK_GPOS_TIME; /// current period start date extension extensions; /** defined in fee_schedule.cpp */ @@ -161,5 +167,8 @@ FC_REFLECT( graphene::chain::chain_parameters, (maximum_tournament_start_time_in_future) (maximum_tournament_start_delay) (maximum_tournament_number_of_wins) + (gpos_period) + (gpos_subperiod) + (gpos_period_start) (extensions) ) From 604fbed49824bac4b337c84e32f5941e40ed0caf Mon Sep 17 00:00:00 2001 From: Alfredo Date: Sun, 30 Dec 2018 18:01:57 -0300 Subject: [PATCH 03/31] add type field to vesting balances --- libraries/chain/db_maint.cpp | 8 ++++---- .../chain/include/graphene/chain/protocol/vesting.hpp | 9 +++++++-- .../include/graphene/chain/vesting_balance_object.hpp | 8 ++++++++ libraries/chain/vesting_balance_evaluator.cpp | 1 + 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index b768460af..89fae5ca4 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -764,9 +764,9 @@ void schedule_pending_dividend_balances(database& db, #ifdef USE_VESTING_OBJECT_BY_ASSET_BALANCE_INDEX // get only once a collection of accounts that hold nonzero vesting balances of the dividend asset auto vesting_balances_begin = - vesting_index.indices().get().lower_bound(boost::make_tuple(dividend_holder_asset_obj.id)); + vesting_index.indices().get().lower_bound(boost::make_tuple(dividend_holder_asset_obj.id, vesting_balance_type::unspecified)); auto vesting_balances_end = - vesting_index.indices().get().upper_bound(boost::make_tuple(dividend_holder_asset_obj.id, share_type())); + vesting_index.indices().get().upper_bound(boost::make_tuple(dividend_holder_asset_obj.id, vesting_balance_type::unspecified, share_type())); for (const vesting_balance_object& vesting_balance_obj : boost::make_iterator_range(vesting_balances_begin, vesting_balances_end)) { vesting_amounts[vesting_balance_obj.owner] += vesting_balance_obj.balance.amount; @@ -1247,9 +1247,9 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g const vesting_balance_index& vesting_index = d.get_index_type(); #ifdef USE_VESTING_OBJECT_BY_ASSET_BALANCE_INDEX auto vesting_balances_begin = - vesting_index.indices().get().lower_bound(boost::make_tuple(asset_id_type())); + vesting_index.indices().get().lower_bound(boost::make_tuple(asset_id_type(), vesting_balance_type::unspecified)); auto vesting_balances_end = - vesting_index.indices().get().upper_bound(boost::make_tuple(asset_id_type(), share_type())); + vesting_index.indices().get().upper_bound(boost::make_tuple(asset_id_type(), vesting_balance_type::unspecified, share_type())); for (const vesting_balance_object& vesting_balance_obj : boost::make_iterator_range(vesting_balances_begin, vesting_balances_end)) { vesting_amounts[vesting_balance_obj.owner] += vesting_balance_obj.balance.amount; diff --git a/libraries/chain/include/graphene/chain/protocol/vesting.hpp b/libraries/chain/include/graphene/chain/protocol/vesting.hpp index 4915b62ec..5a78fd65c 100644 --- a/libraries/chain/include/graphene/chain/protocol/vesting.hpp +++ b/libraries/chain/include/graphene/chain/protocol/vesting.hpp @@ -24,7 +24,9 @@ #pragma once #include -namespace graphene { namespace chain { +namespace graphene { namespace chain { + + enum class vesting_balance_type { unspecified, gpos }; struct linear_vesting_policy_initializer { @@ -72,6 +74,7 @@ namespace graphene { namespace chain { account_id_type owner; ///< Who is able to withdraw the balance asset amount; vesting_policy_initializer policy; + vesting_balance_type balance_type; account_id_type fee_payer()const { return creator; } void validate()const @@ -112,9 +115,11 @@ namespace graphene { namespace chain { FC_REFLECT( graphene::chain::vesting_balance_create_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::vesting_balance_withdraw_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::vesting_balance_create_operation, (fee)(creator)(owner)(amount)(policy) ) +FC_REFLECT( graphene::chain::vesting_balance_create_operation, (fee)(creator)(owner)(amount)(policy)(balance_type) ) FC_REFLECT( graphene::chain::vesting_balance_withdraw_operation, (fee)(vesting_balance)(owner)(amount) ) FC_REFLECT(graphene::chain::linear_vesting_policy_initializer, (begin_timestamp)(vesting_cliff_seconds)(vesting_duration_seconds) ) FC_REFLECT(graphene::chain::cdd_vesting_policy_initializer, (start_claim)(vesting_seconds) ) FC_REFLECT_TYPENAME( graphene::chain::vesting_policy_initializer ) + +FC_REFLECT_ENUM( graphene::chain::vesting_balance_type, (unspecified)(gpos) ) diff --git a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp index dc2fe18c3..6e0bd689a 100644 --- a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp +++ b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp @@ -24,6 +24,8 @@ #pragma once #include +#include + #include #include @@ -143,6 +145,9 @@ namespace graphene { namespace chain { /// The vesting policy stores details on when funds vest, and controls when they may be withdrawn vesting_policy policy; + /// We can have 2 types of vesting, gpos and all the rest + vesting_balance_type balance_type = vesting_balance_type::unspecified; + vesting_balance_object() {} ///@brief Deposit amount into vesting balance, requiring it to vest before withdrawal @@ -185,12 +190,14 @@ namespace graphene { namespace chain { composite_key< vesting_balance_object, member_offset, + member, member_offset //member //member_offset >, composite_key_compare< std::less< asset_id_type >, + std::less< vesting_balance_type >, std::greater< share_type > //std::less< account_id_type > > @@ -224,4 +231,5 @@ FC_REFLECT_DERIVED(graphene::chain::vesting_balance_object, (graphene::db::objec (owner) (balance) (policy) + (balance_type) ) diff --git a/libraries/chain/vesting_balance_evaluator.cpp b/libraries/chain/vesting_balance_evaluator.cpp index ee918fd16..59967d30e 100644 --- a/libraries/chain/vesting_balance_evaluator.cpp +++ b/libraries/chain/vesting_balance_evaluator.cpp @@ -93,6 +93,7 @@ object_id_type vesting_balance_create_evaluator::do_apply( const vesting_balance obj.owner = op.owner; obj.balance = op.amount; op.policy.visit( init_policy_visitor( obj.policy, op.amount.amount, now ) ); + obj.balance_type = op.balance_type; } ); From 57a54f571488c6263b964e345dfa48ab98a9a6d6 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Mon, 31 Dec 2018 11:59:51 -0300 Subject: [PATCH 04/31] add fixed policy to gpos vesting balances --- libraries/chain/vesting_balance_evaluator.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libraries/chain/vesting_balance_evaluator.cpp b/libraries/chain/vesting_balance_evaluator.cpp index 59967d30e..1b51e3732 100644 --- a/libraries/chain/vesting_balance_evaluator.cpp +++ b/libraries/chain/vesting_balance_evaluator.cpp @@ -92,7 +92,19 @@ object_id_type vesting_balance_create_evaluator::do_apply( const vesting_balance // If making changes to this logic, check if those changes should also be made there as well. obj.owner = op.owner; obj.balance = op.amount; - op.policy.visit( init_policy_visitor( obj.policy, op.amount.amount, now ) ); + if(op.balance_type == vesting_balance_type::gpos) + { + const auto &gpo = d.get_global_properties(); + // forcing gpos policy + linear_vesting_policy p; + p.begin_timestamp = now; + p.vesting_cliff_seconds = gpo.parameters.gpos_subperiod; + p.vesting_duration_seconds = gpo.parameters.gpos_subperiod; + obj.policy = p; + } + else { + op.policy.visit(init_policy_visitor(obj.policy, op.amount.amount, now)); + } obj.balance_type = op.balance_type; } ); From 46467a7bbe787581d02c74a51b936a41b4809d40 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Mon, 31 Dec 2018 12:01:31 -0300 Subject: [PATCH 05/31] only allow gpos balance creation after HF --- libraries/chain/vesting_balance_evaluator.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/chain/vesting_balance_evaluator.cpp b/libraries/chain/vesting_balance_evaluator.cpp index 1b51e3732..c3a833cd4 100644 --- a/libraries/chain/vesting_balance_evaluator.cpp +++ b/libraries/chain/vesting_balance_evaluator.cpp @@ -42,6 +42,9 @@ void_result vesting_balance_create_evaluator::do_evaluate( const vesting_balance FC_ASSERT( d.get_balance( creator_account.id, op.amount.asset_id ) >= op.amount ); FC_ASSERT( !op.amount.asset_id(d).is_transfer_restricted() ); + if(d.head_block_time() < HARDFORK_GPOS_TIME) // Todo: can be removed after gpos hf time pass + FC_ASSERT( op.balance_type == vesting_balance_type::unspecified); + return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } From 3de55137d5ccdb86481e655250a12a00353bdfbc Mon Sep 17 00:00:00 2001 From: Alfredo Date: Mon, 31 Dec 2018 12:04:04 -0300 Subject: [PATCH 06/31] bump the database --- libraries/chain/include/graphene/chain/config.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index d5570397b..7b3e87439 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -151,7 +151,7 @@ #define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4 #define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3 -#define GRAPHENE_CURRENT_DB_VERSION "PPY2.1" +#define GRAPHENE_CURRENT_DB_VERSION "PPY2.2" #define GRAPHENE_IRREVERSIBLE_THRESHOLD (70 * GRAPHENE_1_PERCENT) From 6d0128614093025bd389418ad5fed51d16ec17c4 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Mon, 31 Dec 2018 17:48:26 -0300 Subject: [PATCH 07/31] prepare to pay dividends only to vested gpos balances after hf --- libraries/chain/db_maint.cpp | 55 +++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 89fae5ca4..daa1f91e3 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -754,34 +754,41 @@ void schedule_pending_dividend_balances(database& db, balance_index.indices().get().lower_bound(boost::make_tuple(dividend_holder_asset_obj.id)); auto holder_balances_end = balance_index.indices().get().upper_bound(boost::make_tuple(dividend_holder_asset_obj.id, share_type())); - uint32_t holder_account_count = std::distance(holder_balances_begin, holder_balances_end); uint64_t distribution_base_fee = gpo.parameters.current_fees->get().distribution_base_fee; uint32_t distribution_fee_per_holder = gpo.parameters.current_fees->get().distribution_fee_per_holder; - // the fee, in BTS, for distributing each asset in the account - uint64_t total_fee_per_asset_in_core = distribution_base_fee + holder_account_count * (uint64_t)distribution_fee_per_holder; std::map vesting_amounts; + + auto balance_type = vesting_balance_type::unspecified; + if(db.head_block_time() >= HARDFORK_GPOS_TIME) + balance_type = vesting_balance_type::gpos; + + uint32_t holder_account_count = 0; #ifdef USE_VESTING_OBJECT_BY_ASSET_BALANCE_INDEX // get only once a collection of accounts that hold nonzero vesting balances of the dividend asset auto vesting_balances_begin = - vesting_index.indices().get().lower_bound(boost::make_tuple(dividend_holder_asset_obj.id, vesting_balance_type::unspecified)); + vesting_index.indices().get().lower_bound(boost::make_tuple(dividend_holder_asset_obj.id, balance_type)); auto vesting_balances_end = - vesting_index.indices().get().upper_bound(boost::make_tuple(dividend_holder_asset_obj.id, vesting_balance_type::unspecified, share_type())); + vesting_index.indices().get().upper_bound(boost::make_tuple(dividend_holder_asset_obj.id, balance_type, share_type())); + for (const vesting_balance_object& vesting_balance_obj : boost::make_iterator_range(vesting_balances_begin, vesting_balances_end)) { vesting_amounts[vesting_balance_obj.owner] += vesting_balance_obj.balance.amount; - //dlog("Vesting balance for account: ${owner}, amount: ${amount}", - // ("owner", vesting_balance_obj.owner(db).name) - // ("amount", vesting_balance_obj.balance.amount)); + ++holder_account_count; + dlog("Vesting balance for account: ${owner}, amount: ${amount}", + ("owner", vesting_balance_obj.owner(db).name) + ("amount", vesting_balance_obj.balance.amount)); } #else // get only once a collection of accounts that hold nonzero vesting balances of the dividend asset const auto& vesting_balances = vesting_index.indices().get(); for (const vesting_balance_object& vesting_balance_obj : vesting_balances) { - if (vesting_balance_obj.balance.asset_id == dividend_holder_asset_obj.id && vesting_balance_obj.balance.amount) + if (vesting_balance_obj.balance.asset_id == dividend_holder_asset_obj.id && vesting_balance_obj.balance.amount && + vesting_balance_object.balance_type == balance_type) { vesting_amounts[vesting_balance_obj.owner] += vesting_balance_obj.balance.amount; + ++gpos_holder_account_count; dlog("Vesting balance for account: ${owner}, amount: ${amount}", ("owner", vesting_balance_obj.owner(db).name) ("amount", vesting_balance_obj.balance.amount)); @@ -789,6 +796,11 @@ void schedule_pending_dividend_balances(database& db, } #endif + if(db.head_block_time() < HARDFORK_GPOS_TIME) + holder_account_count = std::distance(holder_balances_begin, holder_balances_end); + // the fee, in BTS, for distributing each asset in the account + uint64_t total_fee_per_asset_in_core = distribution_base_fee + holder_account_count * (uint64_t)distribution_fee_per_holder; + auto current_distribution_account_balance_iter = current_distribution_account_balance_range.first; auto previous_distribution_account_balance_iter = previous_distribution_account_balance_range.first; dlog("Current balances in distribution account: ${current}, Previous balances: ${previous}", @@ -799,14 +811,23 @@ void schedule_pending_dividend_balances(database& db, // accounts other than the distribution account (it would be silly to distribute dividends back to // the distribution account) share_type total_balance_of_dividend_asset; - for (const account_balance_object& holder_balance_object : boost::make_iterator_range(holder_balances_begin, holder_balances_end)) - if (holder_balance_object.owner != dividend_data.dividend_distribution_account) - { - total_balance_of_dividend_asset += holder_balance_object.balance; - auto itr = vesting_amounts.find(holder_balance_object.owner); - if (itr != vesting_amounts.end()) - total_balance_of_dividend_asset += itr->second; - } + if(db.head_block_time() >= HARDFORK_GPOS_TIME && dividend_holder_asset_obj.symbol == GRAPHENE_SYMBOL) { // only core + for (const vesting_balance_object &holder_balance_object : boost::make_iterator_range(vesting_balances_begin, + vesting_balances_end)) + if (holder_balance_object.owner != dividend_data.dividend_distribution_account) { + total_balance_of_dividend_asset += holder_balance_object.balance.amount; + } + } + else { + for (const account_balance_object &holder_balance_object : boost::make_iterator_range(holder_balances_begin, + holder_balances_end)) + if (holder_balance_object.owner != dividend_data.dividend_distribution_account) { + total_balance_of_dividend_asset += holder_balance_object.balance; + auto itr = vesting_amounts.find(holder_balance_object.owner); + if (itr != vesting_amounts.end()) + total_balance_of_dividend_asset += itr->second; + } + } // loop through all of the assets currently or previously held in the distribution account while (current_distribution_account_balance_iter != current_distribution_account_balance_range.second || previous_distribution_account_balance_iter != previous_distribution_account_balance_range.second) From 602b8530daa7b9fc51a382fd69f39e34d8343f84 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Mon, 31 Dec 2018 18:17:52 -0300 Subject: [PATCH 08/31] implement functions for gpos --- libraries/chain/db_maint.cpp | 201 ++++++++++++++++++++++++++++------- 1 file changed, 163 insertions(+), 38 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index daa1f91e3..15a72afe9 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -725,6 +725,109 @@ void deprecate_annual_members( database& db ) return; } +double calculate_vesting_factor(const database& d, const account_object& stake_account) +{ + // get last time voted form stats + const auto &stats = stake_account.statistics(d); + fc::time_point_sec last_date_voted = stats.last_vote_time; + + // get global data related to gpos + const auto &gpo = d.get_global_properties(); + const auto vesting_period = gpo.parameters.gpos_period; + const auto vesting_subperiod = gpo.parameters.gpos_subperiod; + const auto period_start = time_point_sec(gpo.parameters.gpos_period_start); + + // variables needed + const fc::time_point_sec period_end = period_start + vesting_period; + const auto number_of_subperiods = vesting_period / vesting_subperiod; + const auto now = d.head_block_time(); + double vesting_factor; + auto seconds_since_period_start = now.sec_since_epoch() - period_start.sec_since_epoch(); + + FC_ASSERT(period_start <= now && now <= period_end); + + // get in what period we are + uint32_t current_period = 0; + std::list period_list(number_of_subperiods); + std::iota(period_list.begin(), period_list.end(), 1); // todo: std::iota(period_list, 1); ?? + + std::for_each(period_list.begin(), period_list.end(),[&](uint32_t period) { + if(seconds_since_period_start > vesting_subperiod * (period - 1) && + seconds_since_period_start < vesting_subperiod * period) + current_period = period; + }); + + if(current_period == 0 || current_period > number_of_subperiods) return 0; + + // coefficient calculation is: (n-1)/number_of_subperiods + double n = number_of_subperiods + 1; + if (current_period > number_of_subperiods) // exception maybe? + return 0; + + auto period = std::find_if(period_list.begin(), period_list.end(),[&](uint32_t p) { + return (p == current_period); + }); + + // todo: improve this loop + std::list subperiod_list(*period); + std::iota(subperiod_list.begin(), subperiod_list.end(), 1); + + for(auto subperiod: subperiod_list) + { + if (current_period - subperiod > 0) { + n = number_of_subperiods - current_period + 2; + + if (last_date_voted < + (period_start + fc::seconds(vesting_subperiod * (current_period - subperiod - 1))) && + last_date_voted >= (period_start + fc::seconds(vesting_subperiod * (current_period - subperiod))) && + last_date_voted >= period_start) { + + n = number_of_subperiods + 1; + break; + } + } + } + vesting_factor = (n - 1) / number_of_subperiods; + + return vesting_factor; +} + +share_type credit_account(database& db, const account_id_type owner_id, const std::string owner_name, + share_type remaining_amount_to_distribute, + const share_type shares_to_credit, const asset_id_type payout_asset_type, + const pending_dividend_payout_balance_for_holder_object_index& pending_payout_balance_index, + const asset_id_type dividend_id) { + + //wdump((delta_balance.value)(holder_balance)(total_balance_of_dividend_asset)); + if (shares_to_credit.value) { + + remaining_amount_to_distribute -= shares_to_credit; + + dlog("Crediting account ${account} with ${amount}", + ("account", owner_name) + ("amount", asset(shares_to_credit, payout_asset_type))); + auto pending_payout_iter = + pending_payout_balance_index.indices().get().find( + boost::make_tuple(dividend_id, payout_asset_type, + owner_id)); + if (pending_payout_iter == + pending_payout_balance_index.indices().get().end()) + db.create( + [&](pending_dividend_payout_balance_for_holder_object &obj) { + obj.owner = owner_id; + obj.dividend_holder_asset_type = dividend_id; + obj.dividend_payout_asset_type = payout_asset_type; + obj.pending_balance = shares_to_credit; + }); + else + db.modify(*pending_payout_iter, + [&](pending_dividend_payout_balance_for_holder_object &pending_balance) { + pending_balance.pending_balance += shares_to_credit; + }); + } + return remaining_amount_to_distribute; +} + // Schedules payouts from a dividend distribution account to the current holders of the // dividend-paying asset. This takes any deposits made to the dividend distribution account // since the last time it was called, and distributes them to the current owners of the @@ -951,46 +1054,68 @@ void schedule_pending_dividend_balances(database& db, ("total", total_balance_of_dividend_asset)); share_type remaining_amount_to_distribute = delta_balance; - // credit each account with their portion, don't send any back to the dividend distribution account - for (const account_balance_object& holder_balance_object : boost::make_iterator_range(holder_balances_begin, holder_balances_end)) - { - if (holder_balance_object.owner == dividend_data.dividend_distribution_account) continue; - - auto holder_balance = holder_balance_object.balance; - - auto itr = vesting_amounts.find(holder_balance_object.owner); - if (itr != vesting_amounts.end()) - holder_balance += itr->second; - - fc::uint128_t amount_to_credit(delta_balance.value); - amount_to_credit *= holder_balance.value; - amount_to_credit /= total_balance_of_dividend_asset.value; - share_type shares_to_credit((int64_t)amount_to_credit.to_uint64()); - if (shares_to_credit.value) - { - wdump((delta_balance.value)(holder_balance)(total_balance_of_dividend_asset)); - - remaining_amount_to_distribute -= shares_to_credit; - - dlog("Crediting account ${account} with ${amount}", - ("account", holder_balance_object.owner(db).name) - ("amount", asset(shares_to_credit, payout_asset_type))); - auto pending_payout_iter = - pending_payout_balance_index.indices().get().find(boost::make_tuple(dividend_holder_asset_obj.id, payout_asset_type, holder_balance_object.owner)); - if (pending_payout_iter == pending_payout_balance_index.indices().get().end()) - db.create( [&]( pending_dividend_payout_balance_for_holder_object& obj ){ - obj.owner = holder_balance_object.owner; - obj.dividend_holder_asset_type = dividend_holder_asset_obj.id; - obj.dividend_payout_asset_type = payout_asset_type; - obj.pending_balance = shares_to_credit; - }); - else - db.modify(*pending_payout_iter, [&]( pending_dividend_payout_balance_for_holder_object& pending_balance ){ - pending_balance.pending_balance += shares_to_credit; - }); + if(db.head_block_time() >= HARDFORK_GPOS_TIME && dividend_holder_asset_obj.symbol == GRAPHENE_SYMBOL) { // core only + // credit each account with their portion, don't send any back to the dividend distribution account + for (const vesting_balance_object &holder_balance_object : boost::make_iterator_range( + vesting_balances_begin, vesting_balances_end)) { + if (holder_balance_object.owner == dividend_data.dividend_distribution_account) continue; + + auto vesting_factor = calculate_vesting_factor(db, holder_balance_object.owner(db)); + + auto holder_balance = holder_balance_object.balance; + + fc::uint128_t amount_to_credit(delta_balance.value); + amount_to_credit *= holder_balance.amount.value; + amount_to_credit /= total_balance_of_dividend_asset.value; + share_type full_shares_to_credit((int64_t) amount_to_credit.to_uint64()); + share_type shares_to_credit = (uint64_t) floor(full_shares_to_credit.value * vesting_factor); + + if (shares_to_credit < full_shares_to_credit) { + // Todo: sending results of decay to committee account, need to change to specified account + dlog("Crediting committee_account with ${amount}", + ("amount", asset(full_shares_to_credit - shares_to_credit, payout_asset_type))); + db.adjust_balance(dividend_data.dividend_distribution_account, + -(full_shares_to_credit - shares_to_credit)); + db.adjust_balance(account_id_type(0), full_shares_to_credit - shares_to_credit); + } + + remaining_amount_to_distribute = credit_account(db, + holder_balance_object.owner, + holder_balance_object.owner(db).name, + remaining_amount_to_distribute, + shares_to_credit, + payout_asset_type, + pending_payout_balance_index, + dividend_holder_asset_obj.id); + } + } + else { + // credit each account with their portion, don't send any back to the dividend distribution account + for (const account_balance_object &holder_balance_object : boost::make_iterator_range( + holder_balances_begin, holder_balances_end)) { + if (holder_balance_object.owner == dividend_data.dividend_distribution_account) continue; + + auto holder_balance = holder_balance_object.balance; + + auto itr = vesting_amounts.find(holder_balance_object.owner); + if (itr != vesting_amounts.end()) + holder_balance += itr->second; + + fc::uint128_t amount_to_credit(delta_balance.value); + amount_to_credit *= holder_balance.value; + amount_to_credit /= total_balance_of_dividend_asset.value; + share_type shares_to_credit((int64_t) amount_to_credit.to_uint64()); + + remaining_amount_to_distribute = credit_account(db, + holder_balance_object.owner, + holder_balance_object.owner(db).name, + remaining_amount_to_distribute, + shares_to_credit, + payout_asset_type, + pending_payout_balance_index, + dividend_holder_asset_obj.id); } } - for (const auto& pending_payout : pending_payout_balance_index.indices()) if (pending_payout.pending_balance.value) dlog("Pending payout: ${account_name} -> ${amount}", From 6b533828db53029702bf1fc690474096b0f54e75 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Mon, 31 Dec 2018 18:20:48 -0300 Subject: [PATCH 09/31] implement rolling_period_start function --- libraries/chain/db_maint.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 15a72afe9..5ffef31ae 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -828,6 +828,24 @@ share_type credit_account(database& db, const account_id_type owner_id, const st return remaining_amount_to_distribute; } +void rolling_period_start(database& db) +{ + if(db.head_block_time() >= HARDFORK_GPOS_TIME) + { + auto period_start = db.get_global_properties().parameters.period_start; + auto vesting_period = db.get_global_properties().parameters.vesting_period; + + auto now = db.head_block_time().sec_since_epoch(); + if(now > (period_start + vesting_period)) + { + // roll + db.modify(db.get_global_properties(), [now](global_property_object& p) { + p.parameters.period_start = now; + }); + } + } +} + // Schedules payouts from a dividend distribution account to the current holders of the // dividend-paying asset. This takes any deposits made to the dividend distribution account // since the last time it was called, and distributes them to the current owners of the @@ -1377,6 +1395,8 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g process_dividend_assets(*this); + rolling_period_start(*this); + struct vote_tally_helper { database& d; const global_property_object& props; From d468b146e878d13d26fd778adf8d81ff22293d63 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Mon, 31 Dec 2018 19:18:00 -0300 Subject: [PATCH 10/31] implement gpos to voting calculations --- libraries/chain/db_maint.cpp | 47 +++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 5ffef31ae..7bb20e4bb 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -832,15 +832,15 @@ void rolling_period_start(database& db) { if(db.head_block_time() >= HARDFORK_GPOS_TIME) { - auto period_start = db.get_global_properties().parameters.period_start; - auto vesting_period = db.get_global_properties().parameters.vesting_period; + auto period_start = db.get_global_properties().parameters.gpos_period_start; + auto vesting_period = db.get_global_properties().parameters.gpos_period; - auto now = db.head_block_time().sec_since_epoch(); - if(now > (period_start + vesting_period)) + auto now = db.head_block_time(); + if(now.sec_since_epoch() > (period_start.sec_since_epoch() + vesting_period)) { // roll db.modify(db.get_global_properties(), [now](global_property_object& p) { - p.parameters.period_start = now; + p.parameters.gpos_period_start = now; }); } } @@ -1410,24 +1410,28 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g d._committee_count_histogram_buffer.resize(props.parameters.maximum_committee_count / 2 + 1); d._total_voting_stake = 0; + auto balance_type = vesting_balance_type::unspecified; + if(d.head_block_time() >= HARDFORK_GPOS_TIME) + balance_type = vesting_balance_type::gpos; + const vesting_balance_index& vesting_index = d.get_index_type(); #ifdef USE_VESTING_OBJECT_BY_ASSET_BALANCE_INDEX auto vesting_balances_begin = - vesting_index.indices().get().lower_bound(boost::make_tuple(asset_id_type(), vesting_balance_type::unspecified)); + vesting_index.indices().get().lower_bound(boost::make_tuple(asset_id_type(), balance_type)); auto vesting_balances_end = - vesting_index.indices().get().upper_bound(boost::make_tuple(asset_id_type(), vesting_balance_type::unspecified, share_type())); + vesting_index.indices().get().upper_bound(boost::make_tuple(asset_id_type(), balance_type, share_type())); for (const vesting_balance_object& vesting_balance_obj : boost::make_iterator_range(vesting_balances_begin, vesting_balances_end)) { vesting_amounts[vesting_balance_obj.owner] += vesting_balance_obj.balance.amount; - //dlog("Vesting balance for account: ${owner}, amount: ${amount}", - // ("owner", vesting_balance_obj.owner(d).name) - // ("amount", vesting_balance_obj.balance.amount)); + dlog("Vesting balance for account: ${owner}, amount: ${amount}", + ("owner", vesting_balance_obj.owner(d).name) + ("amount", vesting_balance_obj.balance.amount)); } #else const auto& vesting_balances = vesting_index.indices().get(); for (const vesting_balance_object& vesting_balance_obj : vesting_balances) { - if (vesting_balance_obj.balance.asset_id == asset_id_type() && vesting_balance_obj.balance.amount) + if (vesting_balance_obj.balance.asset_id == asset_id_type() && vesting_balance_obj.balance.amount && vesting_balance_obj.balance_type == balance_type) { vesting_amounts[vesting_balance_obj.owner] += vesting_balance_obj.balance.amount; dlog("Vesting balance for account: ${owner}, amount: ${amount}", @@ -1455,13 +1459,28 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g const account_object& opinion_account = *opinion_account_ptr; const auto& stats = stake_account.statistics(d); - uint64_t voting_stake = stats.total_core_in_orders.value - + (stake_account.cashback_vb.valid() ? (*stake_account.cashback_vb)(d).balance.amount.value: 0) - + d.get_balance(stake_account.get_id(), asset_id_type()).amount.value; + uint64_t voting_stake = 0; auto itr = vesting_amounts.find(stake_account.id); if (itr != vesting_amounts.end()) voting_stake += itr->second.value; + + if(d.head_block_time() >= HARDFORK_GPOS_TIME) + { + if (itr == vesting_amounts.end()) + return; + + auto vesting_factor = calculate_vesting_factor(d, stake_account); + voting_stake = (uint64_t)floor(voting_stake * vesting_factor); + + } + else + { + voting_stake += stats.total_core_in_orders.value + + (stake_account.cashback_vb.valid() ? (*stake_account.cashback_vb)(d).balance.amount.value : 0) + + d.get_balance(stake_account.get_id(), asset_id_type()).amount.value; + } + for( vote_id_type id : opinion_account.options.votes ) { uint32_t offset = id.instance(); From 83ea345042b8764ec0094a5a7d59d1a4768d7fba Mon Sep 17 00:00:00 2001 From: Alfredo Date: Thu, 3 Jan 2019 14:38:31 -0300 Subject: [PATCH 11/31] hf protection for creating gpos balances in proposals --- libraries/chain/db_maint.cpp | 9 +++------ libraries/chain/proposal_evaluator.cpp | 5 +++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 7bb20e4bb..9aed8b4ec 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -735,7 +735,7 @@ double calculate_vesting_factor(const database& d, const account_object& stake_a const auto &gpo = d.get_global_properties(); const auto vesting_period = gpo.parameters.gpos_period; const auto vesting_subperiod = gpo.parameters.gpos_subperiod; - const auto period_start = time_point_sec(gpo.parameters.gpos_period_start); + const auto period_start = gpo.parameters.gpos_period_start; // variables needed const fc::time_point_sec period_end = period_start + vesting_period; @@ -761,8 +761,6 @@ double calculate_vesting_factor(const database& d, const account_object& stake_a // coefficient calculation is: (n-1)/number_of_subperiods double n = number_of_subperiods + 1; - if (current_period > number_of_subperiods) // exception maybe? - return 0; auto period = std::find_if(period_list.begin(), period_list.end(),[&](uint32_t p) { return (p == current_period); @@ -1393,10 +1391,10 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g distribute_fba_balances(*this); create_buyback_orders(*this); - process_dividend_assets(*this); - rolling_period_start(*this); + process_dividend_assets(*this); + struct vote_tally_helper { database& d; const global_property_object& props; @@ -1472,7 +1470,6 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g auto vesting_factor = calculate_vesting_factor(d, stake_account); voting_stake = (uint64_t)floor(voting_stake * vesting_factor); - } else { diff --git a/libraries/chain/proposal_evaluator.cpp b/libraries/chain/proposal_evaluator.cpp index a6640ea47..8306128dd 100644 --- a/libraries/chain/proposal_evaluator.cpp +++ b/libraries/chain/proposal_evaluator.cpp @@ -135,6 +135,11 @@ struct proposal_operation_hardfork_visitor FC_ASSERT( block_time >= HARDFORK_1000_TIME, "event_update_status_operation not allowed yet!" ); } + void operator()(const vesting_balance_create_operation &vbco) const { + if(block_time < HARDFORK_GPOS_TIME) + FC_ASSERT( vbco.balance_type == vesting_balance_type::unspecified, "balance_type in vesting create not allowed yet!" ); + } + // loop and self visit in proposals void operator()(const proposal_create_operation &v) const { for (const op_wrapper &op : v.proposed_ops) From 49333a2c12cf7a7e559aa7775c11546453ba1d9c Mon Sep 17 00:00:00 2001 From: Alfredo Date: Thu, 3 Jan 2019 15:43:45 -0300 Subject: [PATCH 12/31] add gpos test cases --- tests/tests/gpos_tests.cpp | 785 +++++++++++++++++++++++++++++++++++++ 1 file changed, 785 insertions(+) create mode 100644 tests/tests/gpos_tests.cpp diff --git a/tests/tests/gpos_tests.cpp b/tests/tests/gpos_tests.cpp new file mode 100644 index 000000000..b154eaf40 --- /dev/null +++ b/tests/tests/gpos_tests.cpp @@ -0,0 +1,785 @@ +/* + * Copyright (c) 2018 oxarbitrage 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 +#include +#include + +#include +#include +#include +#include + +#include "../common/database_fixture.hpp" + +using namespace graphene::chain; +using namespace graphene::chain::test; + +struct gpos_fixture: database_fixture +{ + const worker_object& create_worker( const account_id_type owner, const share_type daily_pay, + const fc::microseconds& duration ) { + worker_create_operation op; + op.owner = owner; + op.daily_pay = daily_pay; + op.initializer = vesting_balance_worker_initializer(1); + op.work_begin_date = db.head_block_time(); + op.work_end_date = op.work_begin_date + duration; + trx.operations.push_back(op); + set_expiration(db, trx); + trx.validate(); + processed_transaction ptx = db.push_transaction(trx, ~0); + trx.clear(); + return db.get(ptx.operation_results[0].get()); + } + const vesting_balance_object& create_vesting(const account_id_type owner, const asset amount, + const vesting_balance_type type) + { + vesting_balance_create_operation op; + op.creator = owner; + op.owner = owner; + op.amount = amount; + op.balance_type = type; + + trx.operations.push_back(op); + set_expiration(db, trx); + processed_transaction ptx = PUSH_TX(db, trx, ~0); + trx.clear(); + return db.get(ptx.operation_results[0].get()); + } + + void update_payout_interval(std::string asset_name, fc::time_point start, uint32_t interval) + { + auto dividend_holder_asset_object = get_asset(asset_name); + asset_update_dividend_operation op; + op.issuer = dividend_holder_asset_object.issuer; + op.asset_to_update = dividend_holder_asset_object.id; + op.new_options.next_payout_time = start; + op.new_options.payout_interval = interval; + trx.operations.push_back(op); + set_expiration(db, trx); + PUSH_TX(db, trx, ~0); + trx.operations.clear(); + } + + void update_gpos_global(uint32_t vesting_period, uint32_t vesting_subperiod, fc::time_point_sec period_start) + { + db.modify(db.get_global_properties(), [vesting_period, vesting_subperiod, period_start](global_property_object& p) { + p.parameters.gpos_period = vesting_period; + p.parameters.gpos_subperiod = vesting_subperiod; + p.parameters.gpos_period_start = period_start; + }); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period, vesting_period); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_subperiod, vesting_subperiod); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start.sec_since_epoch(), period_start.sec_since_epoch()); + } + void vote_for(const account_id_type account_id, const vote_id_type vote_for, const fc::ecc::private_key& key) + { + account_update_operation op; + op.account = account_id; + op.new_options = account_id(db).options; + op.new_options->votes.insert(vote_for); + trx.operations.push_back(op); + set_expiration(db, trx); + trx.validate(); + sign(trx, key); + PUSH_TX(db, trx); + trx.clear(); + } + void fill_reserve_pool(const account_id_type account_id, asset amount) + { + asset_reserve_operation op; + op.payer = account_id; + op.amount_to_reserve = amount; + trx.operations.push_back(op); + trx.validate(); + set_expiration(db, trx); + PUSH_TX( db, trx, ~0 ); + trx.clear(); + } +}; + +BOOST_FIXTURE_TEST_SUITE( gpos_tests, gpos_fixture ) + +BOOST_AUTO_TEST_CASE(gpos_vesting_type) +{ + ACTORS((alice)(bob)); + try + { + const auto& core = asset_id_type()(db); + + // send some asset to alice and bob + transfer( committee_account, alice_id, core.amount( 1000 ) ); + transfer( committee_account, bob_id, core.amount( 1000 ) ); + + generate_block(); + + // gpos balance creation is not allowed before HF + vesting_balance_create_operation op; + op.creator = alice_id; + op.owner = alice_id; + op.amount = core.amount(100); + op.balance_type = vesting_balance_type::gpos; + + trx.operations.push_back(op); + set_expiration(db, trx); + GRAPHENE_REQUIRE_THROW( PUSH_TX(db, trx, ~0), fc::exception ); + trx.clear(); + + // pass hardfork + generate_blocks( HARDFORK_GPOS_TIME ); + generate_block(); + + // repeat operation + trx.operations.push_back(op); + set_expiration(db, trx); + processed_transaction ptx = PUSH_TX(db, trx, ~0); + trx.clear(); + + generate_block(); + + auto alice_vesting = db.get(ptx.operation_results[0].get()); + + // check created vesting amount and policy + BOOST_CHECK_EQUAL(alice_vesting.balance.amount.value, 100); + BOOST_CHECK_EQUAL(alice_vesting.policy.get().vesting_duration_seconds, + db.get_global_properties().parameters.gpos_subperiod); + BOOST_CHECK_EQUAL(alice_vesting.policy.get().vesting_cliff_seconds, + db.get_global_properties().parameters.gpos_subperiod); + + // bob creates a gpos vesting with his custom policy + { + vesting_balance_create_operation op; + op.creator = bob_id; + op.owner = bob_id; + op.amount = core.amount(200); + op.balance_type = vesting_balance_type::gpos; + op.policy = cdd_vesting_policy_initializer{ 60*60*24 }; + + trx.operations.push_back(op); + set_expiration(db, trx); + ptx = PUSH_TX(db, trx, ~0); + trx.clear(); + } + auto bob_vesting = db.get(ptx.operation_results[0].get()); + + generate_block(); + + // policy is not the one defined by the user but default + BOOST_CHECK_EQUAL(bob_vesting.balance.amount.value, 200); + BOOST_CHECK_EQUAL(bob_vesting.policy.get().vesting_duration_seconds, + db.get_global_properties().parameters.gpos_subperiod); + BOOST_CHECK_EQUAL(bob_vesting.policy.get().vesting_cliff_seconds, + db.get_global_properties().parameters.gpos_subperiod); + + } + catch (fc::exception& e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE( dividends ) +{ + ACTORS((alice)(bob)); + try + { + // move to 1 week before hardfork + generate_blocks( HARDFORK_GPOS_TIME - fc::days(7) ); + generate_block(); + + const auto& core = asset_id_type()(db); + + // all core coins are in the committee_account + BOOST_CHECK_EQUAL(get_balance(committee_account(db), core), 1000000000000000); + + // transfer half of the total stake to alice so not all the dividends will go to the committee_account + transfer( committee_account, alice_id, core.amount( 500000000000000 ) ); + generate_block(); + + // send some to bob + transfer( committee_account, bob_id, core.amount( 1000 ) ); + generate_block(); + + // committee balance + BOOST_CHECK_EQUAL(get_balance(committee_account(db), core), 499999999999000); + + // alice balance + BOOST_CHECK_EQUAL(get_balance(alice_id(db), core), 500000000000000); + + // bob balance + BOOST_CHECK_EQUAL(get_balance(bob_id(db), core), 1000); + + // get core asset object + const auto& dividend_holder_asset_object = get_asset(GRAPHENE_SYMBOL); + + // by default core token pays dividends once per month + const auto& dividend_data = dividend_holder_asset_object.dividend_data(db); + BOOST_CHECK_EQUAL(*dividend_data.options.payout_interval, 2592000); // 30 days + + // update the payout interval for speed purposes of the test + update_payout_interval(core.symbol, fc::time_point::now() + fc::minutes(1), 60 * 60 * 24); // 1 day + + generate_block(); + + BOOST_CHECK_EQUAL(*dividend_data.options.payout_interval, 86400); // 1 day now + + // get the dividend distribution account + const account_object& dividend_distribution_account = dividend_data.dividend_distribution_account(db); + + // transfering some coins to distribution account. + // simulating the blockchain haves some dividends to pay. + transfer( committee_account, dividend_distribution_account.id, core.amount( 100 ) ); + generate_block(); + + // committee balance + BOOST_CHECK_EQUAL(get_balance(committee_account(db), core), 499999999998900 ); + + // distribution account balance + BOOST_CHECK_EQUAL(get_balance(dividend_distribution_account, core), 100); + + // get when is the next payout time as we need to advance there + auto next_payout_time = dividend_data.options.next_payout_time; + + // advance to next payout + generate_blocks(*next_payout_time); + + // advance to next maint after payout time arrives + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // check balances now, dividends are paid "normally" + BOOST_CHECK_EQUAL(get_balance(committee_account(db), core), 499999999998949 ); + BOOST_CHECK_EQUAL(get_balance(alice_id(db), core), 500000000000050 ); + BOOST_CHECK_EQUAL(get_balance(bob_id(db), core), 1000 ); + BOOST_CHECK_EQUAL(get_balance(dividend_distribution_account, core), 1); + + // advance to hardfork + generate_blocks( HARDFORK_GPOS_TIME ); + + // advance to next maint + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // send 99 to the distribution account so it will have 100 PPY again to share + transfer( committee_account, dividend_distribution_account.id, core.amount( 99 ) ); + generate_block(); + + // get when is the next payout time as we need to advance there + next_payout_time = dividend_data.options.next_payout_time; + + // advance to next payout + generate_blocks(*next_payout_time); + + // advance to next maint + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // make sure no dividends were paid "normally" + BOOST_CHECK_EQUAL(get_balance(committee_account(db), core), 499999999998850 ); + BOOST_CHECK_EQUAL(get_balance(alice_id(db), core), 500000000000050 ); + BOOST_CHECK_EQUAL(get_balance(bob_id(db), core), 1000 ); + BOOST_CHECK_EQUAL(get_balance(dividend_distribution_account, core), 100); + + // lets create a vesting and see what happens + create_vesting(bob_id, core.amount(100), vesting_balance_type::gpos); + + generate_block(); + + // check balances + BOOST_CHECK_EQUAL(get_balance(bob_id(db), core), 900 ); + BOOST_CHECK_EQUAL(get_balance(dividend_distribution_account, core), 100); + + // advance to next payout + generate_blocks(*next_payout_time); + + // advance to next maint + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // check balances, dividends paid to bob + BOOST_CHECK_EQUAL(get_balance(bob_id(db), core), 1000 ); + BOOST_CHECK_EQUAL(get_balance(dividend_distribution_account, core), 0); + } + catch (fc::exception& e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE( voting ) +{ + ACTORS((alice)(bob)); + try { + // move to hardfork + generate_blocks( HARDFORK_GPOS_TIME ); + generate_block(); + + const auto& core = asset_id_type()(db); + + // send some asset to alice + transfer( committee_account, alice_id, core.amount( 1000 ) ); + generate_block(); + + // default maintenance_interval is 1 day + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.maintenance_interval, 86400); + + // add some vesting to alice + create_vesting(alice_id, core.amount(100), vesting_balance_type::gpos); + generate_block(); + + // default gpos values + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period, 15552000); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_subperiod, 2592000); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start.sec_since_epoch(), HARDFORK_GPOS_TIME.sec_since_epoch()); + + // update default gpos for test speed + auto now = db.head_block_time(); + // 518400 = 60x60x24x6 = 6 days + // 86400 = 60x60x24 = 1 day + update_gpos_global(518400, 86400, now); + + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period, 518400); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_subperiod, 86400); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start.sec_since_epoch(), now.sec_since_epoch()); + // end global changes + + generate_block(); + + // no votes for witness 1 + auto witness1 = witness_id_type(1)(db); + BOOST_CHECK_EQUAL(witness1.total_votes, 0); + + // no votes for witness 2 + auto witness2 = witness_id_type(2)(db); + BOOST_CHECK_EQUAL(witness2.total_votes, 0); + + // vote for witness1 + vote_for(alice_id, witness1.vote_id, alice_private_key); + + // go to maint + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // vote is the same as amount in the first subperiod since voting + witness1 = witness_id_type(1)(db); + BOOST_CHECK_EQUAL(witness1.total_votes, 100); + + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // vote decay as time pass + witness1 = witness_id_type(1)(db); + BOOST_CHECK_EQUAL(witness1.total_votes, 83); + + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // decay more + witness1 = witness_id_type(1)(db); + BOOST_CHECK_EQUAL(witness1.total_votes, 66); + + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // more + witness1 = witness_id_type(1)(db); + BOOST_CHECK_EQUAL(witness1.total_votes, 50); + + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // more + witness1 = witness_id_type(1)(db); + BOOST_CHECK_EQUAL(witness1.total_votes, 33); + + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // more + witness1 = witness_id_type(1)(db); + BOOST_CHECK_EQUAL(witness1.total_votes, 16); + + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // until 0 + witness1 = witness_id_type(1)(db); + BOOST_CHECK_EQUAL(witness1.total_votes, 0); + + // as time keeps passing and no voting activity happen alice votes worth 0 + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + BOOST_CHECK_EQUAL(witness1.total_votes, 0); + + // do activity + vote_for(alice_id, witness2.vote_id, alice_private_key); + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + generate_block(); + + // bug here? + witness1 = witness_id_type(1)(db); + witness2 = witness_id_type(2)(db); + BOOST_CHECK_EQUAL(witness1.total_votes, 0); + BOOST_CHECK_EQUAL(witness2.total_votes, 0); + + } + catch (fc::exception &e) { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE( rolling_period_start ) +{ + // period start rolls automatically after HF + try { + // advance to HF + generate_blocks(HARDFORK_GPOS_TIME); + generate_block(); + + // update default gpos global parameters to make this thing faster + auto now = db.head_block_time(); + update_gpos_global(518400, 86400, now); + + // moving outside period: + while( db.head_block_time() <= now + fc::days(6) ) + { + generate_block(); + } + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // rolling is here so getting the new now + now = db.head_block_time(); + generate_block(); + + // period start rolled + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start.sec_since_epoch(), now.sec_since_epoch()); + } + catch (fc::exception &e) { + edump((e.to_detail_string())); + throw; + } +} +BOOST_AUTO_TEST_CASE( worker_dividends_voting ) +{ + try { + // advance to HF + generate_blocks(HARDFORK_GPOS_TIME); + generate_block(); + + // update default gpos global parameters to 4 days + auto now = db.head_block_time(); + update_gpos_global(345600, 86400, now); + + generate_block(); + set_expiration(db, trx); + const auto& core = asset_id_type()(db); + + // get core asset object + const auto& dividend_holder_asset_object = get_asset(GRAPHENE_SYMBOL); + + // by default core token pays dividends once per month + const auto& dividend_data = dividend_holder_asset_object.dividend_data(db); + BOOST_CHECK_EQUAL(*dividend_data.options.payout_interval, 2592000); // 30 days + + // update the payout interval to 1 day for speed purposes of the test + update_payout_interval(core.symbol, fc::time_point::now() + fc::minutes(1), 60 * 60 * 24); // 1 day + + generate_block(); + + // get the dividend distribution account + const account_object& dividend_distribution_account = dividend_data.dividend_distribution_account(db); + + // transfering some coins to distribution account. + transfer( committee_account, dividend_distribution_account.id, core.amount( 100 ) ); + generate_block(); + + ACTORS((nathan)(voter1)(voter2)(voter3)); + + transfer( committee_account, nathan_id, core.amount( 1000 ) ); + transfer( committee_account, voter1_id, core.amount( 1000 ) ); + transfer( committee_account, voter2_id, core.amount( 1000 ) ); + + generate_block(); + + upgrade_to_lifetime_member(nathan_id); + + auto worker = create_worker(nathan_id, 10, fc::days(6)); + + // add some vesting to voter1 + create_vesting(voter1_id, core.amount(100), vesting_balance_type::gpos); + + // add some vesting to voter2 + create_vesting(voter2_id, core.amount(100), vesting_balance_type::gpos); + + generate_block(); + + // vote for worker + vote_for(voter1_id, worker.vote_for, voter1_private_key); + + // first maint pass, coefficient will be 1 + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + worker = worker_id_type()(db); + BOOST_CHECK_EQUAL(worker.total_votes_for, 100); + + // here dividends are paid to voter1 and voter2 + // voter1 get paid full dividend share as coefficent is at 1 here + BOOST_CHECK_EQUAL(get_balance(voter1_id(db), core), 950); + + // voter2 get paid full dividends + BOOST_CHECK_EQUAL(get_balance(voter2_id(db), core), 950); + + // send some asset to the reserve pool so the worker can get paid + fill_reserve_pool(account_id_type(), asset(GRAPHENE_MAX_SHARE_SUPPLY/2)); + + BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().balance(db).balance.amount.value, 0); + BOOST_CHECK_EQUAL(worker.worker.get().balance(db).balance.amount.value, 0); + + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // worker is getting paid + BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().balance(db).balance.amount.value, 10); + BOOST_CHECK_EQUAL(worker.worker.get().balance(db).balance.amount.value, 10); + + // second maint pass, coefficient will be 0.75 + worker = worker_id_type()(db); + BOOST_CHECK_EQUAL(worker.total_votes_for, 75); + + // more decay + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + worker = worker_id_type()(db); + BOOST_CHECK_EQUAL(worker.total_votes_for, 50); + + transfer( committee_account, dividend_distribution_account.id, core.amount( 100 ) ); + generate_block(); + + BOOST_CHECK_EQUAL(get_balance(committee_account(db), core), 499999999996800); + + // more decay + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + worker = worker_id_type()(db); + BOOST_CHECK_EQUAL(worker.total_votes_for, 25); + + // here voter1 and voter2 get paid again but less money by vesting coefficient + BOOST_CHECK_EQUAL(get_balance(voter1_id(db), core), 962); + BOOST_CHECK_EQUAL(get_balance(voter2_id(db), core), 962); + + // remaining dividends not paid by coeffcient are sent to committee account + BOOST_CHECK_EQUAL(get_balance(committee_account(db), core), 499999999996876); + } + catch (fc::exception &e) { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE( account_multiple_vesting ) +{ + try { + // advance to HF + generate_blocks(HARDFORK_GPOS_TIME); + generate_block(); + set_expiration(db, trx); + + ACTORS((sam)(patty)); + + const auto& core = asset_id_type()(db); + + transfer( committee_account, sam_id, core.amount( 300 ) ); + transfer( committee_account, patty_id, core.amount( 100 ) ); + + // add some vesting to sam + create_vesting(sam_id, core.amount(100), vesting_balance_type::gpos); + + // have another balance with 200 more + create_vesting(sam_id, core.amount(200), vesting_balance_type::gpos); + + // patty also have vesting balance + create_vesting(patty_id, core.amount(100), vesting_balance_type::gpos); + + // get core asset object + const auto& dividend_holder_asset_object = get_asset(GRAPHENE_SYMBOL); + const auto& dividend_data = dividend_holder_asset_object.dividend_data(db); + + // update the payout interval + update_payout_interval(core.symbol, fc::time_point::now() + fc::minutes(1), 60 * 60 * 24); // 1 day + + // get the dividend distribution account + const account_object& dividend_distribution_account = dividend_data.dividend_distribution_account(db); + + // transfering some coins to distribution account. + transfer( committee_account, dividend_distribution_account.id, core.amount( 100 ) ); + generate_block(); + + // vote for a votable object + auto witness1 = witness_id_type(1)(db); + vote_for(sam_id, witness1.vote_id, sam_private_key); + + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // amount in vested balanced will sum up as voting power + witness1 = witness_id_type(1)(db); + BOOST_CHECK_EQUAL(witness1.total_votes, 300); + + // sam get paid dividends + BOOST_CHECK_EQUAL(get_balance(sam_id(db), core), 75); + + // patty also + BOOST_CHECK_EQUAL(get_balance(patty_id(db), core), 25); + + //vote not decaying ? + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + generate_block(); + + witness1 = witness_id_type(1)(db); + + BOOST_CHECK_EQUAL(witness1.total_votes, 300); + } + catch (fc::exception &e) { + edump((e.to_detail_string())); + throw; + } +} +BOOST_AUTO_TEST_CASE( competing_proposals ) +{ + try { + // advance to HF + generate_blocks(HARDFORK_GPOS_TIME); + generate_block(); + set_expiration(db, trx); + + ACTORS((voter1)(voter2)(worker1)(worker2)); + + const auto& core = asset_id_type()(db); + + transfer( committee_account, worker1_id, core.amount( 1000 ) ); + transfer( committee_account, worker2_id, core.amount( 1000 ) ); + transfer( committee_account, voter1_id, core.amount( 1000 ) ); + transfer( committee_account, voter2_id, core.amount( 1000 ) ); + + create_vesting(voter1_id, core.amount(200), vesting_balance_type::gpos); + create_vesting(voter2_id, core.amount(300), vesting_balance_type::gpos); + + generate_block(); + + auto now = db.head_block_time(); + update_gpos_global(518400, 86400, now); + + update_payout_interval(core.symbol, fc::time_point::now() + fc::minutes(1), 60 * 60 * 24); // 1 day + + upgrade_to_lifetime_member(worker1_id); + upgrade_to_lifetime_member(worker2_id); + + // create 2 competing proposals asking a lot of token + // todo: maybe a refund worker here so we can test with smaller numbers + auto w1 = create_worker(worker1_id, 100000000000, fc::days(10)); + auto w1_id_instance = w1.id.instance(); + auto w2 = create_worker(worker2_id, 100000000000, fc::days(10)); + auto w2_id_instance = w2.id.instance(); + + fill_reserve_pool(account_id_type(), asset(GRAPHENE_MAX_SHARE_SUPPLY/2)); + + // vote for the 2 workers + vote_for(voter1_id, w1.vote_for, voter1_private_key); + vote_for(voter2_id, w2.vote_for, voter2_private_key); + + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + generate_block(); + + w1 = worker_id_type(w1_id_instance)(db); + w2 = worker_id_type(w2_id_instance)(db); + + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + generate_block(); + + // only w2 is getting paid as it haves more votes and money is only enough for 1 + BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); + BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 73488756706); + + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + generate_block(); + + BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); + BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 123488756706); + + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + generate_block(); + + w1 = worker_id_type(w1_id_instance)(db); + w2 = worker_id_type(w2_id_instance)(db); + + // as votes decay w1 is still getting paid as it always have more votes than w1 + BOOST_CHECK_EQUAL(w1.total_votes_for, 100); + BOOST_CHECK_EQUAL(w2.total_votes_for, 150); + + BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); + BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 173488756706); + + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + generate_block(); + + w1 = worker_id_type(w1_id_instance)(db); + w2 = worker_id_type(w2_id_instance)(db); + + BOOST_CHECK_EQUAL(w1.total_votes_for, 66); + BOOST_CHECK_EQUAL(w2.total_votes_for, 100); + + // worker is sil getting paid as days pass + BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); + BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 223488756706); + + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + generate_block(); + + w1 = worker_id_type(w1_id_instance)(db); + w2 = worker_id_type(w2_id_instance)(db); + + BOOST_CHECK_EQUAL(w1.total_votes_for, 33); + BOOST_CHECK_EQUAL(w2.total_votes_for, 50); + + BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); + BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 273488756706); + + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + generate_block(); + + w1 = worker_id_type(w1_id_instance)(db); + w2 = worker_id_type(w2_id_instance)(db); + + // worker2 will not get paid anymore as it haves 0 votes + BOOST_CHECK_EQUAL(w1.total_votes_for, 0); + BOOST_CHECK_EQUAL(w2.total_votes_for, 0); + + BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); + BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 273488756706); + } + catch (fc::exception &e) { + edump((e.to_detail_string())); + throw; + } +} +BOOST_AUTO_TEST_CASE( proxy_voting ) +{ + try { + + } + catch (fc::exception &e) { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_SUITE_END() From b914a7dc0befeca250845483cef86134b3aecc1b Mon Sep 17 00:00:00 2001 From: Alfredo Date: Tue, 15 Jan 2019 14:25:43 -0300 Subject: [PATCH 13/31] add globals to genesis, update hardfork date, fix test case --- genesis.json | 3 +++ libraries/chain/hardfork.d/GPOS.hf | 4 ++-- tests/tests/gpos_tests.cpp | 12 ++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/genesis.json b/genesis.json index 55dd9c2c8..e5b89c426 100644 --- a/genesis.json +++ b/genesis.json @@ -258,6 +258,9 @@ "maximum_tournament_start_time_in_future": 5184000, "maximum_tournament_start_delay": 259200, "maximum_tournament_number_of_wins": 25, + "gpos_period": 15552000, + "gpos_subperiod": 2592000, + "gpos_period_start": "2019-02-01T00:00:00", "extensions": [] }, "initial_bts_accounts": [], diff --git a/libraries/chain/hardfork.d/GPOS.hf b/libraries/chain/hardfork.d/GPOS.hf index c9855f5d7..3137123f3 100644 --- a/libraries/chain/hardfork.d/GPOS.hf +++ b/libraries/chain/hardfork.d/GPOS.hf @@ -1,4 +1,4 @@ -// GPOS HARDFORK Saturday, January 5, 2019 4:39:39 PM +// GPOS HARDFORK Friday, February 1, 2019 12:00:00 AM #ifndef HARDFORK_GPOS_TIME -#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1546706379 )) +#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1548979200 )) #endif \ No newline at end of file diff --git a/tests/tests/gpos_tests.cpp b/tests/tests/gpos_tests.cpp index b154eaf40..ebae4c6b5 100644 --- a/tests/tests/gpos_tests.cpp +++ b/tests/tests/gpos_tests.cpp @@ -707,13 +707,13 @@ BOOST_AUTO_TEST_CASE( competing_proposals ) // only w2 is getting paid as it haves more votes and money is only enough for 1 BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); - BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 73488756706); + BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 100000000000); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); generate_block(); BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); - BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 123488756706); + BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 150000000000); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); generate_block(); @@ -726,7 +726,7 @@ BOOST_AUTO_TEST_CASE( competing_proposals ) BOOST_CHECK_EQUAL(w2.total_votes_for, 150); BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); - BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 173488756706); + BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 200000000000); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); generate_block(); @@ -739,7 +739,7 @@ BOOST_AUTO_TEST_CASE( competing_proposals ) // worker is sil getting paid as days pass BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); - BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 223488756706); + BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 250000000000); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); generate_block(); @@ -751,7 +751,7 @@ BOOST_AUTO_TEST_CASE( competing_proposals ) BOOST_CHECK_EQUAL(w2.total_votes_for, 50); BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); - BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 273488756706); + BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 300000000000); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); generate_block(); @@ -764,7 +764,7 @@ BOOST_AUTO_TEST_CASE( competing_proposals ) BOOST_CHECK_EQUAL(w2.total_votes_for, 0); BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); - BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 273488756706); + BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 300000000000); } catch (fc::exception &e) { edump((e.to_detail_string())); From 610266481b29e01ff5ca8cf7c2286af3bfb9262d Mon Sep 17 00:00:00 2001 From: Alfredo Date: Tue, 22 Jan 2019 16:19:13 -0300 Subject: [PATCH 14/31] add create_vesting_balance command to cli wallet --- .../wallet/include/graphene/wallet/wallet.hpp | 15 +++++++++ libraries/wallet/wallet.cpp | 31 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 0ba0782b5..a71891381 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1795,6 +1795,20 @@ class wallet_api rock_paper_scissors_gesture gesture, bool broadcast); + /** Create a vesting balance including gpos vesting balance after HARDFORK_GPOS_TIME + * @param owner vesting balance owner and creator + * @param amount amount to vest + * @param asset_symbol the symbol of the asset to vest + * @param is_gpos True if the balance is of gpos type + * @param broadcast true if you wish to broadcast the transaction + * @return the signed version of the transaction + */ + signed_transaction create_vesting_balance(string owner, + string amount, + string asset_symbol, + bool is_gpos, + bool broadcast); + void dbg_make_uia(string creator, string symbol); void dbg_make_mia(string creator, string symbol); void dbg_push_blocks( std::string src_filename, uint32_t count ); @@ -2031,6 +2045,7 @@ FC_API( graphene::wallet::wallet_api, (tournament_join) (tournament_leave) (rps_throw) + (create_vesting_balance) (get_upcoming_tournaments) (get_tournaments) (get_tournaments_by_state) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 74c285bfa..812740e6d 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -5756,6 +5756,37 @@ signed_transaction wallet_api::rps_throw(game_id_type game_id, return my->sign_transaction( tx, broadcast ); } +signed_transaction wallet_api::create_vesting_balance(string owner, + string amount, + string asset_symbol, + bool is_gpos, + bool broadcast) +{ + FC_ASSERT( !is_locked() ); + + account_object owner_account = get_account(owner); + account_id_type owner_id = owner_account.id; + + fc::optional asset_obj = get_asset(asset_symbol); + + auto type = vesting_balance_type::unspecified; + if(is_gpos) + type = vesting_balance_type::gpos; + + vesting_balance_create_operation op; + op.creator = owner_id; + op.owner = owner_id; + op.amount = asset_obj->amount_from_string(amount); + op.balance_type = type; + + signed_transaction trx; + trx.operations.push_back(op); + my->set_operation_fees( trx, my->_remote_db->get_global_properties().parameters.current_fees ); + trx.validate(); + + return my->sign_transaction( trx, broadcast ); +} + // default ctor necessary for FC_REFLECT signed_block_with_info::signed_block_with_info() { From d602e7160108e9e4b2d59538f793e90c77527e9c Mon Sep 17 00:00:00 2001 From: Alfredo Date: Tue, 22 Jan 2019 22:40:15 -0300 Subject: [PATCH 15/31] move gpos global parameters to extensions --- libraries/chain/db_maint.cpp | 15 ++++---- .../chain/protocol/chain_parameters.hpp | 23 +++++++++---- libraries/chain/vesting_balance_evaluator.cpp | 4 +-- tests/tests/gpos_tests.cpp | 34 +++++++++---------- 4 files changed, 43 insertions(+), 33 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 9aed8b4ec..7187fd9b2 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -733,9 +733,9 @@ double calculate_vesting_factor(const database& d, const account_object& stake_a // get global data related to gpos const auto &gpo = d.get_global_properties(); - const auto vesting_period = gpo.parameters.gpos_period; - const auto vesting_subperiod = gpo.parameters.gpos_subperiod; - const auto period_start = gpo.parameters.gpos_period_start; + const auto vesting_period = gpo.parameters.gpos_period(); + const auto vesting_subperiod = gpo.parameters.gpos_subperiod(); + const auto period_start = fc::time_point_sec(gpo.parameters.gpos_period_start()); // variables needed const fc::time_point_sec period_end = period_start + vesting_period; @@ -830,15 +830,16 @@ void rolling_period_start(database& db) { if(db.head_block_time() >= HARDFORK_GPOS_TIME) { - auto period_start = db.get_global_properties().parameters.gpos_period_start; - auto vesting_period = db.get_global_properties().parameters.gpos_period; + auto gpo = db.get_global_properties(); + auto period_start = db.get_global_properties().parameters.gpos_period_start(); + auto vesting_period = db.get_global_properties().parameters.gpos_period(); auto now = db.head_block_time(); - if(now.sec_since_epoch() > (period_start.sec_since_epoch() + vesting_period)) + if(now.sec_since_epoch() > (period_start + vesting_period)) { // roll db.modify(db.get_global_properties(), [now](global_property_object& p) { - p.parameters.gpos_period_start = now; + p.parameters.extensions.value.gpos_period_start = now.sec_since_epoch(); }); } } diff --git a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp index ef12e65e8..87c2e3fef 100644 --- a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp +++ b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp @@ -39,6 +39,10 @@ namespace graphene { namespace chain { optional< uint16_t > betting_rake_fee_percentage; optional< flat_map > permitted_betting_odds_increments; optional< uint16_t > live_betting_delay_time; + /* gpos parameters */ + optional < uint32_t > gpos_period; + optional < uint32_t > gpos_subperiod; + optional < uint32_t > gpos_period_start; }; struct chain_parameters @@ -88,10 +92,6 @@ namespace graphene { namespace chain { uint32_t maximum_tournament_start_time_in_future = TOURNAMENT_MAX_START_TIME_IN_FUTURE; uint32_t maximum_tournament_start_delay = TOURNAMENT_MAX_START_DELAY; uint16_t maximum_tournament_number_of_wins = TOURNAMENT_MAX_NUMBER_OF_WINS; - /* gpos parameters constraints */ - uint32_t gpos_period = GPOS_PERIOD; /// toal seconds of current gpos period - uint32_t gpos_subperiod = GPOS_SUBPERIOD; /// gpos_period % gpos_subperiod = 0 - time_point_sec gpos_period_start = HARDFORK_GPOS_TIME; /// current period start date extension extensions; /** defined in fee_schedule.cpp */ @@ -112,6 +112,15 @@ namespace graphene { namespace chain { inline uint16_t live_betting_delay_time()const { return extensions.value.live_betting_delay_time.valid() ? *extensions.value.live_betting_delay_time : GRAPHENE_DEFAULT_LIVE_BETTING_DELAY_TIME; } + inline uint32_t gpos_period()const { + return extensions.value.gpos_period.valid() ? *extensions.value.gpos_period : GPOS_PERIOD; /// total seconds of current gpos period + } + inline uint32_t gpos_subperiod()const { + return extensions.value.gpos_subperiod.valid() ? *extensions.value.gpos_subperiod : GPOS_SUBPERIOD; /// gpos_period % gpos_subperiod = 0 + } + inline uint32_t gpos_period_start()const { + return extensions.value.gpos_period_start.valid() ? *extensions.value.gpos_period_start : HARDFORK_GPOS_TIME.sec_since_epoch(); /// current period start date + } }; } } // graphene::chain @@ -122,6 +131,9 @@ FC_REFLECT( graphene::chain::parameter_extension, (betting_rake_fee_percentage) (permitted_betting_odds_increments) (live_betting_delay_time) + (gpos_period) + (gpos_subperiod) + (gpos_period_start) ) FC_REFLECT( graphene::chain::chain_parameters, @@ -167,8 +179,5 @@ FC_REFLECT( graphene::chain::chain_parameters, (maximum_tournament_start_time_in_future) (maximum_tournament_start_delay) (maximum_tournament_number_of_wins) - (gpos_period) - (gpos_subperiod) - (gpos_period_start) (extensions) ) diff --git a/libraries/chain/vesting_balance_evaluator.cpp b/libraries/chain/vesting_balance_evaluator.cpp index c3a833cd4..0b6e192e0 100644 --- a/libraries/chain/vesting_balance_evaluator.cpp +++ b/libraries/chain/vesting_balance_evaluator.cpp @@ -101,8 +101,8 @@ object_id_type vesting_balance_create_evaluator::do_apply( const vesting_balance // forcing gpos policy linear_vesting_policy p; p.begin_timestamp = now; - p.vesting_cliff_seconds = gpo.parameters.gpos_subperiod; - p.vesting_duration_seconds = gpo.parameters.gpos_subperiod; + p.vesting_cliff_seconds = gpo.parameters.gpos_subperiod(); + p.vesting_duration_seconds = gpo.parameters.gpos_subperiod(); obj.policy = p; } else { diff --git a/tests/tests/gpos_tests.cpp b/tests/tests/gpos_tests.cpp index ebae4c6b5..b283aceb4 100644 --- a/tests/tests/gpos_tests.cpp +++ b/tests/tests/gpos_tests.cpp @@ -85,13 +85,13 @@ struct gpos_fixture: database_fixture void update_gpos_global(uint32_t vesting_period, uint32_t vesting_subperiod, fc::time_point_sec period_start) { db.modify(db.get_global_properties(), [vesting_period, vesting_subperiod, period_start](global_property_object& p) { - p.parameters.gpos_period = vesting_period; - p.parameters.gpos_subperiod = vesting_subperiod; - p.parameters.gpos_period_start = period_start; + p.parameters.extensions.value.gpos_period = vesting_period; + p.parameters.extensions.value.gpos_subperiod = vesting_subperiod; + p.parameters.extensions.value.gpos_period_start = period_start.sec_since_epoch(); }); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period, vesting_period); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_subperiod, vesting_subperiod); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start.sec_since_epoch(), period_start.sec_since_epoch()); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period(), vesting_period); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_subperiod(), vesting_subperiod); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), period_start.sec_since_epoch()); } void vote_for(const account_id_type account_id, const vote_id_type vote_for, const fc::ecc::private_key& key) { @@ -163,9 +163,9 @@ BOOST_AUTO_TEST_CASE(gpos_vesting_type) // check created vesting amount and policy BOOST_CHECK_EQUAL(alice_vesting.balance.amount.value, 100); BOOST_CHECK_EQUAL(alice_vesting.policy.get().vesting_duration_seconds, - db.get_global_properties().parameters.gpos_subperiod); + db.get_global_properties().parameters.gpos_subperiod()); BOOST_CHECK_EQUAL(alice_vesting.policy.get().vesting_cliff_seconds, - db.get_global_properties().parameters.gpos_subperiod); + db.get_global_properties().parameters.gpos_subperiod()); // bob creates a gpos vesting with his custom policy { @@ -188,9 +188,9 @@ BOOST_AUTO_TEST_CASE(gpos_vesting_type) // policy is not the one defined by the user but default BOOST_CHECK_EQUAL(bob_vesting.balance.amount.value, 200); BOOST_CHECK_EQUAL(bob_vesting.policy.get().vesting_duration_seconds, - db.get_global_properties().parameters.gpos_subperiod); + db.get_global_properties().parameters.gpos_subperiod()); BOOST_CHECK_EQUAL(bob_vesting.policy.get().vesting_cliff_seconds, - db.get_global_properties().parameters.gpos_subperiod); + db.get_global_properties().parameters.gpos_subperiod()); } catch (fc::exception& e) @@ -347,9 +347,9 @@ BOOST_AUTO_TEST_CASE( voting ) generate_block(); // default gpos values - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period, 15552000); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_subperiod, 2592000); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start.sec_since_epoch(), HARDFORK_GPOS_TIME.sec_since_epoch()); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period(), 15552000); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_subperiod(), 2592000); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), HARDFORK_GPOS_TIME.sec_since_epoch()); // update default gpos for test speed auto now = db.head_block_time(); @@ -357,9 +357,9 @@ BOOST_AUTO_TEST_CASE( voting ) // 86400 = 60x60x24 = 1 day update_gpos_global(518400, 86400, now); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period, 518400); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_subperiod, 86400); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start.sec_since_epoch(), now.sec_since_epoch()); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period(), 518400); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_subperiod(), 86400); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), now.sec_since_epoch()); // end global changes generate_block(); @@ -464,7 +464,7 @@ BOOST_AUTO_TEST_CASE( rolling_period_start ) generate_block(); // period start rolled - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start.sec_since_epoch(), now.sec_since_epoch()); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), now.sec_since_epoch()); } catch (fc::exception &e) { edump((e.to_detail_string())); From 26b987a6d21dc89bcd346f341024d758a5577f80 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Tue, 22 Jan 2019 22:43:38 -0300 Subject: [PATCH 16/31] remove globals from genesis --- genesis.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/genesis.json b/genesis.json index e5b89c426..55dd9c2c8 100644 --- a/genesis.json +++ b/genesis.json @@ -258,9 +258,6 @@ "maximum_tournament_start_time_in_future": 5184000, "maximum_tournament_start_delay": 259200, "maximum_tournament_number_of_wins": 25, - "gpos_period": 15552000, - "gpos_subperiod": 2592000, - "gpos_period_start": "2019-02-01T00:00:00", "extensions": [] }, "initial_bts_accounts": [], From 30c95f6010927339d91cb08e0e168f69549a0129 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Thu, 24 Jan 2019 17:52:24 -0300 Subject: [PATCH 17/31] remove not needed period calculation --- libraries/chain/db_maint.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 7187fd9b2..f737b2a38 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -762,12 +762,8 @@ double calculate_vesting_factor(const database& d, const account_object& stake_a // coefficient calculation is: (n-1)/number_of_subperiods double n = number_of_subperiods + 1; - auto period = std::find_if(period_list.begin(), period_list.end(),[&](uint32_t p) { - return (p == current_period); - }); - // todo: improve this loop - std::list subperiod_list(*period); + std::list subperiod_list(current_period); std::iota(subperiod_list.begin(), subperiod_list.end(), 1); for(auto subperiod: subperiod_list) From ec64df788981fed5fc17d7cc83b63fcd21465d8a Mon Sep 17 00:00:00 2001 From: Alfredo Date: Sat, 26 Jan 2019 11:51:15 -0300 Subject: [PATCH 18/31] refactor calculate_vesting_factor --- libraries/chain/db_maint.cpp | 37 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index f737b2a38..fa8bd1b17 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -746,42 +746,29 @@ double calculate_vesting_factor(const database& d, const account_object& stake_a FC_ASSERT(period_start <= now && now <= period_end); - // get in what period we are - uint32_t current_period = 0; + // get in what sub period we are + uint32_t current_subperiod = 0; std::list period_list(number_of_subperiods); - std::iota(period_list.begin(), period_list.end(), 1); // todo: std::iota(period_list, 1); ?? + 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) && seconds_since_period_start < vesting_subperiod * period) - current_period = period; + current_subperiod = period; }); - if(current_period == 0 || current_period > number_of_subperiods) return 0; + if(current_subperiod == 0 || current_subperiod > number_of_subperiods) return 0; - // coefficient calculation is: (n-1)/number_of_subperiods - double n = number_of_subperiods + 1; + double numerator = number_of_subperiods - current_subperiod + 1; - // todo: improve this loop - std::list subperiod_list(current_period); - std::iota(subperiod_list.begin(), subperiod_list.end(), 1); + 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)); - for(auto subperiod: subperiod_list) - { - if (current_period - subperiod > 0) { - n = number_of_subperiods - current_period + 2; - - if (last_date_voted < - (period_start + fc::seconds(vesting_subperiod * (current_period - subperiod - 1))) && - last_date_voted >= (period_start + fc::seconds(vesting_subperiod * (current_period - subperiod))) && - last_date_voted >= period_start) { + // reset n if account voted last period + if (last_date_voted < last_period_start && last_date_voted >= last_period_end) + numerator = number_of_subperiods; - n = number_of_subperiods + 1; - break; - } - } - } - vesting_factor = (n - 1) / number_of_subperiods; + vesting_factor = numerator / number_of_subperiods; return vesting_factor; } From 0e3d87eaad6e80eac1062447d8ced2b7d9a7a446 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Thu, 31 Jan 2019 20:32:19 -0300 Subject: [PATCH 19/31] 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 | 113 ++++++++++++++++++++++------- 3 files changed, 106 insertions(+), 38 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index fa8bd1b17..57cb421fd 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--; - vesting_factor = numerator / number_of_subperiods; + 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 3137123f3..ad914becf 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 b283aceb4..cf133473a 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 Date: Tue, 5 Mar 2019 17:48:47 -0300 Subject: [PATCH 20/31] add get_gpos_info database api call --- libraries/app/database_api.cpp | 51 ++++++++ .../app/include/graphene/app/database_api.hpp | 23 +++- libraries/chain/db_maint.cpp | 12 +- libraries/chain/hardfork.d/GPOS.hf | 4 +- .../chain/include/graphene/chain/database.hpp | 5 +- tests/tests/gpos_tests.cpp | 121 +++++++++++++++++- 6 files changed, 201 insertions(+), 15 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index d3af2f297..3f95a8c16 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -161,6 +161,8 @@ class database_api_impl : public std::enable_shared_from_this vector get_tournaments_by_state(tournament_id_type stop, unsigned limit, tournament_id_type start, tournament_state state); vector get_registered_tournaments(account_id_type account_filter, uint32_t limit) const; + // gpos + gpos_info get_gpos_info(const account_id_type account) const; //private: template @@ -2021,6 +2023,55 @@ vector database_api_impl::get_registered_tournaments(account return tournament_ids; } +////////////////////////////////////////////////////////////////////// +// // +// GPOS methods // +// // +////////////////////////////////////////////////////////////////////// + +graphene::app::gpos_info database_api::get_gpos_info(const account_id_type account) const +{ + return my->get_gpos_info(account); + +} +graphene::app::gpos_info database_api_impl::get_gpos_info(const account_id_type account) const +{ + gpos_info result; + result.vesting_factor = _db.calculate_vesting_factor(account(_db)); + + const auto& dividend_data = asset_id_type()(_db).dividend_data(_db); + const account_object& dividend_distribution_account = dividend_data.dividend_distribution_account(_db); + result.award = _db.get_balance(dividend_distribution_account, asset_id_type()(_db)); + + share_type total_amount; + auto balance_type = vesting_balance_type::gpos; +#ifdef USE_VESTING_OBJECT_BY_ASSET_BALANCE_INDEX + // get only once a collection of accounts that hold nonzero vesting balances of the dividend asset + auto vesting_balances_begin = + vesting_index.indices().get().lower_bound(boost::make_tuple(asset_id_type(), balance_type)); + auto vesting_balances_end = + vesting_index.indices().get().upper_bound(boost::make_tuple(asset_id_type(), balance_type, share_type())); + + for (const vesting_balance_object& vesting_balance_obj : boost::make_iterator_range(vesting_balances_begin, vesting_balances_end)) + { + total_amount += vesting_balance_obj.balance.amount; + } +#else + const vesting_balance_index& vesting_index = _db.get_index_type(); + const auto& vesting_balances = vesting_index.indices().get(); + for (const vesting_balance_object& vesting_balance_obj : vesting_balances) + { + if (vesting_balance_obj.balance.asset_id == asset_id_type() && vesting_balance_obj.balance_type == balance_type) + { + total_amount += vesting_balance_obj.balance.amount; + } + } +#endif + + result.total_amount = total_amount; + return result; +} + ////////////////////////////////////////////////////////////////////// // // // Private methods // diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 7b0943e42..3fac4b5f0 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -114,6 +114,12 @@ struct market_trade double value; }; +struct gpos_info { + double vesting_factor; + asset award; + share_type total_amount; +}; + /** * @brief The database_api class implements the RPC API for the chain database. * @@ -645,7 +651,17 @@ class database_api */ vector get_registered_tournaments(account_id_type account_filter, uint32_t limit) const; - private: + ////////// + // GPOS // + ////////// + /** + * @return account and network GPOS information + */ + gpos_info get_gpos_info(const account_id_type account) const; + + + +private: std::shared_ptr< database_api_impl > my; }; @@ -656,6 +672,8 @@ FC_REFLECT( graphene::app::order_book, (base)(quote)(bids)(asks) ); FC_REFLECT( graphene::app::market_ticker, (base)(quote)(latest)(lowest_ask)(highest_bid)(percent_change)(base_volume)(quote_volume) ); FC_REFLECT( graphene::app::market_volume, (base)(quote)(base_volume)(quote_volume) ); FC_REFLECT( graphene::app::market_trade, (date)(price)(amount)(value) ); +FC_REFLECT( graphene::app::gpos_info, (vesting_factor)(award)(total_amount) ); + FC_API(graphene::app::database_api, // Objects @@ -765,4 +783,7 @@ FC_API(graphene::app::database_api, (get_tournaments_by_state) (get_tournaments ) (get_registered_tournaments) + + // gpos + (get_gpos_info) ) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 57cb421fd..06e15a196 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -725,14 +725,14 @@ void deprecate_annual_members( database& db ) return; } -double calculate_vesting_factor(const database& d, const account_object& stake_account) +double database::calculate_vesting_factor(const account_object& stake_account) { // get last time voted form stats - const auto &stats = stake_account.statistics(d); + const auto &stats = stake_account.statistics(*this); fc::time_point_sec last_date_voted = stats.last_vote_time; // get global data related to gpos - const auto &gpo = d.get_global_properties(); + const auto &gpo = this->get_global_properties(); const auto vesting_period = gpo.parameters.gpos_period(); const auto vesting_subperiod = gpo.parameters.gpos_subperiod(); const auto period_start = fc::time_point_sec(gpo.parameters.gpos_period_start()); @@ -740,7 +740,7 @@ double calculate_vesting_factor(const database& d, const account_object& stake_a // variables needed const fc::time_point_sec period_end = period_start + vesting_period; const auto number_of_subperiods = vesting_period / vesting_subperiod; - const auto now = d.head_block_time(); + const auto now = this->head_block_time(); double vesting_factor; auto seconds_since_period_start = now.sec_since_epoch() - period_start.sec_since_epoch(); @@ -1071,7 +1071,7 @@ void schedule_pending_dividend_balances(database& db, vesting_balances_begin, vesting_balances_end)) { if (holder_balance_object.owner == dividend_data.dividend_distribution_account) continue; - auto vesting_factor = calculate_vesting_factor(db, holder_balance_object.owner(db)); + auto vesting_factor = db.calculate_vesting_factor(holder_balance_object.owner(db)); auto holder_balance = holder_balance_object.balance; @@ -1463,7 +1463,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g if (itr == vesting_amounts.end()) return; - auto vesting_factor = calculate_vesting_factor(d, stake_account); + auto vesting_factor = d.calculate_vesting_factor(stake_account); voting_stake = (uint64_t)floor(voting_stake * vesting_factor); } else diff --git a/libraries/chain/hardfork.d/GPOS.hf b/libraries/chain/hardfork.d/GPOS.hf index ad914becf..f175ef2c5 100644 --- a/libraries/chain/hardfork.d/GPOS.hf +++ b/libraries/chain/hardfork.d/GPOS.hf @@ -1,4 +1,4 @@ -// GPOS HARDFORK Friday, February 15, 2019 5:08:21 PM +// GPOS HARDFORK Friday, March 15, 2019 11:57:28 PM #ifndef HARDFORK_GPOS_TIME -#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1550250501 )) +#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1552694248 )) #endif \ No newline at end of file diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index af50a94b0..179fb2dfb 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -498,8 +498,11 @@ namespace graphene { namespace chain { void update_active_witnesses(); void update_active_committee_members(); void update_worker_votes(); + public: + double calculate_vesting_factor(const account_object& stake_account); - template + + template void perform_account_maintenance(std::tuple helpers); ///@} ///@} diff --git a/tests/tests/gpos_tests.cpp b/tests/tests/gpos_tests.cpp index cf133473a..eb53c9c44 100644 --- a/tests/tests/gpos_tests.cpp +++ b/tests/tests/gpos_tests.cpp @@ -32,6 +32,8 @@ #include "../common/database_fixture.hpp" +#include + using namespace graphene::chain; using namespace graphene::chain::test; @@ -340,6 +342,7 @@ BOOST_AUTO_TEST_CASE( voting ) { ACTORS((alice)(bob)); try { + // move to hardfork generate_blocks( HARDFORK_GPOS_TIME ); generate_block(); @@ -638,16 +641,15 @@ BOOST_AUTO_TEST_CASE( worker_dividends_voting ) BOOST_AUTO_TEST_CASE( account_multiple_vesting ) { try { - - // update default gpos global parameters to 4 days - auto now = db.head_block_time(); - update_gpos_global(345600, 86400, now); - // advance to HF generate_blocks(HARDFORK_GPOS_TIME); generate_block(); set_expiration(db, trx); + // update default gpos global parameters to 4 days + auto now = db.head_block_time(); + update_gpos_global(345600, 86400, now); + ACTORS((sam)(patty)); const auto& core = asset_id_type()(db); @@ -839,4 +841,113 @@ BOOST_AUTO_TEST_CASE( proxy_voting ) } } +BOOST_AUTO_TEST_CASE( no_proposal ) +{ + try { + + } + catch (fc::exception &e) { + edump((e.to_detail_string())); + throw; + } +} +BOOST_AUTO_TEST_CASE( database_api ) +{ + ACTORS((alice)(bob)); + try { + + // move to hardfork + generate_blocks( HARDFORK_GPOS_TIME ); + generate_block(); + + // database api + graphene::app::database_api db_api(db); + + const auto& core = asset_id_type()(db); + + // send some asset to alice and bob + transfer( committee_account, alice_id, core.amount( 1000 ) ); + transfer( committee_account, bob_id, core.amount( 1000 ) ); + generate_block(); + + // add some vesting to alice and bob + create_vesting(alice_id, core.amount(100), vesting_balance_type::gpos); + generate_block(); + + // total balance is 100 rest of data at 0 + auto gpos_info = db_api.get_gpos_info(alice_id); + BOOST_CHECK_EQUAL(gpos_info.vesting_factor, 0); + BOOST_CHECK_EQUAL(gpos_info.award.amount.value, 0); + BOOST_CHECK_EQUAL(gpos_info.total_amount.value, 100); + + create_vesting(bob_id, core.amount(100), vesting_balance_type::gpos); + generate_block(); + + // total gpos balance is now 200 + gpos_info = db_api.get_gpos_info(alice_id); + BOOST_CHECK_EQUAL(gpos_info.total_amount.value, 200); + + // update default gpos and dividend interval to 10 days + auto now = db.head_block_time(); + update_gpos_global(5184000, 864000, now); // 10 days subperiods + update_payout_interval(core.symbol, fc::time_point::now() + fc::minutes(1), 60 * 60 * 24 * 10); // 10 days + + generate_block(); + + // no votes for witness 1 + auto witness1 = witness_id_type(1)(db); + BOOST_CHECK_EQUAL(witness1.total_votes, 0); + + // no votes for witness 2 + auto witness2 = witness_id_type(2)(db); + BOOST_CHECK_EQUAL(witness2.total_votes, 0); + + // transfering some coins to distribution account. + const auto& dividend_holder_asset_object = get_asset(GRAPHENE_SYMBOL); + const auto& dividend_data = dividend_holder_asset_object.dividend_data(db); + const account_object& dividend_distribution_account = dividend_data.dividend_distribution_account(db); + transfer( committee_account, dividend_distribution_account.id, core.amount( 100 ) ); + generate_block(); + + // award balance is now 100 + gpos_info = db_api.get_gpos_info(alice_id); + BOOST_CHECK_EQUAL(gpos_info.vesting_factor, 0); + BOOST_CHECK_EQUAL(gpos_info.award.amount.value, 100); + BOOST_CHECK_EQUAL(gpos_info.total_amount.value, 200); + + // vote for witness1 + vote_for(alice_id, witness1.vote_id, alice_private_key); + vote_for(bob_id, witness1.vote_id, bob_private_key); + + // go to maint + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // payment for alice and bob is done, distribution account is back in 0 + gpos_info = db_api.get_gpos_info(alice_id); + BOOST_CHECK_EQUAL(gpos_info.vesting_factor, 1); + BOOST_CHECK_EQUAL(gpos_info.award.amount.value, 0); + BOOST_CHECK_EQUAL(gpos_info.total_amount.value, 200); + + advance_x_maint(10); + + // alice vesting coeffcient decay + gpos_info = db_api.get_gpos_info(alice_id); + BOOST_CHECK_EQUAL(gpos_info.vesting_factor, 0.83333333333333337); + BOOST_CHECK_EQUAL(gpos_info.award.amount.value, 0); + BOOST_CHECK_EQUAL(gpos_info.total_amount.value, 200); + + advance_x_maint(10); + + // vesting factor for alice decaying more + gpos_info = db_api.get_gpos_info(alice_id); + BOOST_CHECK_EQUAL(gpos_info.vesting_factor, 0.66666666666666663); + BOOST_CHECK_EQUAL(gpos_info.award.amount.value, 0); + BOOST_CHECK_EQUAL(gpos_info.total_amount.value, 200); + } + catch (fc::exception &e) { + edump((e.to_detail_string())); + throw; + } +} + BOOST_AUTO_TEST_SUITE_END() From 0f06a9af2aebf139d43c3b4d0122abadde637c1a Mon Sep 17 00:00:00 2001 From: pbattu Date: Mon, 20 May 2019 22:32:17 -0300 Subject: [PATCH 21/31] Required changes to upgrade blockchain to ubuntu18.04 --- CMakeLists.txt | 2 +- bkup_CMakeCache.txt | 794 ++++++++++++++++++ libraries/CMakeLists.txt | 2 +- libraries/app/api.cpp | 14 - libraries/app/include/graphene/app/api.hpp | 14 +- .../chain/betting_market_group_object.cpp | 2 +- libraries/chain/betting_market_object.cpp | 8 +- .../db/include/graphene/db/generic_index.hpp | 23 +- .../deterministic_openssl_rand/CMakeLists.txt | 28 - .../deterministic_openssl_rand.cpp | 104 --- .../utilities/deterministic_openssl_rand.hpp | 31 - libraries/net/node.cpp | 2 +- programs/cli_wallet/main.cpp | 4 + programs/witness_node/bkup_config.ini | 83 ++ programs/witness_node/bkup_genesis.json | 496 +++++++++++ programs/witness_node/genesis.json | 496 +++++++++++ programs/witness_node/main.cpp | 6 + 17 files changed, 1908 insertions(+), 201 deletions(-) create mode 100644 bkup_CMakeCache.txt delete mode 100644 libraries/deterministic_openssl_rand/CMakeLists.txt delete mode 100644 libraries/deterministic_openssl_rand/deterministic_openssl_rand.cpp delete mode 100644 libraries/deterministic_openssl_rand/include/graphene/utilities/deterministic_openssl_rand.hpp create mode 100644 programs/witness_node/bkup_config.ini create mode 100644 programs/witness_node/bkup_genesis.json create mode 100644 programs/witness_node/genesis.json diff --git a/CMakeLists.txt b/CMakeLists.txt index a71bc0633..20d96a9a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,7 @@ IF( WIN32 ) set(BOOST_ALL_DYN_LINK OFF) # force dynamic linking for all libraries ENDIF(WIN32) -FIND_PACKAGE(Boost 1.57 REQUIRED COMPONENTS ${BOOST_COMPONENTS}) +FIND_PACKAGE(Boost 1.67 REQUIRED COMPONENTS ${BOOST_COMPONENTS}) # For Boost 1.53 on windows, coroutine was not in BOOST_LIBRARYDIR and do not need it to build, but if boost versin >= 1.54, find coroutine otherwise will cause link errors IF(NOT "${Boost_VERSION}" MATCHES "1.53(.*)") SET(BOOST_LIBRARIES_TEMP ${Boost_LIBRARIES}) diff --git a/bkup_CMakeCache.txt b/bkup_CMakeCache.txt new file mode 100644 index 000000000..daa267e93 --- /dev/null +++ b/bkup_CMakeCache.txt @@ -0,0 +1,794 @@ +# This is the CMakeCache file. +# For build in directory: /home/pbattu/git/18.04/peerplays +# It was generated by CMake: /usr/bin/cmake +# You can edit this file to change values found and used by cmake. +# If you do not want to change any of the values, simply exit the editor. +# If you do want to change a value, simply edit, save, and exit the editor. +# The syntax for the file is as follows: +# KEY:TYPE=VALUE +# KEY is the name of a variable in the cache. +# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. +# VALUE is the current value for the KEY. + +######################## +# EXTERNAL cache entries +######################## + +//No help, variable specified on the command line. +BOOST_ROOT:PATH=/home/pbattu/git/18.04/boost_1_67_0 + +//The threading library used by boost-thread +BOOST_THREAD_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libpthread.so + +//Build bitshares executables (witness node, cli wallet, etc) +BUILD_BITSHARES_PROGRAMS:BOOL=TRUE + +//Build bitshares unit tests +BUILD_BITSHARES_TESTS:BOOL=TRUE + +//Build websocketpp examples. +BUILD_EXAMPLES:BOOL=OFF + +//Build websocketpp tests. +BUILD_TESTS:BOOL=OFF + +//Value Computed by CMake +BitShares_BINARY_DIR:STATIC=/home/pbattu/git/18.04/peerplays + +//Value Computed by CMake +BitShares_SOURCE_DIR:STATIC=/home/pbattu/git/18.04/peerplays + +//Boost chrono library (debug) +Boost_CHRONO_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_chrono.a + +//Boost chrono library (release) +Boost_CHRONO_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_chrono.a + +//Boost context library (debug) +Boost_CONTEXT_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_context.a + +//Boost context library (release) +Boost_CONTEXT_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_context.a + +//Boost coroutine library (debug) +Boost_COROUTINE_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_coroutine.a + +//Boost coroutine library (release) +Boost_COROUTINE_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_coroutine.a + +//Boost date_time library (debug) +Boost_DATE_TIME_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_date_time.a + +//Boost date_time library (release) +Boost_DATE_TIME_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_date_time.a + +//The directory containing a CMake configuration file for Boost. +Boost_DIR:PATH=Boost_DIR-NOTFOUND + +//Boost filesystem library (debug) +Boost_FILESYSTEM_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_filesystem.a + +//Boost filesystem library (release) +Boost_FILESYSTEM_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_filesystem.a + +//Path to a file. +Boost_INCLUDE_DIR:PATH=/home/pbattu/git/18.04/boost_1_67_0/include + +//Boost iostreams library (debug) +Boost_IOSTREAMS_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_iostreams.a + +//Boost iostreams library (release) +Boost_IOSTREAMS_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_iostreams.a + +//Boost library directory +Boost_LIBRARY_DIR:PATH=/home/pbattu/git/18.04/boost_1_67_0/lib + +//Boost library directory DEBUG +Boost_LIBRARY_DIR_DEBUG:PATH=/home/pbattu/git/18.04/boost_1_67_0/lib + +//Boost library directory RELEASE +Boost_LIBRARY_DIR_RELEASE:PATH=/home/pbattu/git/18.04/boost_1_67_0/lib + +//Boost locale library (debug) +Boost_LOCALE_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_locale.a + +//Boost locale library (release) +Boost_LOCALE_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_locale.a + +//Boost program_options library (debug) +Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_program_options.a + +//Boost program_options library (release) +Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_program_options.a + +//Boost serialization library (debug) +Boost_SERIALIZATION_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_serialization.a + +//Boost serialization library (release) +Boost_SERIALIZATION_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_serialization.a + +//Boost signals library (debug) +Boost_SIGNALS_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_signals.a + +//Boost signals library (release) +Boost_SIGNALS_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_signals.a + +//Boost system library (debug) +Boost_SYSTEM_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_system.a + +//Boost system library (release) +Boost_SYSTEM_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_system.a + +//Boost thread library (debug) +Boost_THREAD_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_thread.a + +//Boost thread library (release) +Boost_THREAD_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_thread.a + +//Boost unit_test_framework library (debug) +Boost_UNIT_TEST_FRAMEWORK_LIBRARY_DEBUG:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_unit_test_framework.a + +//Boost unit_test_framework library (release) +Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE:FILEPATH=/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_unit_test_framework.a + +//ON or OFF +Boost_USE_STATIC_LIBS:STRING=ON + +//Path to a program. +CMAKE_AR:FILEPATH=/usr/bin/ar + +//Choose the type of build, options are: None(CMAKE_CXX_FLAGS or +// CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel. +CMAKE_BUILD_TYPE:STRING=Debug + +//Enable/Disable color output during build. +CMAKE_COLOR_MAKEFILE:BOOL=ON + +//Configurations +CMAKE_CONFIGURATION_TYPES:STRING=Release;RelWithDebInfo;Debug + +//CXX compiler +CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++-5 + +//A wrapper around 'ar' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-5 + +//A wrapper around 'ranlib' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-5 + +//Flags used by the compiler during all build types. +CMAKE_CXX_FLAGS:STRING= + +//Flags used by the compiler during debug builds. +CMAKE_CXX_FLAGS_DEBUG:STRING=-g + +//Flags used by the compiler during release builds for minimum +// size. +CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG + +//Flags used by the compiler during release builds. +CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG + +//Flags used by the compiler during release builds with debug info. +CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG + +//C compiler +CMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc-5 + +//A wrapper around 'ar' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-5 + +//A wrapper around 'ranlib' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-5 + +//Flags used by the compiler during all build types. +CMAKE_C_FLAGS:STRING= + +//Flags used by the compiler during debug builds. +CMAKE_C_FLAGS_DEBUG:STRING=-g + +//Flags used by the compiler during release builds for minimum +// size. +CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG + +//Flags used by the compiler during release builds. +CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG + +//Flags used by the compiler during release builds with debug info. +CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG + +//Flags used by the linker. +CMAKE_EXE_LINKER_FLAGS:STRING= + +//Flags used by the linker during debug builds. +CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during release minsize builds. +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during release builds. +CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during Release with Debug Info builds. +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Enable/Disable output of compile commands during generation. +CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=OFF + +//Install path prefix, prepended onto install directories. +CMAKE_INSTALL_PREFIX:PATH=/usr/local + +//Path to a program. +CMAKE_LINKER:FILEPATH=/usr/bin/ld + +//Path to a program. +CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/make + +//Flags used by the linker during the creation of modules. +CMAKE_MODULE_LINKER_FLAGS:STRING= + +//Flags used by the linker during debug builds. +CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during release minsize builds. +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during release builds. +CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during Release with Debug Info builds. +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Path to a program. +CMAKE_NM:FILEPATH=/usr/bin/nm + +//Path to a program. +CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy + +//Path to a program. +CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump + +//Value Computed by CMake +CMAKE_PROJECT_NAME:STATIC=BitShares + +//Path to a program. +CMAKE_RANLIB:FILEPATH=/usr/bin/ranlib + +//Flags used by the linker during the creation of dll's. +CMAKE_SHARED_LINKER_FLAGS:STRING= + +//Flags used by the linker during debug builds. +CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during release minsize builds. +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during release builds. +CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during Release with Debug Info builds. +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//If set, runtime paths are not added when installing shared libraries, +// but are added when building. +CMAKE_SKIP_INSTALL_RPATH:BOOL=NO + +//If set, runtime paths are not added when using shared libraries. +CMAKE_SKIP_RPATH:BOOL=NO + +//Flags used by the linker during the creation of static libraries. +CMAKE_STATIC_LINKER_FLAGS:STRING= + +//Flags used by the linker during debug builds. +CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during release minsize builds. +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during release builds. +CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during Release with Debug Info builds. +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Path to a program. +CMAKE_STRIP:FILEPATH=/usr/bin/strip + +//If this value is on, makefiles will be generated without the +// .SILENT directive, and all commands will be echoed to the console +// during the make. This is useful for debugging only. With Visual +// Studio IDE projects all commands are done without /nologo. +CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE + +//Path to a library. +CURSES_CURSES_LIBRARY:FILEPATH=CURSES_CURSES_LIBRARY-NOTFOUND + +//Path to a library. +CURSES_FORM_LIBRARY:FILEPATH=CURSES_FORM_LIBRARY-NOTFOUND + +//Path to a file. +CURSES_INCLUDE_PATH:PATH=CURSES_INCLUDE_PATH-NOTFOUND + +//Path to a library. +CURSES_NCURSES_LIBRARY:FILEPATH=CURSES_NCURSES_LIBRARY-NOTFOUND + +//Dot tool for use with Doxygen +DOXYGEN_DOT_EXECUTABLE:FILEPATH=DOXYGEN_DOT_EXECUTABLE-NOTFOUND + +//Doxygen documentation generation tool (http://www.doxygen.org) +DOXYGEN_EXECUTABLE:FILEPATH=DOXYGEN_EXECUTABLE-NOTFOUND + +//secp256k1 or openssl or mixed +ECC_IMPL:STRING=secp256k1 + +//Build BitShares for code coverage analysis +ENABLE_COVERAGE_TESTING:BOOL=FALSE + +//Build websocketpp with CPP11 features enabled. +ENABLE_CPP11:BOOL=ON + +//TRUE to try to use full zlib for compression, FALSE to use miniz.c +FC_USE_FULL_ZLIB:BOOL=FALSE + +//Git command line client +GIT_EXECUTABLE:FILEPATH=/usr/bin/git + +//location of the genesis.json to embed in the executable +GRAPHENE_EGENESIS_JSON:PATH=/home/pbattu/git/18.04/peerplays/genesis.json + +//The directory containing a CMake configuration file for Gperftools. +Gperftools_DIR:PATH=Gperftools_DIR-NOTFOUND + +//Installation directory for CMake files +INSTALL_CMAKE_DIR:PATH=lib/cmake/websocketpp + +//Installation directory for header files +INSTALL_INCLUDE_DIR:PATH=include + +//Log long API calls over websocket (ON OR OFF) +LOG_LONG_API:BOOL=ON + +//Max API execution time in ms +LOG_LONG_API_MAX_MS:STRING=1000 + +//API execution time in ms at which to warn +LOG_LONG_API_WARN_MS:STRING=750 + +//Path to a library. +OPENSSL_CRYPTO_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libcrypto.a + +//Path to a file. +OPENSSL_INCLUDE_DIR:PATH=/usr/include + +//Path to a library. +OPENSSL_SSL_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libssl.a + +//Path to a program. +PERL_EXECUTABLE:FILEPATH=/usr/bin/perl + +//pkg-config executable +PKG_CONFIG_EXECUTABLE:FILEPATH=/usr/bin/pkg-config + +//Path to a file. +READLINE_INCLUDE_DIR:PATH=/usr/include + +//Path to a library. +READLINE_LIBRARIES:FILEPATH=/usr/lib/x86_64-linux-gnu/libreadline.so + +//Path to a file. +Readline_INCLUDE_DIR:PATH=/usr/include + +//Path to a library. +Readline_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libreadline.so + +//Path to a file. +Readline_ROOT_DIR:PATH=/usr + +//OFF +UNITY_BUILD:BOOL=OFF + +//Path to a file. +ZLIB_INCLUDE_DIR:PATH=/usr/include + +//Path to a library. +ZLIB_LIBRARY_DEBUG:FILEPATH=ZLIB_LIBRARY_DEBUG-NOTFOUND + +//Path to a library. +ZLIB_LIBRARY_RELEASE:FILEPATH=/usr/lib/x86_64-linux-gnu/libz.so + +//Value Computed by CMake +fc_BINARY_DIR:STATIC=/home/pbattu/git/18.04/peerplays/libraries/fc + +//Dependencies for the target +fc_LIB_DEPENDS:STATIC=general;-L/usr/local/lib;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_thread.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_date_time.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_filesystem.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_system.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_program_options.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_signals.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_serialization.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_chrono.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_unit_test_framework.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_context.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_locale.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_iostreams.a;general;/home/pbattu/git/18.04/boost_1_67_0/lib/libboost_coroutine.a;general;/usr/lib/x86_64-linux-gnu/libpthread.so;general;/usr/lib/x86_64-linux-gnu/libssl.a;general;/usr/lib/x86_64-linux-gnu/libcrypto.a;general;/usr/lib/x86_64-linux-gnu/libz.so;general;dl;general;rt;general;/usr/lib/x86_64-linux-gnu/libreadline.so;general;secp256k1; + +//Value Computed by CMake +fc_SOURCE_DIR:STATIC=/home/pbattu/git/18.04/peerplays/libraries/fc + +//Dependencies for the target +graphene_account_history_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_accounts_list_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_affiliate_stats_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_app_LIB_DEPENDS:STATIC=general;graphene_market_history;general;graphene_account_history;general;graphene_accounts_list;general;graphene_affiliate_stats;general;graphene_chain;general;fc;general;graphene_db;general;graphene_net;general;graphene_time;general;graphene_utilities;general;graphene_debug_witness;general;graphene_bookie; + +//Dependencies for the target +graphene_bookie_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_chain_LIB_DEPENDS:STATIC=general;fc;general;graphene_db; + +//Dependencies for the target +graphene_db_LIB_DEPENDS:STATIC=general;fc; + +//Dependencies for the target +graphene_debug_witness_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_delayed_node_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_egenesis_brief_LIB_DEPENDS:STATIC=general;graphene_chain;general;fc; + +//Dependencies for the target +graphene_egenesis_full_LIB_DEPENDS:STATIC=general;graphene_chain;general;fc; + +//Dependencies for the target +graphene_egenesis_none_LIB_DEPENDS:STATIC=general;graphene_chain;general;fc; + +//Dependencies for the target +graphene_generate_genesis_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app;general;graphene_time; + +//Dependencies for the target +graphene_generate_uia_sharedrop_genesis_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app;general;graphene_time; + +//Dependencies for the target +graphene_market_history_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_net_LIB_DEPENDS:STATIC=general;fc;general;graphene_db; + +//Dependencies for the target +graphene_snapshot_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Dependencies for the target +graphene_time_LIB_DEPENDS:STATIC=general;fc; + +//Dependencies for the target +graphene_utilities_LIB_DEPENDS:STATIC=general;fc; + +//Dependencies for the target +graphene_wallet_LIB_DEPENDS:STATIC=general;graphene_app;general;graphene_net;general;graphene_chain;general;graphene_utilities;general;fc;general;dl; + +//Dependencies for the target +graphene_witness_LIB_DEPENDS:STATIC=general;graphene_chain;general;graphene_app; + +//Value Computed by CMake +websocketpp_BINARY_DIR:STATIC=/home/pbattu/git/18.04/peerplays/libraries/fc/vendor/websocketpp + +//Value Computed by CMake +websocketpp_SOURCE_DIR:STATIC=/home/pbattu/git/18.04/peerplays/libraries/fc/vendor/websocketpp + + +######################## +# INTERNAL cache entries +######################## + +//ADVANCED property for variable: BOOST_ROOT +BOOST_ROOT-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_CHRONO_LIBRARY_DEBUG +Boost_CHRONO_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_CHRONO_LIBRARY_RELEASE +Boost_CHRONO_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_CONTEXT_LIBRARY_DEBUG +Boost_CONTEXT_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_CONTEXT_LIBRARY_RELEASE +Boost_CONTEXT_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_COROUTINE_LIBRARY_DEBUG +Boost_COROUTINE_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_COROUTINE_LIBRARY_RELEASE +Boost_COROUTINE_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_DATE_TIME_LIBRARY_DEBUG +Boost_DATE_TIME_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_DATE_TIME_LIBRARY_RELEASE +Boost_DATE_TIME_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_DIR +Boost_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_FILESYSTEM_LIBRARY_DEBUG +Boost_FILESYSTEM_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_FILESYSTEM_LIBRARY_RELEASE +Boost_FILESYSTEM_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_INCLUDE_DIR +Boost_INCLUDE_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_IOSTREAMS_LIBRARY_DEBUG +Boost_IOSTREAMS_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_IOSTREAMS_LIBRARY_RELEASE +Boost_IOSTREAMS_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_LIBRARY_DIR +Boost_LIBRARY_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_LIBRARY_DIR_DEBUG +Boost_LIBRARY_DIR_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_LIBRARY_DIR_RELEASE +Boost_LIBRARY_DIR_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_LOCALE_LIBRARY_DEBUG +Boost_LOCALE_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_LOCALE_LIBRARY_RELEASE +Boost_LOCALE_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG +Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE +Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_SERIALIZATION_LIBRARY_DEBUG +Boost_SERIALIZATION_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_SERIALIZATION_LIBRARY_RELEASE +Boost_SERIALIZATION_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_SIGNALS_LIBRARY_DEBUG +Boost_SIGNALS_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_SIGNALS_LIBRARY_RELEASE +Boost_SIGNALS_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_SYSTEM_LIBRARY_DEBUG +Boost_SYSTEM_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_SYSTEM_LIBRARY_RELEASE +Boost_SYSTEM_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_THREAD_LIBRARY_DEBUG +Boost_THREAD_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_THREAD_LIBRARY_RELEASE +Boost_THREAD_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_UNIT_TEST_FRAMEWORK_LIBRARY_DEBUG +Boost_UNIT_TEST_FRAMEWORK_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE +Boost_UNIT_TEST_FRAMEWORK_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_AR +CMAKE_AR-ADVANCED:INTERNAL=1 +//This is the directory where this CMakeCache.txt was created +CMAKE_CACHEFILE_DIR:INTERNAL=/home/pbattu/git/18.04/peerplays +//Major version of cmake used to create the current loaded cache +CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 +//Minor version of cmake used to create the current loaded cache +CMAKE_CACHE_MINOR_VERSION:INTERNAL=10 +//Patch version of cmake used to create the current loaded cache +CMAKE_CACHE_PATCH_VERSION:INTERNAL=2 +//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE +CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1 +//Path to CMake executable. +CMAKE_COMMAND:INTERNAL=/usr/bin/cmake +//Path to cpack program executable. +CMAKE_CPACK_COMMAND:INTERNAL=/usr/bin/cpack +//Path to ctest program executable. +CMAKE_CTEST_COMMAND:INTERNAL=/usr/bin/ctest +//ADVANCED property for variable: CMAKE_CXX_COMPILER +CMAKE_CXX_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_COMPILER_AR +CMAKE_CXX_COMPILER_AR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_COMPILER_RANLIB +CMAKE_CXX_COMPILER_RANLIB-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS +CMAKE_CXX_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_DEBUG +CMAKE_CXX_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_MINSIZEREL +CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELEASE +CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO +CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER +CMAKE_C_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER_AR +CMAKE_C_COMPILER_AR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER_RANLIB +CMAKE_C_COMPILER_RANLIB-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS +CMAKE_C_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG +CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL +CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE +CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO +CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//Executable file format +CMAKE_EXECUTABLE_FORMAT:INTERNAL=ELF +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS +CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG +CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE +CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXPORT_COMPILE_COMMANDS +CMAKE_EXPORT_COMPILE_COMMANDS-ADVANCED:INTERNAL=1 +//Name of external makefile project generator. +CMAKE_EXTRA_GENERATOR:INTERNAL= +//Name of generator. +CMAKE_GENERATOR:INTERNAL=Unix Makefiles +//Name of generator platform. +CMAKE_GENERATOR_PLATFORM:INTERNAL= +//Name of generator toolset. +CMAKE_GENERATOR_TOOLSET:INTERNAL= +//Have symbol pthread_create +CMAKE_HAVE_LIBC_CREATE:INTERNAL= +//Have library pthreads +CMAKE_HAVE_PTHREADS_CREATE:INTERNAL= +//Have library pthread +CMAKE_HAVE_PTHREAD_CREATE:INTERNAL=1 +//Have include pthread.h +CMAKE_HAVE_PTHREAD_H:INTERNAL=1 +//Source directory with the top level CMakeLists.txt file for this +// project +CMAKE_HOME_DIRECTORY:INTERNAL=/home/pbattu/git/18.04/peerplays +//Install .so files without execute permission. +CMAKE_INSTALL_SO_NO_EXE:INTERNAL=1 +//ADVANCED property for variable: CMAKE_LINKER +CMAKE_LINKER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MAKE_PROGRAM +CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS +CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG +CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE +CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_NM +CMAKE_NM-ADVANCED:INTERNAL=1 +//number of local generators +CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=37 +//ADVANCED property for variable: CMAKE_OBJCOPY +CMAKE_OBJCOPY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_OBJDUMP +CMAKE_OBJDUMP-ADVANCED:INTERNAL=1 +//Platform information initialized +CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RANLIB +CMAKE_RANLIB-ADVANCED:INTERNAL=1 +//Path to CMake installation. +CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.10 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS +CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG +CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE +CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH +CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_RPATH +CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS +CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG +CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE +CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STRIP +CMAKE_STRIP-ADVANCED:INTERNAL=1 +//uname command +CMAKE_UNAME:INTERNAL=/bin/uname +//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE +CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CURSES_CURSES_LIBRARY +CURSES_CURSES_LIBRARY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CURSES_FORM_LIBRARY +CURSES_FORM_LIBRARY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CURSES_INCLUDE_PATH +CURSES_INCLUDE_PATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CURSES_NCURSES_LIBRARY +CURSES_NCURSES_LIBRARY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: DOXYGEN_DOT_EXECUTABLE +DOXYGEN_DOT_EXECUTABLE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: DOXYGEN_EXECUTABLE +DOXYGEN_EXECUTABLE-ADVANCED:INTERNAL=1 +//Details about finding OpenSSL +FIND_PACKAGE_MESSAGE_DETAILS_OpenSSL:INTERNAL=[/usr/lib/x86_64-linux-gnu/libcrypto.a][/usr/include][v1.1.0g()] +//Details about finding Perl +FIND_PACKAGE_MESSAGE_DETAILS_Perl:INTERNAL=[/usr/bin/perl][v5.26.1()] +//Details about finding Readline +FIND_PACKAGE_MESSAGE_DETAILS_Readline:INTERNAL=[/usr/include][/usr/lib/x86_64-linux-gnu/libreadline.so][v()] +//Details about finding Threads +FIND_PACKAGE_MESSAGE_DETAILS_Threads:INTERNAL=[TRUE][v()] +//Details about finding ZLIB +FIND_PACKAGE_MESSAGE_DETAILS_ZLIB:INTERNAL=[/usr/lib/x86_64-linux-gnu/libz.so][/usr/include][v1.2.11()] +//ADVANCED property for variable: GIT_EXECUTABLE +GIT_EXECUTABLE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: OPENSSL_CRYPTO_LIBRARY +OPENSSL_CRYPTO_LIBRARY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: OPENSSL_INCLUDE_DIR +OPENSSL_INCLUDE_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: OPENSSL_SSL_LIBRARY +OPENSSL_SSL_LIBRARY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: PERL_EXECUTABLE +PERL_EXECUTABLE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: PKG_CONFIG_EXECUTABLE +PKG_CONFIG_EXECUTABLE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Readline_INCLUDE_DIR +Readline_INCLUDE_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Readline_LIBRARY +Readline_LIBRARY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Readline_ROOT_DIR +Readline_ROOT_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: ZLIB_INCLUDE_DIR +ZLIB_INCLUDE_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: ZLIB_LIBRARY_DEBUG +ZLIB_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: ZLIB_LIBRARY_RELEASE +ZLIB_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//Last used BOOST_ROOT value. +_BOOST_ROOT_LAST:INTERNAL=/home/pbattu/git/18.04/boost_1_67_0 +//Components requested for this build tree. +_Boost_COMPONENTS_SEARCHED:INTERNAL=chrono;context;coroutine;date_time;filesystem;iostreams;locale;program_options;serialization;signals;system;thread;unit_test_framework +//Last used Boost_INCLUDE_DIR value. +_Boost_INCLUDE_DIR_LAST:INTERNAL=/home/pbattu/git/18.04/boost_1_67_0/include +//Last used Boost_LIBRARY_DIR_DEBUG value. +_Boost_LIBRARY_DIR_DEBUG_LAST:INTERNAL=/home/pbattu/git/18.04/boost_1_67_0/lib +//Last used Boost_LIBRARY_DIR value. +_Boost_LIBRARY_DIR_LAST:INTERNAL=/home/pbattu/git/18.04/boost_1_67_0/lib +//Last used Boost_LIBRARY_DIR_RELEASE value. +_Boost_LIBRARY_DIR_RELEASE_LAST:INTERNAL=/home/pbattu/git/18.04/boost_1_67_0/lib +//Last used Boost_NAMESPACE value. +_Boost_NAMESPACE_LAST:INTERNAL=boost +//Last used Boost_USE_MULTITHREADED value. +_Boost_USE_MULTITHREADED_LAST:INTERNAL=TRUE +//Last used Boost_USE_STATIC_LIBS value. +_Boost_USE_STATIC_LIBS_LAST:INTERNAL=ON +_OPENSSL_CFLAGS:INTERNAL= +_OPENSSL_CFLAGS_I:INTERNAL= +_OPENSSL_CFLAGS_OTHER:INTERNAL= +_OPENSSL_FOUND:INTERNAL=1 +_OPENSSL_INCLUDEDIR:INTERNAL=/usr/include +_OPENSSL_INCLUDE_DIRS:INTERNAL= +_OPENSSL_LDFLAGS:INTERNAL=-lssl;-lcrypto +_OPENSSL_LDFLAGS_OTHER:INTERNAL= +_OPENSSL_LIBDIR:INTERNAL=/usr/lib/x86_64-linux-gnu +_OPENSSL_LIBRARIES:INTERNAL=ssl;crypto +_OPENSSL_LIBRARY_DIRS:INTERNAL= +_OPENSSL_LIBS:INTERNAL= +_OPENSSL_LIBS_L:INTERNAL= +_OPENSSL_LIBS_OTHER:INTERNAL= +_OPENSSL_LIBS_PATHS:INTERNAL= +_OPENSSL_PREFIX:INTERNAL=/usr +_OPENSSL_STATIC_CFLAGS:INTERNAL= +_OPENSSL_STATIC_CFLAGS_I:INTERNAL= +_OPENSSL_STATIC_CFLAGS_OTHER:INTERNAL= +_OPENSSL_STATIC_INCLUDE_DIRS:INTERNAL= +_OPENSSL_STATIC_LDFLAGS:INTERNAL=-lssl;-ldl;-lcrypto;-ldl +_OPENSSL_STATIC_LDFLAGS_OTHER:INTERNAL= +_OPENSSL_STATIC_LIBDIR:INTERNAL= +_OPENSSL_STATIC_LIBRARIES:INTERNAL=ssl;dl;crypto;dl +_OPENSSL_STATIC_LIBRARY_DIRS:INTERNAL= +_OPENSSL_STATIC_LIBS:INTERNAL= +_OPENSSL_STATIC_LIBS_L:INTERNAL= +_OPENSSL_STATIC_LIBS_OTHER:INTERNAL= +_OPENSSL_STATIC_LIBS_PATHS:INTERNAL= +_OPENSSL_VERSION:INTERNAL=1.1.0g +_OPENSSL_openssl_INCLUDEDIR:INTERNAL= +_OPENSSL_openssl_LIBDIR:INTERNAL= +_OPENSSL_openssl_PREFIX:INTERNAL= +_OPENSSL_openssl_VERSION:INTERNAL= +__pkg_config_arguments__OPENSSL:INTERNAL=QUIET;openssl +__pkg_config_checked__OPENSSL:INTERNAL=1 +prefix_result:INTERNAL=/usr/lib/x86_64-linux-gnu + diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt index be71012dc..18ca31303 100644 --- a/libraries/CMakeLists.txt +++ b/libraries/CMakeLists.txt @@ -1,6 +1,6 @@ add_subdirectory( fc ) add_subdirectory( db ) -add_subdirectory( deterministic_openssl_rand ) +#add_subdirectory( deterministic_openssl_rand ) add_subdirectory( chain ) add_subdirectory( egenesis ) add_subdirectory( net ) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index d46eab07b..0cb6ae0de 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -679,20 +679,6 @@ namespace graphene { namespace app { crypto_api::crypto_api(){}; - blind_signature crypto_api::blind_sign( const extended_private_key_type& key, const blinded_hash& hash, int i ) - { - return fc::ecc::extended_private_key( key ).blind_sign( hash, i ); - } - - signature_type crypto_api::unblind_signature( const extended_private_key_type& key, - const extended_public_key_type& bob, - const blind_signature& sig, - const fc::sha256& hash, - int i ) - { - return fc::ecc::extended_private_key( key ).unblind_signature( extended_public_key( bob ), sig, hash, i ); - } - commitment_type crypto_api::blind( const blind_factor_type& blind, uint64_t value ) { return fc::ecc::blind( blind, value ); diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 44ce7b68b..e92db7531 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -292,16 +292,8 @@ namespace graphene { namespace app { class crypto_api { public: - crypto_api(); - - fc::ecc::blind_signature blind_sign( const extended_private_key_type& key, const fc::ecc::blinded_hash& hash, int i ); - - signature_type unblind_signature( const extended_private_key_type& key, - const extended_public_key_type& bob, - const fc::ecc::blind_signature& sig, - const fc::sha256& hash, - int i ); - + crypto_api(); + fc::ecc::commitment_type blind( const fc::ecc::blind_factor_type& blind, uint64_t value ); fc::ecc::blind_factor_type blind_sum( const std::vector& blinds_in, uint32_t non_neg ); @@ -447,8 +439,6 @@ FC_API(graphene::app::network_node_api, (unsubscribe_from_pending_transactions) ) FC_API(graphene::app::crypto_api, - (blind_sign) - (unblind_signature) (blind) (blind_sum) (verify_sum) diff --git a/libraries/chain/betting_market_group_object.cpp b/libraries/chain/betting_market_group_object.cpp index 584039c9c..71135e073 100644 --- a/libraries/chain/betting_market_group_object.cpp +++ b/libraries/chain/betting_market_group_object.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include diff --git a/libraries/chain/betting_market_object.cpp b/libraries/chain/betting_market_object.cpp index a0beeb7d6..cb0e006e4 100644 --- a/libraries/chain/betting_market_object.cpp +++ b/libraries/chain/betting_market_object.cpp @@ -25,7 +25,7 @@ #define DEFAULT_LOGGER "betting" #include #include -#include +#include #include #include @@ -101,7 +101,7 @@ share_type bet_object::get_exact_matching_amount() const /* static */ std::pair bet_object::get_ratio(bet_multiplier_type backer_multiplier) { - share_type gcd = boost::math::gcd(GRAPHENE_BETTING_ODDS_PRECISION, backer_multiplier - GRAPHENE_BETTING_ODDS_PRECISION); + share_type gcd = boost::integer::gcd(GRAPHENE_BETTING_ODDS_PRECISION, static_cast(backer_multiplier - GRAPHENE_BETTING_ODDS_PRECISION)); return std::make_pair(GRAPHENE_BETTING_ODDS_PRECISION / gcd, (backer_multiplier - GRAPHENE_BETTING_ODDS_PRECISION) / gcd); } @@ -112,13 +112,13 @@ std::pair bet_object::get_ratio() const share_type bet_object::get_minimum_matchable_amount() const { - share_type gcd = boost::math::gcd(GRAPHENE_BETTING_ODDS_PRECISION, backer_multiplier - GRAPHENE_BETTING_ODDS_PRECISION); + share_type gcd = boost::integer::gcd(GRAPHENE_BETTING_ODDS_PRECISION, static_cast(backer_multiplier - GRAPHENE_BETTING_ODDS_PRECISION)); return (back_or_lay == bet_type::back ? GRAPHENE_BETTING_ODDS_PRECISION : backer_multiplier - GRAPHENE_BETTING_ODDS_PRECISION) / gcd; } share_type bet_object::get_minimum_matching_amount() const { - share_type gcd = boost::math::gcd(GRAPHENE_BETTING_ODDS_PRECISION, backer_multiplier - GRAPHENE_BETTING_ODDS_PRECISION); + share_type gcd = boost::integer::gcd(GRAPHENE_BETTING_ODDS_PRECISION, static_cast(backer_multiplier - GRAPHENE_BETTING_ODDS_PRECISION)); return (back_or_lay == bet_type::lay ? GRAPHENE_BETTING_ODDS_PRECISION : backer_multiplier - GRAPHENE_BETTING_ODDS_PRECISION) / gcd; } diff --git a/libraries/db/include/graphene/db/generic_index.hpp b/libraries/db/include/graphene/db/generic_index.hpp index 8a433264e..10e5d19ee 100644 --- a/libraries/db/include/graphene/db/generic_index.hpp +++ b/libraries/db/include/graphene/db/generic_index.hpp @@ -67,10 +67,25 @@ namespace graphene { namespace chain { virtual void modify( const object& obj, const std::function& m )override { - assert( nullptr != dynamic_cast(&obj) ); - auto ok = _indices.modify( _indices.iterator_to( static_cast(obj) ), - [&m]( ObjectType& o ){ m(o); } ); - FC_ASSERT( ok, "Could not modify object, most likely a index constraint was violated" ); + assert(nullptr != dynamic_cast(&obj)); + std::exception_ptr exc; + auto ok = _indices.modify(_indices.iterator_to(static_cast(obj)), + [&m, &exc](ObjectType& o) mutable { + try { + m(o); + } catch (fc::exception e) { + exc = std::current_exception(); + elog("Exception while modifying object: ${e} -- object may be corrupted", + ("e", e)); + } catch (...) { + exc = std::current_exception(); + elog("Unknown exception while modifying object"); + } + } + ); + if (exc) + std::rethrow_exception(exc); + FC_ASSERT(ok, "Could not modify object, most likely an index constraint was violated"); } virtual void remove( const object& obj )override diff --git a/libraries/deterministic_openssl_rand/CMakeLists.txt b/libraries/deterministic_openssl_rand/CMakeLists.txt deleted file mode 100644 index 1d9c5870c..000000000 --- a/libraries/deterministic_openssl_rand/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ - -file(GLOB headers "include/graphene/utilities/*.hpp") - -set(sources deterministic_openssl_rand.cpp - ${headers}) - -add_library( deterministic_openssl_rand - ${sources} - ${HEADERS} ) -target_link_libraries( deterministic_openssl_rand fc ) -target_include_directories( deterministic_openssl_rand - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" - "${CMAKE_CURRENT_SOURCE_DIR}/../blockchain/include" - ) - -if (USE_PCH) - set_target_properties(deterministic_openssl_rand PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) - cotire(deterministic_openssl_rand) -endif(USE_PCH) - -install( TARGETS - deterministic_openssl_rand - - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib -) -install( FILES ${headers} DESTINATION "include/graphene/deterministic_openssl_rand" ) diff --git a/libraries/deterministic_openssl_rand/deterministic_openssl_rand.cpp b/libraries/deterministic_openssl_rand/deterministic_openssl_rand.cpp deleted file mode 100644 index e88e5c26c..000000000 --- a/libraries/deterministic_openssl_rand/deterministic_openssl_rand.cpp +++ /dev/null @@ -1,104 +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 -#include -#include -#include -#include -#include -#include -//#include - -#include -#include -#include -#include - -static bool deterministic_rand_warning_shown = false; - -static void _warn() -{ - if (!deterministic_rand_warning_shown) - { - std::cerr << "********************************************************************************\n" - << "DETERMINISTIC RANDOM NUMBER GENERATION ENABLED\n" - << "********************************************************************************\n" - << "TESTING PURPOSES ONLY -- NOT SUITABLE FOR PRODUCTION USE\n" - << "DO NOT USE PRIVATE KEYS GENERATED WITH THIS PROGRAM FOR LIVE FUNDS\n" - << "********************************************************************************\n"; - deterministic_rand_warning_shown = true; - } -#ifndef GRAPHENE_TEST_NETWORK - std::cerr << "This program looks like a production application, but is calling the deterministic RNG.\n" - << "Perhaps the compile-time options in config.hpp were misconfigured?\n"; - exit(1); -#else - return; -#endif -} - -// These don't need to do anything if you don't have anything for them to do. -static void deterministic_rand_cleanup() { _warn(); } -static void deterministic_rand_add(const void *buf, int num, double add_entropy) { _warn(); } -static int deterministic_rand_status() { _warn(); return 1; } -static void deterministic_rand_seed(const void *buf, int num) { _warn(); } - -static fc::sha512 seed; - -static int deterministic_rand_bytes(unsigned char *buf, int num) -{ - _warn(); - while (num) - { - seed = fc::sha512::hash(seed); - - int bytes_to_copy = std::min(num, sizeof(seed)); - memcpy(buf, &seed, bytes_to_copy); - num -= bytes_to_copy; - buf += bytes_to_copy; - } - return 1; -} - -// Create the table that will link OpenSSL's rand API to our functions. -static RAND_METHOD deterministic_rand_vtable = { - deterministic_rand_seed, - deterministic_rand_bytes, - deterministic_rand_cleanup, - deterministic_rand_add, - deterministic_rand_bytes, - deterministic_rand_status -}; - -namespace graphene { namespace utilities { - -void set_random_seed_for_testing(const fc::sha512& new_seed) -{ - _warn(); - RAND_set_rand_method(&deterministic_rand_vtable); - seed = new_seed; - return; -} - -} } diff --git a/libraries/deterministic_openssl_rand/include/graphene/utilities/deterministic_openssl_rand.hpp b/libraries/deterministic_openssl_rand/include/graphene/utilities/deterministic_openssl_rand.hpp deleted file mode 100644 index 693723cb4..000000000 --- a/libraries/deterministic_openssl_rand/include/graphene/utilities/deterministic_openssl_rand.hpp +++ /dev/null @@ -1,31 +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 - -namespace graphene { namespace utilities { - -void set_random_seed_for_testing(const fc::sha512& new_seed); - -} } // end namespace graphene::utilities diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 9d8b95290..dfdaf1ccb 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -827,7 +827,7 @@ namespace graphene { namespace net { namespace detail { _maximum_blocks_per_peer_during_syncing(GRAPHENE_NET_MAX_BLOCKS_PER_PEER_DURING_SYNCING) { _rate_limiter.set_actual_rate_time_constant(fc::seconds(2)); - fc::rand_pseudo_bytes(&_node_id.data[0], (int)_node_id.size()); + fc::rand_bytes(&_node_id.data[0], (int)_node_id.size()); } node_impl::~node_impl() diff --git a/programs/cli_wallet/main.cpp b/programs/cli_wallet/main.cpp index 040b6fac4..0155897c2 100644 --- a/programs/cli_wallet/main.cpp +++ b/programs/cli_wallet/main.cpp @@ -50,6 +50,10 @@ #include #include +#include +#include +#include + #ifdef WIN32 # include #else diff --git a/programs/witness_node/bkup_config.ini b/programs/witness_node/bkup_config.ini new file mode 100644 index 000000000..912230cb4 --- /dev/null +++ b/programs/witness_node/bkup_config.ini @@ -0,0 +1,83 @@ +# Endpoint for P2P node to listen on +p2p-endpoint = 0.0.0.0:9777 + +# P2P nodes to connect to on startup (may specify multiple times) +# seed-node = + +# JSON array of P2P nodes to connect to on startup +# seed-nodes = + +# Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints. +# checkpoint = + +# Endpoint for websocket RPC to listen on +rpc-endpoint = 0.0.0.0:8090 + +# Endpoint for TLS websocket RPC to listen on +# rpc-tls-endpoint = + +# The TLS certificate file for this server +# server-pem = + +# Password for this certificate +# server-pem-password = + +# File to read Genesis State from + genesis-json =genesis.json + +# Block signing key to use for init witnesses, overrides genesis file +# dbg-init-key = + +# JSON file specifying API permissions +# api-access = + +# Enable block production, even if the chain is stale. +enable-stale-production = true + +# Percent of witnesses (0-99) that must be participating in order to produce blocks +required-participation = false + +# ID of witness controlled by this node (e.g. "1.6.5", quotes are required, may specify multiple times) +# witness-id = + +# IDs of multiple witnesses controlled by this node (e.g. ["1.6.5", "1.6.6"], quotes are required) + witness-ids = ["1.6.1", "1.6.2", "1.6.3", "1.6.4", "1.6.5", "1.6.6", "1.6.7", "1.6.8", "1.6.9", "1.6.10", "1.6.11"] + +# Tuple of [PublicKey, WIF private key] (may specify multiple times) +private-key = ["TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"] + +# Account ID to track history for (may specify multiple times) +# track-account = + +# Keep only those operations in memory that are related to account history tracking +# partial-operations = + +# Maximum number of operations per account will be kept in memory +# max-ops-per-account = + +# Track market history by grouping orders into buckets of equal size measured in seconds specified as a JSON array of numbers +bucket-size = [15,60,300,3600,86400] + +# How far back in time to track history for each bucket size, measured in the number of buckets (default: 1000) +history-per-size = 1000 + +# declare an appender named "stderr" that writes messages to the console +[log.console_appender.stderr] +stream=std_error + +# declare an appender named "p2p" that writes messages to p2p.log +[log.file_appender.p2p] +filename=logs/p2p/p2p.log +# filename can be absolute or relative to this config file + +# route any messages logged to the default logger to the "stderr" logger we +# declared above, if they are info level are higher +[logger.default] +level=info +appenders=stderr + +# route messages sent to the "p2p" logger to the p2p appender declared above +[logger.p2p] +level=info +appenders=p2p + diff --git a/programs/witness_node/bkup_genesis.json b/programs/witness_node/bkup_genesis.json new file mode 100644 index 000000000..15bcf26ae --- /dev/null +++ b/programs/witness_node/bkup_genesis.json @@ -0,0 +1,496 @@ +{ + "initial_timestamp": "2019-01-02T19:42:12", + "max_core_supply": "1000000000000000", + "initial_parameters": { + "current_fees": { + "parameters": [[ + 0,{ + "fee": 2000000, + "price_per_kbyte": 1000000 + } + ],[ + 1,{ + "fee": 500000 + } + ],[ + 2,{ + "fee": 0 + } + ],[ + 3,{ + "fee": 2000000 + } + ],[ + 4,{} + ],[ + 5,{ + "basic_fee": 500000, + "premium_fee": 200000000, + "price_per_kbyte": 100000 + } + ],[ + 6,{ + "fee": 2000000, + "price_per_kbyte": 100000 + } + ],[ + 7,{ + "fee": 300000 + } + ],[ + 8,{ + "membership_annual_fee": 200000000, + "membership_lifetime_fee": 1000000000 + } + ],[ + 9,{ + "fee": 50000000 + } + ],[ + 10,{ + "symbol3": "50000000000", + "symbol4": "30000000000", + "long_symbol": 500000000, + "price_per_kbyte": 10 + } + ],[ + 11,{ + "fee": 50000000, + "price_per_kbyte": 10 + } + ],[ + 12,{ + "fee": 50000000 + } + ],[ + 13,{ + "fee": 50000000 + } + ],[ + 14,{ + "fee": 2000000, + "price_per_kbyte": 100000 + } + ],[ + 15,{ + "fee": 2000000 + } + ],[ + 16,{ + "fee": 100000 + } + ],[ + 17,{ + "fee": 10000000 + } + ],[ + 18,{ + "fee": 50000000 + } + ],[ + 19,{ + "fee": 100000 + } + ],[ + 20,{ + "fee": 500000000 + } + ],[ + 21,{ + "fee": 2000000 + } + ],[ + 22,{ + "fee": 2000000, + "price_per_kbyte": 10 + } + ],[ + 23,{ + "fee": 2000000, + "price_per_kbyte": 10 + } + ],[ + 24,{ + "fee": 100000 + } + ],[ + 25,{ + "fee": 100000 + } + ],[ + 26,{ + "fee": 100000 + } + ],[ + 27,{ + "fee": 2000000, + "price_per_kbyte": 10 + } + ],[ + 28,{ + "fee": 0 + } + ],[ + 29,{ + "fee": 500000000 + } + ],[ + 30,{ + "fee": 2000000 + } + ],[ + 31,{ + "fee": 100000 + } + ],[ + 32,{ + "fee": 100000 + } + ],[ + 33,{ + "fee": 2000000 + } + ],[ + 34,{ + "fee": 500000000 + } + ],[ + 35,{ + "fee": 100000, + "price_per_kbyte": 10 + } + ],[ + 36,{ + "fee": 100000 + } + ],[ + 37,{} + ],[ + 38,{ + "fee": 2000000, + "price_per_kbyte": 10 + } + ],[ + 39,{ + "fee": 500000, + "price_per_output": 500000 + } + ],[ + 40,{ + "fee": 500000, + "price_per_output": 500000 + } + ],[ + 41,{ + "fee": 500000 + } + ],[ + 42,{} + ],[ + 43,{ + "fee": 2000000 + } + ],[ + 44,{} + ],[ + 45,{ + "fee": 100000 + } + ],[ + 46,{ + "fee": 100000 + } + ],[ + 47,{ + "fee": 100000 + } + ],[ + 48,{ + "fee": 50000000 + } + ],[ + 49,{ + "distribution_base_fee": 0, + "distribution_fee_per_holder": 0 + } + ],[ + 50,{} + ],[ + 51,{ + "fee": 100000 + } + ],[ + 52,{ + "fee": 100000 + } + ],[ + 53,{ + "fee": 100000 + } + ],[ + 54,{ + "fee": 100000 + } + ],[ + 55,{ + "fee": 100000 + } + ],[ + 56,{ + "fee": 100000 + } + ],[ + 57,{ + "fee": 100000 + } + ],[ + 58,{ + "fee": 100000 + } + ],[ + 59,{ + "fee": 100000 + } + ],[ + 60,{ + "fee": 100000 + } + ],[ + 61,{ + "fee": 100000 + } + ],[ + 62,{ + "fee": 1000 + } + ],[ + 63,{ + "fee": 100000 + } + ],[ + 64,{} + ],[ + 65,{} + ],[ + 66,{ + "fee": 100000 + } + ],[ + 67,{} + ],[ + 68,{ + "fee": 0 + } + ],[ + 69,{} + ],[ + 70,{ + "fee": 100000 + } + ],[ + 71,{ + "fee": 100000 + } + ],[ + 72,{ + "fee": 100000 + } + ],[ + 73,{ + "fee": 100000 + } + ],[ + 74,{ + "fee": 100000 + } + ],[ + 75,{} + ],[ + 76,{} + ] + ], + "scale": 10000 + }, + "block_interval": 3, + "maintenance_interval": 900, + "maintenance_skip_slots": 3, + "committee_proposal_review_period": 2000, + "maximum_transaction_size": 2048, + "maximum_block_size": 1228800000, + "maximum_time_until_expiration": 86400, + "maximum_proposal_lifetime": 2419200, + "maximum_asset_whitelist_authorities": 10, + "maximum_asset_feed_publishers": 10, + "maximum_witness_count": 1001, + "maximum_committee_count": 1001, + "maximum_authority_membership": 10, + "reserve_percent_of_fee": 2000, + "network_percent_of_fee": 2000, + "lifetime_referrer_percent_of_fee": 3000, + "cashback_vesting_period_seconds": 31536000, + "cashback_vesting_threshold": 10000000, + "count_non_member_votes": true, + "allow_non_member_whitelists": false, + "witness_pay_per_block": 1000000, + "worker_budget_per_day": "50000000000", + "max_predicate_opcode": 1, + "fee_liquidation_threshold": 10000000, + "accounts_per_fee_scale": 1000, + "account_fee_scale_bitshifts": 4, + "max_authority_depth": 2, + "witness_schedule_algorithm": 1, + "min_round_delay": 0, + "max_round_delay": 600, + "min_time_per_commit_move": 0, + "max_time_per_commit_move": 600, + "min_time_per_reveal_move": 0, + "max_time_per_reveal_move": 600, + "rake_fee_percentage": 300, + "maximum_registration_deadline": 2592000, + "maximum_players_in_tournament": 256, + "maximum_tournament_whitelist_length": 1000, + "maximum_tournament_start_time_in_future": 2419200, + "maximum_tournament_start_delay": 604800, + "maximum_tournament_number_of_wins": 100, + "extensions": {} + }, + "initial_bts_accounts": [], + "initial_accounts": [{ + "name": "init0", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init1", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init2", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init3", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init4", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init5", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init6", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init7", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init8", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init9", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init10", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "nathan", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": false + } + ], + "initial_assets": [], + "initial_balances": [{ + "owner": "TESTFAbAx7yuxt725qSZvfwWqkdCwp9ZnUama", + "asset_symbol": "TEST", + "amount": "1000000000000000" + } + ], + "initial_vesting_balances": [], + "initial_active_witnesses": 11, + "initial_witness_candidates": [{ + "owner_name": "init0", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init1", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init2", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init3", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init4", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init5", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init6", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init7", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init8", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init9", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init10", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + } + ], + "initial_committee_candidates": [{ + "owner_name": "init0" + },{ + "owner_name": "init1" + },{ + "owner_name": "init2" + },{ + "owner_name": "init3" + },{ + "owner_name": "init4" + },{ + "owner_name": "init5" + },{ + "owner_name": "init6" + },{ + "owner_name": "init7" + },{ + "owner_name": "init8" + },{ + "owner_name": "init9" + },{ + "owner_name": "init10" + } + ], + "initial_worker_candidates": [], + "initial_chain_id": "aa34045518f1469a28fa4578240d5f039afa9959c0b95ce3b39674efa691fb21", + "immutable_parameters": { + "min_committee_member_count": 11, + "min_witness_count": 11, + "num_special_accounts": 0, + "num_special_assets": 0 + } +} diff --git a/programs/witness_node/genesis.json b/programs/witness_node/genesis.json new file mode 100644 index 000000000..ab153e7bd --- /dev/null +++ b/programs/witness_node/genesis.json @@ -0,0 +1,496 @@ +{ + "initial_timestamp": "2019-05-14T18:47:51", + "max_core_supply": "1000000000000000", + "initial_parameters": { + "current_fees": { + "parameters": [[ + 0,{ + "fee": 2000000, + "price_per_kbyte": 1000000 + } + ],[ + 1,{ + "fee": 500000 + } + ],[ + 2,{ + "fee": 0 + } + ],[ + 3,{ + "fee": 2000000 + } + ],[ + 4,{} + ],[ + 5,{ + "basic_fee": 500000, + "premium_fee": 200000000, + "price_per_kbyte": 100000 + } + ],[ + 6,{ + "fee": 2000000, + "price_per_kbyte": 100000 + } + ],[ + 7,{ + "fee": 300000 + } + ],[ + 8,{ + "membership_annual_fee": 200000000, + "membership_lifetime_fee": 1000000000 + } + ],[ + 9,{ + "fee": 50000000 + } + ],[ + 10,{ + "symbol3": "50000000000", + "symbol4": "30000000000", + "long_symbol": 500000000, + "price_per_kbyte": 10 + } + ],[ + 11,{ + "fee": 50000000, + "price_per_kbyte": 10 + } + ],[ + 12,{ + "fee": 50000000 + } + ],[ + 13,{ + "fee": 50000000 + } + ],[ + 14,{ + "fee": 2000000, + "price_per_kbyte": 100000 + } + ],[ + 15,{ + "fee": 2000000 + } + ],[ + 16,{ + "fee": 100000 + } + ],[ + 17,{ + "fee": 10000000 + } + ],[ + 18,{ + "fee": 50000000 + } + ],[ + 19,{ + "fee": 100000 + } + ],[ + 20,{ + "fee": 500000000 + } + ],[ + 21,{ + "fee": 2000000 + } + ],[ + 22,{ + "fee": 2000000, + "price_per_kbyte": 10 + } + ],[ + 23,{ + "fee": 2000000, + "price_per_kbyte": 10 + } + ],[ + 24,{ + "fee": 100000 + } + ],[ + 25,{ + "fee": 100000 + } + ],[ + 26,{ + "fee": 100000 + } + ],[ + 27,{ + "fee": 2000000, + "price_per_kbyte": 10 + } + ],[ + 28,{ + "fee": 0 + } + ],[ + 29,{ + "fee": 500000000 + } + ],[ + 30,{ + "fee": 2000000 + } + ],[ + 31,{ + "fee": 100000 + } + ],[ + 32,{ + "fee": 100000 + } + ],[ + 33,{ + "fee": 2000000 + } + ],[ + 34,{ + "fee": 500000000 + } + ],[ + 35,{ + "fee": 100000, + "price_per_kbyte": 10 + } + ],[ + 36,{ + "fee": 100000 + } + ],[ + 37,{} + ],[ + 38,{ + "fee": 2000000, + "price_per_kbyte": 10 + } + ],[ + 39,{ + "fee": 500000, + "price_per_output": 500000 + } + ],[ + 40,{ + "fee": 500000, + "price_per_output": 500000 + } + ],[ + 41,{ + "fee": 500000 + } + ],[ + 42,{} + ],[ + 43,{ + "fee": 2000000 + } + ],[ + 44,{} + ],[ + 45,{ + "fee": 100000 + } + ],[ + 46,{ + "fee": 100000 + } + ],[ + 47,{ + "fee": 100000 + } + ],[ + 48,{ + "fee": 50000000 + } + ],[ + 49,{ + "distribution_base_fee": 0, + "distribution_fee_per_holder": 0 + } + ],[ + 50,{} + ],[ + 51,{ + "fee": 100000 + } + ],[ + 52,{ + "fee": 100000 + } + ],[ + 53,{ + "fee": 100000 + } + ],[ + 54,{ + "fee": 100000 + } + ],[ + 55,{ + "fee": 100000 + } + ],[ + 56,{ + "fee": 100000 + } + ],[ + 57,{ + "fee": 100000 + } + ],[ + 58,{ + "fee": 100000 + } + ],[ + 59,{ + "fee": 100000 + } + ],[ + 60,{ + "fee": 100000 + } + ],[ + 61,{ + "fee": 100000 + } + ],[ + 62,{ + "fee": 100000 + } + ],[ + 63,{ + "fee": 100000 + } + ],[ + 64,{} + ],[ + 65,{} + ],[ + 66,{ + "fee": 100000 + } + ],[ + 67,{} + ],[ + 68,{ + "fee": 100000 + } + ],[ + 69,{} + ],[ + 70,{ + "fee": 100000 + } + ],[ + 71,{ + "fee": 100000 + } + ],[ + 72,{ + "fee": 100000 + } + ],[ + 73,{ + "fee": 100000 + } + ],[ + 74,{ + "fee": 100000 + } + ],[ + 75,{} + ],[ + 76,{} + ] + ], + "scale": 10000 + }, + "block_interval": 3, + "maintenance_interval": 86400, + "maintenance_skip_slots": 3, + "committee_proposal_review_period": 1209600, + "maximum_transaction_size": 2048, + "maximum_block_size": 1228800000, + "maximum_time_until_expiration": 86400, + "maximum_proposal_lifetime": 2419200, + "maximum_asset_whitelist_authorities": 10, + "maximum_asset_feed_publishers": 10, + "maximum_witness_count": 1001, + "maximum_committee_count": 1001, + "maximum_authority_membership": 10, + "reserve_percent_of_fee": 2000, + "network_percent_of_fee": 2000, + "lifetime_referrer_percent_of_fee": 3000, + "cashback_vesting_period_seconds": 31536000, + "cashback_vesting_threshold": 10000000, + "count_non_member_votes": true, + "allow_non_member_whitelists": false, + "witness_pay_per_block": 1000000, + "worker_budget_per_day": "50000000000", + "max_predicate_opcode": 1, + "fee_liquidation_threshold": 10000000, + "accounts_per_fee_scale": 1000, + "account_fee_scale_bitshifts": 4, + "max_authority_depth": 2, + "witness_schedule_algorithm": 1, + "min_round_delay": 0, + "max_round_delay": 600, + "min_time_per_commit_move": 0, + "max_time_per_commit_move": 600, + "min_time_per_reveal_move": 0, + "max_time_per_reveal_move": 600, + "rake_fee_percentage": 300, + "maximum_registration_deadline": 2592000, + "maximum_players_in_tournament": 256, + "maximum_tournament_whitelist_length": 1000, + "maximum_tournament_start_time_in_future": 2419200, + "maximum_tournament_start_delay": 604800, + "maximum_tournament_number_of_wins": 100, + "extensions": {} + }, + "initial_bts_accounts": [], + "initial_accounts": [{ + "name": "init0", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init1", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init2", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init3", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init4", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init5", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init6", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init7", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init8", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init9", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "init10", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": true + },{ + "name": "nathan", + "owner_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "active_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", + "is_lifetime_member": false + } + ], + "initial_assets": [], + "initial_balances": [{ + "owner": "TESTFAbAx7yuxt725qSZvfwWqkdCwp9ZnUama", + "asset_symbol": "TEST", + "amount": "1000000000000000" + } + ], + "initial_vesting_balances": [], + "initial_active_witnesses": 11, + "initial_witness_candidates": [{ + "owner_name": "init0", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init1", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init2", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init3", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init4", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init5", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init6", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init7", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init8", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init9", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + },{ + "owner_name": "init10", + "block_signing_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" + } + ], + "initial_committee_candidates": [{ + "owner_name": "init0" + },{ + "owner_name": "init1" + },{ + "owner_name": "init2" + },{ + "owner_name": "init3" + },{ + "owner_name": "init4" + },{ + "owner_name": "init5" + },{ + "owner_name": "init6" + },{ + "owner_name": "init7" + },{ + "owner_name": "init8" + },{ + "owner_name": "init9" + },{ + "owner_name": "init10" + } + ], + "initial_worker_candidates": [], + "initial_chain_id": "aa34045518f1469a28fa4578240d5f039afa9959c0b95ce3b39674efa691fb21", + "immutable_parameters": { + "min_committee_member_count": 11, + "min_witness_count": 11, + "num_special_accounts": 0, + "num_special_assets": 0 + } +} \ No newline at end of file diff --git a/programs/witness_node/main.cpp b/programs/witness_node/main.cpp index 6f55d5936..34b22a2fd 100644 --- a/programs/witness_node/main.cpp +++ b/programs/witness_node/main.cpp @@ -50,6 +50,10 @@ #include #include +#include +#include +#include + #include #include @@ -117,6 +121,8 @@ int main(int argc, char** argv) { std::cerr << "Version: " << witness_version << "\n"; std::cerr << "Git Revision: " << graphene::utilities::git_revision_sha << "\n"; std::cerr << "Built: " << __DATE__ " at " __TIME__ << "\n"; + std::cout << "SSL: " << OPENSSL_VERSION_TEXT << "\n"; + std::cout << "Boost: " << boost::replace_all_copy(std::string(BOOST_LIB_VERSION), "_", ".") << "\n"; return 0; } From 006eaeeee6f9d1c6bcc38af62bb2ca7e00465cef Mon Sep 17 00:00:00 2001 From: pbattu Date: Tue, 21 May 2019 14:31:44 -0300 Subject: [PATCH 22/31] path to fc modified --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 5572259c0..ca2fa11d7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,5 +4,5 @@ ignore = dirty [submodule "libraries/fc"] path = libraries/fc - url = https://github.com/PBSA/peerplays-fc.git + url = https://github.com/peerplays-network/peerplays-fc.git ignore = dirty From b568fbb842e82f360c3e4cd58b5e61b9ca419327 Mon Sep 17 00:00:00 2001 From: pbattu Date: Tue, 21 May 2019 15:06:00 -0300 Subject: [PATCH 23/31] path to fc modified again --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index ca2fa11d7..be9a43945 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,5 +4,5 @@ ignore = dirty [submodule "libraries/fc"] path = libraries/fc - url = https://github.com/peerplays-network/peerplays-fc.git + url = https://github.com/peerplays-network/peerplays-fc.git#Task/Ubuntu18.04-Upgrade ignore = dirty From 84dff76a0a4adbe0cf91c13271fe86b365f2b317 Mon Sep 17 00:00:00 2001 From: pbattu Date: Tue, 21 May 2019 19:13:44 -0300 Subject: [PATCH 24/31] updated submodules to support 18.04 upgrade --- libraries/fc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/fc b/libraries/fc index c8c05254b..997d211fb 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit c8c05254b1285fdfb1ea345da8342e4575426995 +Subproject commit 997d211fb16acad6bc5f14cc68b1041f3712db7a From ea25a9cc443e837e9e70c280f4aa33aac2c66746 Mon Sep 17 00:00:00 2001 From: pbattu Date: Tue, 21 May 2019 19:43:19 -0300 Subject: [PATCH 25/31] updates to git submodules path --- .gitmodules | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index be9a43945..3b8a2679f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,5 +4,6 @@ ignore = dirty [submodule "libraries/fc"] path = libraries/fc - url = https://github.com/peerplays-network/peerplays-fc.git#Task/Ubuntu18.04-Upgrade + url = https://github.com/PBSA/peerplays-fc.git + branch = feature/ubuntu18.04-upgrade ignore = dirty From ee02f268f51ca71952fd1f79836a10b3c3de6d78 Mon Sep 17 00:00:00 2001 From: pbattu Date: Tue, 21 May 2019 21:29:59 -0300 Subject: [PATCH 26/31] want to update HEAD to latest commit of fc --- libraries/fc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/fc b/libraries/fc index 997d211fb..6c9e857bd 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit 997d211fb16acad6bc5f14cc68b1041f3712db7a +Subproject commit 6c9e857bd26e2acd62953f4783164faba044f98f From 4c174597ff3adec24274074be8b5b2d3ea99a3bf Mon Sep 17 00:00:00 2001 From: PBSA Date: Wed, 22 May 2019 16:34:55 +0000 Subject: [PATCH 27/31] compilation errors resolved --- libraries/fc | 2 +- libraries/wallet/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/fc b/libraries/fc index 6c9e857bd..94b046dce 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit 6c9e857bd26e2acd62953f4783164faba044f98f +Subproject commit 94b046dce6bb86fd22abd1831fc9056103f4aa5d diff --git a/libraries/wallet/CMakeLists.txt b/libraries/wallet/CMakeLists.txt index 53e75abde..74b9f7c55 100644 --- a/libraries/wallet/CMakeLists.txt +++ b/libraries/wallet/CMakeLists.txt @@ -10,7 +10,7 @@ if( PERL_FOUND AND DOXYGEN_FOUND AND NOT "${CMAKE_GENERATOR}" STREQUAL "Ninja" ) COMMAND ${DOXYGEN_EXECUTABLE} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile include/graphene/wallet/wallet.hpp ) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/api_documentation.cpp - COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/generate_api_documentation.pl ${CMAKE_CURRENT_BINARY_DIR}/api_documentation.cpp.new + COMMAND PERLLIB=${CMAKE_CURRENT_SOURCE_DIR} ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/generate_api_documentation.pl ${CMAKE_CURRENT_BINARY_DIR}/api_documentation.cpp.new COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/api_documentation.cpp.new ${CMAKE_CURRENT_BINARY_DIR}/api_documentation.cpp COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/api_documentation.cpp.new From 12c2d0ee33f9e75a5c07cf6b129cfb9c12497513 Mon Sep 17 00:00:00 2001 From: Bobinson K B Date: Thu, 23 May 2019 23:21:01 +0530 Subject: [PATCH 28/31] building on Ubuntu 18.04 updated README to capture support building on Ubuntu 18.04 --- .gitignore | 1 + README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/.gitignore b/.gitignore index 5df52280d..5e9bf5cd0 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ object_database/* *.pyo .vscode .DS_Store +.idea \ No newline at end of file diff --git a/README.md b/README.md index 245e1388e..11c4ca878 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,46 @@ Intro for new developers and witnesses ------------------------ This is a quick introduction to get new developers and witnesses up to speed on Peerplays blockchain. It is intended for witnesses plannig to join a live, already deployed blockchain. +# Building on Ubuntu 18.04 LTS and Installation Instructions + + The following dependencies were necessary for a clean install of Ubuntu 18.04 LTS: + + sudo apt-get install gcc-5 g++-5 cmake make libbz2-dev libdb++-dev libdb-dev libssl-dev openssl libreadline-dev autoconf libtool git + +## Build Boost 1.67.0 + + + + mkdir $HOME/src + cd $HOME/src + export BOOST_ROOT=$HOME/src/boost_1_67_0 + sudo apt-get update + sudo apt-get install -y autotools-dev build-essential libbz2-dev libicu-dev python-dev + wget -c 'http://sourceforge.net/projects/boost/files/boost/1.67.0/boost_1_67_0.tar.bz2/download' -O boost_1_67_0.tar.bz2 + [ $( sha256sum boost_1_67_0.tar.bz2 | cut -d ' ' -f 1 ) == "2684c972994ee57fc5632e03bf044746f6eb45d4920c343937a465fd67a5adba" ] || ( echo 'Corrupt download' ; exit 1 ) + tar xjf boost_1_67_0.tar.bz2 + cd boost_1_67_0/ + ./bootstrap.sh "--prefix=$BOOST_ROOT" + ./b2 install + + + +## Building Peerplays + + + export BOOST_ROOT=/root/boost_1_67_0 + export CC=gcc-5 ; export CXX=g++-5 + cd $HOME/src + git clone https://github.com/peerplays-network/peerplays.git + mkdir $HOME/peerplays/build; cd $HOME/src/peerplays/build + git submodule update --init --recursive + cmake -DBOOST_ROOT="$BOOST_ROOT" -DCMAKE_BUILD_TYPE=Release .. + make -j$(nproc) + + make install # this can install the executable files under /usr/local + + + Rest of the instructions on starting the chain remains same. Starting A Peerplays Node ----------------- From d819afdaf806d6dd807bdcf1a12a665dceb12868 Mon Sep 17 00:00:00 2001 From: Bobinson K B Date: Thu, 23 May 2019 23:27:29 +0530 Subject: [PATCH 29/31] update for README --- README.md | 56 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 11c4ca878..f1c4464a6 100644 --- a/README.md +++ b/README.md @@ -6,40 +6,44 @@ This is a quick introduction to get new developers and witnesses up to speed on The following dependencies were necessary for a clean install of Ubuntu 18.04 LTS: - sudo apt-get install gcc-5 g++-5 cmake make libbz2-dev libdb++-dev libdb-dev libssl-dev openssl libreadline-dev autoconf libtool git - + ``` + sudo apt-get install gcc-5 g++-5 cmake make libbz2-dev\ + libdb++-dev libdb-dev libssl-dev openssl libreadline-dev\ + autoconf libtool git +``` ## Build Boost 1.67.0 - - mkdir $HOME/src - cd $HOME/src - export BOOST_ROOT=$HOME/src/boost_1_67_0 - sudo apt-get update - sudo apt-get install -y autotools-dev build-essential libbz2-dev libicu-dev python-dev - wget -c 'http://sourceforge.net/projects/boost/files/boost/1.67.0/boost_1_67_0.tar.bz2/download' -O boost_1_67_0.tar.bz2 - [ $( sha256sum boost_1_67_0.tar.bz2 | cut -d ' ' -f 1 ) == "2684c972994ee57fc5632e03bf044746f6eb45d4920c343937a465fd67a5adba" ] || ( echo 'Corrupt download' ; exit 1 ) - tar xjf boost_1_67_0.tar.bz2 - cd boost_1_67_0/ - ./bootstrap.sh "--prefix=$BOOST_ROOT" - ./b2 install - +``` +mkdir $HOME/src +cd $HOME/src +export BOOST_ROOT=$HOME/src/boost_1_67_0 +sudo apt-get update +sudo apt-get install -y autotools-dev build-essential libbz2-dev libicu-dev python-dev +wget -c 'http://sourceforge.net/projects/boost/files/boost/1.67.0/boost_1_67_0.tar.bz2/download'\ + -O boost_1_67_0.tar.bz2 +[ $( sha256sum boost_1_67_0.tar.bz2 | cut -d ' ' -f 1 ) == "2684c972994ee57fc5632e03bf044746f6eb45d4920c343937a465fd67a5adba" ] || ( echo 'Corrupt download' ; exit 1 ) +tar xjf boost_1_67_0.tar.bz2 +cd boost_1_67_0/ +./bootstrap.sh "--prefix=$BOOST_ROOT" +./b2 install +``` ## Building Peerplays +``` +export BOOST_ROOT=/root/boost_1_67_0 +export CC=gcc-5 ; export CXX=g++-5 +cd $HOME/src +git clone https://github.com/peerplays-network/peerplays.git +mkdir $HOME/peerplays/build; cd $HOME/src/peerplays/build +git submodule update --init --recursive +cmake -DBOOST_ROOT="$BOOST_ROOT" -DCMAKE_BUILD_TYPE=Release .. +make -j$(nproc) - export BOOST_ROOT=/root/boost_1_67_0 - export CC=gcc-5 ; export CXX=g++-5 - cd $HOME/src - git clone https://github.com/peerplays-network/peerplays.git - mkdir $HOME/peerplays/build; cd $HOME/src/peerplays/build - git submodule update --init --recursive - cmake -DBOOST_ROOT="$BOOST_ROOT" -DCMAKE_BUILD_TYPE=Release .. - make -j$(nproc) - - make install # this can install the executable files under /usr/local - +ake install # this can install the executable files under /usr/local +``` Rest of the instructions on starting the chain remains same. From 9b643777af6a7450724cea255201e76b2f914d15 Mon Sep 17 00:00:00 2001 From: Bobinson K B Date: Thu, 23 May 2019 23:29:15 +0530 Subject: [PATCH 30/31] Update to add build on Ubuntu1804 --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index f1c4464a6..a6f9cf265 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ sudo apt-get update sudo apt-get install -y autotools-dev build-essential libbz2-dev libicu-dev python-dev wget -c 'http://sourceforge.net/projects/boost/files/boost/1.67.0/boost_1_67_0.tar.bz2/download'\ -O boost_1_67_0.tar.bz2 -[ $( sha256sum boost_1_67_0.tar.bz2 | cut -d ' ' -f 1 ) == "2684c972994ee57fc5632e03bf044746f6eb45d4920c343937a465fd67a5adba" ] || ( echo 'Corrupt download' ; exit 1 ) tar xjf boost_1_67_0.tar.bz2 cd boost_1_67_0/ ./bootstrap.sh "--prefix=$BOOST_ROOT" @@ -54,7 +53,7 @@ For Ubuntu 14.04 LTS and up users, see [this](https://github.com/cryptonomex/graphene/wiki/build-ubuntu) and then proceed with: - git clone https://github.com/pbsa/peerplays.git + git clone https://github.com/peerplays-network/peerplays.git cd peerplays git submodule update --init --recursive cmake -DBOOST_ROOT="$BOOST_ROOT" -DCMAKE_BUILD_TYPE=Release . From 67616417b7f0b5d087b9862de0e48b2d8ccc1bca Mon Sep 17 00:00:00 2001 From: pbattu123 <43043205+pbattu123@users.noreply.github.com> Date: Wed, 29 May 2019 18:31:01 -0300 Subject: [PATCH 31/31] Revert "GPOS protocol" --- libraries/app/database_api.cpp | 51 - .../app/include/graphene/app/database_api.hpp | 23 +- libraries/chain/db_maint.cpp | 305 ++---- libraries/chain/hardfork.d/GPOS.hf | 4 - .../chain/include/graphene/chain/config.hpp | 4 +- .../chain/include/graphene/chain/database.hpp | 5 +- .../chain/protocol/chain_parameters.hpp | 18 - .../graphene/chain/protocol/vesting.hpp | 9 +- .../graphene/chain/vesting_balance_object.hpp | 8 - libraries/chain/proposal_evaluator.cpp | 5 - libraries/chain/vesting_balance_evaluator.cpp | 18 +- .../wallet/include/graphene/wallet/wallet.hpp | 15 - libraries/wallet/wallet.cpp | 31 - tests/tests/gpos_tests.cpp | 953 ------------------ 14 files changed, 70 insertions(+), 1379 deletions(-) delete mode 100644 libraries/chain/hardfork.d/GPOS.hf delete mode 100644 tests/tests/gpos_tests.cpp diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 3f95a8c16..d3af2f297 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -161,8 +161,6 @@ class database_api_impl : public std::enable_shared_from_this vector get_tournaments_by_state(tournament_id_type stop, unsigned limit, tournament_id_type start, tournament_state state); vector get_registered_tournaments(account_id_type account_filter, uint32_t limit) const; - // gpos - gpos_info get_gpos_info(const account_id_type account) const; //private: template @@ -2023,55 +2021,6 @@ vector database_api_impl::get_registered_tournaments(account return tournament_ids; } -////////////////////////////////////////////////////////////////////// -// // -// GPOS methods // -// // -////////////////////////////////////////////////////////////////////// - -graphene::app::gpos_info database_api::get_gpos_info(const account_id_type account) const -{ - return my->get_gpos_info(account); - -} -graphene::app::gpos_info database_api_impl::get_gpos_info(const account_id_type account) const -{ - gpos_info result; - result.vesting_factor = _db.calculate_vesting_factor(account(_db)); - - const auto& dividend_data = asset_id_type()(_db).dividend_data(_db); - const account_object& dividend_distribution_account = dividend_data.dividend_distribution_account(_db); - result.award = _db.get_balance(dividend_distribution_account, asset_id_type()(_db)); - - share_type total_amount; - auto balance_type = vesting_balance_type::gpos; -#ifdef USE_VESTING_OBJECT_BY_ASSET_BALANCE_INDEX - // get only once a collection of accounts that hold nonzero vesting balances of the dividend asset - auto vesting_balances_begin = - vesting_index.indices().get().lower_bound(boost::make_tuple(asset_id_type(), balance_type)); - auto vesting_balances_end = - vesting_index.indices().get().upper_bound(boost::make_tuple(asset_id_type(), balance_type, share_type())); - - for (const vesting_balance_object& vesting_balance_obj : boost::make_iterator_range(vesting_balances_begin, vesting_balances_end)) - { - total_amount += vesting_balance_obj.balance.amount; - } -#else - const vesting_balance_index& vesting_index = _db.get_index_type(); - const auto& vesting_balances = vesting_index.indices().get(); - for (const vesting_balance_object& vesting_balance_obj : vesting_balances) - { - if (vesting_balance_obj.balance.asset_id == asset_id_type() && vesting_balance_obj.balance_type == balance_type) - { - total_amount += vesting_balance_obj.balance.amount; - } - } -#endif - - result.total_amount = total_amount; - return result; -} - ////////////////////////////////////////////////////////////////////// // // // Private methods // diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 3fac4b5f0..7b0943e42 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -114,12 +114,6 @@ struct market_trade double value; }; -struct gpos_info { - double vesting_factor; - asset award; - share_type total_amount; -}; - /** * @brief The database_api class implements the RPC API for the chain database. * @@ -651,17 +645,7 @@ class database_api */ vector get_registered_tournaments(account_id_type account_filter, uint32_t limit) const; - ////////// - // GPOS // - ////////// - /** - * @return account and network GPOS information - */ - gpos_info get_gpos_info(const account_id_type account) const; - - - -private: + private: std::shared_ptr< database_api_impl > my; }; @@ -672,8 +656,6 @@ FC_REFLECT( graphene::app::order_book, (base)(quote)(bids)(asks) ); FC_REFLECT( graphene::app::market_ticker, (base)(quote)(latest)(lowest_ask)(highest_bid)(percent_change)(base_volume)(quote_volume) ); FC_REFLECT( graphene::app::market_volume, (base)(quote)(base_volume)(quote_volume) ); FC_REFLECT( graphene::app::market_trade, (date)(price)(amount)(value) ); -FC_REFLECT( graphene::app::gpos_info, (vesting_factor)(award)(total_amount) ); - FC_API(graphene::app::database_api, // Objects @@ -783,7 +765,4 @@ FC_API(graphene::app::database_api, (get_tournaments_by_state) (get_tournaments ) (get_registered_tournaments) - - // gpos - (get_gpos_info) ) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 06e15a196..b768460af 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -725,120 +725,6 @@ void deprecate_annual_members( database& db ) return; } -double database::calculate_vesting_factor(const account_object& stake_account) -{ - // get last time voted form stats - const auto &stats = stake_account.statistics(*this); - fc::time_point_sec last_date_voted = stats.last_vote_time; - - // get global data related to gpos - const auto &gpo = this->get_global_properties(); - const auto vesting_period = gpo.parameters.gpos_period(); - const auto vesting_subperiod = gpo.parameters.gpos_subperiod(); - const auto period_start = fc::time_point_sec(gpo.parameters.gpos_period_start()); - - // variables needed - const fc::time_point_sec period_end = period_start + vesting_period; - const auto number_of_subperiods = vesting_period / vesting_subperiod; - const auto now = this->head_block_time(); - double vesting_factor; - auto seconds_since_period_start = now.sec_since_epoch() - period_start.sec_since_epoch(); - - FC_ASSERT(period_start <= now && now <= period_end); - - // get in what sub period we are - uint32_t current_subperiod = 0; - std::list period_list(number_of_subperiods); - 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) && - 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; - - if(current_subperiod > 1) { - std::list subperiod_list(current_subperiod - 1); - std::iota(subperiod_list.begin(), subperiod_list.end(), 2); - subperiod_list.reverse(); - - 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; -} - -share_type credit_account(database& db, const account_id_type owner_id, const std::string owner_name, - share_type remaining_amount_to_distribute, - const share_type shares_to_credit, const asset_id_type payout_asset_type, - const pending_dividend_payout_balance_for_holder_object_index& pending_payout_balance_index, - const asset_id_type dividend_id) { - - //wdump((delta_balance.value)(holder_balance)(total_balance_of_dividend_asset)); - if (shares_to_credit.value) { - - remaining_amount_to_distribute -= shares_to_credit; - - dlog("Crediting account ${account} with ${amount}", - ("account", owner_name) - ("amount", asset(shares_to_credit, payout_asset_type))); - auto pending_payout_iter = - pending_payout_balance_index.indices().get().find( - boost::make_tuple(dividend_id, payout_asset_type, - owner_id)); - if (pending_payout_iter == - pending_payout_balance_index.indices().get().end()) - db.create( - [&](pending_dividend_payout_balance_for_holder_object &obj) { - obj.owner = owner_id; - obj.dividend_holder_asset_type = dividend_id; - obj.dividend_payout_asset_type = payout_asset_type; - obj.pending_balance = shares_to_credit; - }); - else - db.modify(*pending_payout_iter, - [&](pending_dividend_payout_balance_for_holder_object &pending_balance) { - pending_balance.pending_balance += shares_to_credit; - }); - } - return remaining_amount_to_distribute; -} - -void rolling_period_start(database& db) -{ - if(db.head_block_time() >= HARDFORK_GPOS_TIME) - { - auto gpo = db.get_global_properties(); - auto period_start = db.get_global_properties().parameters.gpos_period_start(); - auto vesting_period = db.get_global_properties().parameters.gpos_period(); - - auto now = db.head_block_time(); - if(now.sec_since_epoch() > (period_start + vesting_period)) - { - // roll - db.modify(db.get_global_properties(), [now](global_property_object& p) { - p.parameters.extensions.value.gpos_period_start = now.sec_since_epoch(); - }); - } - } -} - // Schedules payouts from a dividend distribution account to the current holders of the // dividend-paying asset. This takes any deposits made to the dividend distribution account // since the last time it was called, and distributes them to the current owners of the @@ -868,41 +754,34 @@ void schedule_pending_dividend_balances(database& db, balance_index.indices().get().lower_bound(boost::make_tuple(dividend_holder_asset_obj.id)); auto holder_balances_end = balance_index.indices().get().upper_bound(boost::make_tuple(dividend_holder_asset_obj.id, share_type())); + uint32_t holder_account_count = std::distance(holder_balances_begin, holder_balances_end); uint64_t distribution_base_fee = gpo.parameters.current_fees->get().distribution_base_fee; uint32_t distribution_fee_per_holder = gpo.parameters.current_fees->get().distribution_fee_per_holder; + // the fee, in BTS, for distributing each asset in the account + uint64_t total_fee_per_asset_in_core = distribution_base_fee + holder_account_count * (uint64_t)distribution_fee_per_holder; std::map vesting_amounts; - - auto balance_type = vesting_balance_type::unspecified; - if(db.head_block_time() >= HARDFORK_GPOS_TIME) - balance_type = vesting_balance_type::gpos; - - uint32_t holder_account_count = 0; #ifdef USE_VESTING_OBJECT_BY_ASSET_BALANCE_INDEX // get only once a collection of accounts that hold nonzero vesting balances of the dividend asset auto vesting_balances_begin = - vesting_index.indices().get().lower_bound(boost::make_tuple(dividend_holder_asset_obj.id, balance_type)); + vesting_index.indices().get().lower_bound(boost::make_tuple(dividend_holder_asset_obj.id)); auto vesting_balances_end = - vesting_index.indices().get().upper_bound(boost::make_tuple(dividend_holder_asset_obj.id, balance_type, share_type())); - + vesting_index.indices().get().upper_bound(boost::make_tuple(dividend_holder_asset_obj.id, share_type())); for (const vesting_balance_object& vesting_balance_obj : boost::make_iterator_range(vesting_balances_begin, vesting_balances_end)) { vesting_amounts[vesting_balance_obj.owner] += vesting_balance_obj.balance.amount; - ++holder_account_count; - dlog("Vesting balance for account: ${owner}, amount: ${amount}", - ("owner", vesting_balance_obj.owner(db).name) - ("amount", vesting_balance_obj.balance.amount)); + //dlog("Vesting balance for account: ${owner}, amount: ${amount}", + // ("owner", vesting_balance_obj.owner(db).name) + // ("amount", vesting_balance_obj.balance.amount)); } #else // get only once a collection of accounts that hold nonzero vesting balances of the dividend asset const auto& vesting_balances = vesting_index.indices().get(); for (const vesting_balance_object& vesting_balance_obj : vesting_balances) { - if (vesting_balance_obj.balance.asset_id == dividend_holder_asset_obj.id && vesting_balance_obj.balance.amount && - vesting_balance_object.balance_type == balance_type) + if (vesting_balance_obj.balance.asset_id == dividend_holder_asset_obj.id && vesting_balance_obj.balance.amount) { vesting_amounts[vesting_balance_obj.owner] += vesting_balance_obj.balance.amount; - ++gpos_holder_account_count; dlog("Vesting balance for account: ${owner}, amount: ${amount}", ("owner", vesting_balance_obj.owner(db).name) ("amount", vesting_balance_obj.balance.amount)); @@ -910,11 +789,6 @@ void schedule_pending_dividend_balances(database& db, } #endif - if(db.head_block_time() < HARDFORK_GPOS_TIME) - holder_account_count = std::distance(holder_balances_begin, holder_balances_end); - // the fee, in BTS, for distributing each asset in the account - uint64_t total_fee_per_asset_in_core = distribution_base_fee + holder_account_count * (uint64_t)distribution_fee_per_holder; - auto current_distribution_account_balance_iter = current_distribution_account_balance_range.first; auto previous_distribution_account_balance_iter = previous_distribution_account_balance_range.first; dlog("Current balances in distribution account: ${current}, Previous balances: ${previous}", @@ -925,23 +799,14 @@ void schedule_pending_dividend_balances(database& db, // accounts other than the distribution account (it would be silly to distribute dividends back to // the distribution account) share_type total_balance_of_dividend_asset; - if(db.head_block_time() >= HARDFORK_GPOS_TIME && dividend_holder_asset_obj.symbol == GRAPHENE_SYMBOL) { // only core - for (const vesting_balance_object &holder_balance_object : boost::make_iterator_range(vesting_balances_begin, - vesting_balances_end)) - if (holder_balance_object.owner != dividend_data.dividend_distribution_account) { - total_balance_of_dividend_asset += holder_balance_object.balance.amount; - } - } - else { - for (const account_balance_object &holder_balance_object : boost::make_iterator_range(holder_balances_begin, - holder_balances_end)) - if (holder_balance_object.owner != dividend_data.dividend_distribution_account) { - total_balance_of_dividend_asset += holder_balance_object.balance; - auto itr = vesting_amounts.find(holder_balance_object.owner); - if (itr != vesting_amounts.end()) - total_balance_of_dividend_asset += itr->second; - } - } + for (const account_balance_object& holder_balance_object : boost::make_iterator_range(holder_balances_begin, holder_balances_end)) + if (holder_balance_object.owner != dividend_data.dividend_distribution_account) + { + total_balance_of_dividend_asset += holder_balance_object.balance; + auto itr = vesting_amounts.find(holder_balance_object.owner); + if (itr != vesting_amounts.end()) + total_balance_of_dividend_asset += itr->second; + } // loop through all of the assets currently or previously held in the distribution account while (current_distribution_account_balance_iter != current_distribution_account_balance_range.second || previous_distribution_account_balance_iter != previous_distribution_account_balance_range.second) @@ -1065,68 +930,46 @@ void schedule_pending_dividend_balances(database& db, ("total", total_balance_of_dividend_asset)); share_type remaining_amount_to_distribute = delta_balance; - if(db.head_block_time() >= HARDFORK_GPOS_TIME && dividend_holder_asset_obj.symbol == GRAPHENE_SYMBOL) { // core only - // credit each account with their portion, don't send any back to the dividend distribution account - for (const vesting_balance_object &holder_balance_object : boost::make_iterator_range( - vesting_balances_begin, vesting_balances_end)) { - if (holder_balance_object.owner == dividend_data.dividend_distribution_account) continue; - - auto vesting_factor = db.calculate_vesting_factor(holder_balance_object.owner(db)); - - auto holder_balance = holder_balance_object.balance; - - fc::uint128_t amount_to_credit(delta_balance.value); - amount_to_credit *= holder_balance.amount.value; - amount_to_credit /= total_balance_of_dividend_asset.value; - share_type full_shares_to_credit((int64_t) amount_to_credit.to_uint64()); - share_type shares_to_credit = (uint64_t) floor(full_shares_to_credit.value * vesting_factor); - - if (shares_to_credit < full_shares_to_credit) { - // Todo: sending results of decay to committee account, need to change to specified account - dlog("Crediting committee_account with ${amount}", - ("amount", asset(full_shares_to_credit - shares_to_credit, payout_asset_type))); - db.adjust_balance(dividend_data.dividend_distribution_account, - -(full_shares_to_credit - shares_to_credit)); - db.adjust_balance(account_id_type(0), full_shares_to_credit - shares_to_credit); - } - - remaining_amount_to_distribute = credit_account(db, - holder_balance_object.owner, - holder_balance_object.owner(db).name, - remaining_amount_to_distribute, - shares_to_credit, - payout_asset_type, - pending_payout_balance_index, - dividend_holder_asset_obj.id); - } - } - else { - // credit each account with their portion, don't send any back to the dividend distribution account - for (const account_balance_object &holder_balance_object : boost::make_iterator_range( - holder_balances_begin, holder_balances_end)) { - if (holder_balance_object.owner == dividend_data.dividend_distribution_account) continue; - - auto holder_balance = holder_balance_object.balance; - - auto itr = vesting_amounts.find(holder_balance_object.owner); - if (itr != vesting_amounts.end()) - holder_balance += itr->second; - - fc::uint128_t amount_to_credit(delta_balance.value); - amount_to_credit *= holder_balance.value; - amount_to_credit /= total_balance_of_dividend_asset.value; - share_type shares_to_credit((int64_t) amount_to_credit.to_uint64()); - - remaining_amount_to_distribute = credit_account(db, - holder_balance_object.owner, - holder_balance_object.owner(db).name, - remaining_amount_to_distribute, - shares_to_credit, - payout_asset_type, - pending_payout_balance_index, - dividend_holder_asset_obj.id); + // credit each account with their portion, don't send any back to the dividend distribution account + for (const account_balance_object& holder_balance_object : boost::make_iterator_range(holder_balances_begin, holder_balances_end)) + { + if (holder_balance_object.owner == dividend_data.dividend_distribution_account) continue; + + auto holder_balance = holder_balance_object.balance; + + auto itr = vesting_amounts.find(holder_balance_object.owner); + if (itr != vesting_amounts.end()) + holder_balance += itr->second; + + fc::uint128_t amount_to_credit(delta_balance.value); + amount_to_credit *= holder_balance.value; + amount_to_credit /= total_balance_of_dividend_asset.value; + share_type shares_to_credit((int64_t)amount_to_credit.to_uint64()); + if (shares_to_credit.value) + { + wdump((delta_balance.value)(holder_balance)(total_balance_of_dividend_asset)); + + remaining_amount_to_distribute -= shares_to_credit; + + dlog("Crediting account ${account} with ${amount}", + ("account", holder_balance_object.owner(db).name) + ("amount", asset(shares_to_credit, payout_asset_type))); + auto pending_payout_iter = + pending_payout_balance_index.indices().get().find(boost::make_tuple(dividend_holder_asset_obj.id, payout_asset_type, holder_balance_object.owner)); + if (pending_payout_iter == pending_payout_balance_index.indices().get().end()) + db.create( [&]( pending_dividend_payout_balance_for_holder_object& obj ){ + obj.owner = holder_balance_object.owner; + obj.dividend_holder_asset_type = dividend_holder_asset_obj.id; + obj.dividend_payout_asset_type = payout_asset_type; + obj.pending_balance = shares_to_credit; + }); + else + db.modify(*pending_payout_iter, [&]( pending_dividend_payout_balance_for_holder_object& pending_balance ){ + pending_balance.pending_balance += shares_to_credit; + }); } } + for (const auto& pending_payout : pending_payout_balance_index.indices()) if (pending_payout.pending_balance.value) dlog("Pending payout: ${account_name} -> ${amount}", @@ -1386,8 +1229,6 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g distribute_fba_balances(*this); create_buyback_orders(*this); - rolling_period_start(*this); - process_dividend_assets(*this); struct vote_tally_helper { @@ -1403,28 +1244,24 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g d._committee_count_histogram_buffer.resize(props.parameters.maximum_committee_count / 2 + 1); d._total_voting_stake = 0; - auto balance_type = vesting_balance_type::unspecified; - if(d.head_block_time() >= HARDFORK_GPOS_TIME) - balance_type = vesting_balance_type::gpos; - const vesting_balance_index& vesting_index = d.get_index_type(); #ifdef USE_VESTING_OBJECT_BY_ASSET_BALANCE_INDEX auto vesting_balances_begin = - vesting_index.indices().get().lower_bound(boost::make_tuple(asset_id_type(), balance_type)); + vesting_index.indices().get().lower_bound(boost::make_tuple(asset_id_type())); auto vesting_balances_end = - vesting_index.indices().get().upper_bound(boost::make_tuple(asset_id_type(), balance_type, share_type())); + vesting_index.indices().get().upper_bound(boost::make_tuple(asset_id_type(), share_type())); for (const vesting_balance_object& vesting_balance_obj : boost::make_iterator_range(vesting_balances_begin, vesting_balances_end)) { vesting_amounts[vesting_balance_obj.owner] += vesting_balance_obj.balance.amount; - dlog("Vesting balance for account: ${owner}, amount: ${amount}", - ("owner", vesting_balance_obj.owner(d).name) - ("amount", vesting_balance_obj.balance.amount)); + //dlog("Vesting balance for account: ${owner}, amount: ${amount}", + // ("owner", vesting_balance_obj.owner(d).name) + // ("amount", vesting_balance_obj.balance.amount)); } #else const auto& vesting_balances = vesting_index.indices().get(); for (const vesting_balance_object& vesting_balance_obj : vesting_balances) { - if (vesting_balance_obj.balance.asset_id == asset_id_type() && vesting_balance_obj.balance.amount && vesting_balance_obj.balance_type == balance_type) + if (vesting_balance_obj.balance.asset_id == asset_id_type() && vesting_balance_obj.balance.amount) { vesting_amounts[vesting_balance_obj.owner] += vesting_balance_obj.balance.amount; dlog("Vesting balance for account: ${owner}, amount: ${amount}", @@ -1452,27 +1289,13 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g const account_object& opinion_account = *opinion_account_ptr; const auto& stats = stake_account.statistics(d); - uint64_t voting_stake = 0; + uint64_t voting_stake = stats.total_core_in_orders.value + + (stake_account.cashback_vb.valid() ? (*stake_account.cashback_vb)(d).balance.amount.value: 0) + + d.get_balance(stake_account.get_id(), asset_id_type()).amount.value; auto itr = vesting_amounts.find(stake_account.id); if (itr != vesting_amounts.end()) voting_stake += itr->second.value; - - if(d.head_block_time() >= HARDFORK_GPOS_TIME) - { - if (itr == vesting_amounts.end()) - return; - - auto vesting_factor = d.calculate_vesting_factor(stake_account); - voting_stake = (uint64_t)floor(voting_stake * vesting_factor); - } - else - { - voting_stake += stats.total_core_in_orders.value - + (stake_account.cashback_vb.valid() ? (*stake_account.cashback_vb)(d).balance.amount.value : 0) - + d.get_balance(stake_account.get_id(), asset_id_type()).amount.value; - } - for( vote_id_type id : opinion_account.options.votes ) { uint32_t offset = id.instance(); diff --git a/libraries/chain/hardfork.d/GPOS.hf b/libraries/chain/hardfork.d/GPOS.hf deleted file mode 100644 index f175ef2c5..000000000 --- a/libraries/chain/hardfork.d/GPOS.hf +++ /dev/null @@ -1,4 +0,0 @@ -// GPOS HARDFORK Friday, March 15, 2019 11:57:28 PM -#ifndef HARDFORK_GPOS_TIME -#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1552694248 )) -#endif \ No newline at end of file diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index 7b3e87439..d85cc093e 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -151,7 +151,7 @@ #define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4 #define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3 -#define GRAPHENE_CURRENT_DB_VERSION "PPY2.2" +#define GRAPHENE_CURRENT_DB_VERSION "PPY2.1" #define GRAPHENE_IRREVERSIBLE_THRESHOLD (70 * GRAPHENE_1_PERCENT) @@ -226,5 +226,3 @@ #define TOURNAMENT_MAX_WHITELIST_LENGTH 1000 #define TOURNAMENT_MAX_START_TIME_IN_FUTURE (60*60*24*7*4) // 1 month #define TOURNAMENT_MAX_START_DELAY (60*60*24*7) // 1 week -#define GPOS_PERIOD (60*60*24*30*6) // 6 months -#define GPOS_SUBPERIOD (60*60*24*30) // 1 month diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 179fb2dfb..af50a94b0 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -498,11 +498,8 @@ namespace graphene { namespace chain { void update_active_witnesses(); void update_active_committee_members(); void update_worker_votes(); - public: - double calculate_vesting_factor(const account_object& stake_account); - - template + template void perform_account_maintenance(std::tuple helpers); ///@} ///@} diff --git a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp index 87c2e3fef..b2551e447 100644 --- a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp +++ b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp @@ -27,8 +27,6 @@ #include #include -#include - namespace graphene { namespace chain { struct fee_schedule; } } namespace graphene { namespace chain { @@ -39,10 +37,6 @@ namespace graphene { namespace chain { optional< uint16_t > betting_rake_fee_percentage; optional< flat_map > permitted_betting_odds_increments; optional< uint16_t > live_betting_delay_time; - /* gpos parameters */ - optional < uint32_t > gpos_period; - optional < uint32_t > gpos_subperiod; - optional < uint32_t > gpos_period_start; }; struct chain_parameters @@ -112,15 +106,6 @@ namespace graphene { namespace chain { inline uint16_t live_betting_delay_time()const { return extensions.value.live_betting_delay_time.valid() ? *extensions.value.live_betting_delay_time : GRAPHENE_DEFAULT_LIVE_BETTING_DELAY_TIME; } - inline uint32_t gpos_period()const { - return extensions.value.gpos_period.valid() ? *extensions.value.gpos_period : GPOS_PERIOD; /// total seconds of current gpos period - } - inline uint32_t gpos_subperiod()const { - return extensions.value.gpos_subperiod.valid() ? *extensions.value.gpos_subperiod : GPOS_SUBPERIOD; /// gpos_period % gpos_subperiod = 0 - } - inline uint32_t gpos_period_start()const { - return extensions.value.gpos_period_start.valid() ? *extensions.value.gpos_period_start : HARDFORK_GPOS_TIME.sec_since_epoch(); /// current period start date - } }; } } // graphene::chain @@ -131,9 +116,6 @@ FC_REFLECT( graphene::chain::parameter_extension, (betting_rake_fee_percentage) (permitted_betting_odds_increments) (live_betting_delay_time) - (gpos_period) - (gpos_subperiod) - (gpos_period_start) ) FC_REFLECT( graphene::chain::chain_parameters, diff --git a/libraries/chain/include/graphene/chain/protocol/vesting.hpp b/libraries/chain/include/graphene/chain/protocol/vesting.hpp index 5a78fd65c..4915b62ec 100644 --- a/libraries/chain/include/graphene/chain/protocol/vesting.hpp +++ b/libraries/chain/include/graphene/chain/protocol/vesting.hpp @@ -24,9 +24,7 @@ #pragma once #include -namespace graphene { namespace chain { - - enum class vesting_balance_type { unspecified, gpos }; +namespace graphene { namespace chain { struct linear_vesting_policy_initializer { @@ -74,7 +72,6 @@ namespace graphene { namespace chain { account_id_type owner; ///< Who is able to withdraw the balance asset amount; vesting_policy_initializer policy; - vesting_balance_type balance_type; account_id_type fee_payer()const { return creator; } void validate()const @@ -115,11 +112,9 @@ namespace graphene { namespace chain { FC_REFLECT( graphene::chain::vesting_balance_create_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::vesting_balance_withdraw_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::vesting_balance_create_operation, (fee)(creator)(owner)(amount)(policy)(balance_type) ) +FC_REFLECT( graphene::chain::vesting_balance_create_operation, (fee)(creator)(owner)(amount)(policy) ) FC_REFLECT( graphene::chain::vesting_balance_withdraw_operation, (fee)(vesting_balance)(owner)(amount) ) FC_REFLECT(graphene::chain::linear_vesting_policy_initializer, (begin_timestamp)(vesting_cliff_seconds)(vesting_duration_seconds) ) FC_REFLECT(graphene::chain::cdd_vesting_policy_initializer, (start_claim)(vesting_seconds) ) FC_REFLECT_TYPENAME( graphene::chain::vesting_policy_initializer ) - -FC_REFLECT_ENUM( graphene::chain::vesting_balance_type, (unspecified)(gpos) ) diff --git a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp index 6e0bd689a..dc2fe18c3 100644 --- a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp +++ b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp @@ -24,8 +24,6 @@ #pragma once #include -#include - #include #include @@ -145,9 +143,6 @@ namespace graphene { namespace chain { /// The vesting policy stores details on when funds vest, and controls when they may be withdrawn vesting_policy policy; - /// We can have 2 types of vesting, gpos and all the rest - vesting_balance_type balance_type = vesting_balance_type::unspecified; - vesting_balance_object() {} ///@brief Deposit amount into vesting balance, requiring it to vest before withdrawal @@ -190,14 +185,12 @@ namespace graphene { namespace chain { composite_key< vesting_balance_object, member_offset, - member, member_offset //member //member_offset >, composite_key_compare< std::less< asset_id_type >, - std::less< vesting_balance_type >, std::greater< share_type > //std::less< account_id_type > > @@ -231,5 +224,4 @@ FC_REFLECT_DERIVED(graphene::chain::vesting_balance_object, (graphene::db::objec (owner) (balance) (policy) - (balance_type) ) diff --git a/libraries/chain/proposal_evaluator.cpp b/libraries/chain/proposal_evaluator.cpp index 8306128dd..a6640ea47 100644 --- a/libraries/chain/proposal_evaluator.cpp +++ b/libraries/chain/proposal_evaluator.cpp @@ -135,11 +135,6 @@ struct proposal_operation_hardfork_visitor FC_ASSERT( block_time >= HARDFORK_1000_TIME, "event_update_status_operation not allowed yet!" ); } - void operator()(const vesting_balance_create_operation &vbco) const { - if(block_time < HARDFORK_GPOS_TIME) - FC_ASSERT( vbco.balance_type == vesting_balance_type::unspecified, "balance_type in vesting create not allowed yet!" ); - } - // loop and self visit in proposals void operator()(const proposal_create_operation &v) const { for (const op_wrapper &op : v.proposed_ops) diff --git a/libraries/chain/vesting_balance_evaluator.cpp b/libraries/chain/vesting_balance_evaluator.cpp index 0b6e192e0..ee918fd16 100644 --- a/libraries/chain/vesting_balance_evaluator.cpp +++ b/libraries/chain/vesting_balance_evaluator.cpp @@ -42,9 +42,6 @@ void_result vesting_balance_create_evaluator::do_evaluate( const vesting_balance FC_ASSERT( d.get_balance( creator_account.id, op.amount.asset_id ) >= op.amount ); FC_ASSERT( !op.amount.asset_id(d).is_transfer_restricted() ); - if(d.head_block_time() < HARDFORK_GPOS_TIME) // Todo: can be removed after gpos hf time pass - FC_ASSERT( op.balance_type == vesting_balance_type::unspecified); - return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -95,20 +92,7 @@ object_id_type vesting_balance_create_evaluator::do_apply( const vesting_balance // If making changes to this logic, check if those changes should also be made there as well. obj.owner = op.owner; obj.balance = op.amount; - if(op.balance_type == vesting_balance_type::gpos) - { - const auto &gpo = d.get_global_properties(); - // forcing gpos policy - linear_vesting_policy p; - p.begin_timestamp = now; - p.vesting_cliff_seconds = gpo.parameters.gpos_subperiod(); - p.vesting_duration_seconds = gpo.parameters.gpos_subperiod(); - obj.policy = p; - } - else { - op.policy.visit(init_policy_visitor(obj.policy, op.amount.amount, now)); - } - obj.balance_type = op.balance_type; + op.policy.visit( init_policy_visitor( obj.policy, op.amount.amount, now ) ); } ); diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index a71891381..0ba0782b5 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1795,20 +1795,6 @@ class wallet_api rock_paper_scissors_gesture gesture, bool broadcast); - /** Create a vesting balance including gpos vesting balance after HARDFORK_GPOS_TIME - * @param owner vesting balance owner and creator - * @param amount amount to vest - * @param asset_symbol the symbol of the asset to vest - * @param is_gpos True if the balance is of gpos type - * @param broadcast true if you wish to broadcast the transaction - * @return the signed version of the transaction - */ - signed_transaction create_vesting_balance(string owner, - string amount, - string asset_symbol, - bool is_gpos, - bool broadcast); - void dbg_make_uia(string creator, string symbol); void dbg_make_mia(string creator, string symbol); void dbg_push_blocks( std::string src_filename, uint32_t count ); @@ -2045,7 +2031,6 @@ FC_API( graphene::wallet::wallet_api, (tournament_join) (tournament_leave) (rps_throw) - (create_vesting_balance) (get_upcoming_tournaments) (get_tournaments) (get_tournaments_by_state) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 812740e6d..74c285bfa 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -5756,37 +5756,6 @@ signed_transaction wallet_api::rps_throw(game_id_type game_id, return my->sign_transaction( tx, broadcast ); } -signed_transaction wallet_api::create_vesting_balance(string owner, - string amount, - string asset_symbol, - bool is_gpos, - bool broadcast) -{ - FC_ASSERT( !is_locked() ); - - account_object owner_account = get_account(owner); - account_id_type owner_id = owner_account.id; - - fc::optional asset_obj = get_asset(asset_symbol); - - auto type = vesting_balance_type::unspecified; - if(is_gpos) - type = vesting_balance_type::gpos; - - vesting_balance_create_operation op; - op.creator = owner_id; - op.owner = owner_id; - op.amount = asset_obj->amount_from_string(amount); - op.balance_type = type; - - signed_transaction trx; - trx.operations.push_back(op); - my->set_operation_fees( trx, my->_remote_db->get_global_properties().parameters.current_fees ); - trx.validate(); - - return my->sign_transaction( trx, broadcast ); -} - // default ctor necessary for FC_REFLECT signed_block_with_info::signed_block_with_info() { diff --git a/tests/tests/gpos_tests.cpp b/tests/tests/gpos_tests.cpp deleted file mode 100644 index eb53c9c44..000000000 --- a/tests/tests/gpos_tests.cpp +++ /dev/null @@ -1,953 +0,0 @@ -/* - * Copyright (c) 2018 oxarbitrage 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 -#include -#include - -#include -#include -#include -#include - -#include "../common/database_fixture.hpp" - -#include - -using namespace graphene::chain; -using namespace graphene::chain::test; - -struct gpos_fixture: database_fixture -{ - const worker_object& create_worker( const account_id_type owner, const share_type daily_pay, - const fc::microseconds& duration ) { - worker_create_operation op; - op.owner = owner; - op.daily_pay = daily_pay; - op.initializer = vesting_balance_worker_initializer(1); - op.work_begin_date = db.head_block_time(); - op.work_end_date = op.work_begin_date + duration; - trx.operations.push_back(op); - set_expiration(db, trx); - trx.validate(); - processed_transaction ptx = db.push_transaction(trx, ~0); - trx.clear(); - return db.get(ptx.operation_results[0].get()); - } - const vesting_balance_object& create_vesting(const account_id_type owner, const asset amount, - const vesting_balance_type type) - { - vesting_balance_create_operation op; - op.creator = owner; - op.owner = owner; - op.amount = amount; - op.balance_type = type; - - trx.operations.push_back(op); - set_expiration(db, trx); - processed_transaction ptx = PUSH_TX(db, trx, ~0); - trx.clear(); - return db.get(ptx.operation_results[0].get()); - } - - void update_payout_interval(std::string asset_name, fc::time_point start, uint32_t interval) - { - auto dividend_holder_asset_object = get_asset(asset_name); - asset_update_dividend_operation op; - op.issuer = dividend_holder_asset_object.issuer; - op.asset_to_update = dividend_holder_asset_object.id; - op.new_options.next_payout_time = start; - op.new_options.payout_interval = interval; - trx.operations.push_back(op); - set_expiration(db, trx); - PUSH_TX(db, trx, ~0); - trx.operations.clear(); - } - - void update_gpos_global(uint32_t vesting_period, uint32_t vesting_subperiod, fc::time_point_sec period_start) - { - db.modify(db.get_global_properties(), [vesting_period, vesting_subperiod, period_start](global_property_object& p) { - p.parameters.extensions.value.gpos_period = vesting_period; - p.parameters.extensions.value.gpos_subperiod = vesting_subperiod; - p.parameters.extensions.value.gpos_period_start = period_start.sec_since_epoch(); - }); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period(), vesting_period); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_subperiod(), vesting_subperiod); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), period_start.sec_since_epoch()); - } - void vote_for(const account_id_type account_id, const vote_id_type vote_for, const fc::ecc::private_key& key) - { - account_update_operation op; - op.account = account_id; - op.new_options = account_id(db).options; - op.new_options->votes.insert(vote_for); - trx.operations.push_back(op); - set_expiration(db, trx); - trx.validate(); - sign(trx, key); - PUSH_TX(db, trx); - trx.clear(); - } - void fill_reserve_pool(const account_id_type account_id, asset amount) - { - asset_reserve_operation op; - op.payer = account_id; - op.amount_to_reserve = amount; - trx.operations.push_back(op); - trx.validate(); - set_expiration(db, trx); - PUSH_TX( db, trx, ~0 ); - trx.clear(); - } - - void advance_x_maint(int periods) - { - for(int i=0; i(ptx.operation_results[0].get()); - - // check created vesting amount and policy - BOOST_CHECK_EQUAL(alice_vesting.balance.amount.value, 100); - BOOST_CHECK_EQUAL(alice_vesting.policy.get().vesting_duration_seconds, - db.get_global_properties().parameters.gpos_subperiod()); - BOOST_CHECK_EQUAL(alice_vesting.policy.get().vesting_cliff_seconds, - db.get_global_properties().parameters.gpos_subperiod()); - - // bob creates a gpos vesting with his custom policy - { - vesting_balance_create_operation op; - op.creator = bob_id; - op.owner = bob_id; - op.amount = core.amount(200); - op.balance_type = vesting_balance_type::gpos; - op.policy = cdd_vesting_policy_initializer{ 60*60*24 }; - - trx.operations.push_back(op); - set_expiration(db, trx); - ptx = PUSH_TX(db, trx, ~0); - trx.clear(); - } - auto bob_vesting = db.get(ptx.operation_results[0].get()); - - generate_block(); - - // policy is not the one defined by the user but default - BOOST_CHECK_EQUAL(bob_vesting.balance.amount.value, 200); - BOOST_CHECK_EQUAL(bob_vesting.policy.get().vesting_duration_seconds, - db.get_global_properties().parameters.gpos_subperiod()); - BOOST_CHECK_EQUAL(bob_vesting.policy.get().vesting_cliff_seconds, - db.get_global_properties().parameters.gpos_subperiod()); - - } - catch (fc::exception& e) - { - edump((e.to_detail_string())); - throw; - } -} - -BOOST_AUTO_TEST_CASE( dividends ) -{ - ACTORS((alice)(bob)); - try - { - // move to 1 week before hardfork - generate_blocks( HARDFORK_GPOS_TIME - fc::days(7) ); - generate_block(); - - const auto& core = asset_id_type()(db); - - // all core coins are in the committee_account - BOOST_CHECK_EQUAL(get_balance(committee_account(db), core), 1000000000000000); - - // transfer half of the total stake to alice so not all the dividends will go to the committee_account - transfer( committee_account, alice_id, core.amount( 500000000000000 ) ); - generate_block(); - - // send some to bob - transfer( committee_account, bob_id, core.amount( 1000 ) ); - generate_block(); - - // committee balance - BOOST_CHECK_EQUAL(get_balance(committee_account(db), core), 499999999999000); - - // alice balance - BOOST_CHECK_EQUAL(get_balance(alice_id(db), core), 500000000000000); - - // bob balance - BOOST_CHECK_EQUAL(get_balance(bob_id(db), core), 1000); - - // get core asset object - const auto& dividend_holder_asset_object = get_asset(GRAPHENE_SYMBOL); - - // by default core token pays dividends once per month - const auto& dividend_data = dividend_holder_asset_object.dividend_data(db); - BOOST_CHECK_EQUAL(*dividend_data.options.payout_interval, 2592000); // 30 days - - // update the payout interval for speed purposes of the test - update_payout_interval(core.symbol, fc::time_point::now() + fc::minutes(1), 60 * 60 * 24); // 1 day - - generate_block(); - - BOOST_CHECK_EQUAL(*dividend_data.options.payout_interval, 86400); // 1 day now - - // get the dividend distribution account - const account_object& dividend_distribution_account = dividend_data.dividend_distribution_account(db); - - // transfering some coins to distribution account. - // simulating the blockchain haves some dividends to pay. - transfer( committee_account, dividend_distribution_account.id, core.amount( 100 ) ); - generate_block(); - - // committee balance - BOOST_CHECK_EQUAL(get_balance(committee_account(db), core), 499999999998900 ); - - // distribution account balance - BOOST_CHECK_EQUAL(get_balance(dividend_distribution_account, core), 100); - - // get when is the next payout time as we need to advance there - auto next_payout_time = dividend_data.options.next_payout_time; - - // advance to next payout - generate_blocks(*next_payout_time); - - // advance to next maint after payout time arrives - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - // check balances now, dividends are paid "normally" - BOOST_CHECK_EQUAL(get_balance(committee_account(db), core), 499999999998949 ); - BOOST_CHECK_EQUAL(get_balance(alice_id(db), core), 500000000000050 ); - BOOST_CHECK_EQUAL(get_balance(bob_id(db), core), 1000 ); - BOOST_CHECK_EQUAL(get_balance(dividend_distribution_account, core), 1); - - // advance to hardfork - generate_blocks( HARDFORK_GPOS_TIME ); - - // advance to next maint - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - // send 99 to the distribution account so it will have 100 PPY again to share - transfer( committee_account, dividend_distribution_account.id, core.amount( 99 ) ); - generate_block(); - - // get when is the next payout time as we need to advance there - next_payout_time = dividend_data.options.next_payout_time; - - // advance to next payout - generate_blocks(*next_payout_time); - - // advance to next maint - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - // make sure no dividends were paid "normally" - BOOST_CHECK_EQUAL(get_balance(committee_account(db), core), 499999999998850 ); - BOOST_CHECK_EQUAL(get_balance(alice_id(db), core), 500000000000050 ); - BOOST_CHECK_EQUAL(get_balance(bob_id(db), core), 1000 ); - BOOST_CHECK_EQUAL(get_balance(dividend_distribution_account, core), 100); - - // create vesting balance - create_vesting(bob_id, core.amount(100), vesting_balance_type::gpos); - - // need to vote to get paid - auto witness1 = witness_id_type(1)(db); - vote_for(bob_id, witness1.vote_id, bob_private_key); - - generate_block(); - - // check balances - BOOST_CHECK_EQUAL(get_balance(bob_id(db), core), 900 ); - BOOST_CHECK_EQUAL(get_balance(dividend_distribution_account, core), 100); - - // advance to next payout - generate_blocks(*next_payout_time); - - // advance to next maint - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - // check balances, dividends paid to bob - BOOST_CHECK_EQUAL(get_balance(bob_id(db), core), 1000 ); - BOOST_CHECK_EQUAL(get_balance(dividend_distribution_account, core), 0); - } - catch (fc::exception& e) - { - edump((e.to_detail_string())); - throw; - } -} - -BOOST_AUTO_TEST_CASE( voting ) -{ - ACTORS((alice)(bob)); - try { - - // move to hardfork - generate_blocks( HARDFORK_GPOS_TIME ); - generate_block(); - - const auto& core = asset_id_type()(db); - - // send some asset to alice and bob - transfer( committee_account, alice_id, core.amount( 1000 ) ); - transfer( committee_account, bob_id, core.amount( 1000 ) ); - generate_block(); - - // default maintenance_interval is 1 day - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.maintenance_interval, 86400); - - // add some vesting to alice and bob - create_vesting(alice_id, core.amount(100), vesting_balance_type::gpos); - create_vesting(bob_id, core.amount(100), vesting_balance_type::gpos); - generate_block(); - - // default gpos values - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period(), 15552000); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_subperiod(), 2592000); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), HARDFORK_GPOS_TIME.sec_since_epoch()); - - // update default gpos for test speed - auto now = db.head_block_time(); - // 5184000 = 60x60x24x60 = 60 days - // 864000 = 60x60x24x10 = 10 days - update_gpos_global(5184000, 864000, now); - - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period(), 5184000); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_subperiod(), 864000); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), now.sec_since_epoch()); - // end global changes - - generate_block(); - - // no votes for witness 1 - auto witness1 = witness_id_type(1)(db); - BOOST_CHECK_EQUAL(witness1.total_votes, 0); - - // no votes for witness 2 - auto witness2 = witness_id_type(2)(db); - BOOST_CHECK_EQUAL(witness2.total_votes, 0); - - // vote for witness1 - vote_for(alice_id, witness1.vote_id, alice_private_key); - - // go to maint - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - // vote is the same as amount in the first subperiod since voting - witness1 = witness_id_type(1)(db); - BOOST_CHECK_EQUAL(witness1.total_votes, 100); - - advance_x_maint(10); - - // vote decay as time pass - witness1 = witness_id_type(1)(db); - BOOST_CHECK_EQUAL(witness1.total_votes, 83); - - advance_x_maint(10); - - // decay more - witness1 = witness_id_type(1)(db); - BOOST_CHECK_EQUAL(witness1.total_votes, 66); - - advance_x_maint(10); - - // more - witness1 = witness_id_type(1)(db); - BOOST_CHECK_EQUAL(witness1.total_votes, 50); - - advance_x_maint(10); - - // more - witness1 = witness_id_type(1)(db); - BOOST_CHECK_EQUAL(witness1.total_votes, 33); - - advance_x_maint(10); - - // more - witness1 = witness_id_type(1)(db); - BOOST_CHECK_EQUAL(witness1.total_votes, 16); - - // we are still in gpos period 1 - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), now.sec_since_epoch()); - - advance_x_maint(10); - - // until 0 - witness1 = witness_id_type(1)(db); - BOOST_CHECK_EQUAL(witness1.total_votes, 0); - - // a new GPOS period is in but vote from user is before the start so his voting power is 0 - now = db.head_block_time(); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), now.sec_since_epoch()); - - generate_block(); - - witness1 = witness_id_type(1)(db); - BOOST_CHECK_EQUAL(witness1.total_votes, 0); - - // we are in the second GPOS period, at subperiod 2, lets vote here - vote_for(bob_id, witness2.vote_id, bob_private_key); - generate_block(); - - // go to maint - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - witness1 = witness_id_type(1)(db); - witness2 = witness_id_type(2)(db); - - BOOST_CHECK_EQUAL(witness1.total_votes, 0); - BOOST_CHECK_EQUAL(witness2.total_votes, 100); - - advance_x_maint(10); - - witness1 = witness_id_type(1)(db); - witness2 = witness_id_type(2)(db); - - BOOST_CHECK_EQUAL(witness1.total_votes, 0); - BOOST_CHECK_EQUAL(witness2.total_votes, 83); - - advance_x_maint(10); - - witness1 = witness_id_type(1)(db); - witness2 = witness_id_type(2)(db); - - BOOST_CHECK_EQUAL(witness1.total_votes, 0); - BOOST_CHECK_EQUAL(witness2.total_votes, 66); - - // alice votes again, now for witness 2, her vote worth 100 now - vote_for(alice_id, witness2.vote_id, alice_private_key); - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - witness1 = witness_id_type(1)(db); - witness2 = witness_id_type(2)(db); - - BOOST_CHECK_EQUAL(witness1.total_votes, 100); - BOOST_CHECK_EQUAL(witness2.total_votes, 166); - - } - catch (fc::exception &e) { - edump((e.to_detail_string())); - throw; - } -} - -BOOST_AUTO_TEST_CASE( rolling_period_start ) -{ - // period start rolls automatically after HF - try { - // advance to HF - generate_blocks(HARDFORK_GPOS_TIME); - generate_block(); - - // update default gpos global parameters to make this thing faster - auto now = db.head_block_time(); - update_gpos_global(518400, 86400, now); - - // moving outside period: - while( db.head_block_time() <= now + fc::days(6) ) - { - generate_block(); - } - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - // rolling is here so getting the new now - now = db.head_block_time(); - generate_block(); - - // period start rolled - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), now.sec_since_epoch()); - } - catch (fc::exception &e) { - edump((e.to_detail_string())); - throw; - } -} -BOOST_AUTO_TEST_CASE( worker_dividends_voting ) -{ - try { - // advance to HF - generate_blocks(HARDFORK_GPOS_TIME); - generate_block(); - - // update default gpos global parameters to 4 days - auto now = db.head_block_time(); - update_gpos_global(345600, 86400, now); - - generate_block(); - set_expiration(db, trx); - const auto& core = asset_id_type()(db); - - // get core asset object - const auto& dividend_holder_asset_object = get_asset(GRAPHENE_SYMBOL); - - // by default core token pays dividends once per month - const auto& dividend_data = dividend_holder_asset_object.dividend_data(db); - BOOST_CHECK_EQUAL(*dividend_data.options.payout_interval, 2592000); // 30 days - - // update the payout interval to 1 day for speed purposes of the test - update_payout_interval(core.symbol, fc::time_point::now() + fc::minutes(1), 60 * 60 * 24); // 1 day - - generate_block(); - - // get the dividend distribution account - const account_object& dividend_distribution_account = dividend_data.dividend_distribution_account(db); - - // transfering some coins to distribution account. - transfer( committee_account, dividend_distribution_account.id, core.amount( 100 ) ); - generate_block(); - - ACTORS((nathan)(voter1)(voter2)(voter3)); - - transfer( committee_account, nathan_id, core.amount( 1000 ) ); - transfer( committee_account, voter1_id, core.amount( 1000 ) ); - transfer( committee_account, voter2_id, core.amount( 1000 ) ); - - generate_block(); - - upgrade_to_lifetime_member(nathan_id); - - auto worker = create_worker(nathan_id, 10, fc::days(6)); - - // add some vesting to voter1 - create_vesting(voter1_id, core.amount(100), vesting_balance_type::gpos); - - // add some vesting to voter2 - create_vesting(voter2_id, core.amount(100), vesting_balance_type::gpos); - - generate_block(); - - // vote for worker - vote_for(voter1_id, worker.vote_for, voter1_private_key); - - // first maint pass, coefficient will be 1 - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - worker = worker_id_type()(db); - BOOST_CHECK_EQUAL(worker.total_votes_for, 100); - - // here dividends are paid to voter1 and voter2 - // voter1 get paid full dividend share as coefficent is at 1 here - BOOST_CHECK_EQUAL(get_balance(voter1_id(db), core), 950); - - // voter2 didnt voted so he dont get paid - BOOST_CHECK_EQUAL(get_balance(voter2_id(db), core), 900); - - // send some asset to the reserve pool so the worker can get paid - fill_reserve_pool(account_id_type(), asset(GRAPHENE_MAX_SHARE_SUPPLY/2)); - - BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().balance(db).balance.amount.value, 0); - BOOST_CHECK_EQUAL(worker.worker.get().balance(db).balance.amount.value, 0); - - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - // worker is getting paid - BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().balance(db).balance.amount.value, 10); - BOOST_CHECK_EQUAL(worker.worker.get().balance(db).balance.amount.value, 10); - - // second maint pass, coefficient will be 0.75 - worker = worker_id_type()(db); - BOOST_CHECK_EQUAL(worker.total_votes_for, 75); - - // more decay - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - worker = worker_id_type()(db); - BOOST_CHECK_EQUAL(worker.total_votes_for, 50); - - transfer( committee_account, dividend_distribution_account.id, core.amount( 100 ) ); - generate_block(); - - BOOST_CHECK_EQUAL(get_balance(committee_account(db), core), 499999999996850); - - // more decay - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - worker = worker_id_type()(db); - BOOST_CHECK_EQUAL(worker.total_votes_for, 25); - - // here voter1 get paid again but less money by vesting coefficient - BOOST_CHECK_EQUAL(get_balance(voter1_id(db), core), 962); - BOOST_CHECK_EQUAL(get_balance(voter2_id(db), core), 900); - - // remaining dividends not paid by coeffcient are sent to committee account - BOOST_CHECK_EQUAL(get_balance(committee_account(db), core), 499999999996938); - } - catch (fc::exception &e) { - edump((e.to_detail_string())); - throw; - } -} - -BOOST_AUTO_TEST_CASE( account_multiple_vesting ) -{ - try { - // advance to HF - generate_blocks(HARDFORK_GPOS_TIME); - generate_block(); - set_expiration(db, trx); - - // update default gpos global parameters to 4 days - auto now = db.head_block_time(); - update_gpos_global(345600, 86400, now); - - ACTORS((sam)(patty)); - - const auto& core = asset_id_type()(db); - - transfer( committee_account, sam_id, core.amount( 300 ) ); - transfer( committee_account, patty_id, core.amount( 100 ) ); - - // add some vesting to sam - create_vesting(sam_id, core.amount(100), vesting_balance_type::gpos); - - // have another balance with 200 more - create_vesting(sam_id, core.amount(200), vesting_balance_type::gpos); - - // patty also have vesting balance - create_vesting(patty_id, core.amount(100), vesting_balance_type::gpos); - - // get core asset object - const auto& dividend_holder_asset_object = get_asset(GRAPHENE_SYMBOL); - const auto& dividend_data = dividend_holder_asset_object.dividend_data(db); - - // update the payout interval - update_payout_interval(core.symbol, fc::time_point::now() + fc::minutes(1), 60 * 60 * 24); // 1 day - - // get the dividend distribution account - const account_object& dividend_distribution_account = dividend_data.dividend_distribution_account(db); - - // transfering some coins to distribution account. - transfer( committee_account, dividend_distribution_account.id, core.amount( 100 ) ); - generate_block(); - - // vote for a votable object - auto witness1 = witness_id_type(1)(db); - vote_for(sam_id, witness1.vote_id, sam_private_key); - vote_for(patty_id, witness1.vote_id, patty_private_key); - - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - // amount in vested balanced will sum up as voting power - witness1 = witness_id_type(1)(db); - BOOST_CHECK_EQUAL(witness1.total_votes, 400); - - // sam get paid dividends - BOOST_CHECK_EQUAL(get_balance(sam_id(db), core), 75); - - // patty also - BOOST_CHECK_EQUAL(get_balance(patty_id(db), core), 25); - - // total vote not decaying - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - generate_block(); - - witness1 = witness_id_type(1)(db); - - BOOST_CHECK_EQUAL(witness1.total_votes, 300); - } - catch (fc::exception &e) { - edump((e.to_detail_string())); - throw; - } -} -/* -BOOST_AUTO_TEST_CASE( competing_proposals ) -{ - try { - // advance to HF - generate_blocks(HARDFORK_GPOS_TIME); - generate_block(); - set_expiration(db, trx); - - ACTORS((voter1)(voter2)(worker1)(worker2)); - - const auto& core = asset_id_type()(db); - - transfer( committee_account, worker1_id, core.amount( 1000 ) ); - transfer( committee_account, worker2_id, core.amount( 1000 ) ); - transfer( committee_account, voter1_id, core.amount( 1000 ) ); - transfer( committee_account, voter2_id, core.amount( 1000 ) ); - - create_vesting(voter1_id, core.amount(200), vesting_balance_type::gpos); - create_vesting(voter2_id, core.amount(300), vesting_balance_type::gpos); - - generate_block(); - - auto now = db.head_block_time(); - update_gpos_global(518400, 86400, now); - - update_payout_interval(core.symbol, fc::time_point::now() + fc::minutes(1), 60 * 60 * 24); // 1 day - - upgrade_to_lifetime_member(worker1_id); - upgrade_to_lifetime_member(worker2_id); - - // create 2 competing proposals asking a lot of token - // todo: maybe a refund worker here so we can test with smaller numbers - auto w1 = create_worker(worker1_id, 100000000000, fc::days(10)); - auto w1_id_instance = w1.id.instance(); - auto w2 = create_worker(worker2_id, 100000000000, fc::days(10)); - auto w2_id_instance = w2.id.instance(); - - fill_reserve_pool(account_id_type(), asset(GRAPHENE_MAX_SHARE_SUPPLY/2)); - - // vote for the 2 workers - vote_for(voter1_id, w1.vote_for, voter1_private_key); - vote_for(voter2_id, w2.vote_for, voter2_private_key); - - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - generate_block(); - - w1 = worker_id_type(w1_id_instance)(db); - w2 = worker_id_type(w2_id_instance)(db); - - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - generate_block(); - - // only w2 is getting paid as it haves more votes and money is only enough for 1 - BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); - BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 100000000000); - - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - generate_block(); - - BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); - BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 150000000000); - - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - generate_block(); - - w1 = worker_id_type(w1_id_instance)(db); - w2 = worker_id_type(w2_id_instance)(db); - - // as votes decay w1 is still getting paid as it always have more votes than w1 - BOOST_CHECK_EQUAL(w1.total_votes_for, 100); - BOOST_CHECK_EQUAL(w2.total_votes_for, 150); - - BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); - BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 200000000000); - - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - generate_block(); - - w1 = worker_id_type(w1_id_instance)(db); - w2 = worker_id_type(w2_id_instance)(db); - - BOOST_CHECK_EQUAL(w1.total_votes_for, 66); - BOOST_CHECK_EQUAL(w2.total_votes_for, 100); - - // worker is sil getting paid as days pass - BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); - BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 250000000000); - - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - generate_block(); - - w1 = worker_id_type(w1_id_instance)(db); - w2 = worker_id_type(w2_id_instance)(db); - - BOOST_CHECK_EQUAL(w1.total_votes_for, 33); - BOOST_CHECK_EQUAL(w2.total_votes_for, 50); - - BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); - BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 300000000000); - - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - generate_block(); - - w1 = worker_id_type(w1_id_instance)(db); - w2 = worker_id_type(w2_id_instance)(db); - - // worker2 will not get paid anymore as it haves 0 votes - BOOST_CHECK_EQUAL(w1.total_votes_for, 0); - BOOST_CHECK_EQUAL(w2.total_votes_for, 0); - - BOOST_CHECK_EQUAL(w1.worker.get().balance(db).balance.amount.value, 0); - BOOST_CHECK_EQUAL(w2.worker.get().balance(db).balance.amount.value, 300000000000); - } - catch (fc::exception &e) { - edump((e.to_detail_string())); - throw; - } -} -*/ -BOOST_AUTO_TEST_CASE( proxy_voting ) -{ - try { - - } - catch (fc::exception &e) { - edump((e.to_detail_string())); - throw; - } -} - -BOOST_AUTO_TEST_CASE( no_proposal ) -{ - try { - - } - catch (fc::exception &e) { - edump((e.to_detail_string())); - throw; - } -} -BOOST_AUTO_TEST_CASE( database_api ) -{ - ACTORS((alice)(bob)); - try { - - // move to hardfork - generate_blocks( HARDFORK_GPOS_TIME ); - generate_block(); - - // database api - graphene::app::database_api db_api(db); - - const auto& core = asset_id_type()(db); - - // send some asset to alice and bob - transfer( committee_account, alice_id, core.amount( 1000 ) ); - transfer( committee_account, bob_id, core.amount( 1000 ) ); - generate_block(); - - // add some vesting to alice and bob - create_vesting(alice_id, core.amount(100), vesting_balance_type::gpos); - generate_block(); - - // total balance is 100 rest of data at 0 - auto gpos_info = db_api.get_gpos_info(alice_id); - BOOST_CHECK_EQUAL(gpos_info.vesting_factor, 0); - BOOST_CHECK_EQUAL(gpos_info.award.amount.value, 0); - BOOST_CHECK_EQUAL(gpos_info.total_amount.value, 100); - - create_vesting(bob_id, core.amount(100), vesting_balance_type::gpos); - generate_block(); - - // total gpos balance is now 200 - gpos_info = db_api.get_gpos_info(alice_id); - BOOST_CHECK_EQUAL(gpos_info.total_amount.value, 200); - - // update default gpos and dividend interval to 10 days - auto now = db.head_block_time(); - update_gpos_global(5184000, 864000, now); // 10 days subperiods - update_payout_interval(core.symbol, fc::time_point::now() + fc::minutes(1), 60 * 60 * 24 * 10); // 10 days - - generate_block(); - - // no votes for witness 1 - auto witness1 = witness_id_type(1)(db); - BOOST_CHECK_EQUAL(witness1.total_votes, 0); - - // no votes for witness 2 - auto witness2 = witness_id_type(2)(db); - BOOST_CHECK_EQUAL(witness2.total_votes, 0); - - // transfering some coins to distribution account. - const auto& dividend_holder_asset_object = get_asset(GRAPHENE_SYMBOL); - const auto& dividend_data = dividend_holder_asset_object.dividend_data(db); - const account_object& dividend_distribution_account = dividend_data.dividend_distribution_account(db); - transfer( committee_account, dividend_distribution_account.id, core.amount( 100 ) ); - generate_block(); - - // award balance is now 100 - gpos_info = db_api.get_gpos_info(alice_id); - BOOST_CHECK_EQUAL(gpos_info.vesting_factor, 0); - BOOST_CHECK_EQUAL(gpos_info.award.amount.value, 100); - BOOST_CHECK_EQUAL(gpos_info.total_amount.value, 200); - - // vote for witness1 - vote_for(alice_id, witness1.vote_id, alice_private_key); - vote_for(bob_id, witness1.vote_id, bob_private_key); - - // go to maint - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - // payment for alice and bob is done, distribution account is back in 0 - gpos_info = db_api.get_gpos_info(alice_id); - BOOST_CHECK_EQUAL(gpos_info.vesting_factor, 1); - BOOST_CHECK_EQUAL(gpos_info.award.amount.value, 0); - BOOST_CHECK_EQUAL(gpos_info.total_amount.value, 200); - - advance_x_maint(10); - - // alice vesting coeffcient decay - gpos_info = db_api.get_gpos_info(alice_id); - BOOST_CHECK_EQUAL(gpos_info.vesting_factor, 0.83333333333333337); - BOOST_CHECK_EQUAL(gpos_info.award.amount.value, 0); - BOOST_CHECK_EQUAL(gpos_info.total_amount.value, 200); - - advance_x_maint(10); - - // vesting factor for alice decaying more - gpos_info = db_api.get_gpos_info(alice_id); - BOOST_CHECK_EQUAL(gpos_info.vesting_factor, 0.66666666666666663); - BOOST_CHECK_EQUAL(gpos_info.award.amount.value, 0); - BOOST_CHECK_EQUAL(gpos_info.total_amount.value, 200); - } - catch (fc::exception &e) { - edump((e.to_detail_string())); - throw; - } -} - -BOOST_AUTO_TEST_SUITE_END()