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

Call order and bitAsset related code refactory #1306

Merged
merged 11 commits into from
Sep 10, 2018
Merged

Conversation

abitmore
Copy link
Member

@abitmore abitmore commented Sep 6, 2018

While working on #1270, I ended up refactoring quite some code. Since the change is getting large, for easier code review in the future, I'm now creating this PR.

pmconrad
pmconrad previously approved these changes Sep 9, 2018
Copy link
Contributor

@pmconrad pmconrad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks.

modify( borrower_statistics, [&]( account_statistics_object& b ){
if( collateral_freed.valid() && collateral_freed->amount > 0 && collateral_freed->asset_id == asset_id_type() )
b.total_core_in_orders -= collateral_freed->amount;
modify( get_account_stats_by_owner(order.borrower), [&collateral_freed,&pays]( account_statistics_object& b ){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only call modify if pays.asset_id == asset_id_type() (this also implies collateral_freed.asset_id == core if collateral_freed is defined)

});

const account_object& borrower = order.borrower(*this);
// adjust balance and/or account statistics
if( collateral_freed.valid() || pays.asset_id == asset_id_type() )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add condition && collateral_freed.amount != 0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the code is a bit messy here for potential better performance.

  • The OR check here is for only updating the object once when possible;
  • in most cases collateral_freed.amount is non-zero so it doesn't make much sense to add a check;
    • in addition, adjust_balance() will check if the delta is zero;
  • actually there is a chance that we don't need to execute the modify, since actually pays.asset_id and collateral_freed->asset_id are the same, that means if we don't need to update total_core_in_orders due to pays, we won't need to update it due to collateral_freed. I will improve this. (Just saw your comment above)

libraries/chain/market_evaluator.cpp Show resolved Hide resolved
and added comment in call_order_update_evaluator::do_evaluate()
@abitmore
Copy link
Member Author

abitmore commented Sep 9, 2018

@pmconrad please review again. Thanks a lot.

@abitmore abitmore merged commit 0e86ff5 into develop Sep 10, 2018
@abitmore abitmore deleted the call-order-refactory branch September 10, 2018 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants