Skip to content

Commit

Permalink
Break up
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Aug 21, 2023
1 parent c121c74 commit 1e0e393
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 92 deletions.
19 changes: 16 additions & 3 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ import Cardano.Api hiding (txIns)
import qualified Cardano.Api as Api
import Cardano.Api.Byron (KeyWitness (ByronKeyWitness),
WitnessNetworkIdOrByronAddress (..))
import Cardano.Api.Governance.Actions.VotingProcedure
import Cardano.Api.Script (scriptInEraToRefScript)
import Cardano.Api.Shelley

Expand All @@ -147,6 +148,7 @@ import qualified Data.ByteString.Short as SBS
import Data.Coerce
import Data.Int (Int64)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe
import Data.Ratio (Ratio, (%))
import Data.String
Expand Down Expand Up @@ -1125,7 +1127,18 @@ genTxVotes :: CardanoEra era -> Gen (TxVotes era)
genTxVotes era = fromMaybe (pure TxVotesNone) $ do
w <- featureInEra Nothing Just era
let votes = Gen.list (Range.constant 0 10) $ genVote w
pure $ TxVotes w <$> votes
pure $ TxVotes w . Map.fromList <$> votes
where
genVote :: ConwayEraOnwards era -> Gen (VotingProcedure era)
genVote w = conwayEraOnwardsConstraints w $ VotingProcedure <$> Q.arbitrary
genVote
:: ConwayEraOnwards era
-> Gen ( (Voter era, GovernanceActionId era)
, VotingProcedure era
)
genVote w =
conwayEraOnwardsConstraints w $
(,)
<$> ((,)
<$> (fromVoterRole (conwayEraOnwardsToShelleyBasedEra w) <$> Q.arbitrary)
<*> (GovernanceActionId <$> Q.arbitrary)
)
<*> (VotingProcedure <$> Q.arbitrary)
14 changes: 10 additions & 4 deletions cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ import qualified Cardano.Ledger.Crypto as Ledger
import qualified Cardano.Ledger.Keys as Ledger
import Cardano.Ledger.Mary.Value (MaryValue)
import qualified Cardano.Ledger.Shelley.API.Wallet as Ledger (evaluateTransactionFee)
import Cardano.Ledger.Shelley.TxBody (ShelleyEraTxBody)
import Cardano.Ledger.UTxO as Ledger (EraUTxO)
import qualified Ouroboros.Consensus.HardFork.History as Consensus
import qualified PlutusLedgerApi.V1 as Plutus
Expand Down Expand Up @@ -611,7 +610,16 @@ evaluateTransactionExecutionUnitsShelley sbe systemstart epochInfo pp utxo tx' =
-- This should not occur while using cardano-cli because we zip together
-- the Plutus script and the use site (txin, certificate etc). Therefore
-- the redeemer pointer will always point to a Plutus script.
L.MissingScript rdmrPtr resolveable -> ScriptErrorMissingScript rdmrPtr (ResolvablePointers sbe resolveable)
L.MissingScript rdmrPtr resolveable ->
let cnv1 Alonzo.Plutus
{ Alonzo.plutusLanguage = lang
, Alonzo.plutusScript = Alonzo.BinaryPlutus bytes
} = (bytes, lang)
cnv2 (purpose, mbScript, scriptHash) = (purpose, fmap cnv1 mbScript, scriptHash)
in
ScriptErrorMissingScript rdmrPtr
$ ResolvablePointers sbe
$ Map.map cnv2 resolveable

L.NoCostModelInLedgerState l -> ScriptErrorMissingCostModel l

Expand Down Expand Up @@ -664,7 +672,6 @@ evaluateTransactionBalance pp poolids stakeDelegDeposits utxo

evalMultiAsset :: forall ledgerera.
ShelleyLedgerEra era ~ ledgerera
=> ShelleyEraTxBody ledgerera
=> LedgerEraConstraints ledgerera
=> LedgerMultiAssetConstraints ledgerera
=> MultiAssetSupportedInEra era
Expand All @@ -680,7 +687,6 @@ evaluateTransactionBalance pp poolids stakeDelegDeposits utxo

