Skip to content

Commit

Permalink
extend ProtocolParameters and add impl for Alonzo
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Sep 10, 2021
1 parent 5cf2c88 commit ffea60b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/core/src/Cardano/Wallet/Primitive/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ module Cardano.Wallet.Primitive.Types
, StartTime (..)
, stabilityWindowByron
, stabilityWindowShelley
, ExecutionUnits (..)
, ExecutionUnitPrices (..)

-- * Wallet Metadata
, WalletMetadata(..)
Expand Down Expand Up @@ -1038,6 +1040,12 @@ data ProtocolParameters = ProtocolParameters
:: Word16
-- ^ Limit on the maximum number of collateral inputs present in a
-- transaction.
, executionUnitPrices
:: Maybe ExecutionUnitPrices
-- ^ The prices for 'ExecutionUnits' as a fraction of a 'Lovelace' and
-- used to determine the fee for the use of a script within a
-- transaction, based on the 'ExecutionUnits' needed by the use of
-- the script.
} deriving (Eq, Generic, Show)

instance NFData ProtocolParameters
Expand All @@ -1049,8 +1057,34 @@ instance Buildable ProtocolParameters where
, "Desired number of pools: " <> build (pp ^. #desiredNumberOfStakePools)
, "Minimum UTxO value: " <> build (pp ^. #minimumUTxOvalue)
, "Eras:\n" <> indentF 2 (build (pp ^. #eras))
, "Execution unit prices: " <>
case (pp ^. #executionUnitPrices) of
Just prices -> build prices
Nothing -> "not specified"
]

data ExecutionUnits = ExecutionUnits
{ executionSteps
:: Word64
-- ^ This corresponds roughly to the time to execute a script.

, executionMemory
:: Word64
-- ^ This corresponds roughly to the peak memory used during script
-- execution.
} deriving (Eq, Generic, Show)

data ExecutionUnitPrices = ExecutionUnitPrices
{ priceExecutionSteps :: Rational
, priceExecutionMemory :: Rational
} deriving (Eq, Generic, Show)

instance NFData ExecutionUnitPrices

instance Buildable ExecutionUnitPrices where
build (ExecutionUnitPrices perStep perMem) =
build $ show perStep <> " per step, " <> show perMem <> " per memory unit"

-- | Indicates the current level of decentralization in the network.
--
-- According to the Design Specification for Delegation and Incentives in
Expand Down
2 changes: 2 additions & 0 deletions lib/shelley/src/Cardano/Wallet/Byron/Compatibility.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ mainnetNetworkParameters = W.NetworkParameters
, stakeKeyDeposit = W.Coin 0
, eras = W.emptyEraInfo
, maximumCollateralInputCount = 0
, executionUnitPrices = Nothing
}
}

Expand Down Expand Up @@ -353,6 +354,7 @@ protocolParametersFromPP eraInfo pp = W.ProtocolParameters
, stakeKeyDeposit = W.Coin 0
, eras = fromBound <$> eraInfo
, maximumCollateralInputCount = 0
, executionUnitPrices = Nothing
}
where
fromBound (Bound _relTime _slotNo (O.EpochNo e)) =
Expand Down
19 changes: 19 additions & 0 deletions lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,11 @@ import qualified Cardano.Ledger.Address as SL
import qualified Cardano.Ledger.Alonzo as Alonzo
import qualified Cardano.Ledger.Alonzo.Data as Alonzo
import qualified Cardano.Ledger.Alonzo.PParams as Alonzo
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
import qualified Cardano.Ledger.Alonzo.Tx as Alonzo
import qualified Cardano.Ledger.Alonzo.TxBody as Alonzo
import qualified Cardano.Ledger.Alonzo.TxSeq as Alonzo
import qualified Cardano.Ledger.BaseTypes as Ledger
import qualified Cardano.Ledger.BaseTypes as SL
import qualified Cardano.Ledger.Core as SL.Core
import qualified Cardano.Ledger.Credential as SL
Expand Down Expand Up @@ -596,6 +598,7 @@ fromShelleyPParams eraInfo pp = W.ProtocolParameters
, stakeKeyDeposit = stakeKeyDepositFromPParams pp
, eras = fromBound <$> eraInfo
, maximumCollateralInputCount = minBound
, executionUnitPrices = Nothing
}
where
fromBound (Bound _relTime _slotNo (EpochNo e)) =
Expand All @@ -620,6 +623,8 @@ fromAlonzoPParams eraInfo pp = W.ProtocolParameters
, eras = fromBound <$> eraInfo
, maximumCollateralInputCount = unsafeIntToWord $
Alonzo._maxCollateralInputs pp
, executionUnitPrices =
Just $ executionUnitPricesFromPParams pp
}
where
fromBound (Bound _relTime _slotNo (EpochNo e)) =
Expand Down Expand Up @@ -655,6 +660,20 @@ decentralizationLevelFromPParams pp =
where
d = getField @"_d" pp

executionUnitPricesFromPParams
:: HasField "_prices" pparams Alonzo.Prices
=> pparams
-> W.ExecutionUnitPrices
executionUnitPricesFromPParams pp =
fromAlonzoPrices prices
where
prices = getField @"_prices" pp
fromAlonzoPrices (Alonzo.Prices prSteps prMem) =
W.ExecutionUnitPrices
{ W.priceExecutionSteps = Ledger.unboundRational prSteps
, W.priceExecutionMemory = Ledger.unboundRational prMem
}

txParametersFromPParams
:: HasField "_minfeeA" pparams Natural
=> HasField "_minfeeB" pparams Natural
Expand Down

0 comments on commit ffea60b

Please sign in to comment.