Skip to content

Commit

Permalink
Slightly optimize database::check_for_blackswan()
Browse files Browse the repository at this point in the history
  • Loading branch information
abitmore committed Sep 29, 2021
1 parent d3da53f commit 77665bf
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions libraries/chain/db_market.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ bool database::check_for_blackswan( const asset_object& mia, bool enable_black_s
auto limit_itr = limit_price_index.lower_bound( highest_possible_bid );
auto limit_end = limit_price_index.upper_bound( lowest_possible_bid );

price call_pays_price;
if( limit_itr != limit_end )
{
FC_ASSERT( highest.base.asset_id == limit_itr->sell_price.base.asset_id );
call_pays_price = limit_itr->sell_price;
if( after_core_hardfork_2481 )
{
// due to margin call fee, we check with MCPP (margin call pays price) here
call_pays_price = call_pays_price * bitasset.get_margin_call_pays_ratio();
}
}

using bsrm_type = bitasset_options::black_swan_response_type;
const auto bsrm = bitasset.get_black_swan_response_method();

Expand All @@ -122,13 +134,6 @@ bool database::check_for_blackswan( const asset_object& mia, bool enable_black_s

if( limit_itr != limit_end )
{
FC_ASSERT( highest.base.asset_id == limit_itr->sell_price.base.asset_id );
auto call_pays_price = limit_itr->sell_price;
if( after_core_hardfork_2481 )
{
// due to margin call fee, we check with MCPP (margin call pays price) here
call_pays_price = call_pays_price * bitasset.get_margin_call_pays_ratio();
}
if( bsrm_type::individual_settlement_to_fund != bsrm )
highest = std::max( call_pays_price, highest );
// for individual_settlement_to_fund, if call_pays_price < current_feed.max_short_squeeze_price(),
Expand Down

0 comments on commit 77665bf

Please sign in to comment.