Skip to content

Commit e779a05

Browse files
committed
Consolidate ledger state queries.
Reorganise Ledger.Api.State.Query into domain-specific sub-modules, and re-export everything. Consolidate ledger state queries from consensus, api, and cli. Add stable QueryResult* types to decouple downstream from ledger-internal representation. Wherever it made sense: filter ~ empty set -> return all. This commit adds breaking changes, tests.
1 parent 620aea3 commit e779a05

18 files changed

Lines changed: 2127 additions & 934 deletions

File tree

eras/shelley/impl/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## 1.19.0.0
44

5+
* Deprecate functions in `Cardano.Ledger.Shelley.API.Wallet` in favour of
6+
consolidated queries in `Cardano.Ledger.Api.State.Query`:
7+
- `poolsByTotalStakeFraction``queryStakePoolDistrByTotalSupply`
8+
- `getNonMyopicMemberRewards``queryNonMyopicMemberRewards`
9+
- `getRewardInfoPools``queryRewardInfoPools`
10+
- `getRewardProvenance``queryRewardProvenance`
511
* Add `Shelley.API.Forecast` and `Shelley.Forecast`:
612
- Add `EraForecast` and `ShelleyEraForecast` typeclasses to deprecate `GetLedgerView` from `cardano-ledger-tpraos`.
713
- Add `currentForecast` and `futureForecast` functions to deprecate `currentLedgerView` and `futureLedgerView`.

eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Wallet.hs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ module Cardano.Ledger.Shelley.API.Wallet (
3737
totalAdaES,
3838
totalAdaPotsES,
3939
getStakePools,
40+
41+
-- * Snapshots
42+
currentSnapshot,
4043
) where
4144

