Skip to content

Commit

Permalink
Update and match call orders at hf #1270
Browse files Browse the repository at this point in the history
  • Loading branch information
abitmore committed Sep 13, 2018
1 parent 077f4e0 commit 68c702b
Showing 1 changed file with 50 additions and 10 deletions.
60 changes: 50 additions & 10 deletions libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,9 @@ void database::process_bids( const asset_bitasset_data_object& bad )
_cancel_bids_and_revive_mpa( to_revive, bad );
}

void update_and_match_call_orders( database& db )
/// Reset call_price of all call orders according to their remaining collateral and debt.
/// Do not update orders of prediction markets because we're sure they're up to date.
void update_call_orders_hf_343( database& db )
{
// Update call_price
wlog( "Updating all call orders for hardfork core-343 at block ${n}", ("n",db.head_block_num()) );
Expand All @@ -888,7 +890,30 @@ void update_and_match_call_orders( database& db )
abd->current_feed.maintenance_collateral_ratio );
});
}
wlog( "Done updating all call orders for hardfork core-343 at block ${n}", ("n",db.head_block_num()) );
}

/// Reset call_price of all call orders to (1,1) since it won't be used in the future.
/// Update PMs as well.
void update_call_orders_hf_1270( database& db )
{
// Update call_price
wlog( "Updating all call orders for hardfork core-1270 at block ${n}", ("n",db.head_block_num()) );
for( const auto& call_obj : db.get_index_type<call_order_index>().indices().get<by_id>() )
{
db.modify( call_obj, []( call_order_object& call ) {
call.call_price.base.amount = 1;
call.call_price.quote.amount = 1;
});
}
wlog( "Done updating all call orders for hardfork core-1270 at block ${n}", ("n",db.head_block_num()) );
}

/// Match call orders for all bitAssets, including PMs.
void match_call_orders( database& db )
{
// Match call orders
wlog( "Matching call orders at block ${n}", ("n",db.head_block_num()) );
const auto& asset_idx = db.get_index_type<asset_index>().indices().get<by_type>();
auto itr = asset_idx.lower_bound( true /** market issued */ );
while( itr != asset_idx.end() )
Expand All @@ -898,7 +923,7 @@ void update_and_match_call_orders( database& db )
// be here, next_maintenance_time should have been updated already
db.check_call_orders( a, true, false ); // allow black swan, and call orders are taker
}
wlog( "Done updating all call orders for hardfork core-343 at block ${n}", ("n",db.head_block_num()) );
wlog( "Done matching call orders at block ${n}", ("n",db.head_block_num()) );
}

void database::process_bitassets()
Expand Down Expand Up @@ -1232,28 +1257,43 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
if( (dgpo.next_maintenance_time < HARDFORK_613_TIME) && (next_maintenance_time >= HARDFORK_613_TIME) )
deprecate_annual_members(*this);

// To reset call_price of all call orders, then match by new rule
bool to_update_and_match_call_orders = false;
// To reset call_price of all call orders, then match by new rule, for hard fork core-343
bool to_update_and_match_call_orders_for_hf_343 = false;
if( (dgpo.next_maintenance_time <= HARDFORK_CORE_343_TIME) && (next_maintenance_time > HARDFORK_CORE_343_TIME) )
to_update_and_match_call_orders = true;
to_update_and_match_call_orders_for_hf_343 = true;

// Process inconsistent price feeds
if( (dgpo.next_maintenance_time <= HARDFORK_CORE_868_890_TIME) && (next_maintenance_time > HARDFORK_CORE_868_890_TIME) )
process_hf_868_890( *this, to_update_and_match_call_orders );
process_hf_868_890( *this, to_update_and_match_call_orders_for_hf_343 );

// Explicitly call check_call_orders of all markets
if( (dgpo.next_maintenance_time <= HARDFORK_CORE_935_TIME) && (next_maintenance_time > HARDFORK_CORE_935_TIME)
&& !to_update_and_match_call_orders )
&& !to_update_and_match_call_orders_for_hf_343 )
process_hf_935( *this );

// To reset call_price of all call orders, then match by new rule, for hard fork core-1270
bool to_update_and_match_call_orders_for_hf_1270 = false;
if( (dgpo.next_maintenance_time <= HARDFORK_CORE_1270_TIME) && (next_maintenance_time > HARDFORK_CORE_1270_TIME) )
to_update_and_match_call_orders_for_hf_1270 = true;

modify(dgpo, [next_maintenance_time](dynamic_global_property_object& d) {
d.next_maintenance_time = next_maintenance_time;
d.accounts_registered_this_interval = 0;
});

// We need to do it after updated next_maintenance_time, to apply new rules here
if( to_update_and_match_call_orders )
update_and_match_call_orders(*this);
// We need to do it after updated next_maintenance_time, to apply new rules here, for hard fork core-343
if( to_update_and_match_call_orders_for_hf_343 )
{
update_call_orders_hf_343(*this);
match_call_orders(*this);
}

// We need to do it after updated next_maintenance_time, to apply new rules here, for hard fork core-1270.
if( to_update_and_match_call_orders_for_hf_1270 )
{
update_call_orders_hf_1270(*this);
match_call_orders(*this);
}

process_bitassets();

Expand Down

0 comments on commit 68c702b

Please sign in to comment.