From 884fce43c7c761fb43ee24eafff18ecba02b0774 Mon Sep 17 00:00:00 2001 From: ddylko Date: Wed, 24 Jul 2019 13:50:59 +0300 Subject: [PATCH 1/4] fees forwarded from templ-acc to committee-acc --- libraries/chain/db_market.cpp | 8 ++- libraries/chain/hardfork.d/CORE_1800.hf | 4 ++ tests/tests/market_fee_sharing_tests.cpp | 79 ++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 libraries/chain/hardfork.d/CORE_1800.hf diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index c009d0b830..e0af516b00 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -1249,6 +1249,11 @@ asset database::pay_market_fees(const account_object& seller, const asset_object FC_ASSERT( reward < issuer_fees, "Market reward should be less than issuer fees"); // cut referrer percent from reward auto registrar_reward = reward; + + auto registrar = ( seller.registrar == GRAPHENE_TEMP_ACCOUNT && head_block_time() >= HARDFORK_CORE_1800_TIME ) + ? GRAPHENE_COMMITTEE_ACCOUNT + : seller.registrar; + if( seller.referrer != seller.registrar ) { const auto referrer_rewards_value = detail::calculate_percent( reward.amount, @@ -1263,7 +1268,8 @@ asset database::pay_market_fees(const account_object& seller, const asset_object deposit_market_fee_vesting_balance(seller.referrer, referrer_reward); } } - deposit_market_fee_vesting_balance(seller.registrar, registrar_reward); + deposit_market_fee_vesting_balance(registrar, registrar_reward); + } } } diff --git a/libraries/chain/hardfork.d/CORE_1800.hf b/libraries/chain/hardfork.d/CORE_1800.hf new file mode 100644 index 0000000000..06e4f5341a --- /dev/null +++ b/libraries/chain/hardfork.d/CORE_1800.hf @@ -0,0 +1,4 @@ +// bitshares-core issue #1800 Fix "Temp-account market fee sharing" +#ifndef HARDFORK_CORE_1800_TIME +#define HARDFORK_CORE_1800_TIME (fc::time_point_sec( 1563888919 )) // Tue, 23 Jul 2019 13:35:00 UTC +#endif diff --git a/tests/tests/market_fee_sharing_tests.cpp b/tests/tests/market_fee_sharing_tests.cpp index 2ba95b2c5b..8f6fdc0604 100644 --- a/tests/tests/market_fee_sharing_tests.cpp +++ b/tests/tests/market_fee_sharing_tests.cpp @@ -96,6 +96,18 @@ struct reward_database_fixture : database_fixture database_fixture::generate_block(); } + void generate_blocks_before_hf1800() + { + database_fixture::generate_blocks( HARDFORK_CORE_1800_TIME ); + // database_fixture::generate_block(); + } + + void generate_blocks_past_hf1800() + { + database_fixture::generate_blocks( HARDFORK_CORE_1800_TIME ); + database_fixture::generate_block(); + } + asset core_asset(int64_t x ) { return asset( x*core_precision ); @@ -431,18 +443,85 @@ BOOST_AUTO_TEST_CASE(create_actors) const account_object alice = create_account("alice", izzyregistrar, izzyreferrer, 50/*0.5%*/); const account_object bob = create_account("bob", izzyregistrar, izzyreferrer, 50/*0.5%*/); + const account_object old = create_account("old", GRAPHENE_TEMP_ACCOUNT(db), GRAPHENE_COMMITTEE_ACCOUNT(db), 50u); // prepare users' balance issue_uia( alice, jillcoin.amount( 20000000 ) ); transfer( committee_account, alice.get_id(), core_asset(1000) ); transfer( committee_account, bob.get_id(), core_asset(1000) ); + transfer( committee_account, old.get_id(), core_asset(1000) ); transfer( committee_account, izzyregistrar.get_id(), core_asset(1000) ); transfer( committee_account, izzyreferrer.get_id(), core_asset(1000) ); } FC_LOG_AND_RETHROW() } +BOOST_AUTO_TEST_CASE(MFS_before_hardfork_1800) +{ + try + { + INVOKE(create_actors); + + generate_blocks_before_hf1800(); + GET_ACTOR(jill); + + constexpr auto jillcoin_reward_percent = 2*GRAPHENE_1_PERCENT; + const asset_object &jillcoin = get_asset("JCOIN"); + + flat_set whitelist; + update_asset(jill_id, jill_private_key, jillcoin.get_id(), jillcoin_reward_percent, whitelist); + + BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0); + BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0); + + GET_ACTOR(alice); + GET_ACTOR(old); + + create_sell_order( alice, jillcoin.amount(100000), core_asset(1) ); + create_sell_order( old, core_asset(1), jillcoin.amount(100000) ); + + BOOST_CHECK_GE( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0); + BOOST_CHECK_GE( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0); + + } + FC_LOG_AND_RETHROW() + +} + +BOOST_AUTO_TEST_CASE(MFS_after_hardfork_1800) +{ + try + { + INVOKE(create_actors); + + generate_blocks_past_hf1800(); + GET_ACTOR(jill); + + constexpr auto jillcoin_reward_percent = 2*GRAPHENE_1_PERCENT; + const asset_object &jillcoin = get_asset("JCOIN"); + + flat_set whitelist; + update_asset(jill_id, jill_private_key, jillcoin.get_id(), jillcoin_reward_percent, whitelist); + + BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0); + BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0); + + GET_ACTOR(alice); + GET_ACTOR(old); + + create_sell_order( alice, jillcoin.amount(100000), core_asset(1) ); + create_sell_order( old, core_asset(1), jillcoin.amount(100000) ); + + + BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0); + BOOST_CHECK_GE( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0); + + } + FC_LOG_AND_RETHROW() + +} + BOOST_AUTO_TEST_CASE(white_list_is_empty_test) { try From d5076eee1ddbf05184f538b138144ab73afd609c Mon Sep 17 00:00:00 2001 From: ddylko Date: Thu, 25 Jul 2019 14:26:13 +0300 Subject: [PATCH 2/4] hf time fixes, tests names and cmp condition fixes --- libraries/chain/hardfork.d/CORE_1800.hf | 2 +- tests/tests/market_fee_sharing_tests.cpp | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/libraries/chain/hardfork.d/CORE_1800.hf b/libraries/chain/hardfork.d/CORE_1800.hf index 06e4f5341a..39d8334cc8 100644 --- a/libraries/chain/hardfork.d/CORE_1800.hf +++ b/libraries/chain/hardfork.d/CORE_1800.hf @@ -1,4 +1,4 @@ // bitshares-core issue #1800 Fix "Temp-account market fee sharing" #ifndef HARDFORK_CORE_1800_TIME -#define HARDFORK_CORE_1800_TIME (fc::time_point_sec( 1563888919 )) // Tue, 23 Jul 2019 13:35:00 UTC +#define HARDFORK_CORE_1800_TIME (fc::time_point_sec( 1600000000 )) // Tue, 23 Jul 2019 13:35:00 UTC #endif diff --git a/tests/tests/market_fee_sharing_tests.cpp b/tests/tests/market_fee_sharing_tests.cpp index 8f6fdc0604..378c8f63dc 100644 --- a/tests/tests/market_fee_sharing_tests.cpp +++ b/tests/tests/market_fee_sharing_tests.cpp @@ -96,12 +96,6 @@ struct reward_database_fixture : database_fixture database_fixture::generate_block(); } - void generate_blocks_before_hf1800() - { - database_fixture::generate_blocks( HARDFORK_CORE_1800_TIME ); - // database_fixture::generate_block(); - } - void generate_blocks_past_hf1800() { database_fixture::generate_blocks( HARDFORK_CORE_1800_TIME ); @@ -457,13 +451,13 @@ BOOST_AUTO_TEST_CASE(create_actors) FC_LOG_AND_RETHROW() } -BOOST_AUTO_TEST_CASE(MFS_before_hardfork_1800) +BOOST_AUTO_TEST_CASE(fee_shares_between_temp_acc_and_committee_acc) { try { INVOKE(create_actors); - generate_blocks_before_hf1800(); + generate_blocks_past_hf1268(); GET_ACTOR(jill); constexpr auto jillcoin_reward_percent = 2*GRAPHENE_1_PERCENT; @@ -481,15 +475,15 @@ BOOST_AUTO_TEST_CASE(MFS_before_hardfork_1800) create_sell_order( alice, jillcoin.amount(100000), core_asset(1) ); create_sell_order( old, core_asset(1), jillcoin.amount(100000) ); - BOOST_CHECK_GE( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0); - BOOST_CHECK_GE( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0); + BOOST_CHECK_GT( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0); + BOOST_CHECK_GT( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0); } FC_LOG_AND_RETHROW() } -BOOST_AUTO_TEST_CASE(MFS_after_hardfork_1800) +BOOST_AUTO_TEST_CASE(fee_do_not_shares_between_temp_acc_and_committee_acc) { try { @@ -515,7 +509,7 @@ BOOST_AUTO_TEST_CASE(MFS_after_hardfork_1800) BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0); - BOOST_CHECK_GE( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0); + BOOST_CHECK_GT( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0); } FC_LOG_AND_RETHROW() From 2ddf0470a624257a892355e341f7218bcfc9caa4 Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 10 Apr 2020 14:13:42 +0000 Subject: [PATCH 3/4] Fix market fee sharing for temp-account referrer When the funds are going to temp-account, redirect to committee-account --- libraries/chain/db_market.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index 3dedc4220b..bce8fa9ad7 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -1229,22 +1229,30 @@ asset database::pay_market_fees(const account_object* seller, const asset_object // cut referrer percent from reward auto registrar_reward = reward; - auto registrar = ( seller->registrar == GRAPHENE_TEMP_ACCOUNT && head_block_time() >= HARDFORK_CORE_1800_TIME ) - ? GRAPHENE_COMMITTEE_ACCOUNT - : seller->registrar; + auto registrar = seller->registrar; + auto referrer = seller->referrer; - if( seller->referrer != seller->registrar ) + // After HF core-1800, for funds going to temp-account, redirect to committee-account + if( head_block_time() >= HARDFORK_CORE_1800_TIME ) + { + if( registrar == GRAPHENE_TEMP_ACCOUNT ) + registrar = GRAPHENE_COMMITTEE_ACCOUNT; + if( referrer == GRAPHENE_TEMP_ACCOUNT ) + referrer = GRAPHENE_COMMITTEE_ACCOUNT; + } + + if( referrer != registrar ) { const auto referrer_rewards_value = detail::calculate_percent( reward.amount, seller->referrer_rewards_percentage ); - if ( referrer_rewards_value > 0 && is_authorized_asset(*this, seller->referrer(*this), recv_asset) ) + if ( referrer_rewards_value > 0 && is_authorized_asset(*this, referrer(*this), recv_asset) ) { FC_ASSERT ( referrer_rewards_value <= reward.amount.value, "Referrer reward shouldn't be greater than total reward" ); const asset referrer_reward = recv_asset.amount(referrer_rewards_value); registrar_reward -= referrer_reward; - deposit_market_fee_vesting_balance(seller->referrer, referrer_reward); + deposit_market_fee_vesting_balance(referrer, referrer_reward); } } if( registrar_reward.amount > 0 ) From 0a3a0a6c6d5df8bd5b939e5504ea8ea432c306b3 Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 10 Apr 2020 14:41:27 +0000 Subject: [PATCH 4/4] Add tests for temp-account referrer fee sharing --- tests/tests/market_fee_sharing_tests.cpp | 94 +++++++++++++++++++++--- 1 file changed, 84 insertions(+), 10 deletions(-) diff --git a/tests/tests/market_fee_sharing_tests.cpp b/tests/tests/market_fee_sharing_tests.cpp index 6ca36d680c..4e6b12b35f 100644 --- a/tests/tests/market_fee_sharing_tests.cpp +++ b/tests/tests/market_fee_sharing_tests.cpp @@ -101,6 +101,7 @@ struct reward_database_fixture : database_fixture { database_fixture::generate_blocks( HARDFORK_CORE_1800_TIME ); database_fixture::generate_block(); + set_expiration(db, trx); } asset core_asset(int64_t x ) @@ -435,10 +436,11 @@ BOOST_AUTO_TEST_CASE(create_actors) { try { - ACTORS((jill)(izzyregistrar)(izzyreferrer)); + ACTORS((jill)(izzyregistrar)(izzyreferrer)(tempregistrar)); upgrade_to_lifetime_member(izzyregistrar); upgrade_to_lifetime_member(izzyreferrer); + upgrade_to_lifetime_member(tempregistrar); price price(asset(1, asset_id_type(1)), asset(1)); uint16_t market_fee_percent = 20 * GRAPHENE_1_PERCENT; @@ -447,27 +449,31 @@ BOOST_AUTO_TEST_CASE(create_actors) const account_object alice = create_account("alice", izzyregistrar, izzyreferrer, 50/*0.5%*/); const account_object bob = create_account("bob", izzyregistrar, izzyreferrer, 50/*0.5%*/); - const account_object old = create_account("old", GRAPHENE_TEMP_ACCOUNT(db), GRAPHENE_COMMITTEE_ACCOUNT(db), 50u); + const account_object old = create_account("old", GRAPHENE_TEMP_ACCOUNT(db), + GRAPHENE_COMMITTEE_ACCOUNT(db), 50u); + const account_object tmp = create_account("tmp", tempregistrar, + GRAPHENE_TEMP_ACCOUNT(db), 50u); // prepare users' balance issue_uia( alice, jillcoin.amount( 20000000 ) ); transfer( committee_account, alice.get_id(), core_asset(1000) ); transfer( committee_account, bob.get_id(), core_asset(1000) ); - transfer( committee_account, old.get_id(), core_asset(1000) ); + transfer( committee_account, old.get_id(), core_asset(1000) ); + transfer( committee_account, tmp.get_id(), core_asset(1000) ); transfer( committee_account, izzyregistrar.get_id(), core_asset(1000) ); transfer( committee_account, izzyreferrer.get_id(), core_asset(1000) ); + transfer( committee_account, tempregistrar.get_id(), core_asset(1000) ); } FC_LOG_AND_RETHROW() } -BOOST_AUTO_TEST_CASE(fee_shares_between_temp_acc_and_committee_acc) +BOOST_AUTO_TEST_CASE(fee_shares_between_temp_acc_and_committee_acc_before_hf_1800) { try { INVOKE(create_actors); - generate_blocks_past_hf1268(); GET_ACTOR(jill); constexpr auto jillcoin_reward_percent = 2*GRAPHENE_1_PERCENT; @@ -490,10 +496,10 @@ BOOST_AUTO_TEST_CASE(fee_shares_between_temp_acc_and_committee_acc) } FC_LOG_AND_RETHROW() - + } -BOOST_AUTO_TEST_CASE(fee_do_not_shares_between_temp_acc_and_committee_acc) +BOOST_AUTO_TEST_CASE(fee_do_not_share_between_temp_acc_and_committee_acc_after_hf_1800) { try { @@ -517,13 +523,81 @@ BOOST_AUTO_TEST_CASE(fee_do_not_shares_between_temp_acc_and_committee_acc) create_sell_order( alice, jillcoin.amount(100000), core_asset(1) ); create_sell_order( old, core_asset(1), jillcoin.amount(100000) ); + BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0); + BOOST_CHECK_GT( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0); + + } + FC_LOG_AND_RETHROW() + +} + +BOOST_AUTO_TEST_CASE(fee_shares_to_temp_referrer_before_hf_1800) +{ + try + { + INVOKE(create_actors); + + GET_ACTOR(jill); + GET_ACTOR(tempregistrar); + + constexpr auto jillcoin_reward_percent = 2*GRAPHENE_1_PERCENT; + const asset_object &jillcoin = get_asset("JCOIN"); + + flat_set whitelist; + update_asset(jill_id, jill_private_key, jillcoin.get_id(), jillcoin_reward_percent, whitelist); + + BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0); + BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0); + BOOST_CHECK_EQUAL( get_market_fee_reward( tempregistrar, jillcoin), 0); + + GET_ACTOR(alice); + GET_ACTOR(tmp); + + create_sell_order( alice, jillcoin.amount(100000), core_asset(1) ); + create_sell_order( tmp, core_asset(1), jillcoin.amount(100000) ); + + BOOST_CHECK_GT( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0); + BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0); + BOOST_CHECK_GT( get_market_fee_reward( tempregistrar, jillcoin), 0); + + } + FC_LOG_AND_RETHROW() + +} + +BOOST_AUTO_TEST_CASE(fee_do_not_share_to_temp_referrer_after_hf_1800) +{ + try + { + INVOKE(create_actors); + + generate_blocks_past_hf1800(); + GET_ACTOR(jill); + GET_ACTOR(tempregistrar); + + constexpr auto jillcoin_reward_percent = 2*GRAPHENE_1_PERCENT; + const asset_object &jillcoin = get_asset("JCOIN"); + + flat_set whitelist; + update_asset(jill_id, jill_private_key, jillcoin.get_id(), jillcoin_reward_percent, whitelist); + + BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0); + BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0); + BOOST_CHECK_EQUAL( get_market_fee_reward( tempregistrar, jillcoin), 0); + + GET_ACTOR(alice); + GET_ACTOR(tmp); + + create_sell_order( alice, jillcoin.amount(100000), core_asset(1) ); + create_sell_order( tmp, core_asset(1), jillcoin.amount(100000) ); BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0); BOOST_CHECK_GT( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0); + BOOST_CHECK_GT( get_market_fee_reward( tempregistrar, jillcoin), 0); } FC_LOG_AND_RETHROW() - + } BOOST_AUTO_TEST_CASE(white_list_is_empty_test) @@ -663,7 +737,7 @@ BOOST_AUTO_TEST_CASE(create_asset_via_proposal_test) { ACTOR(issuer); price core_exchange_rate(asset(1, asset_id_type(1)), asset(1)); - + asset_create_operation create_op; create_op.issuer = issuer.id; create_op.fee = asset(); @@ -990,7 +1064,7 @@ BOOST_AUTO_TEST_CASE(white_list_asset_rewards_test) } BOOST_AUTO_TEST_CASE( create_vesting_balance_object_test ) -{ +{ /** * Test checks that an account could have duplicates VBO (with the same asset_type) * for any type of vesting_balance_type