From c025f639d7e9f3479438dde8be217f762ec6ac67 Mon Sep 17 00:00:00 2001 From: Sandip Patel Date: Sat, 19 Oct 2019 10:58:56 +0530 Subject: [PATCH 1/5] Fixed few error messages --- libraries/chain/vesting_balance_evaluator.cpp | 2 +- .../wallet/include/graphene/wallet/wallet.hpp | 7 +++ libraries/wallet/wallet.cpp | 60 ++++++++++++++++--- 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/libraries/chain/vesting_balance_evaluator.cpp b/libraries/chain/vesting_balance_evaluator.cpp index 22cf544f..9630d011 100644 --- a/libraries/chain/vesting_balance_evaluator.cpp +++ b/libraries/chain/vesting_balance_evaluator.cpp @@ -145,7 +145,7 @@ void_result vesting_balance_withdraw_evaluator::do_evaluate( const vesting_balan const vesting_balance_object& vbo = op.vesting_balance( d ); FC_ASSERT( op.owner == vbo.owner, "", ("op.owner", op.owner)("vbo.owner", vbo.owner) ); - FC_ASSERT( vbo.is_withdraw_allowed( now, op.amount ), "", ("now", now)("op", op)("vbo", vbo) ); + FC_ASSERT( vbo.is_withdraw_allowed( now, op.amount ), "GPOS Vested Balance cannont be withdrwan during the locking period", ("now", now)("op", op)("vbo", vbo) ); assert( op.amount <= vbo.balance ); // is_withdraw_allowed should fail before this check is reached /* const account_object& owner_account = op.owner( d ); */ diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 8a15fec0..fed7d55d 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1265,6 +1265,12 @@ class wallet_api */ witness_object get_witness(string owner_account); + /** Returns true if the account is witness, false otherwise + * @param owner_account the name or id of the witness account owner, or the id of the witness + * @returns true if account is witness, false otherwise + */ + bool is_witness(string owner_account); + /** Returns information about the given committee_member. * @param owner_account the name or id of the committee_member account owner, or the id of the committee_member * @returns the information about the committee_member stored in the block chain @@ -1969,6 +1975,7 @@ FC_API( graphene::wallet::wallet_api, (whitelist_account) (create_committee_member) (get_witness) + (is_witness) (get_committee_member) (list_witnesses) (list_committee_members) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index b6aa2cbf..75c47d8a 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1720,6 +1720,42 @@ public: FC_CAPTURE_AND_RETHROW( (owner_account) ) } + bool is_witness(string owner_account) + { + try + { + fc::optional witness_id = maybe_id(owner_account); + if (witness_id) + { + std::vector ids_to_get; + ids_to_get.push_back(*witness_id); + std::vector> witness_objects = _remote_db->get_witnesses(ids_to_get); + if (witness_objects.front()) + return true; + else + return false; + } + else + { + // then maybe it's the owner account + try + { + account_id_type owner_account_id = get_account_id(owner_account); + fc::optional witness = _remote_db->get_witness_by_account(owner_account_id); + if (witness) + return true; + else + return false; + } + catch (const fc::exception&) + { + return false; + } + } + } + FC_CAPTURE_AND_RETHROW( (owner_account) ) + } + committee_member_object get_committee_member(string owner_account) { try @@ -2013,9 +2049,14 @@ public: vbos = _remote_db->get_vesting_balances( *acct_id ); if( vbos.size() == 0 ) { - witness_object wit = get_witness( account_name ); - FC_ASSERT( wit.pay_vb ); - vbid = wit.pay_vb; + if (is_witness(account_name)) + { + witness_object wit = get_witness( account_name ); + FC_ASSERT( wit.pay_vb ); + vbid = wit.pay_vb; + } + else + FC_THROW("Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", account_name)); } } @@ -2080,7 +2121,7 @@ public: vbo_iter = std::find_if(vbo_info.begin(), vbo_info.end(), [](vesting_balance_object_with_info const& obj){return obj.balance_type == vesting_balance_type::gpos;}); if( vbo_info.size() == 0 || vbo_iter == vbo_info.end()) - FC_THROW("Account *** ${account} *** have insufficient or 0 vested balance(GPOS) to vote", ("account", voting_account)); + FC_THROW("Account ${account} has no core Token vested and thus she will not be allowed to vote for the committee member", ("account", voting_account)); account_object voting_account_object = get_account(voting_account); account_id_type committee_member_owner_account_id = get_account_id(committee_member); @@ -2121,7 +2162,7 @@ public: vbo_iter = std::find_if(vbo_info.begin(), vbo_info.end(), [](vesting_balance_object_with_info const& obj){return obj.balance_type == vesting_balance_type::gpos;}); if( vbo_info.size() == 0 || vbo_iter == vbo_info.end()) - FC_THROW("Account *** ${account} *** have insufficient or 0 vested balance(GPOS) to vote", ("account", voting_account)); + FC_THROW("Account ${account} has no core Token vested and thus she will not be allowed to vote for the witness", ("account", voting_account)); account_object voting_account_object = get_account(voting_account); account_id_type witness_owner_account_id = get_account_id(witness); @@ -2132,13 +2173,13 @@ public: { auto insert_result = voting_account_object.options.votes.insert(witness_obj->vote_id); if (!insert_result.second) - FC_THROW("Account ${account} was already voting for witness ${witness}", ("account", voting_account)("witness", witness)); + FC_THROW("Account ${account} has already voted for witness ${witness}", ("account", voting_account)("witness", witness)); } else { unsigned votes_removed = voting_account_object.options.votes.erase(witness_obj->vote_id); if (!votes_removed) - FC_THROW("Account ${account} is already not voting for witness ${witness}", ("account", voting_account)("witness", witness)); + FC_THROW("Account ${account} has not voted for witness ${witness}", ("account", voting_account)("witness", witness)); } account_update_operation account_update_op; account_update_op.account = voting_account_object.id; @@ -4073,6 +4114,11 @@ witness_object wallet_api::get_witness(string owner_account) return my->get_witness(owner_account); } +bool wallet_api::is_witness(string owner_account) +{ + return my->is_witness(owner_account); +} + committee_member_object wallet_api::get_committee_member(string owner_account) { return my->get_committee_member(owner_account); From 0800e2bc6710cd67394943812fbddf29e88cee91 Mon Sep 17 00:00:00 2001 From: Sandip Patel Date: Sat, 19 Oct 2019 16:38:12 +0530 Subject: [PATCH 2/5] error message corrections at other places --- .../include/graphene/chain/protocol/vesting.hpp | 10 ++++++++++ libraries/chain/vesting_balance_evaluator.cpp | 3 ++- libraries/wallet/wallet.cpp | 13 +++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/libraries/chain/include/graphene/chain/protocol/vesting.hpp b/libraries/chain/include/graphene/chain/protocol/vesting.hpp index ac995aaf..2a861b2a 100644 --- a/libraries/chain/include/graphene/chain/protocol/vesting.hpp +++ b/libraries/chain/include/graphene/chain/protocol/vesting.hpp @@ -28,6 +28,16 @@ namespace graphene { namespace chain { enum class vesting_balance_type { normal, gpos }; + inline std::string get_vesting_balance_type(vesting_balance_type type) { + switch (type) { + case vesting_balance_type::normal: + return "NORMAL"; + case vesting_balance_type::gpos: + default: + return "GPOS"; + } + } + struct linear_vesting_policy_initializer { /** while vesting begins on begin_timestamp, none may be claimed before vesting_cliff_seconds have passed */ diff --git a/libraries/chain/vesting_balance_evaluator.cpp b/libraries/chain/vesting_balance_evaluator.cpp index 9630d011..9f42d4ff 100644 --- a/libraries/chain/vesting_balance_evaluator.cpp +++ b/libraries/chain/vesting_balance_evaluator.cpp @@ -145,7 +145,8 @@ void_result vesting_balance_withdraw_evaluator::do_evaluate( const vesting_balan const vesting_balance_object& vbo = op.vesting_balance( d ); FC_ASSERT( op.owner == vbo.owner, "", ("op.owner", op.owner)("vbo.owner", vbo.owner) ); - FC_ASSERT( vbo.is_withdraw_allowed( now, op.amount ), "GPOS Vested Balance cannont be withdrwan during the locking period", ("now", now)("op", op)("vbo", vbo) ); + FC_ASSERT( vbo.is_withdraw_allowed( now, op.amount ), "${balance_type} Vested Balance cannont be withdrwan during the locking period", + ("balance_type", get_vesting_balance_type(vbo.balance_type))("now", now)("op", op)("vbo", vbo) ); assert( op.amount <= vbo.balance ); // is_withdraw_allowed should fail before this check is reached /* const account_object& owner_account = op.owner( d ); */ diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 75c47d8a..c7e605cc 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2005,9 +2005,14 @@ public: fc::optional vbid = maybe_id(witness_name); if( !vbid ) { - witness_object wit = get_witness( witness_name ); - FC_ASSERT( wit.pay_vb ); - vbid = wit.pay_vb; + if (is_witness(witness_name)) + { + witness_object wit = get_witness( witness_name ); + FC_ASSERT( wit.pay_vb, "Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", witness_name)); + vbid = wit.pay_vb; + } + else + FC_THROW("Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", witness_name)); } vesting_balance_object vbo = get_object< vesting_balance_object >( *vbid ); @@ -2052,7 +2057,7 @@ public: if (is_witness(account_name)) { witness_object wit = get_witness( account_name ); - FC_ASSERT( wit.pay_vb ); + FC_ASSERT( wit.pay_vb, "Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", account_name)); vbid = wit.pay_vb; } else From 69630183f961c3489128478acb066d7a9c5a022f Mon Sep 17 00:00:00 2001 From: Sandip Patel Date: Thu, 24 Oct 2019 19:24:09 +0530 Subject: [PATCH 3/5] removed witness check --- libraries/wallet/wallet.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index c7e605cc..0e4f3198 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2052,17 +2052,8 @@ public: acct_id = get_account( account_name ).id; vbos = _remote_db->get_vesting_balances( *acct_id ); - if( vbos.size() == 0 ) - { - if (is_witness(account_name)) - { - witness_object wit = get_witness( account_name ); - FC_ASSERT( wit.pay_vb, "Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", account_name)); - vbid = wit.pay_vb; - } - else - FC_THROW("Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", account_name)); - } + if( vbos.size() == 0 ) + FC_THROW("Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", account_name)); } //whether it is a witness or user, keep it in a container and iterate over to process all vesting balances and types From 78787c2a14a18ba06efb9ebbcbf611c1b5e7f271 Mon Sep 17 00:00:00 2001 From: pbattu123 Date: Thu, 24 Oct 2019 14:39:01 -0300 Subject: [PATCH 4/5] eliminate time gap between two consecutive vesting periods --- libraries/chain/db_maint.cpp | 6 +++--- tests/tests/gpos_tests.cpp | 31 ++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 182c04fc..c983efe8 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -833,7 +833,7 @@ void rolling_period_start(database& db) 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)) + if(now.sec_since_epoch() >= (period_start + vesting_period)) { // roll db.modify(db.get_global_properties(), [now](global_property_object& p) { @@ -1390,10 +1390,10 @@ 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); + rolling_period_start(*this); + struct vote_tally_helper { database& d; const global_property_object& props; diff --git a/tests/tests/gpos_tests.cpp b/tests/tests/gpos_tests.cpp index 5b089685..615e76c4 100644 --- a/tests/tests/gpos_tests.cpp +++ b/tests/tests/gpos_tests.cpp @@ -95,6 +95,15 @@ struct gpos_fixture: database_fixture 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 update_maintenance_interval(uint32_t new_interval) + { + db.modify(db.get_global_properties(), [new_interval](global_property_object& p) { + p.parameters.maintenance_interval = new_interval; + }); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.maintenance_interval, new_interval); + } + 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; @@ -497,26 +506,26 @@ 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); + update_gpos_global(518400, 86400, HARDFORK_GPOS_TIME); + generate_blocks(HARDFORK_GPOS_TIME); + update_maintenance_interval(3600); //update maintenance interval to 1hr to evaluate sub-periods + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.maintenance_interval, 3600); + auto vesting_period_1 = db.get_global_properties().parameters.gpos_period_start(); + + auto now = db.head_block_time(); // 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()); + auto vesting_period_2 = db.get_global_properties().parameters.gpos_period_start(); + + //difference between start of two consecutive vesting periods should be 6 days + BOOST_CHECK_EQUAL(vesting_period_1 + 518400, vesting_period_2); } catch (fc::exception &e) { edump((e.to_detail_string())); From bdd1863cf2a4e3f58b67c01c792e53e2c089f0bc Mon Sep 17 00:00:00 2001 From: pbattu123 Date: Thu, 24 Oct 2019 23:53:47 -0300 Subject: [PATCH 5/5] updated GPOS hf --- libraries/chain/hardfork.d/GPOS.hf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/chain/hardfork.d/GPOS.hf b/libraries/chain/hardfork.d/GPOS.hf index f175ef2c..f86dbc22 100644 --- a/libraries/chain/hardfork.d/GPOS.hf +++ b/libraries/chain/hardfork.d/GPOS.hf @@ -1,4 +1,4 @@ -// GPOS HARDFORK Friday, March 15, 2019 11:57:28 PM +// GPOS HARDFORK Tuesday, October 22, 2019 05:00:00 AM GMT #ifndef HARDFORK_GPOS_TIME -#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1552694248 )) -#endif \ No newline at end of file +#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1571720400 )) +#endif