[bitshares/bitshares-core] Fix for Issue 868 – Reset feeds when changing the backing asset from one asset to another (#882)

pmconrad requested changes on this pull request.

>
– if( should_update_feeds )
– b.update_median_feeds(db().head_block_time());
– });
+ // now do the actual modifications to the database object
+ db().modify(*bitasset_to_update, [&](asset_bitasset_data_object& bdo) {

Please don’t use the capture-all, it’s bad practice. (I know it’s from the original code, but we should try to get rid of these while we’re at it.)

> @@ -800,6 +800,82 @@ void update_and_match_call_orders( database& db )
wlog( “Done updating all call orders for hardfork core-343 at block ${n}”, (“n”,db.head_block_num()) );
}

+/******
+ * @brief cleanup feeds with wrong assets
+ *
+ * Prior to hardfork 868, switching a bitasset’s shorting asset would not reset its
+ * feeds. This method will run at the hardfork time, and erase (or nullify) feeds
+ * that have incorrect backing assets.
+ *

Please add a comment: TODO – remove if not triggered at hf time

> + const auto& current_asset = *asset_itr;
+ // Incorrect witness & committee feeds can simply be removed.
+ // For non-witness-fed and non-committee-fed assets, set incorrect
+ // feeds to price(), since we can’t simply remove them. For more information:
+ // https://github.com/bitshares/bitshares-core/pull/832#issuecomment-384112633
+ bool is_witness_or_committee_fed = false;
+ if ( current_asset.options.flags & (witness_fed_asset | committee_fed_asset) )
+ is_witness_or_committee_fed = true;
+
+ // for each feed
+ const asset_bitasset_data_object& bitasset_data = current_asset.bitasset_data(db);
+ // NOTE: If HF343 and HF868 roll out at the same time
+ // you can remove this double, and the check_call_orders()
+ // below that relies on it. HF343 will take care of the issue
+ // and there is no need for the extra check_call_orders() call
+ auto old_price = bitasset_data.settlement_price;

This should be bitasset_data.current_feed.settlement_price.

This post was last modified on May 7, 2018, 10:58 pm