Conversation
c9d1cb9 to
38aa10e
Compare
There was a problem hiding this comment.
Pull request overview
This PR restructures Cardano.Ledger.Api.State.Query into domain-focused submodules, consolidating ledger-state query helpers previously scattered across downstream packages, and introduces stable QueryResult* types to reduce coupling to ledger-internal representations.
Changes:
- Split
Cardano.Ledger.Api.State.Queryinto 9 submodules (Governance/Pool/Snapshot/StakeDelegation/Reward/UTxO/PParams/Epoch/Debug) and re-export them fromQuery. - Add/rename stable
QueryResult*result types (with deprecated aliases/shims) and update tests/arbitrary instances accordingly. - Deprecate overlapping wallet API functions in
Cardano.Ledger.Shelley.API.Wallet, bumpcardano-ledger-apito1.14.0.0, and update changelogs.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| libs/cardano-ledger-api/testlib/Test/Cardano/Ledger/Api/Arbitrary.hs | Adds Arbitrary instances for new QueryResult* types and imports wallet reward types. |
| libs/cardano-ledger-api/test/Test/Cardano/Ledger/Api/State/QuerySpec.hs | Updates roundtrip tests to new types and adds extraction-function property tests. |
| libs/cardano-ledger-api/test/Test/Cardano/Ledger/Api/State/Imp/QuerySpec.hs | Updates Imp tests to use QueryResult* governance query results. |
| libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query/UTxO.hs | New UTxO query helpers (full/by-address/by-txin). |
| libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query/StakeDelegation.hs | New stake delegation queries + stable result type for delegs/rewards. |
| libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query/Snapshot.hs | New stake snapshot query + stable snapshot result types and deprecated aliases. |
| libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query/Reward.hs | New reward-related queries + stable result type for reward-info pools. |
| libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query/PParams.hs | New protocol parameter query helpers. |
| libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query/Pool.hs | New pool queries + stable pool-state result type and deprecated aliases. |
| libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query/Governance.hs | New governance queries + stable constitution/committee/drep result types and conversions. |
| libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query/Epoch.hs | New epoch/account-state query helpers. |
| libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query/Debug.hs | New debug query helpers + deprecated PParams updates query. |
| libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query/CommitteeMembersState.hs | Removes now-redundant standalone committee-members-state module. |
| libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs | Becomes a thin re-export module for the new submodules. |
| libs/cardano-ledger-api/CHANGELOG.md | Documents the breaking reorg and new query/result types. |
| libs/cardano-ledger-api/cardano-ledger-api.cabal | Bumps version, registers new modules, adds dependencies. |
| eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Wallet.hs | Adds deprecations pointing to new query modules; exports currentSnapshot; adds Ord for reward types. |
| eras/shelley/impl/CHANGELOG.md | Notes wallet API deprecations in favor of consolidated queries. |
| .claude/skills/update-changelogs/SKILL.md | Clarifies changelog process rule: top entry is unreleased; don’t add a new section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add haddock to mark usage sites across downstream dependencies.
Add usage-site sources in haddock.
Add stable types prefixed QueryResult*. Add CBOR round-trip tests.
Add stable QueryResult* types for some of them.
Add stable QueryResult* types for Snapshot and Snapshots. Also simpify querySnapshots to remove the Maybe Set parameter to just a Set, where an emtpy Set means return ALL pools.
Move queryStakePoolDelegsAndRewards into Query.StakeDelegation submodule. Add QueryResultDelegsAndRewards stable type replacing the tuple. Now, passing an emtpy set means the consumer is asking for all credentials.
Rename QueryPoolStateResult to QueryResultPoolState, and queryPoolParameters to queryStakePoolParams. Simplify queryPoolState to return all pool states when given an empty set. Query is now a thin-wrapper re-exporting sub-modules.
These queries are from consensus, cardano-api, cardano-cli, and Shelley.API.Wallet.
Some debug/deprecated queries.
New sub-module for reward-related queries (non-myopic member rewards, per-pool reward info, reward provenance). Adds Ord instances to RewardInfoPool and RewardParams in Wallet.hs to support the QueryResultRewardInfoPools stable type.
Api.State.Query sub-modules are the place for all ledger-state queries.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 19 out of 19 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import Cardano.Ledger.Shelley.PParams (ProposedPPUpdates, emptyPPPUpdates) | ||
|
|
||
| -- | Query the full 'EpochState' for debugging. | ||
| -- Source: ouroboros-consensus:ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query.hs:424 |
There was a problem hiding this comment.
These comments are guaranteed to get out of date very soon. I wonder if it would make sense to just name the module (e.g. Ouroboros.Consensus.Shelley.Ledger.Query)
Are they pointing at current usage or future usage?
There was a problem hiding this comment.
I thought that it will be quite difficult for the release engineer to figure out where to use the new queries added here, as some of them are completely new, whose bodies are currently in-line in certain downstream modules. Furthermore, some queries may have been changed or in a way, optimised, and therefore will not match syntactic searches to find those places. I have made this comment in the re-exporter "mother module" Query, as such.
I know this is weird, and unconventional, and a form of ephemeral communication between team-members by leaving messages in haddock, instead of using slack or issue comments here. But because it lives alongside the actual queries and the integration process is expected to delete them, I thought it is the safest and most clear - in-band, same-channel - form of communication that would be hard to get wrong or miss.
Let me know what you think. 🙂
There was a problem hiding this comment.
I think migrations for breaking changes of this kind are best documented in a migration guide, rather than in the source. The source is by definition a formal spec and represents current intent, but guidance for how the downstream code needs to change is (IMHO) probably best given in a more informal guidance document "look, this functionality you were using is no more, so this is how you achieve circa the same" (e.g. this is how we do migration documents for PureScript, which is what I am thinking about here).
If you'd rather keep this guidance in the source (so it's in-band, which I also understand) then it should be spelled out in the deprecation notices, so that these warnings are notified to the user in the right places in their source.
| import Cardano.Ledger.Slot (EpochNo) | ||
|
|
||
| -- | Query the current epoch number. | ||
| -- Source: ouroboros-consensus:ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query.hs:413 |
There was a problem hiding this comment.
Links to mutable source code make no sense, since they will get outdated very quickly.
If you want to add links to the source, add them in PR review as a comment, since that is the actual audience
There was a problem hiding this comment.
Yes I know this is totally weird, so I answered @f-f 's comment also 🙂 . I may be completely off the optimal solution to this. Let me know what you think. #5690 (comment)
There was a problem hiding this comment.
Should I add a table or something to this PR that the release engineer can then track for the work? Or would it be better to open another tracking issue with all the references?
| ## 1.14.0.0 | ||
|
|
||
| * | ||
| * Refactor pool related queries into `Query.Pool` and re-export from `Query`. |
There was a problem hiding this comment.
This change is not visible to the outside world, as such it should not be even mentioned in the changelog
Since the query consolidation breaks downstream anyway (new types,
renamed functions, changed return types), keeping deprecated aliases
adds noise without value. Remove every deprecation across the Query
sub-modules and Shelley.API.Wallet for a completely fresh API.
Query sub-modules:
- Remove type aliases: CommitteeMemberState, CommitteeMembersState,
QueryPoolStateResult, StakeSnapshot, StakeSnapshots
- Remove function aliases: mkQueryPoolStateResult, queryPoolParameters
- Remove queryProposedPParamsUpdates (always returned empty)
- Un-deprecate queryRewardProvenance (serves a distinct purpose)
- Remove {-# OPTIONS_GHC -Wno-deprecations #-} from Query.hs and
Governance.hs
Shelley.API.Wallet:
- Remove 11 query functions: getUTxO, getFilteredUTxO, getUTxOSubset,
getPools, getStakePools, poolsByTotalStakeFraction, getTotalStake,
getNonMyopicMemberRewards, currentSnapshot, getRewardInfoPools,
getRewardProvenance
- Clean up unused imports and language extensions
Add "Replaces @oldname@" haddock annotations to all 10 replacement
query functions to guide downstream migration. Update both CHANGELOGs
with explicit per-function replacement mappings.
Description
Reorganise
Ledger.Api.State.Queryinto domain-specific sub-modules, and re-export everything.consensus,api, andcli.QueryResult*types to decouple downstream from ledger-internal representation.filter ~ empty set -> return all.Closes #5659 and #5660
Checklist
CHANGELOG.mdfiles updated for packages with externally visible changes.NOTE: New section is never added with the code changes. (See RELEASING.md).
.cabalandCHANGELOG.mdfiles when necessary, according to theversioning process.
.cabalfiles updated when necessary.NOTE: If bounds change in a cabal file, that package itself must have a version increase. (See RELEASING.md).
scripts/fourmolize.sh).scripts/cabal-format.sh).scripts/gen-cddl.sh)hie.yamlupdated (usescripts/gen-hie.sh).