-
Notifications
You must be signed in to change notification settings - Fork 87
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
New query to get snapshots #3898
Conversation
ouroboros-consensus-shelley/src/Ouroboros/Consensus/Shelley/Ledger/Query.hs
Show resolved
Hide resolved
e8a3fa0
to
24660db
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.
I made some comments throughout. HTH. Thanks!
ouroboros-consensus-shelley/src/Ouroboros/Consensus/Shelley/Ledger/Query.hs
Show resolved
Hide resolved
GetPoolState {} -> fromCBOR | ||
GetStakeSnapshot {} -> fromCBOR | ||
|
||
data StakeSnapshot crypto = StakeSnapshot |
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 add a Haddock comment explaining what this is.
Also, I think these fields shouldn't be Integer
s, but rather SL.Coin
?
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.
Added documentation.
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 not return SnapShots crypto
? It seems like we are losing potentially useful information i.e the delegations and pool params. The consumer can do these calculations (indeed we can expose functions from cardano-api
to do this)
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.
It is define like this:
data SnapShots crypto = SnapShots
{ _pstakeMark :: SnapShot crypto, -- Lazy on purpose
_pstakeSet :: !(SnapShot crypto),
_pstakeGo :: !(SnapShot crypto),
_feeSS :: !Coin
}
deriving (Show, Eq, Generic)
data SnapShot crypto = SnapShot
{ _stake :: !(Stake crypto),
_delegations :: !(VMap VB VB (Credential 'Staking crypto) (KeyHash 'StakePool crypto)),
_poolParams :: !(VMap VB VB (KeyHash 'StakePool crypto) (PoolParams crypto))
}
deriving (Show, Eq, Generic)
The maps stored are very big, so in the interest of improving memory and cpu efficiency and not transferring more data than necessary over the socket, I do the map lookup on the node side.
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 not return
SnapShots crypto
?
The maps stored are very big [..., so] I do the map lookup on the node side
On Slack, Jordan also asked: "Should we allow the possibility to get the stake snapshot for multiple pools at once?"
One option occurs to me: we return a SnapShots crypto
(so we don't have to define a new type 🙌) but we restrict all the maps inside that data type to just the keys given (so we support a multi-pool query 🙌).
On the slack thread, you agreed that one-pool at a time is fine for the first PR. So that's not urgent.
But avoiding a new data type might be nice.
So: does the resuse of SnapShots crypto
but with all the maps restricted down to the pools identified by the query make sense?
One immediate downside: such a restricted SnapShot
is probably counter-intuitive: eg it violates some generally-expected invariants of SnapShot
(along the lines of completeness)
ouroboros-consensus-shelley/src/Ouroboros/Consensus/Shelley/Ledger/Query.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus-shelley/src/Ouroboros/Consensus/Shelley/Ledger/Query.hs
Show resolved
Hide resolved
ouroboros-consensus-cardano/src/Ouroboros/Consensus/Cardano/Node.hs
Outdated
Show resolved
Hide resolved
917b819
to
e836ce8
Compare
e836ce8
to
eb5e856
Compare
01549ff
to
551db30
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.
551db30
to
b646f87
Compare
@@ -77,6 +77,7 @@ https://keepachangelog.com/en/1.1.0/, adapted to our plan explained above. | |||
|
|||
- New supported node to client version `NodeToClientV_14` with new queries: | |||
- `GetPoolState`: Get the pool state for the given stake pool ids | |||
- `GetStakeSnapshot`: Get the snapshot of stake distribution |
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 do we write this entry here? Why not in a section above 2022-07-20
?
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 moved it to a new section.
b646f87
to
4fcb5c7
Compare
4fcb5c7
to
172ae40
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.
I made some new comments. But everything is relatively minor (though not necessarily cheap), so I'm clicking Approve.
Thanks for responding to the previous comments 🙏
ouroboros-consensus-shelley/src/Ouroboros/Consensus/Shelley/Ledger/Query.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus-shelley/src/Ouroboros/Consensus/Shelley/Ledger/Query.hs
Outdated
Show resolved
Hide resolved
GetPoolState {} -> fromCBOR | ||
GetStakeSnapshot {} -> fromCBOR | ||
|
||
data StakeSnapshot crypto = StakeSnapshot |
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 not return
SnapShots crypto
?
The maps stored are very big [..., so] I do the map lookup on the node side
On Slack, Jordan also asked: "Should we allow the possibility to get the stake snapshot for multiple pools at once?"
One option occurs to me: we return a SnapShots crypto
(so we don't have to define a new type 🙌) but we restrict all the maps inside that data type to just the keys given (so we support a multi-pool query 🙌).
On the slack thread, you agreed that one-pool at a time is fine for the first PR. So that's not urgent.
But avoiding a new data type might be nice.
So: does the resuse of SnapShots crypto
but with all the maps restricted down to the pools identified by the query make sense?
One immediate downside: such a restricted SnapShot
is probably counter-intuitive: eg it violates some generally-expected invariants of SnapShot
(along the lines of completeness)
ouroboros-consensus-shelley/src/Ouroboros/Consensus/Shelley/Ledger/Query.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus-shelley/src/Ouroboros/Consensus/Shelley/Ledger/Query.hs
Show resolved
Hide resolved
case mPoolIds of | ||
Nothing -> | ||
StakeSnapshots | ||
{ ssStakeSnapshots = getPoolStakes (Set.fromList (VMap.elems (SL._delegations _pstakeMark))) |
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'm assuming that if I get the elems
of _delegations _pstakeMark
that it would give me all of the pool ids.
I'm not confident that this is true. Please validate.
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 is correct @newhoggy. _delegations _pstakeMark
is a map from stake credentials to stake pool IDs. You can tell from they type, if you happen to know that the stake pool IDs are the hash of the stake pool operator's cold verification key:
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!
92fd09c
to
a106d1c
Compare
<*> fromCBOR | ||
|
||
data StakeSnapshots crypto = StakeSnapshots | ||
{ ssStakeSnapshots :: Map (SL.KeyHash 'SL.StakePool crypto) (StakeSnapshot crypto) |
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.
This is the strict Map
, so I think this field should also be strict.
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.
Fixed!
b70ba6a
to
a0d8d63
Compare
a0d8d63
to
ff55347
Compare
bors r+ |
Description
This introduce a new query
GetStakeSnapshots
which extracts the stake snapshots for all pools or for a specified subset of pools. This query is required to improve the CPU and memory efficiency of thequery stake-snapshot
command in the CLI.Checklist
interface-CHANGELOG.md
interface-CHANGELOG.md
cardano-api
changesThe existing query,
QueryDebugLedgerState
, will continue to exist and be slow and use a lot of memory, however, there will be a newGetStakeSnapshot
which uses a lot less CPU and memory:This query takes a set of pool ids so it is possible to query multiple pools at once.
cardano-cli
changesA existing command
query stake-snapshot
will be be functionally unchanged, but use much less CPU and memory.