Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetRewardInfoPools local state query #3423

Merged
merged 5 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ instance CardanoHardForkConstraints c
CardanoNodeToClientVersion5 -> "CardanoNodeToClientVersion5"
CardanoNodeToClientVersion6 -> "CardanoNodeToClientVersion6"
CardanoNodeToClientVersion7 -> "CardanoNodeToClientVersion7"
CardanoNodeToClientVersion8 -> "CardanoNodeToClientVersion8"
_ -> error $ "Unknown version: " <> show blockVersion
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�� X �TF� ���b�Nެ�K��wy�=�Th�|Y
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��X��ts.���?9Z�E����P#�� 2�d
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��X�1���s��]k?�ժ�P�[{%A��X �����-�ò^46���R�>Žb�{L
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�� X ����8����o�fo&&���&n�s�s$&�
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��X��ts.���?9Z�E����P#�� 2��
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��X�1���s��]k?�ժ�P�[{%A��X �����-�ò^46���R�>Žb�{L
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�� X ��E<���p���2W@Y��rJt=&��v��j
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��X��ts.���?9Z�E����P#�� 2�d
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��X�1���s��]k?�ժ�P�[{%A��X �����-�ò^46���R�>Žb�{L
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�� X ��� u��'9Ki�(�׺y���C����)�l
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��X��ts.���?9Z�E����P#�� 2�d
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��X�1���s��]k?�ժ�P�[{%A��X �����-�ò^46���R�>Žb�{L
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�O<CARDANO_BLOCK>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�O<CARDANO_BLOCK>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�O<CARDANO_BLOCK>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�O<CARDANO_BLOCK>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�O<CARDANO_BLOCK>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�O<CARDANO_BLOCK>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module Ouroboros.Consensus.Cardano.Node (
, pattern CardanoNodeToClientVersion5
, pattern CardanoNodeToClientVersion6
, pattern CardanoNodeToClientVersion7
, pattern CardanoNodeToClientVersion8
, pattern CardanoNodeToNodeVersion1
, pattern CardanoNodeToNodeVersion2
, pattern CardanoNodeToNodeVersion3
Expand Down Expand Up @@ -361,6 +362,21 @@ pattern CardanoNodeToClientVersion7 =
:* Nil
)

-- | The hard fork enabled, and the Shelley, Allegra, Mary and Alonzo eras enabled
-- Using 'ShelleyNodeToClientVersion5' for the Shelley-based eras , which
-- enables new queries.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to refer to what these new queries are?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured that since comments are particularly susceptible to bitrot, it would be best if I mention the specific queries in a single place only, in this case the definition of ShelleyNodeToClientVersion5.

But I you prefer, I'm happy to the specific query (GetRewardInfoPools) at the definition of CardanoNodeToClientVersion8 as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured that since comments are particularly susceptible to bitrot, it would be best if I mention the specific queries in a single place only, in this case the definition of ShelleyNodeToClientVersion5.

Sure, that makes sense. I'm ok with the comment as is.

pattern CardanoNodeToClientVersion8 :: BlockNodeToClientVersion (CardanoBlock c)
pattern CardanoNodeToClientVersion8 =
HardForkNodeToClientEnabled
HardForkSpecificNodeToClientVersion2
( EraNodeToClientEnabled ByronNodeToClientVersion1
:* EraNodeToClientEnabled ShelleyNodeToClientVersion5
:* EraNodeToClientEnabled ShelleyNodeToClientVersion5
:* EraNodeToClientEnabled ShelleyNodeToClientVersion5
:* EraNodeToClientEnabled ShelleyNodeToClientVersion5
:* Nil
)

instance CardanoHardForkConstraints c
=> SupportedNetworkProtocolVersion (CardanoBlock c) where
supportedNodeToNodeVersions _ = Map.fromList $
Expand All @@ -380,9 +396,10 @@ instance CardanoHardForkConstraints c
, (NodeToClientV_8 , CardanoNodeToClientVersion6)
, (NodeToClientV_9 , CardanoNodeToClientVersion7)
, (NodeToClientV_10, CardanoNodeToClientVersion7)
, (NodeToClientV_11, CardanoNodeToClientVersion8)
]

latestReleasedNodeVersion _prx = (Just NodeToNodeV_7, Just NodeToClientV_10)
latestReleasedNodeVersion _prx = (Just NodeToNodeV_7, Just NodeToClientV_11)

{-------------------------------------------------------------------------------
ProtocolInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ data ShelleyNodeToClientVersion =

-- | New queries introduced
| ShelleyNodeToClientVersion4

-- | New queries introduced: GetRewardInfoPools
| ShelleyNodeToClientVersion5
deriving (Show, Eq, Ord, Enum, Bounded)

instance HasNetworkProtocolVersion (ShelleyBlock era) where
Expand All @@ -52,6 +55,7 @@ instance SupportedNetworkProtocolVersion (ShelleyBlock era) where
-- Shelley-only when introduced. However, we have retroactively claimed
-- V_4 to enable 'ShelleyNodeToClientVersion3'.
, (NodeToClientV_4, ShelleyNodeToClientVersion3)
, (NodeToClientV_5, ShelleyNodeToClientVersion5)
]

latestReleasedNodeVersion = latestReleasedNodeVersionDefault
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ data instance BlockQuery (ShelleyBlock era) :: Type -> Type where
(Map (SL.KeyHash 'SL.StakePool (EraCrypto era))
(SL.PoolParams (EraCrypto era)))

GetRewardInfoPools
:: BlockQuery (ShelleyBlock era)
(SL.RewardParams,
Map (SL.KeyHash 'SL.StakePool (EraCrypto era))
(SL.RewardInfoPool))

-- 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.
Expand Down Expand Up @@ -247,6 +253,8 @@ instance ShelleyBasedEra era => QueryLedger (ShelleyBlock era) where
SL.getPools st
GetStakePoolParams poolids ->
SL.getPoolParameters st poolids
GetRewardInfoPools ->
SL.getRewardInfoPools globals st
where
lcfg = configLedger $ getExtLedgerCfg cfg
globals = shelleyLedgerGlobals lcfg
Expand Down Expand Up @@ -350,6 +358,10 @@ instance SameDepIndex (BlockQuery (ShelleyBlock era)) where
= Nothing
sameDepIndex (GetStakePoolParams _) _
= Nothing
sameDepIndex GetRewardInfoPools GetRewardInfoPools
= Just Refl
sameDepIndex GetRewardInfoPools _
= Nothing

deriving instance Eq (BlockQuery (ShelleyBlock era) result)
deriving instance Show (BlockQuery (ShelleyBlock era) result)
Expand All @@ -374,6 +386,7 @@ instance ShelleyBasedEra era => ShowQuery (BlockQuery (ShelleyBlock era)) where
GetUTxOByTxIn {} -> show
GetStakePools -> show
GetStakePoolParams {} -> show
GetRewardInfoPools -> show

-- | Is the given query supported by the given 'ShelleyNodeToClientVersion'?
querySupportedVersion :: BlockQuery (ShelleyBlock era) result -> ShelleyNodeToClientVersion -> Bool
Expand All @@ -396,13 +409,15 @@ querySupportedVersion = \case
GetUTxOByTxIn {} -> (>= v4)
GetStakePools -> (>= v4)
GetStakePoolParams {} -> (>= v4)
GetRewardInfoPools -> (>= v5)
-- WARNING: when adding a new query, a new @ShelleyNodeToClientVersionX@
-- must be added. See #2830 for a template on how to do this.
where
v1 = ShelleyNodeToClientVersion1
v2 = ShelleyNodeToClientVersion2
v3 = ShelleyNodeToClientVersion3
v4 = ShelleyNodeToClientVersion4
v5 = ShelleyNodeToClientVersion5

{-------------------------------------------------------------------------------
Auxiliary
Expand Down Expand Up @@ -476,6 +491,8 @@ encodeShelleyQuery query = case query of
CBOR.encodeListLen 1 <> CBOR.encodeWord8 16
GetStakePoolParams poolids ->
CBOR.encodeListLen 2 <> CBOR.encodeWord8 17 <> toCBOR poolids
GetRewardInfoPools ->
CBOR.encodeListLen 1 <> CBOR.encodeWord8 18

decodeShelleyQuery ::
ShelleyBasedEra era
Expand All @@ -502,6 +519,7 @@ decodeShelleyQuery = do
(2, 15) -> SomeSecond . GetUTxOByTxIn <$> fromCBOR
(1, 16) -> return $ SomeSecond GetStakePools
(2, 17) -> SomeSecond . GetStakePoolParams <$> fromCBOR
(1, 18) -> return $ SomeSecond GetRewardInfoPools
_ -> fail $
"decodeShelleyQuery: invalid (len, tag): (" <>
show len <> ", " <> show tag <> ")"
Expand All @@ -528,6 +546,7 @@ encodeShelleyResult query = case query of
GetUTxOByTxIn {} -> toCBOR
GetStakePools -> toCBOR
GetStakePoolParams {} -> toCBOR
GetRewardInfoPools -> toCBOR

decodeShelleyResult ::
ShelleyBasedEra era
Expand All @@ -552,3 +571,4 @@ decodeShelleyResult query = case query of
GetUTxOByTxIn {} -> fromCBOR
GetStakePools -> fromCBOR
GetStakePoolParams {} -> fromCBOR
GetRewardInfoPools -> fromCBOR
9 changes: 9 additions & 0 deletions ouroboros-consensus/docs/interface-CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ may appear out of chronological order.
The internals of each entry are organized similar to
https://keepachangelog.com/en/1.1.0/, adapted to our plan explained above.

## Circa 2021-10-13

### Added

- New supported node to client version `NodeToClientV_11` with new queries:
- `GetRewardInfoPools`: Get *current* stake distribution, pool parameters
and other information that is necessary to predict stake pool member rewards
for the current epoch.

## Circa 2021-09-22

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ nodeToClientVersionToQueryVersion x = case x of
NodeToClientV_8 -> TopLevelQueryDisabled
NodeToClientV_9 -> QueryVersion1
NodeToClientV_10 -> QueryVersion2
NodeToClientV_11 -> QueryVersion2
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ data NodeToClientVersion
-- ^ enabled @CardanoNodeToClientVersion7@, i.e., Alonzo
| NodeToClientV_10
-- ^ added 'GetChainBlockNo' and 'GetChainPoint' queries
| NodeToClientV_11
-- ^ added 'GetRewardInfoPools` Block query
deriving (Eq, Ord, Enum, Bounded, Show, Typeable)

-- | We set 16ths bit to distinguish `NodeToNodeVersion` and
Expand All @@ -65,6 +67,7 @@ nodeToClientVersionCodec = CodecCBORTerm { encodeTerm, decodeTerm }
encodeTerm NodeToClientV_8 = CBOR.TInt (8 `setBit` nodeToClientVersionBit)
encodeTerm NodeToClientV_9 = CBOR.TInt (9 `setBit` nodeToClientVersionBit)
encodeTerm NodeToClientV_10 = CBOR.TInt (10 `setBit` nodeToClientVersionBit)
encodeTerm NodeToClientV_11 = CBOR.TInt (11 `setBit` nodeToClientVersionBit)

decodeTerm (CBOR.TInt tag) =
case ( tag `clearBit` nodeToClientVersionBit
Expand All @@ -80,6 +83,7 @@ nodeToClientVersionCodec = CodecCBORTerm { encodeTerm, decodeTerm }
(8, True) -> Right NodeToClientV_8
(9, True) -> Right NodeToClientV_9
(10, True) -> Right NodeToClientV_10
(11, True) -> Right NodeToClientV_11
(n, _) -> Left ( T.pack "decode NodeToClientVersion: unknown tag: " <> T.pack (show tag)
, Just n)
decodeTerm _ = Left ( T.pack "decode NodeToClientVersion: unexpected term"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ msgRefuse = [2, refuseReason]
versionTable = { * versionNumber => nodeToClientVersionData }

; from version 2 we set 15th bit to 1
versionNumber = 1 / 32770 / 32771 / 32772 / 32773 / 32774 / 32775 / 32776 / 32777 / 32778
versionNumber = 1 / 32770 / 32771 / 32772 / 32773 / 32774 / 32775 / 32776 / 32777 / 32778 / 32779

nodeToClientVersionData = networkMagic

Expand Down