Skip to content
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

Added a new query for a snapshot of big ledger peers #521

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cardano-api/internal/Cardano/Api/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module Cardano.Api.Query
, LedgerState (..)
, getProgress
, getSlotForRelativeTime
, decodeBigLedgerPeerSnapshot

-- * Internal conversion functions
, toLedgerUTxO
Expand Down Expand Up @@ -112,6 +113,7 @@ import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus
import qualified Ouroboros.Consensus.Shelley.Ledger.Query.Types as Consensus
import Ouroboros.Network.Block (Serialised (..))
import Ouroboros.Network.NodeToClient.Version (NodeToClientVersion (..))
import Ouroboros.Network.PeerSelection.LedgerPeers.Type (LedgerPeerSnapshot)
import Ouroboros.Network.Protocol.LocalStateQuery.Client (Some (..))

import Control.Monad.Trans.Except
Expand Down Expand Up @@ -296,6 +298,8 @@ data QueryInShelleyBasedEra era result where
QueryStakeVoteDelegatees
:: Set StakeCredential
-> QueryInShelleyBasedEra era (Map StakeCredential (Ledger.DRep StandardCrypto))
QueryLedgerPeerSnapshot
:: QueryInShelleyBasedEra era (Serialised LedgerPeerSnapshot)

-- | Mapping for queries in Shelley-based eras returning minimal node-to-client protocol versions. More
-- information about queries versioning can be found:
Expand All @@ -314,6 +318,7 @@ instance NodeToClientVersionOf (QueryInShelleyBasedEra era result) where
nodeToClientVersionOf QueryDebugLedgerState = NodeToClientV_9
nodeToClientVersionOf QueryProtocolState = NodeToClientV_9
nodeToClientVersionOf QueryCurrentEpochState = NodeToClientV_9
nodeToClientVersionOf QueryLedgerPeerSnapshot = NodeToClientV_9
-- Babbage >= v13
nodeToClientVersionOf (QueryPoolState _) = NodeToClientV_14
nodeToClientVersionOf (QueryPoolDistribution _) = NodeToClientV_14
Expand Down Expand Up @@ -468,6 +473,11 @@ decodeStakeSnapshot
-> Either DecoderError (StakeSnapshot era)
decodeStakeSnapshot (SerialisedStakeSnapshots (Serialised ls)) = StakeSnapshot <$> Plain.decodeFull ls

decodeBigLedgerPeerSnapshot
:: Serialised LedgerPeerSnapshot
-> Either DecoderError LedgerPeerSnapshot
decodeBigLedgerPeerSnapshot = Plain.decodeFull . unSerialised

toShelleyAddrSet
:: CardanoEra era
-> Set AddressAny
Expand Down Expand Up @@ -703,6 +713,8 @@ toConsensusQueryShelleyBased sbe = \case
where
creds' :: Set (Shelley.Credential Shelley.Staking StandardCrypto)
creds' = Set.map toShelleyStakeCredential creds
QueryLedgerPeerSnapshot ->
Some (consensusQueryInEraInMode era (Consensus.GetCBOR Consensus.GetBigLedgerPeerSnapshot))
where
era = toCardanoEra sbe

Expand Down Expand Up @@ -984,6 +996,11 @@ fromConsensusQueryResultShelleyBased sbe sbeQuery q' r' =
Consensus.GetFilteredVoteDelegatees{} ->
Map.mapKeys fromShelleyStakeCredential r'
_ -> fromConsensusQueryResultMismatch
QueryLedgerPeerSnapshot{} ->
case q' of
Consensus.GetCBOR Consensus.GetBigLedgerPeerSnapshot ->
r'
_ -> fromConsensusQueryResultMismatch

-- | This should /only/ happen if we messed up the mapping in 'toConsensusQuery'
-- and 'fromConsensusQueryResult' so they are inconsistent with each other.
Expand Down
19 changes: 17 additions & 2 deletions cardano-api/internal/Cardano/Api/Query/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Cardano.Api.Query.Expr
, queryStakeSnapshot
, querySystemStart
, queryUtxo
, queryLedgerPeerSnapshot
, L.MemberStatus (..)
, L.CommitteeMembersState (..)
, queryCommitteeMembersState
Expand Down Expand Up @@ -64,6 +65,8 @@ import Cardano.Ledger.SafeHash
import qualified Cardano.Ledger.Shelley.LedgerState as L
import Cardano.Slotting.Slot
import Ouroboros.Consensus.HardFork.Combinator.AcrossEras as Consensus
import Ouroboros.Network.Block (Serialised)
import Ouroboros.Network.PeerSelection.LedgerPeers (LedgerPeerSnapshot)

import Data.Map (Map)
import Data.Set (Set)
Expand Down Expand Up @@ -132,6 +135,19 @@ queryDebugLedgerState
queryDebugLedgerState sbe =
queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe QueryDebugLedgerState

queryLedgerPeerSnapshot
:: ()
=> ShelleyBasedEra era
-> LocalStateQueryExpr
block
point
QueryInMode
r
IO
(Either UnsupportedNtcVersionError (Either EraMismatch (Serialised LedgerPeerSnapshot)))
queryLedgerPeerSnapshot sbe =
queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe QueryLedgerPeerSnapshot

queryEraHistory
:: ()
=> LocalStateQueryExpr block point QueryInMode r IO (Either UnsupportedNtcVersionError EraHistory)
Expand Down Expand Up @@ -303,8 +319,7 @@ queryStakePoolParameters
(Either UnsupportedNtcVersionError (Either EraMismatch (Map PoolId StakePoolParameters)))
queryStakePoolParameters sbe poolIds
| S.null poolIds = pure . pure $ pure mempty
| otherwise =
queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe $ QueryStakePoolParameters poolIds
| otherwise = queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe $ QueryStakePoolParameters poolIds

queryStakePools
:: ()
Expand Down
1 change: 1 addition & 0 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ module Cardano.Api
, queryCurrentEpochState
, queryCurrentEra
, queryDebugLedgerState
, queryLedgerPeerSnapshot
, queryEpoch
, queryConstitutionHash
, queryEraHistory
Expand Down
Loading