-
Notifications
You must be signed in to change notification settings - Fork 720
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
Optimise query stake snapshot command #4179
Optimise query stake snapshot command #4179
Conversation
3460124
to
197680d
Compare
Before:
After:
|
197680d
to
1287358
Compare
fe68cd5
to
76e3bf6
Compare
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.
Couple of minor changes
29b6b80
to
8143b24
Compare
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.
LGTM! Please squash the commits and you have some build errors
561072a
to
eafc49a
Compare
3f2f2e4
to
68b658c
Compare
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.
Please squash the commits
68b658c
to
f3d7b64
Compare
2936b7d
to
535f703
Compare
535f703
to
4459c4d
Compare
4459c4d
to
82aef90
Compare
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.
Why don't we implement something similar to:
data QueryUTxOFilter =
-- | /O(n) time and space/ for utxo size n
QueryUTxOWhole
-- | /O(n) time, O(m) space/ for utxo size n, and address set size m
| QueryUTxOByAddress (Set AddressAny)
-- | /O(m log n) time, O(m) space/ for utxo size n, and address set size m
| QueryUTxOByTxIn (Set TxIn)
deriving (Eq, Show)
We can then account for the case where we are interested in single or multiple pool stake snapshots.
e.g
data QueryStakeSnapshotFilter =
QuerySinglePoolStakeSnapshot PoolId
| QueryMutiplePoolStakeSnapshots (Set PoolId)
And then we can pipe that through in a similar fashion to QueryUTxOFilter
toJSON = object . stakeSnapshotsToPair | ||
toEncoding = pairs . mconcat . stakeSnapshotsToPair | ||
|
||
stakeSnapshotsToPair :: Aeson.KeyValue a => Consensus.StakeSnapshots crypto -> [a] |
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.
I think this logic shouldn't be in the JSON instance but at the point of rendering. The JSON instance should only be concerned with rendering JSON. In the cli we should determine how we render depending on if we get a Map
of length 1 or more.
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.
There's not a good way to do the fact there is a Map
at all breaks backwards compatibility.
This PR is meant to preserve backwards compatibility.
A follow up PR simplifies this code but breaks backwards compatibility. #4279
It would be good to get an optimised version of this command merged first before merging the change that breaks compatibility.
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.
I've just re-discovered data Stakes
. This is what we were rendering. What we should do to maintain backwards compatibility is create a function with type signature Consensus.StakeSnapshots crypto -> Stakes
. Imposing our cli logic on a JSON instance seems wrong, which should just be concerned with rendering JSON and should not be dictated by the needs of our query.
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.
The data doesn't fit into data Stakes
either because the map can be empty and I would not have anything to fill the pool fields in that case.
I've rendered the JSON manually instead.
82aef90
to
028d0dc
Compare
I feel that What's the case for adding an extra single pool id constructor? |
028d0dc
to
ed897dc
Compare
2b02875
to
3f95f83
Compare
3f95f83
to
8cd88e5
Compare
Depends on IntersectMBO/ouroboros-network#3898
Resolves #2717