diff --git a/cardano-api/internal/Cardano/Api/Query.hs b/cardano-api/internal/Cardano/Api/Query.hs index 2d1ac760e0..dd9d9c65c8 100644 --- a/cardano-api/internal/Cardano/Api/Query.hs +++ b/cardano-api/internal/Cardano/Api/Query.hs @@ -57,6 +57,7 @@ module Cardano.Api.Query , LedgerState (..) , getProgress , getSlotForRelativeTime + , decodeBigLedgerPeerSnapshot -- * Internal conversion functions , toLedgerUTxO @@ -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 @@ -300,6 +302,8 @@ data QueryInShelleyBasedEra era result where QueryProposals :: Set (L.GovActionId StandardCrypto) -> QueryInShelleyBasedEra era (Seq (L.GovActionState (ShelleyLedgerEra era))) + 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: @@ -333,6 +337,7 @@ instance NodeToClientVersionOf (QueryInShelleyBasedEra era result) where nodeToClientVersionOf QueryCommitteeMembersState{} = NodeToClientV_16 nodeToClientVersionOf QueryStakeVoteDelegatees{} = NodeToClientV_16 nodeToClientVersionOf QueryProposals{} = NodeToClientV_17 + nodeToClientVersionOf QueryLedgerPeerSnapshot = NodeToClientV_19 deriving instance Show (QueryInShelleyBasedEra era result) @@ -473,6 +478,11 @@ decodeStakeSnapshot -> Either DecoderError (StakeSnapshot era) decodeStakeSnapshot (SerialisedStakeSnapshots (Serialised ls)) = StakeSnapshot <$> Plain.decodeFull ls +decodeBigLedgerPeerSnapshot + :: Serialised LedgerPeerSnapshot + -> Either (LBS.ByteString, DecoderError) LedgerPeerSnapshot +decodeBigLedgerPeerSnapshot (Serialised lps) = first (lps,) (Plain.decodeFull lps) + toShelleyAddrSet :: CardanoEra era -> Set AddressAny @@ -718,6 +728,8 @@ toConsensusQueryShelleyBased sbe = \case (consensusQueryInEraInMode era (Consensus.GetProposals govActs)) ) sbe + QueryLedgerPeerSnapshot -> + Some (consensusQueryInEraInMode era (Consensus.GetCBOR Consensus.GetBigLedgerPeerSnapshot)) where era = toCardanoEra sbe @@ -1004,6 +1016,11 @@ fromConsensusQueryResultShelleyBased sbe sbeQuery q' r' = Consensus.GetProposals{} -> 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. diff --git a/cardano-api/internal/Cardano/Api/Query/Expr.hs b/cardano-api/internal/Cardano/Api/Query/Expr.hs index f7cf15a16b..03cf44b308 100644 --- a/cardano-api/internal/Cardano/Api/Query/Expr.hs +++ b/cardano-api/internal/Cardano/Api/Query/Expr.hs @@ -27,6 +27,7 @@ module Cardano.Api.Query.Expr , queryStakeSnapshot , querySystemStart , queryUtxo + , queryLedgerPeerSnapshot , L.MemberStatus (..) , L.CommitteeMembersState (..) , queryCommitteeMembersState @@ -67,6 +68,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.Sequence (Seq) @@ -136,6 +139,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) diff --git a/cardano-api/internal/Cardano/Api/ReexposeNetwork.hs b/cardano-api/internal/Cardano/Api/ReexposeNetwork.hs index d9ea8c0731..e1d1e5ba2a 100644 --- a/cardano-api/internal/Cardano/Api/ReexposeNetwork.hs +++ b/cardano-api/internal/Cardano/Api/ReexposeNetwork.hs @@ -1,5 +1,12 @@ -module Cardano.Api.ReexposeNetwork (Target (..), Serialised (..), SubmitResult (..)) where +module Cardano.Api.ReexposeNetwork + ( LedgerPeerSnapshot (..) + , Target (..) + , Serialised (..) + , SubmitResult (..) + ) +where import Ouroboros.Network.Block (Serialised (..)) +import Ouroboros.Network.PeerSelection.LedgerPeers.Type (LedgerPeerSnapshot (..)) import Ouroboros.Network.Protocol.LocalStateQuery.Type (Target (..)) import Ouroboros.Network.Protocol.LocalTxSubmission.Type (SubmitResult (..)) diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index 4ca9994569..32e457aea5 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -998,6 +998,7 @@ module Cardano.Api , queryCurrentEpochState , queryCurrentEra , queryDebugLedgerState + , queryLedgerPeerSnapshot , queryEpoch , queryConstitutionHash , queryEraHistory diff --git a/cardano-api/src/Cardano/Api/Shelley.hs b/cardano-api/src/Cardano/Api/Shelley.hs index 6ae36572f7..615bde4346 100644 --- a/cardano-api/src/Cardano/Api/Shelley.hs +++ b/cardano-api/src/Cardano/Api/Shelley.hs @@ -244,6 +244,7 @@ module Cardano.Api.Shelley , StakeSnapshot (..) , SerialisedStakeSnapshots (..) , decodeStakeSnapshot + , decodeBigLedgerPeerSnapshot , UTxO (..) , AcquiringFailure (..) , SystemStart (..)