evalAdaOnly :: forall ledgerera.
ShelleyLedgerEra era ~ ledgerera
=> ShelleyEraTxBody ledgerera
=> LedgerEraConstraints ledgerera
=> LedgerAdaOnlyConstraints ledgerera
=> OnlyAdaSupportedInEra era
Expand Down
12 changes: 6 additions & 6 deletions cardano-api/internal/Cardano/Api/Keys/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ instance HasTypeProxy CommitteeHotKey where
instance Key CommitteeHotKey where

newtype VerificationKey CommitteeHotKey =
CommitteeHotVerificationKey (Shelley.VKey Shelley.CommitteeHotKey StandardCrypto)
CommitteeHotVerificationKey (Shelley.VKey Shelley.HotCommitteeRole StandardCrypto)
deriving stock (Eq)
deriving (Show, IsString) via UsingRawBytesHex (VerificationKey CommitteeHotKey)
deriving newtype (ToCBOR, FromCBOR)
Expand Down Expand Up @@ -734,7 +734,7 @@ instance SerialiseAsRawBytes (SigningKey CommitteeHotKey) where


newtype instance Hash CommitteeHotKey =
CommitteeHotKeyHash (Shelley.KeyHash Shelley.CommitteeHotKey StandardCrypto)
CommitteeHotKeyHash (Shelley.KeyHash Shelley.HotCommitteeRole StandardCrypto)
deriving stock (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash CommitteeHotKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash CommitteeHotKey)
Expand Down Expand Up @@ -791,7 +791,7 @@ instance HasTypeProxy CommitteeColdKey where
instance Key CommitteeColdKey where

newtype VerificationKey CommitteeColdKey =
CommitteeColdVerificationKey (Shelley.VKey Shelley.CommitteeColdKey StandardCrypto)
CommitteeColdVerificationKey (Shelley.VKey Shelley.ColdCommitteeRole StandardCrypto)
deriving stock (Eq)
deriving (Show, IsString) via UsingRawBytesHex (VerificationKey CommitteeColdKey)
deriving newtype (ToCBOR, FromCBOR)
Expand Down Expand Up @@ -842,7 +842,7 @@ instance SerialiseAsRawBytes (SigningKey CommitteeColdKey) where


newtype instance Hash CommitteeColdKey =
CommitteeColdKeyHash (Shelley.KeyHash Shelley.CommitteeColdKey StandardCrypto)
CommitteeColdKeyHash (Shelley.KeyHash Shelley.ColdCommitteeRole StandardCrypto)
deriving stock (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash CommitteeColdKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash CommitteeColdKey)
Expand Down Expand Up @@ -1498,7 +1498,7 @@ instance HasTypeProxy DRepKey where
instance Key DRepKey where

newtype VerificationKey DRepKey =
DRepVerificationKey (Shelley.VKey Shelley.Voting StandardCrypto)
DRepVerificationKey (Shelley.VKey Shelley.DRepRole StandardCrypto)
deriving stock (Eq)
deriving (Show, IsString) via UsingRawBytesHex (VerificationKey DRepKey)
deriving newtype (ToCBOR, FromCBOR)
Expand Down Expand Up @@ -1557,7 +1557,7 @@ instance SerialiseAsBech32 (SigningKey DRepKey) where
bech32PrefixesPermitted _ = ["drep_sk"]

