Skip to content

Commit 78ff14e

Browse files
committed
Simplified code in database::pay_workers()
1 parent 08e9e0a commit 78ff14e

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

libraries/chain/db_maint.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,20 @@ void database::pay_workers( share_type& budget )
170170

171171
const auto last_budget_time = get_dynamic_global_properties().last_budget_time;
172172
const auto passed_time_ms = head_time - last_budget_time;
173-
const bool passed_time_is_a_day = ( passed_time_ms == fc::days(1) );
174-
// the variable above is more likely false on BitShares mainnet, so do calculations below anyway
175173
const auto passed_time_count = passed_time_ms.count();
176174
const auto day_count = fc::days(1).count();
177175
for( uint32_t i = 0; i < active_workers.size() && budget > 0; ++i )
178176
{
179177
const worker_object& active_worker = active_workers[i];
180178
share_type requested_pay = active_worker.daily_pay;
181-
if( !passed_time_is_a_day )
182-
{
183-
fc::uint128 pay(requested_pay.value);
184-
pay *= passed_time_count;
185-
pay /= day_count;
186-
requested_pay = pay.to_uint64();
187-
}
179+
180+
// Note: if there is a good chance that passed_time_count == day_count,
181+
// for better performance, can avoid the 128 bit calculation by adding a check.
182+
// Since it's not the case on BitShares mainnet, we're not using a check here.
183+
fc::uint128 pay(requested_pay.value);
184+
pay *= passed_time_count;
185+
pay /= day_count;
186+
requested_pay = pay.to_uint64();
188187

189188
share_type actual_pay = std::min(budget, requested_pay);
190189
//ilog(" ==> Paying ${a} to worker ${w}", ("w", active_worker.id)("a", actual_pay));

0 commit comments

Comments
 (0)