Skip to content

Commit

Permalink
Merge #3812
Browse files Browse the repository at this point in the history
3812: cardano-api 1.36.0 r=Unisay a=Unisay

This PR updates the `cardano-api` version used in the wallet to `1.36.0` to make use of the new `BundledProtocolParameters`.


Co-authored-by: Yura Lazarev <Unisay@users.noreply.github.com>
Co-authored-by: Johannes Lund <johannes.lund@iohk.io>
  • Loading branch information
3 people committed Mar 30, 2023
2 parents ec30c07 + bed3ba9 commit 0456438
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 81 deletions.
8 changes: 4 additions & 4 deletions cabal.project
Expand Up @@ -118,8 +118,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-node
tag: 84a871ed86fc1b86018231b9cb24ba7b83493c0d
--sha256: 0qnr847z4fvxvbjsa0x0vfhmdwwmr99d6m3j4sh6jxdyph099b2n
tag: c02b0ab3786dce24bcd9899509be767057286f53
--sha256: 1igxway613vzgkjypk4vbn9dkws7faygbdd72x90h0n14p47i2js
subdir:
cardano-api
cardano-git-rev
Expand Down Expand Up @@ -161,8 +161,8 @@ constraints:
, Cabal >= 3.4.0.0
, async-timer >= 0.2.0.0
, unliftio-core >= 0.2.0.1
, cardano-api >= 1.35.4
, cardano-node >= 1.35.4
, cardano-api >= 1.35.6
, cardano-node >= 1.35.6
, generic-arbitrary >= 0.2.2
, iohk-monitoring >= 0.1.11

Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -3071,12 +3071,14 @@ balanceTransaction
(getState wallet)
partialTx
where
nodePParams = fromMaybe
nodePParams = maybe
(error $ unwords
[ "balanceTransaction: no nodePParams."
, "Should only be possible in Byron, where"
, "withRecentEra should prevent this being reached."
])
(Cardano.bundleProtocolParams
(WriteTx.fromRecentEra (WriteTx.recentEra @era)))
$ W.currentNodeProtocolParameters pp

anyRecentTx <- maybeToHandler (Write.ErrOldEraNotSupported era)
Expand Down
17 changes: 16 additions & 1 deletion lib/wallet/src/Cardano/Api/Extra.hs
Expand Up @@ -12,12 +12,14 @@ module Cardano.Api.Extra
, inAnyCardanoEra
, asAnyShelleyBasedEra
, fromShelleyBasedScript
, unbundleLedgerShelleyBasedProtocolParams
) where

import Prelude

