diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 4e3e9b96..ff840363 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -93,7 +93,7 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o wlog( "Asset ${s} has a name which requires hardfork 385", ("s",op.symbol) ); } - core_fee_paid -= core_fee_paid.value/2; + // core_fee_paid -= core_fee_paid.value/2; if( op.bitasset_opts ) { @@ -121,13 +121,31 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } +// copied from bitshares. (https://github.com/bitshares/bitshares-core/issues/429) +void asset_create_evaluator::pay_fee() +{ + fee_is_odd = core_fee_paid.value & 1; + core_fee_paid -= core_fee_paid.value/2; + generic_evaluator::pay_fee(); +} + object_id_type asset_create_evaluator::do_apply( const asset_create_operation& op ) { try { + // includes changes from bitshares. (https://github.com/bitshares/bitshares-core/issues/429) + bool hf_429 = fee_is_odd && db().head_block_time() > HARDFORK_CORE_429_TIME; + const asset_dynamic_data_object& dyn_asset = db().create( [&]( asset_dynamic_data_object& a ) { a.current_supply = 0; - a.fee_pool = core_fee_paid; //op.calculate_fee(db().current_fee_schedule()).value / 2; + a.fee_pool = core_fee_paid - (hf_429 ? 1 : 0); }); + if( fee_is_odd && !hf_429 ) + { + const auto& core_dd = db().get( asset_id_type() ).dynamic_data( db() ); + db().modify( core_dd, [=]( asset_dynamic_data_object& dd ) { + dd.current_supply++; + }); + } asset_bitasset_data_id_type bit_asset_id; if( op.bitasset_opts.valid() ) diff --git a/libraries/chain/include/graphene/chain/asset_evaluator.hpp b/libraries/chain/include/graphene/chain/asset_evaluator.hpp index 234a60d7..4dd4a930 100644 --- a/libraries/chain/include/graphene/chain/asset_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/asset_evaluator.hpp @@ -35,6 +35,14 @@ namespace graphene { namespace chain { void_result do_evaluate( const asset_create_operation& o ); object_id_type do_apply( const asset_create_operation& o ); + + // copied from bitshares. (https://github.com/bitshares/bitshares-core/issues/429) + /** override the default behavior defined by generic_evalautor which is to + * post the fee to fee_paying_account_stats.pending_fees + */ + virtual void pay_fee() override; + private: + bool fee_is_odd; }; class asset_issue_evaluator : public evaluator diff --git a/tests/tests/fee_tests.cpp b/tests/tests/fee_tests.cpp index d6f26170..465e1934 100644 --- a/tests/tests/fee_tests.cpp +++ b/tests/tests/fee_tests.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -942,5 +943,192 @@ BOOST_AUTO_TEST_CASE( stealth_fba_test ) throw; } } +// added test from bitshares for issues: +// https://github.com/bitshares/bitshares-core/issues/429 +// https://github.com/bitshares/bitshares-core/issues/433 +BOOST_AUTO_TEST_CASE( defaults_test ) +{ try { + fee_schedule schedule; + const limit_order_create_operation::fee_parameters_type default_order_fee; -BOOST_AUTO_TEST_SUITE_END() + // no fees set yet -> default + asset fee = schedule.calculate_fee( limit_order_create_operation() ); + BOOST_CHECK_EQUAL( default_order_fee.fee, fee.amount.value ); + + limit_order_create_operation::fee_parameters_type new_order_fee; new_order_fee.fee = 123; + // set fee + check + schedule.parameters.insert( new_order_fee ); + fee = schedule.calculate_fee( limit_order_create_operation() ); + BOOST_CHECK_EQUAL( new_order_fee.fee, fee.amount.value ); + + // NO bid_collateral_operation in this version + + // bid_collateral fee defaults to call_order_update fee + // call_order_update fee is unset -> default + // const call_order_update_operation::fee_parameters_type default_short_fee; + // call_order_update_operation::fee_parameters_type new_short_fee; new_short_fee.fee = 123; + // fee = schedule.calculate_fee( bid_collateral_operation() ); + // BOOST_CHECK_EQUAL( default_short_fee.fee, fee.amount.value ); + + // set call_order_update fee + check bid_collateral fee + // schedule.parameters.insert( new_short_fee ); + // fee = schedule.calculate_fee( bid_collateral_operation() ); + // BOOST_CHECK_EQUAL( new_short_fee.fee, fee.amount.value ); + + // set bid_collateral fee + check + // bid_collateral_operation::fee_parameters_type new_bid_fee; new_bid_fee.fee = 124; + // schedule.parameters.insert( new_bid_fee ); + // fee = schedule.calculate_fee( bid_collateral_operation() ); + // BOOST_CHECK_EQUAL( new_bid_fee.fee, fee.amount.value ); + } + catch( const fc::exception& e ) + { + elog( "caught exception ${e}", ("e", e.to_detail_string()) ); + throw; + } +} + +BOOST_AUTO_TEST_CASE( issue_429_test ) +{ + try + { + ACTORS((alice)); + + transfer( committee_account, alice_id, asset( 1000000 * asset::scaled_precision( asset_id_type()(db).precision ) ) ); + + // make sure the database requires our fee to be nonzero + enable_fees(); + + auto fees_to_pay = db.get_global_properties().parameters.current_fees->get(); + + { + signed_transaction tx; + asset_create_operation op; + op.issuer = alice_id; + op.symbol = "ALICE"; + op.common_options.core_exchange_rate = asset( 1 ) / asset( 1, asset_id_type( 1 ) ); + op.fee = asset( (fees_to_pay.long_symbol + fees_to_pay.price_per_kbyte) & (~1) ); + tx.operations.push_back( op ); + set_expiration( db, tx ); + sign( tx, alice_private_key ); + PUSH_TX( db, tx ); + } + + verify_asset_supplies( db ); + + { + signed_transaction tx; + asset_create_operation op; + op.issuer = alice_id; + op.symbol = "ALICE.ODD"; + op.common_options.core_exchange_rate = asset( 1 ) / asset( 1, asset_id_type( 1 ) ); + op.fee = asset((fees_to_pay.long_symbol + fees_to_pay.price_per_kbyte) | 1); + tx.operations.push_back( op ); + set_expiration( db, tx ); + sign( tx, alice_private_key ); + PUSH_TX( db, tx ); + } + + verify_asset_supplies( db ); + + generate_blocks( HARDFORK_CORE_429_TIME + 10 ); + { + signed_transaction tx; + asset_create_operation op; + op.issuer = alice_id; + op.symbol = "ALICE.ODDER"; + op.common_options.core_exchange_rate = asset( 1 ) / asset( 1, asset_id_type( 1 ) ); + op.fee = asset((fees_to_pay.long_symbol + fees_to_pay.price_per_kbyte) | 1); + tx.operations.push_back( op ); + set_expiration( db, tx ); + sign( tx, alice_private_key ); + PUSH_TX( db, tx ); + } + + verify_asset_supplies( db ); + } + catch( const fc::exception& e ) + { + edump((e.to_detail_string())); + throw; + } +} + + +BOOST_AUTO_TEST_CASE( issue_433_test ) +{ + try + { + ACTORS((alice)); + + auto& core = asset_id_type()(db); + + transfer( committee_account, alice_id, asset( 1000000 * asset::scaled_precision( core.precision ) ) ); + + const auto& myusd = create_user_issued_asset( "MYUSD", alice, 0 ); + issue_uia( alice, myusd.amount( 2000000000 ) ); + + // make sure the database requires our fee to be nonzero + enable_fees(); + + const auto& fees = *db.get_global_properties().parameters.current_fees; + const auto asset_create_fees = fees.get(); + + fund_fee_pool( alice, myusd, 5*asset_create_fees.long_symbol ); + + asset_create_operation op; + op.issuer = alice_id; + op.symbol = "ALICE"; + op.common_options.core_exchange_rate = asset( 1 ) / asset( 1, asset_id_type( 1 ) ); + op.fee = myusd.amount( ((asset_create_fees.long_symbol + asset_create_fees.price_per_kbyte) & (~1)) ); + { + signed_transaction tx; + tx.operations.push_back( op ); + set_expiration( db, tx ); + sign( tx, alice_private_key ); + PUSH_TX( db, tx ); + } + + verify_asset_supplies( db ); + + const auto proposal_create_fees = fees.get(); + proposal_create_operation prop; + op.symbol = "ALICE.PROP"; + prop.fee_paying_account = alice_id; + prop.proposed_ops.emplace_back( op ); + prop.expiration_time = db.head_block_time() + fc::days(1); + prop.fee = asset( proposal_create_fees.fee + proposal_create_fees.price_per_kbyte ); + object_id_type proposal_id; + { + signed_transaction tx; + tx.operations.push_back( prop ); + set_expiration( db, tx ); + sign( tx, alice_private_key ); + proposal_id = PUSH_TX( db, tx ).operation_results.front().get(); + } + const proposal_object& proposal = db.get( proposal_id ); + + const auto proposal_update_fees = fees.get(); + proposal_update_operation pup; + pup.proposal = proposal.id; + pup.fee_paying_account = alice_id; + pup.active_approvals_to_add.insert(alice_id); + pup.fee = asset( proposal_update_fees.fee + proposal_update_fees.price_per_kbyte ); + { + signed_transaction tx; + tx.operations.push_back( pup ); + set_expiration( db, tx ); + sign( tx, alice_private_key ); + PUSH_TX( db, tx ); + } + + verify_asset_supplies( db ); + } + catch( const fc::exception& e ) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file