-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore en-/decoding compatibility for
GetCurrentPParams
(#95)
IntersectMBO/ouroboros-network#4349 changed/fixed the encoding of `PParams`, which broke compatibility of older clients with Node 8.0. This PR restores compatibility, by making the en-/decoding version-dependent. See the commit message for some implementation details. Also, note how the golden files changed due to this PR: - Pre-Alonzo serialization did not change. - Alonzo and Babbage changed, but only for `CardanoNodeToClientVersion <= 10`; these are enabled by `NodeToClient <= 14`, which are the currently released node-to-client versions. - Note that no golden files changed for `CardanoNodeToClientVersion{11,12}` (which are enabled by `NodeToClientV_{15,16}`). `NodeToClientV_15` will be released in Node 8.1, and indeed, we want to use the new and fixed encoding when this version is negotiated.
- Loading branch information
Showing
14 changed files
with
256 additions
and
10 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
...-cardano/changelog.d/20230522_123103_alexander.esgen_pparams_encoding_compat.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
### Breaking | ||
|
||
- The `GetCurrentPParams` query now uses the legacy en-/decoding for its result again when the `NodeToClientVersion` is `<15`, restoring compatibility with older clients. | ||
|
Binary file modified
BIN
-1 Byte
(98%)
...rdano/golden/cardano/QueryVersion1/CardanoNodeToClientVersion7/Result_Alonzo_EmptyPParams
Binary file not shown.
Binary file modified
BIN
-1 Byte
(98%)
...dano/golden/cardano/QueryVersion2/CardanoNodeToClientVersion10/Result_Alonzo_EmptyPParams
Binary file not shown.
Binary file modified
BIN
-1 Byte
(98%)
...ano/golden/cardano/QueryVersion2/CardanoNodeToClientVersion10/Result_Babbage_EmptyPParams
Binary file not shown.
Binary file modified
BIN
-1 Byte
(98%)
...rdano/golden/cardano/QueryVersion2/CardanoNodeToClientVersion7/Result_Alonzo_EmptyPParams
Binary file not shown.
Binary file modified
BIN
-1 Byte
(98%)
...rdano/golden/cardano/QueryVersion2/CardanoNodeToClientVersion8/Result_Alonzo_EmptyPParams
Binary file not shown.
Binary file modified
BIN
-1 Byte
(98%)
...rdano/golden/cardano/QueryVersion2/CardanoNodeToClientVersion9/Result_Alonzo_EmptyPParams
Binary file not shown.
Binary file modified
BIN
-1 Byte
(98%)
...dano/golden/cardano/QueryVersion2/CardanoNodeToClientVersion9/Result_Babbage_EmptyPParams
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
211 changes: 211 additions & 0 deletions
211
...nsus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query/PParamsLegacyEncoder.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
-- | Ledger fixed/changed the serialisation of @PParams@ in a | ||
-- backwards-incompatible way in | ||
-- <https://github.com/input-output-hk/ouroboros-network/pull/4349/>. | ||
-- | ||
-- This module contains the legacy serialisation in order to keep compatibility | ||
-- with applications (like cardano-cli or Ogmios) that still use the old | ||
-- serialisation logic. We use the negotiated node-to-client version to detect | ||
-- when the client does not yet support the fixed serialisation. | ||
-- | ||
-- This module can be removed once the next HF (Conway) has happened. | ||
module Ouroboros.Consensus.Shelley.Ledger.Query.PParamsLegacyEncoder ( | ||
LegacyPParams (..) | ||
, decodeLegacyPParams | ||
, encodeLegacyPParams | ||
) where | ||
|
||
import Cardano.Ledger.Allegra | ||
import Cardano.Ledger.Alonzo | ||
import Cardano.Ledger.Alonzo.PParams | ||
import Cardano.Ledger.Babbage | ||
import Cardano.Ledger.Babbage.PParams | ||
import Cardano.Ledger.Binary | ||
import Cardano.Ledger.Binary.Coders | ||
import qualified Cardano.Ledger.Binary.Plain as Plain | ||
import Cardano.Ledger.Conway | ||
import Cardano.Ledger.Core | ||
import Cardano.Ledger.Crypto | ||
import Cardano.Ledger.Mary | ||
import Cardano.Ledger.Shelley | ||
import Data.Functor.Identity | ||
|
||
newtype LegacyPParams era = LegacyPParams | ||
{ unLegacyPParams :: PParams era | ||
} | ||
|
||
encodeLegacyPParams :: ToCBOR (LegacyPParams era) => PParams era -> Plain.Encoding | ||
encodeLegacyPParams pp = toCBOR (LegacyPParams pp) | ||
|
||
decodeLegacyPParams :: FromCBOR (LegacyPParams era) => Plain.Decoder s (PParams era) | ||
decodeLegacyPParams = unLegacyPParams <$> fromCBOR | ||
|
||
instance Crypto c => ToCBOR (LegacyPParams (ShelleyEra c)) where | ||
toCBOR (LegacyPParams pp) = toCBOR pp | ||
|
||
instance Crypto c => FromCBOR (LegacyPParams (ShelleyEra c)) where | ||
fromCBOR = LegacyPParams <$> fromCBOR | ||
|
||
instance Crypto c => ToCBOR (LegacyPParams (MaryEra c)) where | ||
toCBOR (LegacyPParams pp) = toCBOR pp | ||
|
||
instance Crypto c => FromCBOR (LegacyPParams (MaryEra c)) where | ||
fromCBOR = LegacyPParams <$> fromCBOR | ||
|
||
instance Crypto c => ToCBOR (LegacyPParams (AllegraEra c)) where | ||
toCBOR (LegacyPParams pp) = toCBOR pp | ||
|
||
instance Crypto c => FromCBOR (LegacyPParams (AllegraEra c)) where | ||
fromCBOR = LegacyPParams <$> fromCBOR | ||
|
||
instance Crypto c => ToCBOR (LegacyPParams (AlonzoEra c)) where | ||
toCBOR (LegacyPParams (PParams AlonzoPParams{..})) = | ||
toPlainEncoding (eraProtVerLow @(AlonzoEra c)) $ | ||
encode | ||
( Rec mkLegacyAlonzoPParams | ||
!> To appMinFeeA | ||
!> To appMinFeeB | ||
!> To appMaxBBSize | ||
!> To appMaxTxSize | ||
!> To appMaxBHSize | ||
!> To appKeyDeposit | ||
!> To appPoolDeposit | ||
!> To appEMax | ||
!> To appNOpt | ||
!> To appA0 | ||
!> To appRho | ||
!> To appTau | ||
!> To appD | ||
!> To appExtraEntropy | ||
!> E encCBORGroup appProtocolVersion | ||
!> To appMinPoolCost | ||
-- new/updated for alonzo | ||
!> To appCoinsPerUTxOWord | ||
!> To appCostModels | ||
!> To appPrices | ||
!> To appMaxTxExUnits | ||
!> To appMaxBlockExUnits | ||
!> To appMaxValSize | ||
!> To appCollateralPercentage | ||
!> To appMaxCollateralInputs | ||
) | ||
where | ||
mkLegacyAlonzoPParams a b c d e f g h i j k l m n o p q r s t u v w x = | ||
LegacyPParams $ | ||
PParams $ | ||
AlonzoPParams @Identity @(AlonzoEra c) a b c d e f g h i j k l m n o p q r s t u v w x | ||
|
||
instance Crypto c => FromCBOR (LegacyPParams (AlonzoEra c)) where | ||
fromCBOR = | ||
toPlainDecoder (eraProtVerLow @(AlonzoEra c)) $ | ||
decode $ | ||
RecD mkLegacyAlonzoPParams | ||
<! From -- appMinFeeA | ||
<! From -- appMinFeeB | ||
<! From -- appMaxBBSize | ||
<! From -- appMaxTxSize | ||
<! From -- appMaxBHSize | ||
<! From -- appKeyDeposit | ||
<! From -- appPoolDeposit | ||
<! From -- appEMax | ||
<! From -- appNOpt | ||
<! From -- appA0 | ||
<! From -- appRho | ||
<! From -- appTau | ||
<! From -- appD | ||
<! From -- appExtraEntropy | ||
<! D decCBORGroup -- appProtocolVersion | ||
<! From -- appMinPoolCost | ||
-- new/updated for alonzo | ||
<! From -- appCoinsPerUTxOWord | ||
<! From -- appCostModels | ||
<! From -- appPrices | ||
<! From -- appMaxTxExUnits | ||
<! From -- appMaxBlockExUnits | ||
<! From -- appMaxValSize | ||
<! From -- appCollateralPercentage | ||
<! From -- appMaxCollateralInputs | ||
where | ||
mkLegacyAlonzoPParams a b c d e f g h i j k l m n o p q r s t u v w x = | ||
LegacyPParams $ | ||
PParams $ | ||
AlonzoPParams @Identity @(AlonzoEra c) a b c d e f g h i j k l m n o p q r s t u v w x | ||
|
||
instance Crypto c => ToCBOR (LegacyPParams (BabbageEra c)) where | ||
toCBOR (LegacyPParams (PParams BabbagePParams{..})) = | ||
toPlainEncoding (eraProtVerLow @(BabbageEra c)) $ | ||
encode | ||
( Rec mkLegacyBabbagePParams | ||
!> To bppMinFeeA | ||
!> To bppMinFeeB | ||
!> To bppMaxBBSize | ||
!> To bppMaxTxSize | ||
!> To bppMaxBHSize | ||
!> To bppKeyDeposit | ||
!> To bppPoolDeposit | ||
!> To bppEMax | ||
!> To bppNOpt | ||
!> To bppA0 | ||
!> To bppRho | ||
!> To bppTau | ||
!> E encCBORGroup bppProtocolVersion | ||
!> To bppMinPoolCost | ||
!> To bppCoinsPerUTxOByte | ||
!> To bppCostModels | ||
!> To bppPrices | ||
!> To bppMaxTxExUnits | ||
!> To bppMaxBlockExUnits | ||
!> To bppMaxValSize | ||
!> To bppCollateralPercentage | ||
!> To bppMaxCollateralInputs | ||
) | ||
where | ||
mkLegacyBabbagePParams a b c d e f g h i j k l m n o p q r s t u v = | ||
LegacyPParams $ | ||
PParams $ | ||
BabbagePParams @Identity @(BabbageEra c) a b c d e f g h i j k l m n o p q r s t u v | ||
|
||
instance Crypto c => FromCBOR (LegacyPParams (BabbageEra c)) where | ||
fromCBOR = | ||
toPlainDecoder (eraProtVerLow @(BabbageEra c)) $ | ||
decode $ | ||
RecD mkLegacyBabbagePParams | ||
<! From -- bppMinFeeA | ||
<! From -- bppMinFeeB | ||
<! From -- bppMaxBBSize | ||
<! From -- bppMaxTxSize | ||
<! From -- bppMaxBHSize | ||
<! From -- bppKeyDeposit | ||
<! From -- bppPoolDeposit | ||
<! From -- bppEMax | ||
<! From -- bppNOpt | ||
<! From -- bppA0 | ||
<! From -- bppRho | ||
<! From -- bppTau | ||
<! D decCBORGroup -- bppProtocolVersion | ||
<! From -- bppMinPoolCost | ||
<! From -- bppCoinsPerUTxOByte | ||
<! From -- bppCostModels | ||
<! From -- bppPrices | ||
<! From -- bppMaxTxExUnits | ||
<! From -- bppMaxBlockExUnits | ||
<! From -- maxValSize | ||
<! From -- collateralPercentage | ||
<! From -- maxCollateralInputs | ||
where | ||
mkLegacyBabbagePParams a b c d e f g h i j k l m n o p q r s t u v = | ||
LegacyPParams $ | ||
PParams $ | ||
BabbagePParams @Identity @(BabbageEra c) a b c d e f g h i j k l m n o p q r s t u v | ||
|
||
instance Crypto c => ToCBOR (LegacyPParams (ConwayEra c)) where | ||
toCBOR (LegacyPParams pp) = toCBOR pp | ||
|
||
instance Crypto c => FromCBOR (LegacyPParams (ConwayEra c)) where | ||
fromCBOR = LegacyPParams <$> fromCBOR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters