Skip to content

Commit 1347dad

Browse files
committed
New GetMaxMajorProtocolVersion shelley query
1 parent ae6a3c4 commit 1347dad

File tree

7 files changed

+75
-1
lines changed

7 files changed

+75
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
-->
6+
7+
<!--
8+
### Patch
9+
10+
- A bullet item for the Patch category.
11+
12+
-->
13+
<!--
14+
### Non-Breaking
15+
16+
- A bullet item for the Non-Breaking category.
17+
18+
-->
19+
20+
### Breaking
21+
22+
- Expose new query `GetMaxMajorProtocolVersion` as a Shelley query, for getting
23+
the max known protocol version for a node.

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ import Ouroboros.Consensus.Ledger.Query
9696
import Ouroboros.Consensus.Ledger.SupportsPeerSelection
9797
import Ouroboros.Consensus.Ledger.SupportsProtocol
9898
import Ouroboros.Consensus.Protocol.Abstract (ChainDepState)
99+
import Ouroboros.Consensus.Protocol.Praos.Common
99100
import qualified Ouroboros.Consensus.Shelley.Eras as SE
100101
import Ouroboros.Consensus.Shelley.Ledger.Block
101102
import Ouroboros.Consensus.Shelley.Ledger.Config
@@ -360,6 +361,8 @@ data instance BlockQuery (ShelleyBlock proto era) fp result where
360361
-- pools, in an extensible fashion.
361362
GetStakeDistribution2 ::
362363
BlockQuery (ShelleyBlock proto era) QFNoTables SL.PoolDistr
364+
GetMaxMajorProtocolVersion ::
365+
BlockQuery (ShelleyBlock proto era) QFNoTables MaxMajorProtVer
363366

364367
-- WARNING: please add new queries to the end of the list and stick to this
365368
-- order in all other pattern matches on queries. This helps in particular
@@ -534,6 +537,11 @@ instance
534537
in SL.calculatePoolDistr' (maybe (const True) (flip Set.member) mPoolIds) stakeSet
535538
GetStakeDistribution2 ->
536539
SL.poolsByTotalStakeFraction globals st
540+
GetMaxMajorProtocolVersion ->
541+
protoMaxMajorPV
542+
. configConsensus
543+
. getExtLedgerCfg
544+
$ cfg
537545
where
538546
lcfg = configLedger $ getExtLedgerCfg cfg
539547
globals = shelleyLedgerGlobals lcfg
@@ -592,6 +600,7 @@ instance
592600
QueryStakePoolDefaultVote{} -> (>= v12)
593601
GetPoolDistr2{} -> (>= v13)
594602
GetStakeDistribution2{} -> (>= v13)
603+
GetMaxMajorProtocolVersion -> (>= v13)
595604
where
596605
-- WARNING: when adding a new query, a new @ShelleyNodeToClientVersionX@
597606
-- must be added. See #2830 for a template on how to do this.
@@ -759,6 +768,8 @@ instance SameDepIndex2 (BlockQuery (ShelleyBlock proto era)) where
759768
sameDepIndex2 GetPoolDistr2{} _ = Nothing
760769
sameDepIndex2 GetStakeDistribution2{} GetStakeDistribution2{} = Just Refl
761770
sameDepIndex2 GetStakeDistribution2{} _ = Nothing
771+
sameDepIndex2 GetMaxMajorProtocolVersion{} GetMaxMajorProtocolVersion{} = Just Refl
772+
sameDepIndex2 GetMaxMajorProtocolVersion{} _ = Nothing
762773

