Skip to content

Commit

Permalink
feat: save hash rate on epoch statistic worker
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Jan 2, 2020
1 parent e0746df commit 48be8e4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/workers/charts/epoch_statistic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ def perform
uncles_count = Block.where(epoch: target_epoch_number).sum(:uncles_count)
uncle_rate = uncles_count / blocks_count.to_d
difficulty = Block.where(epoch: target_epoch_number).first.difficulty
first_block_in_epoch = Block.where(epoch: target_epoch_number).order(:number).first
last_lock_in_epoch = Block.where(epoch: target_epoch_number).order(:number).last
block_time = last_lock_in_epoch.timestamp - first_block_in_epoch.timestamp
hash_rate = difficulty * first_block_in_epoch.length / block_time

::EpochStatistic.create(epoch_number: target_epoch_number, difficulty: difficulty, uncle_rate: uncle_rate)
::EpochStatistic.create(epoch_number: target_epoch_number, difficulty: difficulty, uncle_rate: uncle_rate, hash_rate: hash_rate)
end
end
end

0 comments on commit 48be8e4

Please sign in to comment.