Skip to content

Commit

Permalink
Merge pull request #2608 from bitshares/testnet_release
Browse files Browse the repository at this point in the history
Merge release branch into testnet branch
  • Loading branch information
abitmore authored Jul 3, 2022
2 parents 7ae4a93 + fad02bf commit b9bfb3f
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 50 deletions.
22 changes: 21 additions & 1 deletion libraries/chain/asset_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,9 @@ static bool update_bitasset_object_options(
const fc::time_point_sec next_maint_time = db.get_dynamic_global_properties().next_maintenance_time;
bool after_hf_core_868_890 = ( next_maint_time > HARDFORK_CORE_868_890_TIME );

const auto& head_time = db.head_block_time();
bool after_core_hardfork_2582 = HARDFORK_CORE_2582_PASSED( head_time ); // Price feed issues

// If the minimum number of feeds to calculate a median has changed, we need to recalculate the median
bool should_update_feeds = false;
if( op.new_options.minimum_feeds != bdo.options.minimum_feeds )
Expand Down Expand Up @@ -1001,12 +1004,19 @@ static bool update_bitasset_object_options(
if( should_update_feeds || update_feeds_due_to_bsrm_change )
{
const auto old_feed = bdo.current_feed;
const auto old_median_feed = bdo.median_feed;
// skip recalculating median feed if it is not needed
db.update_bitasset_current_feed( bdo, !should_update_feeds );
// Note: we don't try to revive the bitasset here if it was GSed // TODO probably we should do it

// TODO potential optimization: check only when should_update_feeds == true

// We need to call check_call_orders if the settlement price changes after hardfork core-868-890
feed_actually_changed = ( after_hf_core_868_890 && !old_feed.margin_call_params_equal( bdo.current_feed ) );

if( !feed_actually_changed && after_core_hardfork_2582
&& !old_median_feed.margin_call_params_equal( bdo.median_feed ) )
feed_actually_changed = true;
}

// Conditions under which a call to check_call_orders is needed in response to the updates applied here:
Expand Down Expand Up @@ -1336,6 +1346,11 @@ operation_result asset_settle_evaluator::do_apply(const asset_settle_evaluator::
const auto& head_time = d.head_block_time();
const auto& maint_time = d.get_dynamic_global_properties().next_maintenance_time;
d.adjust_balance( op.account, -to_settle );

bool after_core_hardfork_2582 = HARDFORK_CORE_2582_PASSED( head_time ); // Price feed issues
if( after_core_hardfork_2582 && 0 == to_settle.amount )
return result;

const auto& settle = d.create<force_settlement_object>(
[&op,&to_settle,&head_time,&bitasset](force_settlement_object& s) {
s.owner = op.account;
Expand Down Expand Up @@ -1427,14 +1442,19 @@ void_result asset_publish_feeds_evaluator::do_apply(const asset_publish_feed_ope
const asset_bitasset_data_object& bad = *bitasset_ptr;

auto old_feed = bad.current_feed;
auto old_median_feed = bad.median_feed;
// Store medians for this asset
d.modify( bad , [&o,&head_time](asset_bitasset_data_object& a) {
a.feeds[o.publisher] = make_pair( head_time, price_feed_with_icr( o.feed,
o.extensions.value.initial_collateral_ratio ) );
});
d.update_bitasset_current_feed( bad );

if( old_feed.margin_call_params_equal(bad.current_feed) )
bool after_core_hardfork_2582 = HARDFORK_CORE_2582_PASSED( head_time ); // Price feed issues

if( !after_core_hardfork_2582 && old_feed.margin_call_params_equal(bad.current_feed) )
return void_result();
if( after_core_hardfork_2582 && old_median_feed.margin_call_params_equal(bad.median_feed) )
return void_result();

// Feed changed, check whether need to revive the asset and proceed if need
Expand Down
26 changes: 22 additions & 4 deletions libraries/chain/db_market.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,9 @@ void database::apply_force_settlement( const force_settlement_object& new_settle
FC_ASSERT( !bitasset.has_settlement(), "Internal error: asset is globally settled already" );
FC_ASSERT( !bitasset.current_feed.settlement_price.is_null(), "Internal error: no sufficient price feeds" );

auto head_time = head_block_time();
bool after_core_hardfork_2582 = HARDFORK_CORE_2582_PASSED( head_time ); // Price feed issues

auto new_obj_id = new_settlement.id;

// Price at which margin calls sit on the books.
Expand Down Expand Up @@ -940,8 +943,10 @@ void database::apply_force_settlement( const force_settlement_object& new_settle
|| call_itr->collateralization() > bitasset.current_maintenance_collateralization )
break;
// TCR applies here
auto settle_price = after_core_hardfork_2582 ? bitasset.median_feed.settlement_price
: bitasset.current_feed.settlement_price;
asset max_debt_to_cover( call_itr->get_max_debt_to_cover( call_pays_price,
bitasset.current_feed.settlement_price,
settle_price,
bitasset.current_feed.maintenance_collateral_ratio,
bitasset.current_maintenance_collateralization ),
new_settlement.balance.asset_id );
Expand Down Expand Up @@ -1155,7 +1160,11 @@ database::match_result_type database::match( const limit_order_object& bid, cons
bool before_core_hardfork_1270 = ( maint_time <= HARDFORK_CORE_1270_TIME ); // call price caching issue
bool after_core_hardfork_2481 = HARDFORK_CORE_2481_PASSED( maint_time ); // Match settle orders with margin calls

const auto& feed_price = bitasset.current_feed.settlement_price;
auto head_time = head_block_time();
bool after_core_hardfork_2582 = HARDFORK_CORE_2582_PASSED( head_time ); // Price feed issues

const auto& feed_price = after_core_hardfork_2582 ? bitasset.median_feed.settlement_price
: bitasset.current_feed.settlement_price;
const auto& maintenance_collateral_ratio = bitasset.current_feed.maintenance_collateral_ratio;
optional<price> maintenance_collateralization;
if( !before_core_hardfork_1270 )
Expand Down Expand Up @@ -1828,6 +1837,8 @@ bool database::check_call_orders( const asset_object& mia, bool enable_black_swa
bool before_core_hardfork_606 = ( maint_time <= HARDFORK_CORE_606_TIME ); // feed always trigger call
bool before_core_hardfork_834 = ( maint_time <= HARDFORK_CORE_834_TIME ); // target collateral ratio option

bool after_core_hardfork_2582 = HARDFORK_CORE_2582_PASSED( head_time ); // Price feed issues

auto has_call_order = [ before_core_hardfork_1270,
&call_collateral_itr,&call_collateral_end,
&call_price_itr,&call_price_end ]()
Expand Down Expand Up @@ -1906,8 +1917,10 @@ bool database::check_call_orders( const asset_object& mia, bool enable_black_swa

if( !before_core_hardfork_1270 )
{
auto settle_price = after_core_hardfork_2582 ? bitasset.median_feed.settlement_price
: bitasset.current_feed.settlement_price;
usd_to_buy.amount = call_order.get_max_debt_to_cover( call_pays_price,
bitasset.current_feed.settlement_price,
settle_price,
bitasset.current_feed.maintenance_collateral_ratio,
bitasset.current_maintenance_collateralization );
}
Expand Down Expand Up @@ -2084,6 +2097,9 @@ bool database::match_force_settlements( const asset_bitasset_data_object& bitass
FC_ASSERT( !bitasset.has_settlement(), "Internal error: asset is globally settled already" );
FC_ASSERT( !bitasset.current_feed.settlement_price.is_null(), "Internal error: no sufficient price feeds" );

auto head_time = head_block_time();
bool after_core_hardfork_2582 = HARDFORK_CORE_2582_PASSED( head_time ); // Price feed issues

const auto& settlement_index = get_index_type<force_settlement_index>().indices().get<by_expiration>();
auto settle_itr = settlement_index.lower_bound( bitasset.asset_id );
auto settle_end = settlement_index.upper_bound( bitasset.asset_id );
Expand Down Expand Up @@ -2114,8 +2130,10 @@ bool database::match_force_settlements( const asset_bitasset_data_object& bitass
return false;

// TCR applies here
auto settle_price = after_core_hardfork_2582 ? bitasset.median_feed.settlement_price
: bitasset.current_feed.settlement_price;
asset max_debt_to_cover( call_order.get_max_debt_to_cover( call_pays_price,
bitasset.current_feed.settlement_price,
settle_price,
bitasset.current_feed.maintenance_collateral_ratio,
bitasset.current_maintenance_collateralization ),
bitasset.asset_id );
Expand Down
11 changes: 9 additions & 2 deletions libraries/chain/db_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ void database::update_expired_feeds()
{
const auto head_time = head_block_time();
bool after_hardfork_615 = ( head_time >= HARDFORK_615_TIME );
bool after_core_hardfork_2582 = HARDFORK_CORE_2582_PASSED( head_time ); // Price feed issues

const auto& idx = get_index_type<asset_bitasset_data_index>().indices().get<by_feed_expiration>();
auto itr = idx.begin();
Expand All @@ -489,13 +490,19 @@ void database::update_expired_feeds()
if( !( after_hardfork_615 || b.feed_is_expired_before_hf_615( head_time ) ) )
continue;

auto old_median_feed = b.current_feed;
auto old_current_feed = b.current_feed;
auto old_median_feed = b.median_feed;
const asset_object& asset_obj = b.asset_id( *this );
update_bitasset_current_feed( b );
// Note: we don't try to revive the bitasset here if it was GSed // TODO probably we should do it

if( !b.current_feed.settlement_price.is_null()
&& !b.current_feed.margin_call_params_equal( old_median_feed ) )
&& !b.current_feed.margin_call_params_equal( old_current_feed ) )
{
check_call_orders( asset_obj, true, false, &b, true );
}
else if( after_core_hardfork_2582 && !b.median_feed.settlement_price.is_null()
&& !b.median_feed.margin_call_params_equal( old_median_feed ) )
{
check_call_orders( asset_obj, true, false, &b, true );
}
Expand Down
5 changes: 5 additions & 0 deletions libraries/chain/hardfork.d/CORE_2582.hf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// bitshares-core issue #2582 price feed issues
#ifndef HARDFORK_CORE_2582_TIME
#define HARDFORK_CORE_2582_TIME (fc::time_point_sec( 1657636498 )) // testnet, Tuesday, July 12, 2022 14:34:58 UTC
#define HARDFORK_CORE_2582_PASSED(head_block_time) (head_block_time >= HARDFORK_CORE_2582_TIME)
#endif
Loading

0 comments on commit b9bfb3f

Please sign in to comment.