763774
deriving instance Eq (BlockQuery (ShelleyBlock proto era) fp result)
764775
deriving instance Show (BlockQuery (ShelleyBlock proto era) fp result)
@@ -803,6 +814,7 @@ instance ShelleyCompatible proto era => ShowQuery (BlockQuery (ShelleyBlock prot
803814
QueryStakePoolDefaultVote{} -> show
804815
GetPoolDistr2{} -> show
805816
GetStakeDistribution2{} -> show
817+
GetMaxMajorProtocolVersion{} -> show
806818

807819
{-------------------------------------------------------------------------------
808820
Auxiliary
@@ -929,6 +941,8 @@ encodeShelleyQuery query = case query of
929941
CBOR.encodeListLen 2 <> CBOR.encodeWord8 36 <> toCBOR poolids
930942
GetStakeDistribution2 ->
931943
CBOR.encodeListLen 1 <> CBOR.encodeWord8 37
944+
GetMaxMajorProtocolVersion ->
945+
CBOR.encodeListLen 1 <> CBOR.encodeWord8 38
932946

933947
decodeShelleyQuery ::
934948
forall era proto.
@@ -1002,6 +1016,7 @@ decodeShelleyQuery = do
10021016
(2, 35) -> requireCG $ SomeBlockQuery . QueryStakePoolDefaultVote <$> LC.fromEraCBOR @era
10031017
(2, 36) -> SomeBlockQuery . GetPoolDistr2 <$> fromCBOR
10041018
(1, 37) -> return $ SomeBlockQuery GetStakeDistribution2
1019+
(1, 38) -> return $ SomeBlockQuery GetMaxMajorProtocolVersion
10051020
_ -> failmsg "invalid"
10061021

10071022
encodeShelleyResult ::
@@ -1050,6 +1065,7 @@ encodeShelleyResult v query = case query of
10501065
QueryStakePoolDefaultVote{} -> toCBOR
10511066
GetPoolDistr2{} -> LC.toEraCBOR @era
10521067
GetStakeDistribution2{} -> LC.toEraCBOR @era
1068+
GetMaxMajorProtocolVersion -> toCBOR
10531069

10541070
decodeShelleyResult ::
10551071
forall proto era fp result.
@@ -1097,6 +1113,7 @@ decodeShelleyResult v query = case query of
10971113
QueryStakePoolDefaultVote{} -> fromCBOR
10981114
GetPoolDistr2{} -> LC.fromEraCBOR @era
10991115
GetStakeDistribution2 -> LC.fromEraCBOR @era
1116+
GetMaxMajorProtocolVersion -> fromCBOR
11001117

11011118
currentPParamsEnDecoding ::
11021119
forall era s.

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Protocol/Abstract.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import Ouroboros.Consensus.Protocol.Abstract
6060
, ValidateView
6161
)
6262
import Ouroboros.Consensus.Protocol.Ledger.HotKey (HotKey)
63+
import Ouroboros.Consensus.Protocol.Praos.Common (HasMaxMajorProtVer)
6364
import Ouroboros.Consensus.Protocol.Signed (SignedHeader)
6465
import Ouroboros.Consensus.Util.Condense (Condense (..))
6566

@@ -201,5 +202,6 @@ class
201202
, ProtocolHeaderSupportsLedger proto
202203
, Serialise (ChainDepState proto)
203204
, SignedHeader (ShelleyProtocolHeader proto)
205+
, HasMaxMajorProtVer proto
204206
) =>
205207
ShelleyProtocol proto
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
-->
6+
7+
<!--
8+
### Patch
9+
10+
- A bullet item for the Patch category.
11+
12+
-->
13+
<!--
14+
### Non-Breaking
15+
16+
- A bullet item for the Non-Breaking category.
17+
18+
-->
19+
### Breaking
20+
21+
- Add new `HasMaxMajorProtVer` class for consensus protocols.

ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ instance PraosCrypto c => NoThunks (ConsensusConfig (Praos c))
260260

261261
type PraosValidateView c = Views.HeaderView c
262262

263+
instance HasMaxMajorProtVer (Praos c) where
264+
protoMaxMajorPV = praosMaxMajorPV . praosParams
265+
263266
{-------------------------------------------------------------------------------
264267
ConsensusProtocol
265268
-------------------------------------------------------------------------------}

ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos/Common.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
-- | Various things common to iterations of the Praos protocol.
1010
module Ouroboros.Consensus.Protocol.Praos.Common
1111
( MaxMajorProtVer (..)
12+
, HasMaxMajorProtVer (..)
1213
, PraosCanBeLeader (..)
1314
, PraosChainSelectView (..)
1415
, VRFTiebreakerFlavor (..)
@@ -21,6 +22,7 @@ module Ouroboros.Consensus.Protocol.Praos.Common
2122
import qualified Cardano.Crypto.VRF as VRF
2223
import Cardano.Ledger.BaseTypes (Nonce)
2324
import qualified Cardano.Ledger.BaseTypes as SL
25+
import Cardano.Ledger.Binary (FromCBOR, ToCBOR)
2426
import Cardano.Ledger.Keys (KeyHash, KeyRole (BlockIssuer))
2527
import qualified Cardano.Ledger.Shelley.API as SL
2628
import Cardano.Protocol.Crypto (Crypto, VRF)
@@ -59,7 +61,10 @@ newtype MaxMajorProtVer = MaxMajorProtVer
5961
{ getMaxMajorProtVer :: SL.Version
6062
}
6163
deriving (Eq, Show, Generic)
62-
deriving newtype NoThunks
64+
deriving newtype (NoThunks, ToCBOR, FromCBOR)
65+
66+
class HasMaxMajorProtVer proto where
67+
protoMaxMajorPV :: ConsensusConfig proto -> MaxMajorProtVer
6368

6469
-- | View of the tip of a header fragment for chain selection.
6570
data PraosChainSelectView c = PraosChainSelectView

ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/TPraos.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ data instance ConsensusConfig (TPraos c) = TPraosConfig
257257

258258
instance SL.PraosCrypto c => NoThunks (ConsensusConfig (TPraos c))
259259

260+
instance HasMaxMajorProtVer (TPraos c) where
261+
protoMaxMajorPV = tpraosMaxMajorPV . tpraosParams
262+
260263
-- | Transitional Praos consensus state.
261264
--
262265
-- In addition to the 'ChainDepState' provided by the ledger, we track the slot

0 commit comments

Comments
 (0)