Skip to content

Commit

Permalink
Revert to by_price index when globally settling
Browse files Browse the repository at this point in the history
Because all positions will be closed anyway, using which index
doesn't matter in terms of amounts, however, using another index may
change the ID of historical virtual operations, specifically,
`fill_order_operation` -- we usually try to avoid this.
  • Loading branch information
abitmore committed Feb 1, 2019
1 parent 54c4c02 commit b494609
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libraries/chain/db_market.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ void database::globally_settle_asset( const asset_object& mia, const price& sett
const asset_dynamic_data_object& mia_dyn = mia.dynamic_asset_data_id(*this);
auto original_mia_supply = mia_dyn.current_supply;

const auto& call_index = get_index_type<call_order_index>().indices().get<by_collateral>();
const auto& call_price_index = get_index_type<call_order_index>().indices().get<by_price>();

auto maint_time = get_dynamic_global_properties().next_maintenance_time;
bool before_core_hardfork_342 = ( maint_time <= HARDFORK_CORE_342_TIME ); // better rounding

// cancel all call orders and accumulate it into collateral_gathered
auto call_itr = call_index.lower_bound( price::min( bitasset.options.short_backing_asset, mia.id ) );
auto call_end = call_index.upper_bound( price::max( bitasset.options.short_backing_asset, mia.id ) );
auto call_itr = call_price_index.lower_bound( price::min( bitasset.options.short_backing_asset, mia.id ) );
auto call_end = call_price_index.upper_bound( price::max( bitasset.options.short_backing_asset, mia.id ) );
asset pays;
while( call_itr != call_end )
{
Expand All @@ -94,7 +94,7 @@ void database::globally_settle_asset( const asset_object& mia, const price& sett
}

modify( bitasset, [&mia,original_mia_supply,&collateral_gathered]( asset_bitasset_data_object& obj ){
obj.settlement_price = mia.amount(original_mia_supply) / collateral_gathered; //settlement_price;
obj.settlement_price = mia.amount(original_mia_supply) / collateral_gathered;
obj.settlement_fund = collateral_gathered.amount;
});

Expand Down

0 comments on commit b494609

Please # to comment.