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

Integrate newer cardano-ledger and ouroboros-consensus #496

Merged
merged 1 commit into from
Apr 4, 2024
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
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository cardano-haskell-packages
-- you need to run if you change them
index-state:
, hackage.haskell.org 2024-03-18T13:14:14Z
, cardano-haskell-packages 2024-03-18T15:21:15Z
, cardano-haskell-packages 2024-04-04T10:00:00Z

packages:
cardano-api
Expand Down
30 changes: 15 additions & 15 deletions cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ library internal
, cardano-crypto-class ^>= 2.1.2
, cardano-crypto-wrapper ^>= 1.5
, cardano-data >= 1.0
, cardano-ledger-alonzo >= 1.6.0
, cardano-ledger-alonzo >= 1.7.0
, cardano-ledger-allegra >= 1.3
, cardano-ledger-api ^>= 1.8
, cardano-ledger-api ^>= 1.9
, cardano-ledger-babbage >= 1.6.0
, cardano-ledger-binary ^>= 1.3
, cardano-ledger-byron >= 1.0.0.4
Expand All @@ -173,7 +173,7 @@ library internal
, cardano-ledger-mary >= 1.5
, cardano-ledger-shelley >= 1.9.0
, cardano-protocol-tpraos >= 1.0.3.6
, cardano-slotting >= 0.1
, cardano-slotting >= 0.2.0.0
, cardano-strict-containers >= 0.1
, cborg
, containers
Expand All @@ -192,24 +192,24 @@ library internal
, mtl
, network
, optparse-applicative-fork
, ouroboros-consensus ^>= 0.16
, ouroboros-consensus-cardano ^>= 0.14
, ouroboros-consensus-diffusion ^>= 0.12
, ouroboros-consensus-protocol ^>= 0.7
, ouroboros-consensus ^>= 0.17
, ouroboros-consensus-cardano ^>= 0.15
, ouroboros-consensus-diffusion ^>= 0.13
, ouroboros-consensus-protocol ^>= 0.8
, ouroboros-network
, ouroboros-network-api ^>= 0.7
, ouroboros-network-framework
, ouroboros-network-protocols
, parsec
, plutus-ledger-api:{plutus-ledger-api, plutus-ledger-api-testlib} ^>= 1.21
, plutus-ledger-api:{plutus-ledger-api, plutus-ledger-api-testlib} ^>= 1.23.0
, prettyprinter
, prettyprinter-ansi-terminal
, prettyprinter-configurable ^>= 1.21
, prettyprinter-configurable ^>= 1.23.0
, random
, safe-exceptions
, scientific
, serialise
, small-steps ^>= 1.0
, small-steps ^>= 1.1
, sop-core
, stm
, strict-sop-core
Expand Down Expand Up @@ -312,7 +312,7 @@ test-suite cardano-api-test
, cardano-crypto-class ^>= 2.1.2
, cardano-crypto-test ^>= 1.5
, cardano-crypto-tests ^>= 2.1
, cardano-ledger-api ^>= 1.8
, cardano-ledger-api ^>= 1.9
, cardano-ledger-core:{cardano-ledger-core, testlib} >= 1.8
, containers
, directory
Expand Down Expand Up @@ -361,20 +361,20 @@ test-suite cardano-api-golden
, cardano-crypto-class ^>= 2.1.2
, cardano-data >= 1.0
, cardano-ledger-alonzo
, cardano-ledger-api ^>= 1.8
, cardano-ledger-api ^>= 1.9
, cardano-ledger-core:{cardano-ledger-core, testlib} >= 1.8
, cardano-ledger-shelley
, cardano-ledger-shelley-test >= 1.2.0.1
, cardano-slotting ^>= 0.1
, cardano-slotting ^>= 0.2.0.0
, containers
, errors
, filepath
, hedgehog >= 1.1
, hedgehog-extras ^>= 0.6.1.0
, microlens
, parsec
, plutus-core ^>= 1.21
, plutus-ledger-api ^>= 1.21
, plutus-core ^>= 1.23
, plutus-ledger-api ^>= 1.23.0
, tasty
, tasty-hedgehog
, time
Expand Down
18 changes: 9 additions & 9 deletions cardano-api/internal/Cardano/Api/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,12 @@ instance HasTypeProxy StakeAddress where

instance SerialiseAsRawBytes StakeAddress where
serialiseToRawBytes (StakeAddress nw sc) =
Shelley.serialiseRewardAcnt (Shelley.RewardAcnt nw sc)
Shelley.serialiseRewardAccount (Shelley.RewardAccount nw sc)

