-
Notifications
You must be signed in to change notification settings - Fork 649
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
Improve account maintenance performance #803 #1085
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,12 +72,45 @@ vector<std::reference_wrapper<const typename Index::object_type>> database::sort | |
return refs; | ||
} | ||
|
||
template<class... Types> | ||
void database::perform_account_maintenance(std::tuple<Types...> helpers) | ||
template<class Type> | ||
void database::perform_account_maintenance(Type tally_helper) | ||
{ | ||
const auto& idx = get_index_type<account_index>().indices().get<by_name>(); | ||
for( const account_object& a : idx ) | ||
detail::for_each(helpers, a, detail::gen_seq<sizeof...(Types)>()); | ||
const auto& bal_idx = get_index_type< account_balance_index >().indices().get< by_maintenance_flag >(); | ||
if( bal_idx.begin() != bal_idx.end() ) | ||
{ | ||
auto bal_itr = bal_idx.rbegin(); | ||
while( bal_itr->maintenance_flag ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must check bal_itr != bal_idx.rend(), then you can remove enclosing if. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean change it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, now I see - if bal_idx is not empty() then bal_idx.rbegin() will always exist and the while loop ends when all entries with maintenance_flag have been handled. Ok. |
||
{ | ||
const account_balance_object& bal_obj = *bal_itr; | ||
|
||
modify( get_account_stats_by_owner( bal_obj.owner ), [&bal_obj](account_statistics_object& aso) { | ||
aso.core_in_balance = bal_obj.balance; | ||
}); | ||
|
||
modify( bal_obj, []( account_balance_object& abo ) { | ||
abo.maintenance_flag = false; | ||
}); | ||
|
||
bal_itr = bal_idx.rbegin(); | ||
} | ||
} | ||
|
||
const auto& stats_idx = get_index_type< account_stats_index >().indices().get< by_maintenance_seq >(); | ||
auto stats_itr = stats_idx.lower_bound( true ); | ||
|
||
while( stats_itr != stats_idx.end() ) | ||
{ | ||
const account_statistics_object& acc_stat = *stats_itr; | ||
const account_object& acc_obj = acc_stat.owner( *this ); | ||
++stats_itr; | ||
|
||
if( acc_stat.has_some_core_voting() ) | ||
tally_helper( acc_obj, acc_stat ); | ||
|
||
if( acc_stat.has_pending_fees() ) | ||
acc_stat.process_fees( acc_obj, *this ); | ||
} | ||
|
||
} | ||
|
||
/// @brief A visitor for @ref worker_type which calls pay_worker on the worker within | ||
|
@@ -1014,7 +1047,8 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g | |
d._total_voting_stake = 0; | ||
} | ||
|
||
void operator()(const account_object& stake_account) { | ||
void operator()( const account_object& stake_account, const account_statistics_object& stats ) | ||
{ | ||
if( props.parameters.count_non_member_votes || stake_account.is_member(d.head_block_time()) ) | ||
{ | ||
// There may be a difference between the account whose stake is voting and the one specifying opinions. | ||
|
@@ -1025,10 +1059,9 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g | |
GRAPHENE_PROXY_TO_SELF_ACCOUNT)? stake_account | ||
: d.get(stake_account.options.voting_account); | ||
|
||
const auto& stats = stake_account.statistics(d); | ||
uint64_t voting_stake = stats.total_core_in_orders.value | ||
+ (stake_account.cashback_vb.valid() ? (*stake_account.cashback_vb)(d).balance.amount.value: 0) | ||
+ d.get_balance(stake_account.get_id(), asset_id_type()).amount.value; | ||
+ stats.core_in_balance.value; | ||
|
||
for( vote_id_type id : opinion_account.options.votes ) | ||
{ | ||
|
@@ -1065,22 +1098,8 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g | |
} | ||
} | ||
} tally_helper(*this, gpo); | ||
struct process_fees_helper { | ||
database& d; | ||
const global_property_object& props; | ||
|
||
process_fees_helper(database& d, const global_property_object& gpo) | ||
: d(d), props(gpo) {} | ||
|
||
void operator()(const account_object& a) { | ||
a.statistics(d).process_fees(a, d); | ||
} | ||
} fee_helper(*this, gpo); | ||
|
||
perform_account_maintenance(std::tie( | ||
tally_helper, | ||
fee_helper | ||
)); | ||
perform_account_maintenance( tally_helper ); | ||
|
||
struct clear_canary { | ||
clear_canary(vector<uint64_t>& target): target(target){} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very minor: It looks like this is the only use of global_properties. Perhaps grab params instead of global_properties (line 191)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, nevermind. I see its use further down.