newtype instance Hash DRepKey =
DRepKeyHash { unDRepKeyHash :: Shelley.KeyHash Shelley.Voting StandardCrypto }
DRepKeyHash { unDRepKeyHash :: Shelley.KeyHash Shelley.DRepRole StandardCrypto }
deriving stock (Eq, Ord)
deriving (Show, IsString) via UsingRawBytesHex (Hash DRepKey)
deriving (ToCBOR, FromCBOR) via UsingRawBytes (Hash DRepKey)
Expand Down
58 changes: 44 additions & 14 deletions cardano-api/internal/Cardano/Api/LedgerState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ import Ouroboros.Consensus.Protocol.Abstract (ChainDepState, Consensus
import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus
import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus
import Ouroboros.Consensus.Protocol.Praos.VRF (mkInputVRF, vrfLeaderValue)
import Ouroboros.Consensus.Protocol.TPraos (TPraos)
import qualified Ouroboros.Consensus.Protocol.TPraos as TPraos
import qualified Ouroboros.Consensus.Shelley.Eras as Shelley
import qualified Ouroboros.Consensus.Shelley.Ledger.Block as Shelley
import qualified Ouroboros.Consensus.Shelley.Ledger.Ledger as Shelley
import qualified Ouroboros.Consensus.Shelley.Node.Praos as Consensus
import Ouroboros.Consensus.TypeFamilyWrappers (WrapLedgerEvent (WrapLedgerEvent))
import qualified Ouroboros.Network.Block
import qualified Ouroboros.Network.Protocol.ChainSync.Client as CS
Expand Down Expand Up @@ -805,12 +805,18 @@ data NodeConfig = NodeConfig
, ncByronProtocolVersion :: !Cardano.Chain.Update.ProtocolVersion

-- Per-era parameters for the hardfok transitions:
, ncByronToShelley :: !(Consensus.ProtocolTransitionParamsShelleyBased
Shelley.StandardShelley)
, ncShelleyToAllegra :: !(Consensus.ProtocolTransitionParamsShelleyBased
Shelley.StandardAllegra)
, ncAllegraToMary :: !(Consensus.ProtocolTransitionParamsShelleyBased
Shelley.StandardMary)
, ncByronToShelley :: !(Consensus.ProtocolTransitionParams
Byron.ByronBlock
(Shelley.ShelleyBlock (TPraos Shelley.StandardCrypto) Shelley.StandardShelley)
)
, ncShelleyToAllegra :: !(Consensus.ProtocolTransitionParams
(Shelley.ShelleyBlock (TPraos Shelley.StandardCrypto) Shelley.StandardShelley)
(Shelley.ShelleyBlock (TPraos Shelley.StandardCrypto) Shelley.StandardAllegra)
)
, ncAllegraToMary :: !(Consensus.ProtocolTransitionParams
(Shelley.ShelleyBlock (TPraos Shelley.StandardCrypto) Shelley.StandardAllegra)
(Shelley.ShelleyBlock (TPraos Shelley.StandardCrypto) Shelley.StandardMary)
)
, ncMaryToAlonzo :: !Consensus.TriggerHardFork
, ncAlonzoToBabbage :: !Consensus.TriggerHardFork
, ncBabbageToConway :: !Consensus.TriggerHardFork
Expand All @@ -834,11 +840,11 @@ instance FromJSON NodeConfig where
<*> fmap GenesisHashConway (o .: "ConwayGenesisHash")
<*> o .: "RequiresNetworkMagic"
<*> parseByronProtocolVersion o
<*> (Consensus.ProtocolTransitionParamsShelleyBased emptyFromByronTranslationContext
<*> (Consensus.ProtocolTransitionParamsByronToShelley emptyFromByronTranslationContext
<$> parseShelleyHardForkEpoch o)
<*> (Consensus.ProtocolTransitionParamsShelleyBased ()
<*> (Consensus.ProtocolTransitionParamsIntraShelley ()
<$> parseAllegraHardForkEpoch o)
<*> (Consensus.ProtocolTransitionParamsShelleyBased ()
<*> (Consensus.ProtocolTransitionParamsIntraShelley ()
<$> parseMaryHardForkEpoch o)
<*> parseAlonzoHardForkEpoch o
<*> parseBabbageHardForkEpoch o
Expand Down Expand Up @@ -997,7 +1003,8 @@ mkProtocolInfoCardano ::
, IO [BlockForging IO (HFC.HardForkBlock
(Consensus.CardanoEras Consensus.StandardCrypto))])
mkProtocolInfoCardano (GenesisCardano dnc byronGenesis shelleyGenesis alonzoGenesis conwayGenesis)
= Consensus.protocolInfoCardano
= Consensus.protocolInfoCardano Consensus.CardanoProtocolParams
{ Consensus.paramsByron =
Consensus.ProtocolParamsByron
{ Consensus.byronGenesis = byronGenesis
, Consensus.byronPbftSignatureThreshold = Consensus.PBftSignatureThreshold <$> ncPBftSignatureThreshold dnc
Expand All @@ -1006,41 +1013,64 @@ mkProtocolInfoCardano (GenesisCardano dnc byronGenesis shelleyGenesis alonzoGene
, Consensus.byronLeaderCredentials = Nothing
, Consensus.byronMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
, Consensus.paramsShelleyBased =
Consensus.ProtocolParamsShelleyBased
{ Consensus.shelleyBasedGenesis = scConfig shelleyGenesis
, Consensus.shelleyBasedInitialNonce = shelleyPraosNonce shelleyGenesis
, Consensus.shelleyBasedLeaderCredentials = []
}
, Consensus.paramsShelley =
Consensus.ProtocolParamsShelley
{ Consensus.shelleyProtVer = ProtVer (natVersion @3) 0
, Consensus.shelleyMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
, Consensus.paramsAllegra =
Consensus.ProtocolParamsAllegra
{ Consensus.allegraProtVer = ProtVer (natVersion @4) 0
, Consensus.allegraMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
, Consensus.paramsMary =
Consensus.ProtocolParamsMary
{ Consensus.maryProtVer = ProtVer (natVersion @5) 0
, Consensus.maryMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
, Consensus.paramsAlonzo =
Consensus.ProtocolParamsAlonzo
{ Consensus.alonzoProtVer = ProtVer (natVersion @7) 0
, Consensus.alonzoMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
, Consensus.paramsBabbage =
Consensus.ProtocolParamsBabbage
{ Consensus.babbageProtVer = ProtVer (natVersion @9) 0
, Consensus.babbageMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
, Consensus.paramsConway =
Consensus.ProtocolParamsConway
{ Consensus.conwayProtVer = ProtVer (natVersion @10) 0
, Consensus.conwayMaxTxCapacityOverrides = TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
, Consensus.transitionParamsByronToShelley =
(ncByronToShelley dnc)
, Consensus.transitionParamsShelleyToAllegra =
(ncShelleyToAllegra dnc)
, Consensus.transitionParamsAllegraToMary =
(ncAllegraToMary dnc)
(Consensus.ProtocolTransitionParamsShelleyBased alonzoGenesis (ncMaryToAlonzo dnc))
(Consensus.ProtocolTransitionParamsShelleyBased () (ncAlonzoToBabbage dnc))
(Consensus.ProtocolTransitionParamsShelleyBased conwayGenesis (ncBabbageToConway dnc))
, Consensus.transitionParamsMaryToAlonzo =
Consensus.ProtocolTransitionParamsIntraShelley
{ Consensus.transitionIntraShelleyTranslationContext = alonzoGenesis
, Consensus.transitionIntraShelleyTrigger = ncMaryToAlonzo dnc
}
, Consensus.transitionParamsAlonzoToBabbage =
Consensus.ProtocolTransitionParamsIntraShelley
{ Consensus.transitionIntraShelleyTranslationContext = ()
, Consensus.transitionIntraShelleyTrigger = ncAlonzoToBabbage dnc
}
, Consensus.transitionParamsBabbageToConway =
Consensus.ProtocolTransitionParamsIntraShelley
{ Consensus.transitionIntraShelleyTranslationContext = conwayGenesis
, Consensus.transitionIntraShelleyTrigger = ncBabbageToConway dnc
}
}

-- | Compute the Nonce from the ShelleyGenesis file.
shelleyPraosNonce :: ShelleyConfig -> Ledger.Nonce
Expand Down
35 changes: 35 additions & 0 deletions cardano-api/internal/Cardano/Api/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import qualified Cardano.Ledger.Alonzo.PParams as Ledger
import qualified Cardano.Ledger.Babbage.PParams as Ledger
import Cardano.Ledger.BaseTypes (strictMaybeToMaybe)
import qualified Cardano.Ledger.BaseTypes as Ledger
import qualified Cardano.Ledger.Conway.PParams as Ledger
import Cardano.Ledger.Crypto (StandardCrypto)
import qualified Cardano.Ledger.Crypto as CC (Crypto)
import qualified Cardano.Ledger.Crypto as Crypto
Expand Down Expand Up @@ -291,3 +292,37 @@ instance Semigroup (Ledger.BabbagePParams StrictMaybe era) where
, Ledger.bppCollateralPercentage = fbppCollateralPercentage
, Ledger.bppMaxCollateralInputs = fbppMaxCollateralInputs
}

instance Semigroup (Ledger.ConwayPParams StrictMaybe era) where
(<>) p1 p2 = Ledger.ConwayPParams
{ Ledger.cppMinFeeA = Ledger.cppMinFeeA p1 `lastMappend` Ledger.cppMinFeeA p2
, Ledger.cppMinFeeB = Ledger.cppMinFeeB p1 `lastMappend` Ledger.cppMinFeeB p2
, Ledger.cppMaxBBSize = Ledger.cppMaxBBSize p1 `lastMappend` Ledger.cppMaxBBSize p2
, Ledger.cppMaxTxSize = Ledger.cppMaxTxSize p1 `lastMappend` Ledger.cppMaxTxSize p2
, Ledger.cppMaxBHSize = Ledger.cppMaxBHSize p1 `lastMappend` Ledger.cppMaxBHSize p2
, Ledger.cppKeyDeposit = Ledger.cppKeyDeposit p1 `lastMappend` Ledger.cppKeyDeposit p2
, Ledger.cppPoolDeposit = Ledger.cppPoolDeposit p1 `lastMappend` Ledger.cppPoolDeposit p2
, Ledger.cppEMax = Ledger.cppEMax p1 `lastMappend` Ledger.cppEMax p2
, Ledger.cppNOpt = Ledger.cppNOpt p1 `lastMappend` Ledger.cppNOpt p2
, Ledger.cppA0 = Ledger.cppA0 p1 `lastMappend` Ledger.cppA0 p2
, Ledger.cppRho = Ledger.cppRho p1 `lastMappend` Ledger.cppRho p2
, Ledger.cppTau = Ledger.cppTau p1 `lastMappend` Ledger.cppTau p2
, Ledger.cppProtocolVersion = Ledger.cppProtocolVersion p1 `lastMappend` Ledger.cppProtocolVersion p2
, Ledger.cppMinPoolCost = Ledger.cppMinPoolCost p1 `lastMappend` Ledger.cppMinPoolCost p2
, Ledger.cppCoinsPerUTxOByte = Ledger.cppCoinsPerUTxOByte p1 `lastMappend` Ledger.cppCoinsPerUTxOByte p2
, Ledger.cppCostModels = Ledger.cppCostModels p1 `lastMappend` Ledger.cppCostModels p2
, Ledger.cppPrices = Ledger.cppPrices p1 `lastMappend` Ledger.cppPrices p2
, Ledger.cppMaxTxExUnits = Ledger.cppMaxTxExUnits p1 `lastMappend` Ledger.cppMaxTxExUnits p2
, Ledger.cppMaxBlockExUnits = Ledger.cppMaxBlockExUnits p1 `lastMappend` Ledger.cppMaxBlockExUnits p2
, Ledger.cppMaxValSize = Ledger.cppMaxValSize p1 `lastMappend` Ledger.cppMaxValSize p2
, Ledger.cppCollateralPercentage = Ledger.cppCollateralPercentage p1 `lastMappend` Ledger.cppCollateralPercentage p2
, Ledger.cppMaxCollateralInputs = Ledger.cppMaxCollateralInputs p1 `lastMappend` Ledger.cppMaxCollateralInputs p2
, Ledger.cppPoolVotingThresholds = Ledger.cppPoolVotingThresholds p1 `lastMappend` Ledger.cppPoolVotingThresholds p2
, Ledger.cppDRepVotingThresholds = Ledger.cppDRepVotingThresholds p1 `lastMappend` Ledger.cppDRepVotingThresholds p2
, Ledger.cppMinCommitteeSize = Ledger.cppMinCommitteeSize p1 `lastMappend` Ledger.cppMinCommitteeSize p2
, Ledger.cppCommitteeTermLimit = Ledger.cppCommitteeTermLimit p1 `lastMappend` Ledger.cppCommitteeTermLimit p2
, Ledger.cppGovActionExpiration = Ledger.cppGovActionExpiration p1 `lastMappend` Ledger.cppGovActionExpiration p2
, Ledger.cppGovActionDeposit = Ledger.cppGovActionDeposit p1 `lastMappend` Ledger.cppGovActionDeposit p2
, Ledger.cppDRepDeposit = Ledger.cppDRepDeposit p1 `lastMappend` Ledger.cppDRepDeposit p2
, Ledger.cppDRepActivity = Ledger.cppDRepActivity p1 `lastMappend` Ledger.cppDRepActivity p2
}
Loading

0 comments on commit 1e0e393

Please sign in to comment.