4245
import Cardano.Ledger.Address (compactAddr)
@@ -200,6 +203,10 @@ poolsByTotalStakeFraction globals nes =
200203
IndividualPoolStake
201204
toTotalStakeFrac (IndividualPoolStake s c vrf) =
202205
IndividualPoolStake (s * stakeRatio) c vrf
206+
{-# DEPRECATED
207+
poolsByTotalStakeFraction
208+
"Use queryStakePoolDistrByTotalSupply from Cardano.Ledger.Api.State.Query.Pool instead"
209+
#-}
203210

204211
-- | Calculate the current total stake.
205212
getTotalStake :: Globals -> NewEpochState era -> Coin
@@ -252,6 +259,10 @@ getNonMyopicMemberRewards globals ss = Map.fromSet nmmRewards
252259
getTopRankedPools rPot totalStakeCoin pp $
253260
Map.intersectionWith (,) (VMap.toMap (VMap.map percentile' ls)) $
254261
VMap.toMap stakePoolsSnapShot
262+
{-# DEPRECATED
263+
getNonMyopicMemberRewards
264+
"Use queryNonMyopicMemberRewards from Cardano.Ledger.Api.State.Query.Reward instead"
265+
#-}
255266

256267
-- | Create a current snapshot of the ledger state.
257268
--
@@ -284,7 +295,7 @@ data RewardInfoPool = RewardInfoPool
284295
-- Can be larger than @1.0@ for pool that gets lucky.
285296
-- (If some pools get unlucky, some pools must get lucky.)
286297
}
287-
deriving (Eq, Show, Generic)
298+
deriving (Eq, Ord, Show, Generic)
288299

289300
instance NoThunks RewardInfoPool
290301

@@ -305,7 +316,7 @@ data RewardParams = RewardParams
305316
, totalStake :: Coin
306317
-- ^ Maximum lovelace supply minus treasury
307318
}
308-
deriving (Eq, Show, Generic)
319+
deriving (Eq, Ord, Show, Generic)
309320

310321
instance NoThunks RewardParams
311322

@@ -359,17 +370,14 @@ getRewardInfoPools globals nes =
359370
, performanceEstimate =
360371
unPerformanceEstimate $ percentile' $ histLookup poolId
361372
}
373+
{-# DEPRECATED getRewardInfoPools "Use queryRewardInfoPools from Cardano.Ledger.Api.State.Query.Reward instead" #-}
362374

363375
-- | Calculate stake pool rewards from the snapshot labeled `go`.
364376
-- Also includes information on how the rewards were calculated
365377
-- ('RewardProvenance').
366378
--
367379
-- For a calculation of rewards based on the current stake distribution,
368380
-- see 'getRewardInfoPools'.
369-
--
370-
-- TODO: Deprecate 'getRewardProvenance', because wallets are more
371-
-- likely to use 'getRewardInfoPools' for up-to-date information
372-
-- on stake pool rewards.
373381
getRewardProvenance ::
374382
forall era.
375383
(EraGov era, EraCertState era) =>
@@ -391,6 +399,7 @@ getRewardProvenance globals newEpochState =
391399
slotsPerEpoch = epochInfoSize (epochInfoPure globals) epochNo
392400
asc = activeSlotCoeff globals
393401
secparam = securityParameter globals
402+
{-# DEPRECATED getRewardProvenance "Use queryRewardProvenance from Cardano.Ledger.Api.State.Query.Reward instead" #-}
394403

395404
--------------------------------------------------------------------------------
396405
-- Transaction helpers

libs/cardano-ledger-api/CHANGELOG.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
11
# Version history for `cardano-ledger-api`
22

3-
## 1.13.0.1
4-
5-
*
3+
## 1.14.0.0
4+
5+
* Reorganize `Cardano.Ledger.Api.State.Query` into 9 sub-modules with stable
6+
query result types and deprecation shims for downstream migration:
7+
- `Query.Governance` — governance, constitution, committee, and DRep queries
8+
- `Query.Pool` — stake pool queries and stake distribution
9+
- `Query.Snapshot` — mark/set/go stake snapshots
10+
- `Query.StakeDelegation` — stake pool delegations and reward accounts
11+
- `Query.Reward` — reward provenance and non-myopic member rewards
12+
- `Query.UTxO` — UTxO queries by address, TxIn, or whole
13+
- `Query.PParams` — protocol parameter queries
14+
- `Query.Epoch` — epoch number and chain account state
15+
- `Query.Debug` — debug and deprecated queries
16+
* Add new stable query result types:
17+
- `QueryResultConstitution` (replaces `Constitution era` in `queryConstitution`)
18+
- `QueryResultCommitteeMemberState`, `QueryResultCommitteeMembersState`
19+
(replace `CommitteeMemberState`, `CommitteeMembersState` — deprecated aliases provided)
20+
- `QueryResultDRepState`, `QueryResultDRepStates`
21+
(replaces `Map (Credential DRepRole) DRepState` in `queryDRepState`)
22+
- `QueryResultDelegsAndRewards`
23+
(replaces `(Map, Map)` tuple in `queryStakePoolDelegsAndRewards`)
24+
- `QueryResultRewardInfoPools`
25+
- Rename `StakeSnapshot``QueryResultStakeSnapshot` (deprecated alias provided)
26+
- Rename `StakeSnapshots``QueryResultStakeSnapshots` (deprecated alias provided)
27+
- Rename `QueryPoolStateResult``QueryResultPoolState` (deprecated alias provided)
28+
* Add 22 newly consolidated query functions (from ouroboros-consensus, cardano-api, cardano-cli):
29+
- `queryEpochNo`
30+
- `queryNonMyopicMemberRewards`, `queryRewardInfoPools`, `queryRewardProvenance`
31+
- `queryStakePools`, `queryStakePoolDistrByTotalSupply`, `queryStakePoolDistrFromSnapshot`
32+
- `queryStakeDelegDeposits`, `queryDRepDelegatees`, `queryStakeVoteDelegatees`
33+
- `queryUTxOByAddress`, `queryUTxOByTxIn`, `queryUTxOFull`
34+
- `queryDebugEpochState`, `queryDebugNewEpochState`, `queryProposedPParamsUpdates`
35+
- `queryStakePoolParams` (renamed from `queryPoolParameters` — deprecated alias provided)
36+
- `toQueryResultConstitution`, `toQueryResultPoolState`, `toQueryResultDRepState`
37+
* Deprecate functions in `Cardano.Ledger.Shelley.API.Wallet` pointing to new query module locations:
38+
- `poolsByTotalStakeFraction``queryStakePoolDistrByTotalSupply`
39+
- `getNonMyopicMemberRewards``queryNonMyopicMemberRewards`
40+
- `getRewardInfoPools``queryRewardInfoPools`
41+
- `getRewardProvenance``queryRewardProvenance`
642

743
## 1.13.0.0
844

libs/cardano-ledger-api/cardano-ledger-api.cabal

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.0
22
name: cardano-ledger-api
3-
version: 1.13.0.1
3+
version: 1.14.0.0
44
license: Apache-2.0
55
maintainer: operations@iohk.io
66
author: IOHK
@@ -42,7 +42,15 @@ library
4242
hs-source-dirs: src
4343
other-modules:
4444
Cardano.Ledger.Api.Scripts.ExUnits
45-
Cardano.Ledger.Api.State.Query.CommitteeMembersState
45+
Cardano.Ledger.Api.State.Query.Debug
46+
Cardano.Ledger.Api.State.Query.Epoch
47+
Cardano.Ledger.Api.State.Query.Governance
48+
Cardano.Ledger.Api.State.Query.PParams
49+
Cardano.Ledger.Api.State.Query.Pool
50+
Cardano.Ledger.Api.State.Query.Reward
51+
Cardano.Ledger.Api.State.Query.Snapshot
52+
Cardano.Ledger.Api.State.Query.StakeDelegation
53+
Cardano.Ledger.Api.State.Query.UTxO
4654

4755
default-language: Haskell2010
4856
ghc-options:
@@ -78,6 +86,7 @@ library
7886
data-default,
7987
deepseq,
8088
microlens,
89+
nothunks,
8190
transformers,
8291
vector-map >=1.2,
8392

@@ -106,6 +115,7 @@ library testlib
106115
cardano-ledger-binary:{cardano-ledger-binary, testlib},
107116
cardano-ledger-core:{cardano-ledger-core, testlib},
108117
cardano-ledger-dijkstra:testlib,
118+
cardano-ledger-shelley,
109119
data-default,
110120
generic-random,
111121
prettyprinter,

0 commit comments

Comments
 (0)