import Cardano.Api
( CardanoEra (..)
( BundledProtocolParameters (..)
, CardanoEra (..)
, InAnyCardanoEra (..)
, InAnyShelleyBasedEra (..)
, IsCardanoEra (cardanoEra)
Expand Down Expand Up @@ -135,3 +137,16 @@ fromShelleyBasedScript era script = case era of
ScriptInEra PlutusScriptV2InConway $
PlutusScript PlutusScriptV2 $
PlutusScriptSerialised s

-- Not exposed by cardano-api
unbundleLedgerShelleyBasedProtocolParams
:: ShelleyBasedEra era
-> BundledProtocolParameters era
-> Ledger.PParams (ShelleyLedgerEra era)
unbundleLedgerShelleyBasedProtocolParams = \case
ShelleyBasedEraShelley -> \(BundleAsShelleyBasedProtocolParameters _ _ lpp) -> lpp
ShelleyBasedEraAllegra -> \(BundleAsShelleyBasedProtocolParameters _ _ lpp) -> lpp
ShelleyBasedEraMary -> \(BundleAsShelleyBasedProtocolParameters _ _ lpp) -> lpp
ShelleyBasedEraAlonzo -> \(BundleAsShelleyBasedProtocolParameters _ _ lpp) -> lpp
ShelleyBasedEraBabbage -> \(BundleAsShelleyBasedProtocolParameters _ _ lpp) -> lpp
ShelleyBasedEraConway -> \(BundleAsShelleyBasedProtocolParameters _ _ lpp) -> lpp
4 changes: 3 additions & 1 deletion lib/wallet/src/Cardano/Wallet.hs
Expand Up @@ -2253,12 +2253,14 @@ buildTransactionPure
where
nodeProtocolParameters =
( protocolParams
, fromMaybe
, maybe
(error $ unwords
[ "buildAndSignTransactionPure: no nodePParams."
, "should only be possible in Byron, where"
, "withRecentEra should prevent this to be reached."
])
(Cardano.bundleProtocolParams
(WriteTx.fromRecentEra (WriteTx.recentEra @era)))
$ currentNodeProtocolParameters protocolParams
)

Expand Down
Expand Up @@ -58,7 +58,9 @@ computeMinimumCoinForUTxO_CardanoApi
unsafeCoinFromResult $
Cardano.calculateMinimumUTxO era
(toCardanoTxOut era txOut)
(Cardano.fromLedgerPParams era pp)
(Cardano.bundleProtocolParams
(Cardano.shelleyBasedToCardanoEra era)
(Cardano.fromLedgerPParams era pp))
where
unsafeCoinFromResult
:: Either Cardano.MinimumUTxOError Cardano.Lovelace
Expand Down
47 changes: 23 additions & 24 deletions lib/wallet/src/Cardano/Wallet/Shelley/Transaction.hs
Expand Up @@ -276,6 +276,7 @@ import Ouroboros.Network.Block

import qualified Cardano.Api as Cardano
import qualified Cardano.Api.Byron as Byron
import qualified Cardano.Api.Extra as Cardano
import qualified Cardano.Api.Shelley as Cardano
import qualified Cardano.Chain.Common as Byron
import qualified Cardano.Crypto as CC
Expand Down Expand Up @@ -1010,7 +1011,7 @@ dummySkeleton inputCount outputs = SelectionSkeleton
-- using ledger's functionality.
evaluateMinimumFee
:: Cardano.IsShelleyBasedEra era
=> Cardano.ProtocolParameters
=> Cardano.BundledProtocolParameters era
-> KeyWitnessCount
-> Cardano.TxBody era
-> Coin
Expand All @@ -1021,15 +1022,16 @@ evaluateMinimumFee pp (KeyWitnessCount nWits nBootWits) body =
-- nBootWits, so we need to account for it separately.
where
bootWitFees = Coin.fromNatural $
Cardano.protocolParamTxFeePerByte pp * bytes
Cardano.protocolParamTxFeePerByte
(Cardano.unbundleProtocolParams pp) * bytes
where
bytes :: Natural
bytes = fromIntegral $ sizeOf_BootstrapWitnesses $ intCast nBootWits

-- | Estimate the size of the transaction (body) when fully signed.
estimateSignedTxSize
:: Cardano.IsShelleyBasedEra era
=> Cardano.ProtocolParameters
=> Cardano.BundledProtocolParameters era
-> KeyWitnessCount
-> Cardano.TxBody era
-> TxSize
Expand Down Expand Up @@ -1072,7 +1074,7 @@ estimateSignedTxSize pparams nWits body =

feePerByte :: Coin
feePerByte = Coin.fromNatural $
view #protocolParamTxFeePerByte pparams
view #protocolParamTxFeePerByte (Cardano.unbundleProtocolParams pparams)

numberOfShelleyWitnesses :: Word -> KeyWitnessCount
numberOfShelleyWitnesses n = KeyWitnessCount n 0
Expand Down Expand Up @@ -1216,7 +1218,7 @@ type ConwayTx =

assignScriptRedeemers
:: forall era. Cardano.IsShelleyBasedEra era
=> Cardano.ProtocolParameters
=> Cardano.BundledProtocolParameters era
-> TimeInterpreter (Either PastHorizonException)
-> Cardano.UTxO era
-> [Redeemer]
Expand Down Expand Up @@ -1272,6 +1274,10 @@ assignScriptRedeemers pparams ti utxo redeemers tx =

systemStart = getSystemStart ti

pparams' = Cardano.unbundleLedgerShelleyBasedProtocolParams
(shelleyBasedEra @era)
pparams

-- | Assign redeemers with null execution units to the input transaction.
--
-- Redeemers are determined from the context given to the caller via the
Expand Down Expand Up @@ -1352,8 +1358,6 @@ assignScriptRedeemers pparams ti utxo redeemers tx =
-> Either ErrAssignRedeemers
(Map Alonzo.RdmrPtr (Either ErrAssignRedeemers Alonzo.ExUnits))
evaluateExecutionUnitsAlonzo indexedRedeemers alonzoTx = do
let pparams' = Cardano.toLedgerPParams
Cardano.ShelleyBasedEraAlonzo pparams
let costs = toCostModelsAsArray
(Alonzo.unCostModels $ Alonzo._costmdls pparams')
let res = evaluateTransactionExecutionUnits
Expand All @@ -1376,8 +1380,6 @@ assignScriptRedeemers pparams ti utxo redeemers tx =
-> Either ErrAssignRedeemers
(Map Alonzo.RdmrPtr (Either ErrAssignRedeemers Alonzo.ExUnits))
evaluateExecutionUnitsBabbage indexedRedeemers babbageTx = do
let pparams' = Cardano.toLedgerPParams
Cardano.ShelleyBasedEraBabbage pparams
let costs = toCostModelsAsArray
(Alonzo.unCostModels $ Babbage._costmdls pparams')

Expand All @@ -1401,8 +1403,6 @@ assignScriptRedeemers pparams ti utxo redeemers tx =
-> Either ErrAssignRedeemers
(Map Alonzo.RdmrPtr (Either ErrAssignRedeemers Alonzo.ExUnits))
evaluateExecutionUnitsConway indexedRedeemers conwayTx = do
let pparams' = Cardano.toLedgerPParams
Cardano.ShelleyBasedEraConway pparams
let costs = toCostModelsAsArray
(Alonzo.unCostModels $ Conway._costmdls pparams')

Expand Down Expand Up @@ -1485,7 +1485,9 @@ assignScriptRedeemers pparams ti utxo redeemers tx =

-- | Finally, calculate and add the script integrity hash with the new
-- final redeemers, if any.
addScriptIntegrityHashAlonzo :: AlonzoTx -> AlonzoTx
addScriptIntegrityHashAlonzo
:: era ~ Cardano.AlonzoEra
=> AlonzoTx -> AlonzoTx
addScriptIntegrityHashAlonzo alonzoTx =
let wits = Alonzo.wits alonzoTx
langs =
Expand All @@ -1497,16 +1499,15 @@ assignScriptRedeemers pparams ti utxo redeemers tx =
in alonzoTx
{ Alonzo.body = (Alonzo.body alonzoTx)
{ Alonzo.scriptIntegrityHash = Alonzo.hashScriptIntegrity
(Set.fromList $ Alonzo.getLanguageView
(Cardano.toLedgerPParams
Cardano.ShelleyBasedEraAlonzo pparams)
<$> langs)
(Set.fromList $ Alonzo.getLanguageView pparams' <$> langs)
(Alonzo.txrdmrs wits)
(Alonzo.txdats wits)
}
}

addScriptIntegrityHashBabbage :: BabbageTx -> BabbageTx
addScriptIntegrityHashBabbage
:: era ~ Cardano.BabbageEra
=> BabbageTx -> BabbageTx
addScriptIntegrityHashBabbage babbageTx =
let wits = Alonzo.wits babbageTx
langs =
Expand All @@ -1518,16 +1519,16 @@ assignScriptRedeemers pparams ti utxo redeemers tx =
in babbageTx
{ Babbage.body = (Babbage.body babbageTx)
{ Babbage.scriptIntegrityHash = Alonzo.hashScriptIntegrity
(Set.fromList $ Alonzo.getLanguageView
(Cardano.toLedgerPParams
Cardano.ShelleyBasedEraBabbage pparams)
(Set.fromList $ Alonzo.getLanguageView pparams'
<$> langs)
(Alonzo.txrdmrs wits)
(Alonzo.txdats wits)
}
}

addScriptIntegrityHashConway :: ConwayTx -> ConwayTx
addScriptIntegrityHashConway
:: era ~ Cardano.ConwayEra
=> ConwayTx -> ConwayTx
addScriptIntegrityHashConway conwayTx =
let wits = Alonzo.wits conwayTx
langs =
Expand All @@ -1539,9 +1540,7 @@ assignScriptRedeemers pparams ti utxo redeemers tx =
in conwayTx
{ Conway.body = (Conway.body conwayTx)
{ Conway.scriptIntegrityHash = Alonzo.hashScriptIntegrity
(Set.fromList $ Alonzo.getLanguageView
(Cardano.toLedgerPParams
Cardano.ShelleyBasedEraConway pparams)
(Set.fromList $ Alonzo.getLanguageView pparams'
<$> langs)
(Alonzo.txrdmrs wits)
(Alonzo.txdats wits)
Expand Down
17 changes: 9 additions & 8 deletions lib/wallet/src/Cardano/Wallet/Write/Tx/Balance.hs
Expand Up @@ -164,6 +164,7 @@ import Text.Pretty.Simple

import qualified Cardano.Address.Script as CA
import qualified Cardano.Api as Cardano
import qualified Cardano.Api.Extra as Cardano
import qualified Cardano.Api.Shelley as Cardano
import qualified Cardano.Wallet.Primitive.Types as W
import qualified Cardano.Wallet.Primitive.Types.Address as W
Expand Down Expand Up @@ -351,7 +352,7 @@ balanceTransaction
)
=> Tracer m BalanceTxLog
-> UTxOAssumptions
-> (W.ProtocolParameters, Cardano.ProtocolParameters)
-> (W.ProtocolParameters, Cardano.BundledProtocolParameters era)
-- ^ 'Cardano.ProtocolParameters' can be retrieved via a Local State Query
-- to a local node.
--
Expand All @@ -377,11 +378,9 @@ balanceTransaction
-> PartialTx era
-> ExceptT ErrBalanceTx m (Cardano.Tx era, changeState)
balanceTransaction tr utxoAssumptions pp ti utxo genChange s unadjustedPtx = do
-- TODO [ADP-1490] Take 'Ledger.PParams era' directly as argument, and avoid
-- converting to/from Cardano.ProtocolParameters. This may affect
-- performance. The addition of this one specific conversion seems to have
-- made the --match "balanceTransaction" unit tests 11% slower in CPU time.
let ledgerPP = Cardano.toLedgerPParams shelleyEra $ snd pp
let ledgerPP = Cardano.unbundleLedgerShelleyBasedProtocolParams
shelleyEra
(snd pp)
let adjustedPtx = over (#tx)
(increaseZeroAdaOutputs (recentEra @era) ledgerPP)
unadjustedPtx
Expand Down Expand Up @@ -470,7 +469,7 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment
)
=> Tracer m BalanceTxLog
-> UTxOAssumptions
-> (W.ProtocolParameters, Cardano.ProtocolParameters)
-> (W.ProtocolParameters, Cardano.BundledProtocolParameters era)
-> TimeInterpreter (Either PastHorizonException)
-> UTxOIndex WalletUTxO
-> ChangeAddressGen changeState
Expand Down Expand Up @@ -704,7 +703,9 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment
. Write.Tx.fromCardanoTx

ledgerPP =
Cardano.toLedgerPParams (Cardano.shelleyBasedEra @era) nodePParams
Cardano.unbundleLedgerShelleyBasedProtocolParams
(Cardano.shelleyBasedEra @era)
nodePParams

balanceAfterSettingMinFee
:: Cardano.Tx era
Expand Down

0 comments on commit 0456438

Please sign in to comment.