-
Notifications
You must be signed in to change notification settings - Fork 26
db-analyser: add DumpStakeDistributions pass #1421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nfrisby
wants to merge
4
commits into
main
Choose a base branch
from
nfrisby/stake-drift-tool
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
24 changes: 24 additions & 0 deletions
24
...s-consensus-cardano/changelog.d/20250312_142505_nick.frisby_stake_drift_tool.md
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!-- | ||
A new scriv changelog fragment. | ||
|
||
Uncomment the section that is right (remove the HTML comment wrapper). | ||
--> | ||
|
||
<!-- | ||
### Patch | ||
|
||
- A bullet item for the Patch category. | ||
|
||
--> | ||
|
||
### Non-Breaking | ||
|
||
- Added the --dump-stake-distributions pass to `db-analyser` | ||
|
||
|
||
<!-- | ||
### Breaking | ||
|
||
- A bullet item for the Breaking category. | ||
|
||
--> |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
The `scrutinize-stake-drift.sh` bash script postprocesses the output of the `db-analyser --dump-stake-distributions` pass. | ||
|
||
It yields several temporary files in the local directory, so run it in a temporary folder. | ||
|
||
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. | ||
|
||
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. |
48 changes: 48 additions & 0 deletions
48
scripts/genesis-stake-drift-analysis/scrutinize-stake-drift.sh
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# For example: | ||
# | ||
# $ db-analyser ... --dump-stake-distributions >foo.txt | ||
# $ bash scrutinize-stake-drift.sh foo.txt | ||
|
||
db_analyser_output_file=$1 | ||
|
||
echo "# the PoolDistrs in tabular form >tidied.txt" | ||
cat "${db_analyser_output_file}" | tr '(,){=}"' ' ' | sed 's/KeyHash/\n/g' | awk -f tidy.awk >tidied.txt | ||
|
||
firstEpoch=$(head -n1 tidied.txt | awk '{print $1}') | ||
lastEpoch=$(tail -n1 tidied.txt | awk '{print $1}') | ||
nepochs=$(expr $lastEpoch - $firstEpoch + 1) | ||
|
||
echo "# discard pools outside of the 90% in each epoch >big.txt" | ||
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 | ||
# cp tidied.txt big.txt # uncomment this command to use pools that were in all epochs regardless of their relative stake | ||
|
||
echo "# for how many epochs was each pool in the top 90% >epochs.txt" | ||
cat big.txt | awk '{print $4}' | sort | uniq -c >epochs.txt | ||
|
||
echo "# histogram of epochs.txt" | ||
cat epochs.txt | awk '{print $1}' | sort -n | uniq -c | ||
|
||
echo "# big.txt sorted by pool and then by epoch >sorted.txt" | ||
cat big.txt | sort -k4,4 -k1,1n >sorted.txt | ||
|
||
echo "# restrict sorted.txt to the pools that are in all $nepochs epochs >steady.txt" | ||
join -1 2 -2 4 <(grep -w -e $nepochs epochs.txt) sorted.txt >steady.txt | ||
|
||
echo "# wc -l" | ||
wc -l tidied.txt epochs.txt sorted.txt steady.txt | ||
|
||
echo "# head -n5" | ||
head -n5 tidied.txt epochs.txt sorted.txt steady.txt | ||
|
||
echo "# cumulative stake per epoch within steady.txt" | ||
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 | ||
|
||
echo "# the statistical distance between each epoch and epoch $lastEpoch" | ||
echo "# " | ||
echo "# see https://en.wikipedia.org/wiki/Statistical_distance#Statistically_close" | ||
cat steady.txt | awk -v eno=$lastEpoch '(eno == $3) { print $0 }' >tmpfile-lastEpoch | ||
for i in $(seq $firstEpoch $lastEpoch); do | ||
cat steady.txt | awk -v eno=$i '(eno == $3) { print $0 }' >tmpfile-$i | ||
|
||
paste tmpfile-lastEpoch tmpfile-$i | awk -v eno=$i '($6 > $12) { x = x + ($6 - $12) } ($6 < $12) { x = x + ($12 - $6) } END { printf("%i %.3f\n", eno, (x / 2)) }' | ||
done |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/EpochNo/ { | ||
eno = $3; | ||
n = $7; | ||
i = 0; | ||
} | ||
|
||
(/%/) { | ||
print eno, i, n, $1, $5 / $7; | ||
i++; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK
pdTotalActiveStake
andindividualTotalPoolStake
are only used for Conway voting stuff, soindividualTotalPoolStake / pdTotalActiveStake
does not necessarily equalindividualPoolStake
, which is used for leader election:ouroboros-consensus/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos.hs
Line 521 in 43c1fef
ouroboros-consensus/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/PeerSelection.hs
Line 48 in 43c1fef
So I think it makes sense to either ignore them here or make this explicit in the output somehow.
I looked at all epochs until 544, and so far, we apparently didn't have a difference here, no idea how likely it is for a difference to arise in the future.
See IntersectMBO/cardano-ledger#4324 (comment), cc @lehins for confirmation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That statement is not quite correct.
IndividualPoolStake
that is extracted fromPoolDistr
as it is done in consensus, will not have any voting related stake within it. However, the version of this in DRep pulser will have proposal deposits added to that stake. The issue was that the haddock forindividualTotalPoolStake
should not have stated anything about proposal deposits.So, individualTotalPoolStake / pdTotalActiveStake should always equal individualPoolStake for leader election, unless you are looking into the version from pulser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that is good to hear! I guess then the remaining mentions of proposal deposits here and here should also be removed?