deserialiseFromRawBytes AsStakeAddress bs =
case Shelley.deserialiseRewardAcnt bs of
case Shelley.deserialiseRewardAccount bs of
Nothing -> Left (SerialiseAsRawBytesError "Unable to deserialise StakeAddress")
Just (Shelley.RewardAcnt nw sc) -> Right (StakeAddress nw sc)
Just (Shelley.RewardAccount nw sc) -> Right (StakeAddress nw sc)


instance SerialiseAsBech32 StakeAddress where
Expand Down Expand Up @@ -637,11 +637,11 @@ toShelleyAddr (AddressInEra (ShelleyAddressInEra _)
(ShelleyAddress nw pc scr)) =
Shelley.Addr nw pc scr

toShelleyStakeAddr :: StakeAddress -> Shelley.RewardAcnt StandardCrypto
toShelleyStakeAddr :: StakeAddress -> Shelley.RewardAccount StandardCrypto
toShelleyStakeAddr (StakeAddress nw sc) =
Shelley.RewardAcnt {
Shelley.getRwdNetwork = nw,
Shelley.getRwdCred = sc
Shelley.RewardAccount {
Shelley.raNetwork = nw,
Shelley.raCredential = sc
}

toShelleyPaymentCredential :: PaymentCredential
Expand Down Expand Up @@ -689,8 +689,8 @@ fromShelleyAddr sBasedEra (Shelley.Addr nw pc scr) =
(ShelleyAddressInEra sBasedEra)
(ShelleyAddress nw pc scr)

fromShelleyStakeAddr :: Shelley.RewardAcnt StandardCrypto -> StakeAddress
fromShelleyStakeAddr (Shelley.RewardAcnt nw sc) = StakeAddress nw sc
fromShelleyStakeAddr :: Shelley.RewardAccount StandardCrypto -> StakeAddress
fromShelleyStakeAddr (Shelley.RewardAccount nw sc) = StakeAddress nw sc

fromShelleyStakeCredential :: Shelley.StakeCredential StandardCrypto
-> StakeCredential
Expand Down
6 changes: 3 additions & 3 deletions cardano-api/internal/Cardano/Api/Certificate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ toShelleyPoolParams StakePoolParameters {
, Ledger.ppMargin = fromMaybe
(error "toShelleyPoolParams: invalid PoolMargin")
(Ledger.boundRational stakePoolMargin)
, Ledger.ppRewardAcnt = toShelleyStakeAddr stakePoolRewardAccount
, Ledger.ppRewardAccount = toShelleyStakeAddr stakePoolRewardAccount
, Ledger.ppOwners = Set.fromList
[ kh | StakeKeyHash kh <- stakePoolOwners ]
, Ledger.ppRelays = Seq.fromList
Expand Down Expand Up @@ -652,7 +652,7 @@ fromShelleyPoolParams
, Ledger.ppPledge
, Ledger.ppCost
, Ledger.ppMargin
, Ledger.ppRewardAcnt
, Ledger.ppRewardAccount
, Ledger.ppOwners
, Ledger.ppRelays
, Ledger.ppMetadata
Expand All @@ -662,7 +662,7 @@ fromShelleyPoolParams
, stakePoolVRF = VrfKeyHash ppVrf
, stakePoolCost = ppCost
, stakePoolMargin = Ledger.unboundRational ppMargin
, stakePoolRewardAccount = fromShelleyStakeAddr ppRewardAcnt
, stakePoolRewardAccount = fromShelleyStakeAddr ppRewardAccount
, stakePoolPledge = ppPledge
, stakePoolOwners = map StakeKeyHash (Set.toList ppOwners)
, stakePoolRelays = map fromShelleyStakePoolRelay
Expand Down
13 changes: 7 additions & 6 deletions cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ evaluateTransactionFee :: forall era. ()
-> TxBody era
-> Word -- ^ The number of Shelley key witnesses
-> Word -- ^ The number of Byron key witnesses
-> Int -- ^ Reference script size in bytes
-> L.Coin
evaluateTransactionFee sbe pp txbody keywitcount byronwitcount =
evaluateTransactionFee sbe pp txbody keywitcount byronwitcount refScriptsSize =
shelleyBasedEraConstraints sbe $
case makeSignedTransaction' (shelleyBasedToCardanoEra sbe) [] txbody of
ShelleyTx _ tx ->
L.estimateMinFeeTx pp tx (fromIntegral keywitcount) (fromIntegral byronwitcount)
L.estimateMinFeeTx pp tx (fromIntegral keywitcount) (fromIntegral byronwitcount) refScriptsSize

-- | Estimate minimum transaction fee for a proposed transaction by looking
-- into the transaction and figuring out how many and what kind of key
Expand Down Expand Up @@ -196,13 +197,13 @@ type PlutusScriptBytes = ShortByteString
data ResolvablePointers where
ResolvablePointers ::
( Ledger.Era (ShelleyLedgerEra era)
, Show (L.PlutusPurpose L.AsIndex (ShelleyLedgerEra era))
, Show (L.PlutusPurpose L.AsIx (ShelleyLedgerEra era))
, Show (L.PlutusPurpose L.AsItem (ShelleyLedgerEra era))
, Show (Alonzo.PlutusScript (ShelleyLedgerEra era))
)
=> ShelleyBasedEra era
-> !(Map
(L.PlutusPurpose L.AsIndex (ShelleyLedgerEra era))
(L.PlutusPurpose L.AsIx (ShelleyLedgerEra era))
( L.PlutusPurpose L.AsItem (ShelleyLedgerEra era)
, Maybe (PlutusScriptBytes, Plutus.Language)
, Ledger.ScriptHash Ledger.StandardCrypto
Expand All @@ -219,7 +220,7 @@ deriving instance Show ResolvablePointers
-- the script, and two are the result of execution.
--
-- TODO: We should replace ScriptWitnessIndex with ledger's
-- PlutusPurpose AsIndex ledgerera. This would necessitate the
-- PlutusPurpose AsIx ledgerera. This would necessitate the
-- parameterization of ScriptExecutionError.
data ScriptExecutionError =

Expand Down Expand Up @@ -429,7 +430,7 @@ evaluateTransactionExecutionUnitsShelley sbe systemstart epochInfo (LedgerProtoc
fromLedgerScriptExUnitsMap
:: Alonzo.AlonzoEraScript (ShelleyLedgerEra era)
=> AlonzoEraOnwards era
-> Map (L.PlutusPurpose L.AsIndex (ShelleyLedgerEra era))
-> Map (L.PlutusPurpose L.AsIx (ShelleyLedgerEra era))
(Either (L.TransactionScriptFailure (ShelleyLedgerEra era)) Alonzo.ExUnits)
-> Map ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits)
fromLedgerScriptExUnitsMap aOnwards exmap =
Expand Down
3 changes: 3 additions & 0 deletions cardano-api/internal/Cardano/Api/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ conwayGenesisDefaults = ConwayGenesis { cgUpgradePParams = defaultUpgradeConwayP
, ucppDRepActivity = EpochInterval 100
, ucppCommitteeMinSize = 0
, ucppCommitteeMaxTermLength = EpochInterval 200
, ucppMinFeeRefScriptCostPerByte = 0 %! 1 -- TODO: set to correct value after benchmarking
}
where
defaultPoolVotingThresholds :: PoolVotingThresholds
Expand Down Expand Up @@ -240,6 +241,7 @@ alonzoGenesisDefaults = AlonzoGenesis { agPrices = Prices { prSteps = 721 %! 100
, 32, 32696, 32, 43357, 32, 32247, 32, 38314, 32, 35892428, 10, 9462713, 1021, 10, 38887044
, 32947, 10
]
-- taken from https://github.com/IntersectMBO/plutus/blob/master/plutus-core/cost-model/data/builtinCostModel.json
defaultV3CostModel = [ 205665, 812, 1, 1, 1000, 571, 0, 1, 1000, 24177, 4, 1, 1000, 32, 117366, 10475, 4, 117366, 10475, 4, 832808, 18
, 3209094, 6, 331451, 1, 65990684, 23097, 18, 114242, 18, 94393407
, 87060, 18, 16420089, 18, 2145798, 36, 3795345, 12, 889023, 1, 204237282, 23271, 36, 129165, 36, 189977790
Expand All @@ -252,4 +254,5 @@ alonzoGenesisDefaults = AlonzoGenesis { agPrices = Prices { prSteps = 721 %! 100
, 1, 1, 69522, 11687, 0, 1, 60091, 32, 196500, 453240, 220, 0, 1, 1, 196500, 453240, 220, 0, 1, 1, 1159724, 392670, 0, 2, 806990
, 30482, 4, 1927926, 82523, 4, 265318, 0, 4, 0, 85931, 32, 205665, 812, 1, 1, 41182
, 32, 212342, 32, 31220, 32, 32696, 32, 43357, 32, 32247, 32, 38314, 32, 35190005, 10, 57996947, 18975, 10, 39121781, 32260, 10
, 1292075, 24469, 74, 0, 1, 936157, 49601, 237, 0, 1
]
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ toGovernanceAction sbe =
InfoAct ->
Gov.InfoAction
TreasuryWithdrawal withdrawals govPol ->
let m = fromList [(L.RewardAcnt nw (toShelleyStakeCredential sc), l) | (nw,sc,l) <- withdrawals]
let m = fromList [(L.RewardAccount nw (toShelleyStakeCredential sc), l) | (nw,sc,l) <- withdrawals]
in Gov.TreasuryWithdrawals m govPol
InitiateHardfork prevGovId pVer ->
Gov.HardForkInitiation prevGovId pVer
Expand All @@ -117,7 +117,7 @@ fromGovernanceAction = \case
Gov.HardForkInitiation prevGovId pVer ->
InitiateHardfork prevGovId pVer
Gov.TreasuryWithdrawals withdrawlMap govPolicy ->
let res = [ (L.getRwdNetwork rwdAcnt, fromShelleyStakeCredential (L.getRwdCred rwdAcnt), coin)
let res = [ (L.raNetwork rwdAcnt, fromShelleyStakeCredential (L.raCredential rwdAcnt), coin)
| (rwdAcnt, coin) <- toList withdrawlMap
]
in TreasuryWithdrawal res govPolicy
Expand Down Expand Up @@ -170,7 +170,7 @@ createProposalProcedure sbe nw dep cred govAct anchor =
shelleyBasedEraConstraints sbe $
Proposal Gov.ProposalProcedure
{ Gov.pProcDeposit = dep
, Gov.pProcReturnAddr = L.RewardAcnt nw $ toShelleyStakeCredential cred
, Gov.pProcReturnAddr = L.RewardAccount nw $ toShelleyStakeCredential cred
, Gov.pProcGovAction = toGovernanceAction sbe govAct
, Gov.pProcAnchor = anchor
}
Expand All @@ -182,7 +182,7 @@ fromProposalProcedure
fromProposalProcedure sbe (Proposal pp) =
shelleyBasedEraConstraints sbe
( Gov.pProcDeposit pp
, case fromShelleyStakeCredential (L.getRwdCred (Gov.pProcReturnAddr pp)) of
, case fromShelleyStakeCredential (L.raCredential (Gov.pProcReturnAddr pp)) of
StakeCredentialByKey keyhash -> keyhash
StakeCredentialByScript _scripthash ->
error "fromProposalProcedure TODO: Conway era script reward addresses not yet supported"
Expand Down Expand Up @@ -213,4 +213,3 @@ createAnchor url anchorData =
{ anchorUrl = url
, anchorDataHash = hashAnchorData $ Ledger.AnchorData anchorData
}

Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ instance ConvertLedgerEvent (ShelleyBlock protocol (BabbageEra StandardCrypto))
toLedgerEvent = toAlonzoOrBabbageLedgerEvents

toAlonzoOrBabbageLedgerEvents
:: EraCrypto ledgerera ~ StandardCrypto
=> LatestTickEventConstraints ledgerera
:: LatestTickEventConstraints ledgerera
=> LatestBBodyEventConstraints ledgerera
=> EraCrypto ledgerera ~ StandardCrypto
=> WrapLedgerEvent (ShelleyBlock protocol ledgerera) -> Maybe LedgerEvent
toAlonzoOrBabbageLedgerEvents e =
case unwrapLedgerEvent e of
Expand All @@ -144,6 +144,7 @@ toAlonzoOrBabbageLedgerEvents e =

handleAlonzoToBabbageLedgerBBODYEvents
:: LatestBBodyEventConstraints ledgerera
=> EraCrypto ledgerera ~ StandardCrypto
=> AlonzoBbodyEvent ledgerera -> Maybe LedgerEvent
handleAlonzoToBabbageLedgerBBODYEvents (ShelleyInAlonzoEvent (LedgersEvent (Shelley.LedgerEvent ledgerEvent))) =
handleShelleyLEDGEREvents ledgerEvent
Expand Down
4 changes: 2 additions & 2 deletions cardano-api/internal/Cardano/Api/LedgerEvents/LedgerEvent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ data LedgerEvent
| -- | Pools have been reaped and deposits refunded.
PoolReap PoolReapDetails
-- | A number of succeeded Plutus script evaluations.
| SuccessfulPlutusScript (NonEmpty PlutusWithContext)
| SuccessfulPlutusScript (NonEmpty (PlutusWithContext StandardCrypto))
-- | A number of failed Plutus script evaluations.
| FailedPlutusScript (NonEmpty PlutusWithContext)
| FailedPlutusScript (NonEmpty (PlutusWithContext StandardCrypto))


-- Only events available on the Conway Era.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Cardano.Ledger.Alonzo.Rules (AlonzoUtxoEvent (..), AlonzoUtxosE
AlonzoUtxowEvent (..))
import qualified Cardano.Ledger.Alonzo.Rules as Alonzo
import qualified Cardano.Ledger.Core as Ledger.Core
import qualified Cardano.Ledger.Crypto as Crypto
import qualified Cardano.Ledger.Shelley.Rules as Shelley

import Control.State.Transition.Extended
Expand All @@ -35,6 +36,7 @@ handleShelleyLEDGEREvents
=> Event (Ledger.Core.EraRule "UTXO" ledgerera) ~ AlonzoUtxoEvent ledgerera
=> Event (Ledger.Core.EraRule "UTXOS" ledgerera) ~ AlonzoUtxosEvent ledgerera
=> Event (Ledger.Core.EraRule "DELEGS" ledgerera) ~ Shelley.ShelleyDelegsEvent ledgerera
=> Ledger.Core.EraCrypto ledgerera ~ Crypto.StandardCrypto
=> Shelley.ShelleyLedgerEvent ledgerera -> Maybe LedgerEvent
handleShelleyLEDGEREvents ledgerEvent =
case ledgerEvent of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Cardano.Ledger.Alonzo.Rules (AlonzoUtxoEvent (..), AlonzoUtxosE
AlonzoUtxowEvent (..))
import qualified Cardano.Ledger.Alonzo.Rules as Alonzo
import qualified Cardano.Ledger.Core as Ledger.Core
import qualified Cardano.Ledger.Crypto as Crypto
import qualified Cardano.Ledger.Shelley.Rules as Shelley

import Control.State.Transition.Extended
Expand All @@ -24,6 +25,7 @@ import Control.State.Transition.Extended
handleAlonzoOnwardsUTxOWEvent
:: Event (Ledger.Core.EraRule "UTXO" ledgerera) ~ AlonzoUtxoEvent ledgerera
=> Event (Ledger.Core.EraRule "UTXOS" ledgerera) ~ AlonzoUtxosEvent ledgerera
=> Ledger.Core.EraCrypto ledgerera ~ Crypto.StandardCrypto
=> AlonzoUtxowEvent ledgerera -> Maybe LedgerEvent
handleAlonzoOnwardsUTxOWEvent (WrappedShelleyEraEvent (Shelley.UtxoEvent (UtxosEvent utxoEvent))) =
case utxoEvent of
Expand All @@ -37,19 +39,19 @@ handlePreAlonzoUTxOWEvent
:: Event (Ledger.Core.EraRule "UTXO" ledgerera) ~ Shelley.UtxoEvent ledgerera
=> Event (Ledger.Core.EraRule "PPUP" ledgerera) ~ Shelley.PpupEvent ledgerera
=> Shelley.ShelleyUtxowEvent ledgerera -> Maybe LedgerEvent
handlePreAlonzoUTxOWEvent (Shelley.UtxoEvent e)=
handlePreAlonzoUTxOWEvent (Shelley.UtxoEvent e) =
case e of
Shelley.TotalDeposits{} -> Nothing
Shelley.UpdateEvent (Shelley.NewEpoch _) -> Nothing
Shelley.UpdateEvent (Shelley.PpupNewEpoch _) -> Nothing
Shelley.TxUTxODiff _ _ -> Nothing


handleAllegraMaryUTxOWEvent
:: Event (Ledger.Core.EraRule "UTXO" ledgerera) ~ Allegra.AllegraUtxoEvent ledgerera
=> Event (Ledger.Core.EraRule "PPUP" ledgerera) ~ Shelley.PpupEvent ledgerera
=> Shelley.ShelleyUtxowEvent ledgerera -> Maybe LedgerEvent
handleAllegraMaryUTxOWEvent (Shelley.UtxoEvent e)=
handleAllegraMaryUTxOWEvent (Shelley.UtxoEvent e) =
case e of
Allegra.TotalDeposits{} -> Nothing
Allegra.UpdateEvent (Shelley.NewEpoch _) -> Nothing
Allegra.UpdateEvent (Shelley.PpupNewEpoch _) -> Nothing
Allegra.TxUTxODiff _ _ -> Nothing
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ handleConwayNEWEPOCHEvents conwayNewEpochEvent =
(convertRetiredPoolsMap refundPools)
(convertRetiredPoolsMap unclaimedPools)
Conway.SnapEvent _ -> Nothing
Conway.TotalAdaPotsEvent _ -> Nothing

Conway.GovInfoEvent {} -> Nothing -- FIXME: Confirm if we need a new event here
carbolymer marked this conversation as resolved.
Show resolved Hide resolved

Conway.TotalAdaPotsEvent _ -> Nothing
Loading
Loading