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

Bsip36: clear expired feeds on maintenance interval #889

Merged
merged 17 commits into from
May 7, 2018
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
6 changes: 4 additions & 2 deletions libraries/chain/asset_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,16 @@ object_id_type asset_create_evaluator::do_apply( const asset_create_operation& o
}

asset_bitasset_data_id_type bit_asset_id;

auto next_asset_id = db().get_index_type<asset_index>().get_next_id();

if( op.bitasset_opts.valid() )
bit_asset_id = db().create<asset_bitasset_data_object>( [&]( asset_bitasset_data_object& a ) {
a.options = *op.bitasset_opts;
a.is_prediction_market = op.is_prediction_market;
a.asset_id = next_asset_id;
}).id;

auto next_asset_id = db().get_index_type<asset_index>().get_next_id();

const asset_object& new_asset =
db().create<asset_object>( [&]( asset_object& a ) {
a.issuer = op.issuer;
Expand Down
46 changes: 39 additions & 7 deletions libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,44 @@ 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()) );
}

void database::process_bitassets()
{
time_point_sec head_time = head_block_time();
uint32_t head_epoch_seconds = head_time.sec_since_epoch();
bool after_hf_core_518 = ( head_time >= HARDFORK_CORE_518_TIME ); // clear expired feeds

const auto update_bitasset = [this,head_time,head_epoch_seconds,after_hf_core_518]( asset_bitasset_data_object &o )
{
o.force_settled_volume = 0; // Reset all BitAsset force settlement volumes to zero

// clear expired feeds
if( after_hf_core_518 )
{
const auto &asset = get( o.asset_id );
auto flags = asset.options.flags;
if ( ( flags & ( witness_fed_asset | committee_fed_asset ) ) &&
o.options.feed_lifetime_sec < head_epoch_seconds ) // if smartcoin && check overflow
{
fc::time_point_sec calculated = head_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 < calculated )
o.feeds.erase( itr.base() ); // delete expired feed
}
}
}
};

for( const auto& d : get_index_type<asset_bitasset_data_index>().indices() )
{
modify( d, update_bitasset );
if( d.has_settlement() )
process_bids(d);
}
}

void database::perform_chain_maintenance(const signed_block& next_block, const global_property_object& global_props)
{
const auto& gpo = get_global_properties();
Expand Down Expand Up @@ -965,13 +1003,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
if( to_update_and_match_call_orders )
update_and_match_call_orders(*this);

// 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);
}
process_bitassets();

// process_budget needs to run at the bottom because
// it needs to know the next_maintenance_time
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
4 changes: 4 additions & 0 deletions libraries/chain/include/graphene/chain/asset_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ namespace graphene { namespace chain {
static const uint8_t space_id = implementation_ids;
static const uint8_t type_id = impl_asset_bitasset_data_type;

/// The asset this object belong to
asset_id_type asset_id;
Copy link
Contributor

Choose a reason for hiding this comment

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

Must bump GRAPHENE_CURRENT_DB_VERSION when modifying DB object structures.

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.


/// The tunable options for BitAssets are stored in this field.
bitasset_options options;

Expand Down Expand Up @@ -255,6 +258,7 @@ FC_REFLECT_DERIVED( graphene::chain::asset_dynamic_data_object, (graphene::db::o
(current_supply)(confidential_supply)(accumulated_fees)(fee_pool) )

FC_REFLECT_DERIVED( graphene::chain::asset_bitasset_data_object, (graphene::db::object),
(asset_id)
(feeds)
(current_feed)
(current_feed_publication_time)
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/graphene/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
#define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4
#define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3

#define GRAPHENE_CURRENT_DB_VERSION "BTS2.13"
#define GRAPHENE_CURRENT_DB_VERSION "BTS2.14"

#define GRAPHENE_IRREVERSIBLE_THRESHOLD (70 * GRAPHENE_1_PERCENT)

Expand Down
1 change: 1 addition & 0 deletions libraries/chain/include/graphene/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ namespace graphene { namespace chain {
void update_active_committee_members();
void update_worker_votes();
void process_bids( const asset_bitasset_data_object& bad );
void process_bitassets();

template<class... Types>
void perform_account_maintenance(std::tuple<Types...> helpers);
Expand Down
Loading