Skip to content

Commit 2886dc7

Browse files
authored
Expose querySupportedVersions (#1437)
This PR exposes a `querySupportedVersions` function that provides the list of versions in which a query is available, to be used by `cardano-api`
2 parents 99e49de + 7d2129d commit 2886dc7

File tree

22 files changed

+275
-153
lines changed

22 files changed

+275
-153
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### Breaking
2+
3+
- Define `blockQueryIsSupportedOnVersion` for Byron and Shelley.
4+
- For Shelley, this is just a relocation of the now gone `querySupportedVersion` function.

ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Ledger/Ledger.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ data instance BlockQuery ByronBlock :: Type -> Type where
200200
instance BlockSupportsLedgerQuery ByronBlock where
201201
answerBlockQuery _cfg GetUpdateInterfaceState (ExtLedgerState ledgerState _) =
202202
CC.cvsUpdateState (byronLedgerState ledgerState)
203+
blockQueryIsSupportedOnVersion GetUpdateInterfaceState = const True
203204

204205
instance SameDepIndex (BlockQuery ByronBlock) where
205206
sameDepIndex GetUpdateInterfaceState GetUpdateInterfaceState = Just Refl

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query.hs

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ module Ouroboros.Consensus.Shelley.Ledger.Query (
2323
, NonMyopicMemberRewards (..)
2424
, StakeSnapshot (..)
2525
, StakeSnapshots (..)
26-
, querySupportedVersion
2726
-- * Serialisation
2827
, decodeShelleyQuery
2928
, decodeShelleyResult
@@ -509,6 +508,53 @@ instance
509508
hst = headerState ext
510509
st = shelleyLedgerState lst
511510

511+
-- | Is the given query supported by the given 'ShelleyNodeToClientVersion'?
512+
blockQueryIsSupportedOnVersion = \case
513+
GetLedgerTip -> const True
514+
GetEpochNo -> const True
515+
GetNonMyopicMemberRewards {} -> const True
516+
GetCurrentPParams -> const True
517+
GetProposedPParamsUpdates -> (< v12)
518+
GetStakeDistribution -> const True
519+
GetUTxOByAddress {} -> const True
520+
GetUTxOWhole -> const True
521+
DebugEpochState -> const True
522+
GetCBOR q -> blockQueryIsSupportedOnVersion q
523+
GetFilteredDelegationsAndRewardAccounts {} -> const True
524+
GetGenesisConfig -> const True
525+
DebugNewEpochState -> const True
526+
DebugChainDepState -> const True
527+
GetRewardProvenance -> const True
528+
GetUTxOByTxIn {} -> const True
529+
GetStakePools -> const True
530+
GetStakePoolParams {} -> const True
531+
GetRewardInfoPools -> const True
532+
GetPoolState {} -> const True
533+
GetStakeSnapshots {} -> const True
534+
GetPoolDistr {} -> const True
535+
GetStakeDelegDeposits {} -> const True
536+
GetConstitution -> (>= v8)
537+
GetGovState -> (>= v8)
538+
GetDRepState {} -> (>= v8)
539+
GetDRepStakeDistr {} -> (>= v8)
540+
GetCommitteeMembersState {} -> (>= v8)
541+
GetFilteredVoteDelegatees {} -> (>= v8)
542+
GetAccountState {} -> (>= v8)
543+
GetSPOStakeDistr {} -> (>= v8)
544+
GetProposals {} -> (>= v9)
545+
GetRatifyState {} -> (>= v9)
546+
GetFuturePParams {} -> (>= v10)
547+
GetBigLedgerPeerSnapshot -> (>= v11)
548+
QueryStakePoolDefaultVote {} -> (>= v12)
549+
-- WARNING: when adding a new query, a new @ShelleyNodeToClientVersionX@
550+
-- must be added. See #2830 for a template on how to do this.
551+
where
552+
v8 = ShelleyNodeToClientVersion8
553+
v9 = ShelleyNodeToClientVersion9
554+
v10 = ShelleyNodeToClientVersion10
555+
v11 = ShelleyNodeToClientVersion11
556+
v12 = ShelleyNodeToClientVersion12
557+
512558
instance SameDepIndex (BlockQuery (ShelleyBlock proto era)) where
513559
sameDepIndex GetLedgerTip GetLedgerTip
514560
= Just Refl
@@ -703,54 +749,6 @@ instance ShelleyCompatible proto era => ShowQuery (BlockQuery (ShelleyBlock prot
703749
GetBigLedgerPeerSnapshot -> show
704750
QueryStakePoolDefaultVote {} -> show
705751

706-
-- | Is the given query supported by the given 'ShelleyNodeToClientVersion'?
707-
querySupportedVersion :: BlockQuery (ShelleyBlock proto era) result -> ShelleyNodeToClientVersion -> Bool
708-
querySupportedVersion = \case
709-
GetLedgerTip -> const True
710-
GetEpochNo -> const True
711-
GetNonMyopicMemberRewards {} -> const True
712-
GetCurrentPParams -> const True
713-
GetProposedPParamsUpdates -> (< v12)
714-
GetStakeDistribution -> const True
715-
GetUTxOByAddress {} -> const True
716-
GetUTxOWhole -> const True
717-
DebugEpochState -> const True
718-
GetCBOR q -> querySupportedVersion q
719-
GetFilteredDelegationsAndRewardAccounts {} -> const True
720-
GetGenesisConfig -> const True
721-
DebugNewEpochState -> const True
722-
DebugChainDepState -> const True
723-
GetRewardProvenance -> const True
724-
GetUTxOByTxIn {} -> const True
725-
GetStakePools -> const True
726-
GetStakePoolParams {} -> const True
727-
GetRewardInfoPools -> const True
728-
GetPoolState {} -> const True
729-
GetStakeSnapshots {} -> const True
730-
GetPoolDistr {} -> const True
731-
GetStakeDelegDeposits {} -> const True
732-
GetConstitution -> (>= v8)
733-
GetGovState -> (>= v8)
734-
GetDRepState {} -> (>= v8)
735-
GetDRepStakeDistr {} -> (>= v8)
736-
GetCommitteeMembersState {} -> (>= v8)
737-
GetFilteredVoteDelegatees {} -> (>= v8)
738-
GetAccountState {} -> (>= v8)
739-
GetSPOStakeDistr {} -> (>= v8)
740-
GetProposals {} -> (>= v9)
741-
GetRatifyState {} -> (>= v9)
742-
GetFuturePParams {} -> (>= v10)
743-
GetBigLedgerPeerSnapshot -> (>= v11)
744-
QueryStakePoolDefaultVote {} -> (>= v12)
745-
-- WARNING: when adding a new query, a new @ShelleyNodeToClientVersionX@
746-
-- must be added. See #2830 for a template on how to do this.
747-
where
748-
v8 = ShelleyNodeToClientVersion8
749-
v9 = ShelleyNodeToClientVersion9
750-
v10 = ShelleyNodeToClientVersion10
751-
v11 = ShelleyNodeToClientVersion11
752-
v12 = ShelleyNodeToClientVersion12
753-
754752
{-------------------------------------------------------------------------------
755753
Auxiliary
756754
-------------------------------------------------------------------------------}

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/Serialisation.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import Ouroboros.Consensus.HardFork.Combinator.PartialConfig
3232
import Ouroboros.Consensus.HardFork.History.EpochInfo
3333
import Ouroboros.Consensus.HardFork.Simple
3434
import Ouroboros.Consensus.HeaderValidation
35+
import Ouroboros.Consensus.Ledger.Query
3536
import Ouroboros.Consensus.Ledger.SupportsMempool (GenTxId)
3637
import Ouroboros.Consensus.Node.Run
3738
import Ouroboros.Consensus.Node.Serialisation
@@ -294,7 +295,7 @@ instance ShelleyBasedEra era => SerialiseNodeToClient (ShelleyBlock proto era) (
294295
instance ShelleyCompatible proto era
295296
=> SerialiseNodeToClient (ShelleyBlock proto era) (SomeSecond BlockQuery (ShelleyBlock proto era)) where
296297
encodeNodeToClient _ version (SomeSecond q)
297-
| querySupportedVersion q version
298+
| blockQueryIsSupportedOnVersion q version
298299
= encodeShelleyQuery q
299300
| otherwise
300301
= throw $ ShelleyEncoderUnsupportedQuery (SomeSecond q) version

ouroboros-consensus-cardano/src/unstable-shelley-testlib/Test/Consensus/Shelley/Generators.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,5 +278,5 @@ instance CanMock proto era
278278
=> Arbitrary (WithVersion ShelleyNodeToClientVersion (SomeSecond BlockQuery (ShelleyBlock proto era))) where
279279
arbitrary = do
280280
query@(SomeSecond q) <- arbitrary
281-
version <- arbitrary `suchThat` querySupportedVersion q
281+
version <- arbitrary `suchThat` blockQueryIsSupportedOnVersion q
282282
return $ WithVersion version query
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!-- empty, only two redundant constraints were removed -->

ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Network/NodeToClient.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ type ClientCodecs blk m =
180180
defaultCodecs :: forall m blk.
181181
( MonadST m
182182
, SerialiseNodeToClientConstraints blk
183-
, ShowQuery (BlockQuery blk)
184183
, StandardHash blk
185184
, Serialise (HeaderHash blk)
186185
)
@@ -241,7 +240,6 @@ defaultCodecs ccfg version networkVersion = Codecs {
241240
clientCodecs :: forall m blk.
242241
( MonadST m
243242
, SerialiseNodeToClientConstraints blk
244-
, ShowQuery (BlockQuery blk)
245243
, StandardHash blk
246244
, Serialise (HeaderHash blk)
247245
)

ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator/A.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ data instance BlockQuery BlockA result
358358

359359
instance BlockSupportsLedgerQuery BlockA where
360360
answerBlockQuery _ qry = case qry of {}
361+
blockQueryIsSupportedOnVersion qry _ = case qry of {}
361362

362363
instance SameDepIndex (BlockQuery BlockA) where
363364
sameDepIndex qry _qry' = case qry of {}

ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator/B.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ data instance BlockQuery BlockB result
291291

292292
instance BlockSupportsLedgerQuery BlockB where
293293
answerBlockQuery _ qry = case qry of {}
294+
blockQueryIsSupportedOnVersion qry _ = case qry of {}
294295

295296
instance SameDepIndex (BlockQuery BlockB) where
296297
sameDepIndex qry _qry' = case qry of {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### Breaking
2+
3+
- Add method `blockQueryIsSupportedOnVersion` to `BlockSupportsLedgerQuery`.
4+
- Export new function `querySupportedVersions`.

0 commit comments

Comments
 (0)