Created
November 10, 2023 16:27
-
-
Save trepca/057ca2291fb01f44fa2662883f6e2938 to your computer and use it in GitHub Desktop.
Calculate Nakamoto Coefficient for Chia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select count(*) | |
from (select ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS enumerator, | |
puzzle_hash, | |
percent, | |
SUM(percent) OVER (ORDER BY percent desc ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as percent_sum | |
from (select puzzle_hash, count(*) as blocks, count(*) / bb.block_count::float * 100 as percent | |
from coin_records, | |
-- this is to get the total number of blocks in the last 7 days | |
(select count(*) as block_count | |
from coin_records | |
where coinbase = true | |
and created_at > current_timestamp - interval '7 days' | |
-- only count pool rewards to avoid 3rd part harvesters | |
and amount = 1750000000000) as bb | |
where coinbase = true | |
and created_at > current_timestamp - interval '7 days' | |
-- only count pool rewards to avoid 3rd part harvesters | |
and amount = 1750000000000 | |
group by puzzle_hash, bb.block_count | |
order by blocks desc) | |
as b | |
order by percent desc) as c | |
where c.percent_sum < 50 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment