Skip to content

Commit 46d1640

Browse files
committed
scrutinize-stake-drift.sh: first draft
1 parent 119d5b7 commit 46d1640

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The `scrutinize-stake-drift.sh` bash script postprocesses the output of the `db-analyser --dump-stake-distributions` pass.
2+
3+
It yields several temporary files in the local directory, so run it in a temporary folder.
4+
5+
The script prints out a table that indicate how much stake the pools that have been in the top 90% of every epoch in the data had in each epoch.
6+
7+
The script also prints out a counterfactual table that pretends each of those pools' least-stake epochs were coincident, where that minimum iterates over every suffix of the list of epochs.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# For example:
2+
#
3+
# $ db-analyser ... --dump-stake-distributions >foo.txt
4+
# $ bash scrutinize-stake-drift.sh foo.txt
5+
6+
db_analyser_output_file=$1
7+
8+
echo "# the PoolDistrs in tabular form >tidied.txt"
9+
cat "${db_analyser_output_file}" | tr '(,){=}"' ' ' | sed 's/KeyHash/\n/g' | awk -f tidy.awk >tidied.txt
10+
11+
firstEpoch=$(head -n1 tidied.txt | awk '{print $1}')
12+
lastEpoch=$(tail -n1 tidied.txt | awk '{print $1}')
13+
nepochs=$(expr $lastEpoch - $firstEpoch + 1)
14+
15+
echo "# how many epochs each pool was in >epochs.txt"
16+
cat tidied.txt | awk '{print $4}' | sort | uniq -c >epochs.txt
17+
18+
echo "# histogram of epochs.txt"
19+
cat epochs.txt | awk '{print $1}' | sort -n | uniq -c
20+
21+
echo "# discard pools outside of the 90% in each epoch >big.txt"
22+
cat tidied.txt | sort -k1,1n -k5,5gr | awk '(eno != $1) { eno = $1; acc = 0 } (acc < 0.9) { acc = acc + $5; print $0 }' >big.txt
23+
24+
echo "# big.txt sorted by pool and then by epoch >sorted.txt"
25+
cat big.txt | sort -k4,4 -k1,1n >sorted.txt
26+
27+
echo "# restrict to the pools that are in all $nepochs epochs >steady.txt"
28+
join -1 2 -2 4 <(grep -w -e $nepochs epochs.txt) sorted.txt >steady.txt
29+
30+
echo "# wc -l"
31+
wc -l tidied.txt epochs.txt sorted.txt steady.txt
32+
33+
echo "# head -n5"
34+
head -n5 tidied.txt epochs.txt sorted.txt steady.txt
35+
36+
echo "# cumulative stake per epoch within steady.txt"
37+
cat steady.txt | awk '{x[$3] = x[$3] + $6} END { acc = 1/0; for (k in x) { if (acc > x[k]) { kacc = k; acc = x[k] }; print k, x[k] }; print " Min is ", kacc, acc }' | sort -n
38+
39+
echo "# least stake for each pool in some epoch in steady.txt, for each tail of the epochs >lows.txt"
40+
for i in $(seq $firstEpoch $lastEpoch); do
41+
cat steady.txt | awk -v low=$i '{pool = $1; eno = $3; stake = $6} (low <= eno && !(pool in acc && stake >= acc[pool])) { kacc[pool] = eno; acc[pool] = stake } END { for (pool in acc) { print low, acc[pool], kacc[pool], pool } }' | sort -g
42+
done >lows.txt
43+
44+
echo "# sum of lows.txt for each age bound"
45+
cat lows.txt | awk '($1 != x) {if (x) { print x, acc}; x = $1; acc = 0} {acc = acc + $2} END {print x, acc}'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/EpochNo/ {
2+
eno = $3;
3+
n = $7;
4+
i = 0;
5+
}
6+
7+
(/%/) {
8+
print eno, i, n, $1, $5 / $7;
9+
i++;
10+
}

0 commit comments

Comments
 (0)