diff --git a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/NetworkProtocolVersion.hs b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/NetworkProtocolVersion.hs index 283312674d..be56523d45 100644 --- a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/NetworkProtocolVersion.hs +++ b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/NetworkProtocolVersion.hs @@ -37,6 +37,9 @@ data ShelleyNodeToClientVersion = -- | New queries introduced: GetConstitutionHash, GetFilteredVoteDelegatees | ShelleyNodeToClientVersion8 + + -- | New queries introduced: GetPeerSnapshot + | ShelleyNodeToClientVersion9 deriving (Show, Eq, Ord, Enum, Bounded) instance HasNetworkProtocolVersion (ShelleyBlock proto era) where @@ -63,6 +66,7 @@ instance SupportedNetworkProtocolVersion (ShelleyBlock proto era) where , (NodeToClientV_14, ShelleyNodeToClientVersion6) , (NodeToClientV_15, ShelleyNodeToClientVersion7) , (NodeToClientV_16, ShelleyNodeToClientVersion8) + , (NodeToClientV_16, ShelleyNodeToClientVersion9) ] latestReleasedNodeVersion = latestReleasedNodeVersionDefault diff --git a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query.hs b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query.hs index def3c190a1..5db5670a8f 100644 --- a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query.hs +++ b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query.hs @@ -58,6 +58,7 @@ import Codec.CBOR.Encoding (Encoding) import qualified Codec.CBOR.Encoding as CBOR import Codec.Serialise (decode, encode) import Control.DeepSeq (NFData) +import Data.Bifunctor (second) import Data.Kind (Type) import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map @@ -72,8 +73,10 @@ import Lens.Micro.Extras (view) import Ouroboros.Consensus.Block import Ouroboros.Consensus.Config import Ouroboros.Consensus.HeaderValidation +import Ouroboros.Consensus.Ledger.Basics import Ouroboros.Consensus.Ledger.Extended import Ouroboros.Consensus.Ledger.Query +import Ouroboros.Consensus.Ledger.SupportsPeerSelection import Ouroboros.Consensus.Protocol.Abstract (ChainDepState) import Ouroboros.Consensus.Shelley.Eras (EraCrypto) import qualified Ouroboros.Consensus.Shelley.Eras as SE @@ -82,11 +85,14 @@ import Ouroboros.Consensus.Shelley.Ledger.Config import Ouroboros.Consensus.Shelley.Ledger.Ledger import Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion (ShelleyNodeToClientVersion (..)) +import Ouroboros.Consensus.Shelley.Ledger.PeerSelection () import Ouroboros.Consensus.Shelley.Ledger.Query.PParamsLegacyEncoder import Ouroboros.Consensus.Shelley.Protocol.Abstract (ProtoCrypto) import Ouroboros.Consensus.Util (ShowProxy (..)) import Ouroboros.Network.Block (Serialised (..), decodePoint, encodePoint, mkSerialised) +import Ouroboros.Network.PeerSelection.LedgerPeers.Type +import Ouroboros.Network.PeerSelection.LedgerPeers.Util {------------------------------------------------------------------------------- QueryLedger @@ -283,6 +289,13 @@ data instance BlockQuery (ShelleyBlock proto era) :: Type -> Type where => Set (SL.Credential 'SL.Staking (EraCrypto era)) -> BlockQuery (ShelleyBlock proto era) (VoteDelegatees (EraCrypto era)) + -- | Obtain a snapshot of big ledger peers. CLI can serialize these, + -- and if made available to the node by topology configuration, + -- the diffusion layer can use these peers when syncing up from scratch + -- or stale ledger state - especially useful for Genesis mode + GetPeerSnapshot + :: BlockQuery (ShelleyBlock proto era) LedgerPeerSnapshot + -- WARNING: please add new queries to the end of the list and stick to this -- order in all other pattern matches on queries. This helps in particular -- with the en/decoders, as we want the CBOR tags to be ordered. @@ -434,6 +447,11 @@ instance (ShelleyCompatible proto era, ProtoCrypto proto ~ crypto) SL.queryCommitteeMembersState coldCreds hotCreds statuses st GetFilteredVoteDelegatees stakeCreds -> getFilteredVoteDelegatees st stakeCreds + GetPeerSnapshot -> + let slot = getTipSlot lst + ledgerPeers = second (fmap stakePoolRelayAccessPoint) <$> getPeers lst + bigLedgerPeers = accBigPoolStake ledgerPeers + in LedgerPeerSnapshot (slot, bigLedgerPeers) where lcfg = configLedger $ getExtLedgerCfg cfg globals = shelleyLedgerGlobals lcfg @@ -585,6 +603,8 @@ instance SameDepIndex (BlockQuery (ShelleyBlock proto era)) where | otherwise = Nothing sameDepIndex GetFilteredVoteDelegatees {} _ = Nothing + sameDepIndex GetPeerSnapshot GetPeerSnapshot = Just Refl + sameDepIndex GetPeerSnapshot _ = Nothing deriving instance Eq (BlockQuery (ShelleyBlock proto era) result) deriving instance Show (BlockQuery (ShelleyBlock proto era) result) @@ -620,6 +640,7 @@ instance ShelleyCompatible proto era => ShowQuery (BlockQuery (ShelleyBlock prot GetDRepStakeDistr {} -> show GetCommitteeMembersState {} -> show GetFilteredVoteDelegatees {} -> show + GetPeerSnapshot -> show -- | Is the given query supported by the given 'ShelleyNodeToClientVersion'? querySupportedVersion :: BlockQuery (ShelleyBlock proto era) result -> ShelleyNodeToClientVersion -> Bool @@ -653,6 +674,7 @@ querySupportedVersion = \case GetDRepStakeDistr {} -> (>= v8) GetCommitteeMembersState {} -> (>= v8) GetFilteredVoteDelegatees {} -> (>= v8) + GetPeerSnapshot -> (>= v9) -- WARNING: when adding a new query, a new @ShelleyNodeToClientVersionX@ -- must be added. See #2830 for a template on how to do this. where @@ -664,6 +686,7 @@ querySupportedVersion = \case v6 = ShelleyNodeToClientVersion6 v7 = ShelleyNodeToClientVersion7 v8 = ShelleyNodeToClientVersion8 + v9 = ShelleyNodeToClientVersion9 {------------------------------------------------------------------------------- Auxiliary @@ -774,9 +797,11 @@ encodeShelleyQuery query = case query of CBOR.encodeListLen 4 <> CBOR.encodeWord8 27 <> toCBOR coldCreds <> toCBOR hotCreds <> LC.toEraCBOR @era statuses GetFilteredVoteDelegatees stakeCreds -> CBOR.encodeListLen 2 <> CBOR.encodeWord8 28 <> LC.toEraCBOR @era stakeCreds + GetPeerSnapshot -> + CBOR.encodeListLen 1 <> CBOR.encodeWord8 29 decodeShelleyQuery :: - forall era proto. ShelleyBasedEra era + forall era proto . (ShelleyBasedEra era) => forall s. Decoder s (SomeSecond BlockQuery (ShelleyBlock proto era)) decodeShelleyQuery = do len <- CBOR.decodeListLen @@ -830,6 +855,7 @@ decodeShelleyQuery = do return $ SomeSecond $ GetCommitteeMembersState coldCreds hotCreds statuses (2, 28) -> requireCG $ do SomeSecond . GetFilteredVoteDelegatees <$> LC.fromEraCBOR @era + (1, 29) -> return $ SomeSecond GetPeerSnapshot _ -> failmsg "invalid" encodeShelleyResult :: @@ -866,6 +892,7 @@ encodeShelleyResult v query = case query of GetDRepStakeDistr {} -> LC.toEraCBOR @era GetCommitteeMembersState {} -> LC.toEraCBOR @era GetFilteredVoteDelegatees {} -> LC.toEraCBOR @era + GetPeerSnapshot -> toCBOR decodeShelleyResult :: forall proto era result. ShelleyCompatible proto era @@ -902,6 +929,7 @@ decodeShelleyResult v query = case query of GetDRepStakeDistr {} -> LC.fromEraCBOR @era GetCommitteeMembersState {} -> LC.fromEraCBOR @era GetFilteredVoteDelegatees {} -> LC.fromEraCBOR @era + GetPeerSnapshot -> fromCBOR currentPParamsEnDecoding :: forall era s. diff --git a/ouroboros-consensus-diffusion/CHANGELOG.md b/ouroboros-consensus-diffusion/CHANGELOG.md index 6be934ded1..3fe14cad78 100644 --- a/ouroboros-consensus-diffusion/CHANGELOG.md +++ b/ouroboros-consensus-diffusion/CHANGELOG.md @@ -12,6 +12,9 @@ NOTE: version jumps from `0.13.0.0` to `0.15.0.0` because `0.14.0.0` was created - Updated `ouroboros-consensus-diffusion` to use `ouroboros-network-0.14.0.0`. `LowLevelRounNodeArgs` and `NodeKernel` records hold `PublicPeerSelectionState` variable. +- Added `GetPeerSnapshot` block query + +### Non-Breaking ## 0.13.0.0 — 2024-04-03