diff --git a/cardano-api/CHANGELOG.md b/cardano-api/CHANGELOG.md index 6e8fb63d21..ead53cf0d7 100644 --- a/cardano-api/CHANGELOG.md +++ b/cardano-api/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog for cardano-api +- New query `queryLedgerPeerSnapshot` + [PR 521](https://github.com/IntersectMBO/cardano-api/pull/521) + ## 8.45.0.0 - Sort metadata keys for no-schema json for canonical CBOR diff --git a/cardano-api/internal/Cardano/Api/Query.hs b/cardano-api/internal/Cardano/Api/Query.hs index 4fa03c05e0..b460fcfbe0 100644 --- a/cardano-api/internal/Cardano/Api/Query.hs +++ b/cardano-api/internal/Cardano/Api/Query.hs @@ -124,6 +124,7 @@ import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger 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 @@ -324,6 +325,9 @@ data QueryInShelleyBasedEra era result where :: 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: @@ -342,6 +346,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 @@ -705,6 +710,9 @@ toConsensusQueryShelleyBased sbe = \case creds' :: Set (Shelley.Credential Shelley.Staking StandardCrypto) creds' = Set.map toShelleyStakeCredential creds + QueryLedgerPeerSnapshot -> + Some (consensusQueryInEraInMode era (Consensus.GetCBOR Consensus.GetPeerSnapshot)) + where era = shelleyBasedToCardanoEra sbe @@ -969,6 +977,11 @@ fromConsensusQueryResultShelleyBased _ QueryStakeVoteDelegatees{} q' delegs' = -> Map.mapKeys fromShelleyStakeCredential delegs' _ -> fromConsensusQueryResultMismatch +fromConsensusQueryResultShelleyBased _ QueryLedgerPeerSnapshot q' r' = + case q' of + Consensus.GetCBOR Consensus.GetPeerSnapshot -> r' + _ -> fromConsensusQueryResultMismatch + -- | This should /only/ happen if we messed up the mapping in 'toConsensusQuery' -- and 'fromConsensusQueryResult' so they are inconsistent with each other. -- diff --git a/cardano-api/internal/Cardano/Api/Query/Expr.hs b/cardano-api/internal/Cardano/Api/Query/Expr.hs index ed019c9582..21e0b538be 100644 --- a/cardano-api/internal/Cardano/Api/Query/Expr.hs +++ b/cardano-api/internal/Cardano/Api/Query/Expr.hs @@ -25,6 +25,7 @@ module Cardano.Api.Query.Expr , queryStakeSnapshot , querySystemStart , queryUtxo + , queryLedgerPeerSnapshot , L.MemberStatus (..) , L.CommitteeMembersState (..) , queryCommitteeMembersState @@ -60,6 +61,8 @@ import qualified Cardano.Ledger.Keys as L import Cardano.Ledger.SafeHash 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) @@ -98,6 +101,12 @@ 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) queryEraHistory = diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index fc966e074c..54e544bfb8 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -944,6 +944,7 @@ module Cardano.Api ( queryCurrentEpochState, queryCurrentEra, queryDebugLedgerState, + queryLedgerPeerSnapshot, queryEpoch, queryConstitutionHash, queryEraHistory,