Skip to content

Commit

Permalink
fix hash rate estimator overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
revflash committed Apr 19, 2016
1 parent e96a4b2 commit 38e456e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions libraries/plugins/witness/witness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,14 @@ void witness_plugin::on_applied_block( const chain::signed_block& b )

const auto& dgp = db.get_dynamic_global_properties();
double hps = (_total_hashes*1000000)/(fc::time_point::now()-_hash_start_time).count();
auto bits = (dgp.num_pow_witnesses/4) + 4;
auto hashes = 1 << bits;
auto seconds = hashes/hps;
auto minutes = seconds / 60.0;
int64_t bits = (dgp.num_pow_witnesses/4) + 4;
fc::uint128 hashes = fc::uint128(1) << bits;
hashes *= 1000000;
hps += 1;
hashes /= int64_t(hps*1000000);
auto seconds = hashes.to_uint64();
//double seconds = hashes/hps;
auto minutes = uint64_t(seconds / 60.0);


auto target = db.get_pow_target();
Expand Down

0 comments on commit 38e456e

Please sign in to comment.