From fbd832b4508518b728b05d1dcf7cbbd53785acba Mon Sep 17 00:00:00 2001 From: christophersanborn <23085117+christophersanborn@users.noreply.github.com> Date: Thu, 7 May 2020 18:12:46 -0400 Subject: [PATCH] Move force_settle_fee_percent from asset_options to bitasset_options --- libraries/chain/asset_evaluator.cpp | 18 +++++++++++------- libraries/chain/db_market.cpp | 13 +++++++------ libraries/chain/proposal_evaluator.cpp | 17 ++++++++++------- libraries/protocol/asset_ops.cpp | 6 ++++-- .../include/graphene/protocol/asset_ops.hpp | 9 ++++----- 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 93982f9436..0781321eac 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -66,7 +66,7 @@ namespace detail { } } - void check_asset_options_hf_bsip87(const fc::time_point_sec& block_time, const asset_options& options) + void check_bitasset_options_hf_bsip87(const fc::time_point_sec& block_time, const bitasset_options& options) { // HF_REMOVABLE: Following hardfork check should be removable after hardfork date passes: FC_ASSERT( !options.extensions.value.force_settle_fee_percent.valid() @@ -94,7 +94,10 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o // Hardfork Checks: detail::check_asset_options_hf_1774(now, op.common_options); detail::check_asset_options_hf_bsip81(now, op.common_options); - detail::check_asset_options_hf_bsip87(now, op.common_options); // HF_REMOVABLE + if( op.bitasset_opts ) { + detail::check_bitasset_options_hf_bsip77( now, *op.bitasset_opts ); + detail::check_bitasset_options_hf_bsip87( now, *op.bitasset_opts ); // HF_REMOVABLE + } const auto& chain_parameters = d.get_global_properties().parameters; FC_ASSERT( op.common_options.whitelist_authorities.size() <= chain_parameters.maximum_asset_whitelist_authorities ); @@ -128,7 +131,6 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o if( op.bitasset_opts ) { - detail::check_bitasset_options_hf_bsip77( now, *op.bitasset_opts ); const asset_object& backing = op.bitasset_opts->short_backing_asset(d); if( backing.is_market_issued() ) { @@ -317,7 +319,6 @@ void_result asset_update_evaluator::do_evaluate(const asset_update_operation& o) // Hardfork Checks: detail::check_asset_options_hf_1774(now, o.new_options); detail::check_asset_options_hf_bsip81(now, o.new_options); - detail::check_asset_options_hf_bsip87(now, o.new_options); // HF_REMOVABLE const asset_object& a = o.asset_to_update(d); auto a_copy = a; @@ -434,7 +435,7 @@ void_result asset_update_issuer_evaluator::do_apply(const asset_update_issuer_op * @param true if after hf 922/931 (if nothing triggers, this and the logic that depends on it * should be removed). */ -void check_children_of_bitasset(database& d, const asset_update_bitasset_operation& op, +void check_children_of_bitasset(const database& d, const asset_update_bitasset_operation& op, const asset_object& new_backing_asset) { // no need to do these checks if the new backing asset is CORE @@ -463,9 +464,12 @@ void check_children_of_bitasset(database& d, const asset_update_bitasset_operati void_result asset_update_bitasset_evaluator::do_evaluate(const asset_update_bitasset_operation& op) { try { - database& d = db(); + const database& d = db(); + const time_point_sec now = d.head_block_time(); - detail::check_bitasset_options_hf_bsip77( d.head_block_time(), op.new_options ); + // Hardfork Checks: + detail::check_bitasset_options_hf_bsip77( now, op.new_options ); + detail::check_bitasset_options_hf_bsip87( now, op.new_options ); // HF_REMOVABLE const asset_object& asset_obj = op.asset_to_update(d); diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index b7bbb60405..c3a03fa9f3 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -1408,14 +1408,15 @@ asset database::pay_force_settle_fees(const asset_object& collecting_asset, cons { FC_ASSERT( collecting_asset.get_id() != collat_receives.asset_id ); - const asset_object& collat_asset = get(collat_receives.asset_id); - if( !collecting_asset.options.extensions.value.force_settle_fee_percent.valid() - || *collecting_asset.options.extensions.value.force_settle_fee_percent == 0 ) - return collat_asset.amount(0); + const bitasset_options& collecting_bitasset_opts = collecting_asset.bitasset_data(*this).options; + + if( !collecting_bitasset_opts.extensions.value.force_settle_fee_percent.valid() + || *collecting_bitasset_opts.extensions.value.force_settle_fee_percent == 0 ) + return asset{ 0, collat_receives.asset_id }; auto value = detail::calculate_percent(collat_receives.amount, - *collecting_asset.options.extensions.value.force_settle_fee_percent); - asset settle_fee = collat_asset.amount(value); + *collecting_bitasset_opts.extensions.value.force_settle_fee_percent); + asset settle_fee = asset{ value, collat_receives.asset_id }; // Deposit fee in asset's dynamic data object: if( value > 0) { diff --git a/libraries/chain/proposal_evaluator.cpp b/libraries/chain/proposal_evaluator.cpp index 912a2ed2c0..d73e343759 100644 --- a/libraries/chain/proposal_evaluator.cpp +++ b/libraries/chain/proposal_evaluator.cpp @@ -32,8 +32,8 @@ namespace detail { void check_asset_options_hf_1774(const fc::time_point_sec& block_time, const asset_options& options); void check_bitasset_options_hf_bsip77(const fc::time_point_sec& block_time, const bitasset_options& options); void check_asset_options_hf_bsip81(const fc::time_point_sec& block_time, const asset_options& options); - void check_asset_options_hf_bsip87(const fc::time_point_sec& block_time, - const asset_options& options); // HF_REMOVABLE + void check_bitasset_options_hf_bsip87(const fc::time_point_sec& block_time, + const bitasset_options& options); // HF_REMOVABLE void check_asset_claim_fees_hardfork_87_74_collatfee(const fc::time_point_sec& block_time, const asset_claim_fees_operation& op); // HF_REMOVABLE } @@ -54,10 +54,11 @@ struct proposal_operation_hardfork_visitor void operator()(const graphene::chain::asset_create_operation &v) const { detail::check_asset_options_hf_1774(block_time, v.common_options); - if( v.bitasset_opts.valid() ) - detail::check_bitasset_options_hf_bsip77( block_time, *v.bitasset_opts ); detail::check_asset_options_hf_bsip81(block_time, v.common_options); - detail::check_asset_options_hf_bsip87(block_time, v.common_options); // HF_REMOVABLE + if( v.bitasset_opts.valid() ) { + detail::check_bitasset_options_hf_bsip77( block_time, *v.bitasset_opts ); + detail::check_bitasset_options_hf_bsip87( block_time, *v.bitasset_opts ); // HF_REMOVABLE + } } @@ -65,12 +66,14 @@ struct proposal_operation_hardfork_visitor detail::check_asset_options_hf_1774(block_time, v.new_options); detail::check_asset_options_hf_bsip81(block_time, v.new_options); - detail::check_asset_options_hf_bsip87(block_time, v.new_options); // HF_REMOVABLE } + void operator()(const graphene::chain::asset_update_bitasset_operation &v) const { - // HARDFORK_BSIP_77 + detail::check_bitasset_options_hf_bsip77( block_time, v.new_options ); + detail::check_bitasset_options_hf_bsip87( block_time, v.new_options ); // HF_REMOVABLE + } void operator()(const graphene::chain::asset_claim_fees_operation &v) const { diff --git a/libraries/protocol/asset_ops.cpp b/libraries/protocol/asset_ops.cpp index 24318199ab..812df9b98c 100644 --- a/libraries/protocol/asset_ops.cpp +++ b/libraries/protocol/asset_ops.cpp @@ -216,6 +216,10 @@ void bitasset_options::validate() const FC_ASSERT( *extensions.value.initial_collateral_ratio >= GRAPHENE_MIN_COLLATERAL_RATIO ); FC_ASSERT( *extensions.value.initial_collateral_ratio <= GRAPHENE_MAX_COLLATERAL_RATIO ); } + + if( extensions.value.force_settle_fee_percent.valid() ) + FC_ASSERT( *extensions.value.force_settle_fee_percent <= GRAPHENE_100_PERCENT ); + } void asset_options::validate()const @@ -252,8 +256,6 @@ void asset_options::validate()const } if( extensions.value.reward_percent.valid() ) FC_ASSERT( *extensions.value.reward_percent <= GRAPHENE_100_PERCENT ); - if( extensions.value.force_settle_fee_percent.valid() ) - FC_ASSERT( *extensions.value.force_settle_fee_percent <= GRAPHENE_100_PERCENT ); } void asset_claim_fees_operation::validate()const { diff --git a/libraries/protocol/include/graphene/protocol/asset_ops.hpp b/libraries/protocol/include/graphene/protocol/asset_ops.hpp index 19f8fc6e6a..fd4c53297c 100644 --- a/libraries/protocol/include/graphene/protocol/asset_ops.hpp +++ b/libraries/protocol/include/graphene/protocol/asset_ops.hpp @@ -34,8 +34,6 @@ namespace graphene { namespace protocol { fc::optional> whitelist_market_fee_sharing; // After BSIP81 activation, taker_fee_percent is the taker fee fc::optional taker_fee_percent; - // MERGE NOTE: BSIP-74 additions here - fc::optional force_settle_fee_percent; // BSIP-87 }; typedef extension additional_asset_options_t; @@ -108,7 +106,8 @@ namespace graphene { namespace protocol { /// After BSIP77, when creating a new debt position or updating an existing position, /// the position will be checked against this parameter. /// Unused for prediction markets, although we allow it to be set for simpler implementation - fc::optional initial_collateral_ratio; + fc::optional initial_collateral_ratio; // BSIP-77 + fc::optional force_settle_fee_percent; // BSIP-87 }; /// Time before a price feed expires @@ -564,7 +563,7 @@ FC_REFLECT( graphene::protocol::asset_options, (extensions) ) -FC_REFLECT( graphene::protocol::bitasset_options::ext, (initial_collateral_ratio) ) +FC_REFLECT( graphene::protocol::bitasset_options::ext, (initial_collateral_ratio)(force_settle_fee_percent) ) FC_REFLECT( graphene::protocol::bitasset_options, (feed_lifetime_sec) @@ -577,7 +576,7 @@ FC_REFLECT( graphene::protocol::bitasset_options, ) FC_REFLECT( graphene::protocol::additional_asset_options, - (reward_percent)(whitelist_market_fee_sharing)(taker_fee_percent)(force_settle_fee_percent) ) + (reward_percent)(whitelist_market_fee_sharing)(taker_fee_percent) ) FC_REFLECT( graphene::protocol::asset_create_operation::fee_parameters_type, (symbol3)(symbol4)(long_symbol)(price_per_kbyte) )