Skip to content

Commit

Permalink
Adds new query for a snapshot of big ledger peers
Browse files Browse the repository at this point in the history
This change introduces a new query tag and handler
to support retrieval of a snapshot of big ledger peers
from the current tip of a node.
  • Loading branch information
crocodile-dentist committed Jun 17, 2024
1 parent bd58f07 commit bd4afe0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cardano-api/internal/Cardano/Api/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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.GetBigLedgerPeerSnapshot))

where
era = shelleyBasedToCardanoEra sbe

Expand Down Expand Up @@ -969,6 +977,11 @@ fromConsensusQueryResultShelleyBased _ QueryStakeVoteDelegatees{} q' delegs' =
-> Map.mapKeys fromShelleyStakeCredential delegs'
_ -> fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased _ QueryLedgerPeerSnapshot q' serLedgerPeerSnapshot =
case q' of
Consensus.GetCBOR Consensus.GetBigLedgerPeerSnapshot -> serLedgerPeerSnapshot
_ -> fromConsensusQueryResultMismatch

-- | This should /only/ happen if we messed up the mapping in 'toConsensusQuery'
-- and 'fromConsensusQueryResult' so they are inconsistent with each other.
--
Expand Down
9 changes: 9 additions & 0 deletions cardano-api/internal/Cardano/Api/Query/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Cardano.Api.Query.Expr
, queryStakeSnapshot
, querySystemStart
, queryUtxo
, queryLedgerPeerSnapshot
, L.MemberStatus (..)
, L.CommitteeMembersState (..)
, queryCommitteeMembersState
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 =
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 @@ -947,6 +947,7 @@ module Cardano.Api (
queryCurrentEpochState,
queryCurrentEra,
queryDebugLedgerState,
queryLedgerPeerSnapshot,
queryEpoch,
queryConstitutionHash,
queryEraHistory,
Expand Down

0 comments on commit bd4afe0

Please sign in to comment.