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
24 changes: 23 additions & 1 deletion libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,29 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
// 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(head_block_time() < HARDFORK_CORE_518_TIME)
Copy link
Member

Choose a reason for hiding this comment

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

For better performance, please move this check out of the for loop.

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

modify( d, [](asset_bitasset_data_object& o) { o.force_settled_volume = 0; });
else { // clean expired feeds
modify( d, [this](asset_bitasset_data_object& o) {
o.force_settled_volume = 0;

// Check if asset is smartcoin
const auto& settlement_price = o.feeds.begin()->second.second.settlement_price;
Copy link
Member

Choose a reason for hiding this comment

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

This is not safe. Before dereferencing begin(), please check whether feeds is empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

silly me, fixed here f60a953 thank you.

if(!settlement_price.is_null()) {
Copy link
Member

Choose a reason for hiding this comment

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

This check is incorrect. The first feed is null doesn't mean all feeds are null.

Copy link
Member Author

Choose a reason for hiding this comment

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

#832 (comment)
you think that is wrong ? makes sense to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

waiting for more comments from @pmconrad maybe.

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
for (auto itr = o.feeds.begin(); itr != o.feeds.end();) { // loop feeds
auto feed_time = itr->second.first;
if (feed_time + (o.options.feed_lifetime_sec) < head_block_time())
Copy link
Member

Choose a reason for hiding this comment

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

For better performance, please calculate head_block_time()-feed_lifetime_sec out of the for loop (and be careful about Integer overflow or underflow) and only check feed_time while looping.

Copy link
Member Author

Choose a reason for hiding this comment

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

done this one, checked for overflow only as we are dealing with all unsigned ints so underflow will not be possible. overflow could occur with a feed_lifetime_sec is too big. hard to happen in practice as when we are here we are in a smartcoin but check was added anyways.

itr = o.feeds.erase(itr); // delete expired feed
else
++itr;
}
}
}
});
}
if( d.has_settlement() )
process_bids(d);
}
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