Skip to content

Commit

Permalink
Merge #4166
Browse files Browse the repository at this point in the history
4166: Fix building of Alonzo transaction in Babbage era. r=newhoggy a=newhoggy

This is achieved by auto-converting from Babbage field `protocolParamUTxOCostPerByte` to Alonzo field `protocolParamUTxOCostPerWord`, which is a multiplication by `8`.

Fixes #4164


Co-authored-by: John Ky <john.ky@iohk.io>
  • Loading branch information
iohk-bors[bot] and newhoggy authored Jul 23, 2022
2 parents d25f48a + 51b9a22 commit f7d574e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions cardano-api/src/Cardano/Api/ProtocolParameters.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
Expand Down Expand Up @@ -64,6 +65,7 @@ module Cardano.Api.ProtocolParameters (

import Prelude

import Control.Applicative ((<|>))
import Control.Monad
import Data.Aeson (FromJSON (..), ToJSON (..), object, withObject, (.!=), (.:), (.:?),
(.=))
Expand Down Expand Up @@ -106,8 +108,8 @@ import Text.PrettyBy.Default (display)
import Cardano.Api.Address
import Cardano.Api.Eras
import Cardano.Api.Error
import Cardano.Api.HasTypeProxy
import Cardano.Api.Hash
import Cardano.Api.HasTypeProxy
import Cardano.Api.KeysByron
import Cardano.Api.KeysShelley
import Cardano.Api.Script
Expand All @@ -120,7 +122,6 @@ import Cardano.Api.TxMetadata
import Cardano.Api.Utils
import Cardano.Api.Value


-- | The values of the set of /updatable/ protocol parameters. At any
-- particular point on the chain there is a current set of parameters in use.
--
Expand Down Expand Up @@ -1436,15 +1437,20 @@ toAlonzoPParams ProtocolParameters {
protocolParamPoolPledgeInfluence,
protocolParamMonetaryExpansion,
protocolParamTreasuryCut,
protocolParamUTxOCostPerWord = Just utxoCostPerWord,
protocolParamUTxOCostPerWord,
protocolParamCostModels,
protocolParamPrices = Just prices,
protocolParamMaxTxExUnits = Just maxTxExUnits,
protocolParamMaxBlockExUnits = Just maxBlockExUnits,
protocolParamMaxValueSize = Just maxValueSize,
protocolParamCollateralPercent = Just collateralPercentage,
protocolParamMaxCollateralInputs = Just maxCollateralInputs
protocolParamMaxCollateralInputs = Just maxCollateralInputs,
protocolParamUTxOCostPerByte
} =
let !coinsPerUTxOWord = fromMaybe
(error "toAlonzoPParams: must specify protocolParamUTxOCostPerWord or protocolParamUTxOCostPerByte") $
protocolParamUTxOCostPerWord <|> ((* 8) <$> protocolParamUTxOCostPerByte)
in
Alonzo.PParams {
Alonzo._protocolVersion
= let (maj, minor) = protocolParamProtocolVersion
Expand Down Expand Up @@ -1483,7 +1489,7 @@ toAlonzoPParams ProtocolParameters {
(Ledger.boundRational protocolParamTreasuryCut)

-- New params in Alonzo:
, Alonzo._coinsPerUTxOWord = toShelleyLovelace utxoCostPerWord
, Alonzo._coinsPerUTxOWord = toShelleyLovelace coinsPerUTxOWord
, Alonzo._costmdls = either
(\e -> error $ "toAlonzoPParams: invalid cost models, error: " <> e)
id
Expand Down

0 comments on commit f7d574e

Please sign in to comment.