|
| 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}' |
0 commit comments