Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settlement code refactory #2748

Merged
merged 5 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions libraries/chain/asset_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ void_result asset_update_bitasset_evaluator::do_evaluate(const asset_update_bita
const asset_bitasset_data_object& current_bitasset_data = asset_obj.bitasset_data(d);

if( !HARDFORK_CORE_2282_PASSED( next_maint_time ) )
FC_ASSERT( !current_bitasset_data.has_settlement(),
FC_ASSERT( !current_bitasset_data.is_globally_settled(),
"Cannot update a bitasset after a global settlement has executed" );

if( current_bitasset_data.is_prediction_market )
Expand Down Expand Up @@ -784,14 +784,14 @@ void_result asset_update_bitasset_evaluator::do_evaluate(const asset_update_bita
if( old_bsrm != new_bsrm )
{
FC_ASSERT( asset_obj.can_owner_update_bsrm(), "No permission to update BSRM" );
FC_ASSERT( !current_bitasset_data.has_settlement(),
FC_ASSERT( !current_bitasset_data.is_globally_settled(),
"Unable to update BSRM when the asset has been globally settled" );

// Note: it is probably OK to allow BSRM update, be conservative here so far
using bsrm_type = bitasset_options::black_swan_response_type;
if( bsrm_type::individual_settlement_to_fund == old_bsrm )
FC_ASSERT( !current_bitasset_data.has_individual_settlement(),
"Unable to update BSRM when the individual settlement pool is not empty" );
FC_ASSERT( !current_bitasset_data.is_individually_settled_to_fund(),
"Unable to update BSRM when the individual settlement pool (for force-settlements) is not empty" );
else if( bsrm_type::individual_settlement_to_order == old_bsrm )
FC_ASSERT( !d.find_settled_debt_order( op.asset_to_update ),
"Unable to update BSRM when there exists an individual settlement order" );
Expand All @@ -808,7 +808,7 @@ void_result asset_update_bitasset_evaluator::do_evaluate(const asset_update_bita
// Are we changing the backing asset?
if( op.new_options.short_backing_asset != current_bitasset_data.options.short_backing_asset )
{
FC_ASSERT( !current_bitasset_data.has_settlement(),
FC_ASSERT( !current_bitasset_data.is_globally_settled(),
"Cannot change backing asset after a global settlement has executed" );

const asset_dynamic_data_object& dyn = asset_obj.dynamic_asset_data_id(d);
Expand Down Expand Up @@ -1119,7 +1119,7 @@ void_result asset_global_settle_evaluator::do_evaluate(const asset_global_settle

const asset_bitasset_data_object& _bitasset_data = asset_to_settle->bitasset_data(d);
// if there is a settlement for this asset, then no further global settle may be taken
FC_ASSERT( !_bitasset_data.has_settlement(),
FC_ASSERT( !_bitasset_data.is_globally_settled(),
"This asset has been globally settled, cannot globally settle again" );

// Note: after core-2467 hard fork, there can be no debt position due to individual settlements, so we check here
Expand Down Expand Up @@ -1150,14 +1150,14 @@ void_result asset_settle_evaluator::do_evaluate(const asset_settle_evaluator::op
"Can only force settle a predition market or a market issued asset" );

const auto& bitasset = asset_to_settle->bitasset_data(d);
FC_ASSERT( asset_to_settle->can_force_settle() || bitasset.has_settlement()
|| bitasset.has_individual_settlement(),
FC_ASSERT( asset_to_settle->can_force_settle() || bitasset.is_globally_settled()
|| bitasset.is_individually_settled_to_fund(),
"Either the asset need to have the force_settle flag enabled, or it need to be globally settled, "
"or the individual settlement pool is not empty" );
"or the individual settlement pool (for force-settlements) is not empty" );

if( bitasset.is_prediction_market )
{
FC_ASSERT( bitasset.has_settlement(),
FC_ASSERT( bitasset.is_globally_settled(),
"Global settlement must occur before force settling a prediction market" );
}
else if( bitasset.current_feed.settlement_price.is_null() )
Expand All @@ -1169,11 +1169,11 @@ void_result asset_settle_evaluator::do_evaluate(const asset_settle_evaluator::op
"Before the core-216 hard fork, unable to force settle when there is no sufficient "
" price feeds, no matter if the asset has been globally settled" );
}
if( !bitasset.has_settlement() && !bitasset.has_individual_settlement() )
if( !bitasset.is_globally_settled() && !bitasset.is_individually_settled_to_fund() )
{
FC_THROW_EXCEPTION( insufficient_feeds,
"Cannot force settle with no price feed if the asset is not globally settled and the "
"individual settlement pool is not empty" );
"individual settlement pool (for force-settlements) is not empty" );
}
}

Expand Down Expand Up @@ -1363,18 +1363,18 @@ operation_result asset_settle_evaluator::do_apply(const asset_settle_evaluator::
const auto& bitasset = *bitasset_ptr;

// Process global settlement fund
if( bitasset.has_settlement() )
if( bitasset.is_globally_settled() )
return pay_settle_from_gs_fund( d, op, fee_paying_account, *asset_to_settle, bitasset );

// Process individual settlement pool
extendable_operation_result result;
asset to_settle = op.amount;
if( bitasset.has_individual_settlement() )
if( bitasset.is_individually_settled_to_fund() )
{
result = pay_settle_from_individual_pool( d, op, fee_paying_account, *asset_to_settle, bitasset );

// If the amount to settle is too small, or force settlement is disabled, we return
if( bitasset.has_individual_settlement() || !asset_to_settle->can_force_settle() )
if( bitasset.is_individually_settled_to_fund() || !asset_to_settle->can_force_settle() )
return result;

to_settle -= result.value.paid->front();
Expand Down Expand Up @@ -1426,7 +1426,7 @@ void_result asset_publish_feeds_evaluator::do_evaluate(const asset_publish_feed_
const asset_bitasset_data_object& bitasset = base.bitasset_data(d);
if( bitasset.is_prediction_market || now <= HARDFORK_CORE_216_TIME )
{
FC_ASSERT( !bitasset.has_settlement(), "No further feeds may be published after a settlement event" );
FC_ASSERT( !bitasset.is_globally_settled(), "No further feeds may be published after a settlement event" );
}

// the settlement price must be quoted in terms of the backing asset
Expand Down Expand Up @@ -1500,7 +1500,7 @@ void_result asset_publish_feeds_evaluator::do_apply(const asset_publish_feed_ope
return void_result();

// Feed changed, check whether need to revive the asset and proceed if need
if( bad.has_settlement() // has globally settled, implies head_block_time > HARDFORK_CORE_216_TIME
if( bad.is_globally_settled() // has globally settled, implies head_block_time > HARDFORK_CORE_216_TIME
&& !bad.current_feed.settlement_price.is_null() ) // has a valid feed
{
bool should_revive = false;
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ void database::process_bitassets()
for( const auto& d : get_index_type<asset_bitasset_data_index>().indices() )
{
modify( d, update_bitasset );
if( d.has_settlement() )
if( d.is_globally_settled() )
process_bids(d);
}
}
Expand Down
Loading