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

BSIP 36 Candidate #832

Merged
merged 11 commits into from
May 7, 2018
42 changes: 36 additions & 6 deletions libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,12 +922,42 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
d.accounts_registered_this_interval = 0;
});

// Reset all BitAsset force settlement volumes to zero
for( const auto& d : get_index_type<asset_bitasset_data_index>().indices() )
{
modify( d, [](asset_bitasset_data_object& o) { o.force_settled_volume = 0; });
if( d.has_settlement() )
process_bids(d);
if(head_block_time() >= HARDFORK_CORE_518_TIME) {
for( const auto& d : get_index_type<asset_bitasset_data_index>().indices() ) {
modify(d, [this](asset_bitasset_data_object &o) {
o.force_settled_volume = 0; // Reset all BitAsset force settlement volumes to zero
// Check if asset is smartcoin
if (o.feeds.size() > 0) {
const auto &settlement_price = o.feeds.begin()->second.second.settlement_price;
if (!settlement_price.is_null()) {
const auto &asset = get(settlement_price.base.asset_id);
auto flags = asset.options.flags;
if ((flags & witness_fed_asset) || (flags & committee_fed_asset)) { // if smartcoin
// check overflow
if (std::numeric_limits<uint32_t>::max() - o.options.feed_lifetime_sec >
head_block_time().sec_since_epoch()) {
fc::time_point_sec calculate = head_block_time() - o.options.feed_lifetime_sec;
for (auto itr = o.feeds.rbegin(); itr != o.feeds.rend();) { // loop feeds
auto feed_time = itr->second.first;
std::advance(itr, 1);
if (feed_time < calculate)
o.feeds.erase(itr.base()); // delete expired feed
}
}
}
}
}
});
if (d.has_settlement())
process_bids(d);
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this is a bit ugly (duplicate code). But I guess it's better to live with it at this moment.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather avoid the duplicate code. Why not pull the HF check into the lambda?

Copy link
Member

Choose a reason for hiding this comment

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

@pmconrad it's a side-effect of one of my earlier requests, since hard fork time check is independent, for slightly better performance, moved it to out of for.

}
}
else {
for( const auto& d : get_index_type<asset_bitasset_data_index>().indices() ) {
modify(d, [](asset_bitasset_data_object &o) { o.force_settled_volume = 0; });
Copy link
Member

Choose a reason for hiding this comment

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

Better leave the "Reset all BitAsset force settlement volumes to zero" comment here.

if (d.has_settlement())
process_bids(d);
}
}

// process_budget needs to run at the bottom because
Expand Down
4 changes: 4 additions & 0 deletions libraries/chain/hardfork.d/CORE_518.hf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// bitshares-core issue #518 Clean up bitasset_data during maintenance
#ifndef HARDFORK_CORE_518_TIME
#define HARDFORK_CORE_518_TIME (fc::time_point_sec( 1600000000 ))
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a newline.

Loading