Minor performance improvement for db_maint
This commit is contained in:
parent
cabbd7d070
commit
ac7ac9f1f2
1 changed files with 17 additions and 11 deletions
|
|
@ -151,12 +151,13 @@ void database::update_worker_votes()
|
|||
|
||||
void database::pay_workers( share_type& budget )
|
||||
{
|
||||
const auto head_time = head_block_time();
|
||||
// ilog("Processing payroll! Available budget is ${b}", ("b", budget));
|
||||
vector<std::reference_wrapper<const worker_object>> active_workers;
|
||||
get_index_type<worker_index>().inspect_all_objects([this, &active_workers](const object& o) {
|
||||
// TODO optimization: add by_expiration index to avoid iterating through all objects
|
||||
get_index_type<worker_index>().inspect_all_objects([head_time, &active_workers](const object& o) {
|
||||
const worker_object& w = static_cast<const worker_object&>(o);
|
||||
auto now = head_block_time();
|
||||
if( w.is_active(now) && w.approving_stake() > 0 )
|
||||
if( w.is_active(head_time) && w.approving_stake() > 0 )
|
||||
active_workers.emplace_back(w);
|
||||
});
|
||||
|
||||
|
|
@ -170,15 +171,21 @@ void database::pay_workers( share_type& budget )
|
|||
return wa.id < wb.id;
|
||||
});
|
||||
|
||||
const auto last_budget_time = get_dynamic_global_properties().last_budget_time;
|
||||
const auto passed_time_ms = head_time - last_budget_time;
|
||||
const bool passed_time_is_a_day = ( passed_time_ms == fc::days(1) );
|
||||
// the variable above is more likely false on BitShares mainnet, so do calculations below anyway
|
||||
const auto passed_time_count = passed_time_ms.count();
|
||||
const auto day_count = fc::days(1).count();
|
||||
for( uint32_t i = 0; i < active_workers.size() && budget > 0; ++i )
|
||||
{
|
||||
const worker_object& active_worker = active_workers[i];
|
||||
share_type requested_pay = active_worker.daily_pay;
|
||||
if( head_block_time() - get_dynamic_global_properties().last_budget_time != fc::days(1) )
|
||||
if( !passed_time_is_a_day )
|
||||
{
|
||||
fc::uint128 pay(requested_pay.value);
|
||||
pay *= (head_block_time() - get_dynamic_global_properties().last_budget_time).count();
|
||||
pay /= fc::days(1).count();
|
||||
pay *= passed_time_count;
|
||||
pay /= day_count;
|
||||
requested_pay = pay.to_uint64();
|
||||
}
|
||||
|
||||
|
|
@ -1587,9 +1594,10 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
|
|||
update_active_committee_members();
|
||||
update_worker_votes();
|
||||
|
||||
modify(gpo, [this](global_property_object& p) {
|
||||
const dynamic_global_property_object& dgpo = get_dynamic_global_properties();
|
||||
|
||||
modify(gpo, [&dgpo](global_property_object& p) {
|
||||
// Remove scaling of account registration fee
|
||||
const auto& dgpo = get_dynamic_global_properties();
|
||||
p.parameters.current_fees->get<account_create_operation>().basic_fee >>= p.parameters.account_fee_scale_bitshifts *
|
||||
(dgpo.accounts_registered_this_interval / p.parameters.accounts_per_fee_scale);
|
||||
|
||||
|
|
@ -1610,7 +1618,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
|
|||
}
|
||||
});
|
||||
|
||||
auto next_maintenance_time = get<dynamic_global_property_object>(dynamic_global_property_id_type()).next_maintenance_time;
|
||||
auto next_maintenance_time = dgpo.next_maintenance_time;
|
||||
auto maintenance_interval = gpo.parameters.maintenance_interval;
|
||||
|
||||
if( next_maintenance_time <= next_block.timestamp )
|
||||
|
|
@ -1640,8 +1648,6 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
|
|||
}
|
||||
}
|
||||
|
||||
const dynamic_global_property_object& dgpo = get_dynamic_global_properties();
|
||||
|
||||
if( (dgpo.next_maintenance_time < HARDFORK_613_TIME) && (next_maintenance_time >= HARDFORK_613_TIME) )
|
||||
deprecate_annual_members(*this);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue