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

Conway era #201

Merged
merged 12 commits into from
Sep 6, 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ work/
nohup.out
haddocks/
.direnv
.envrc
.envrc
get-protocol-parameters.sh
protocol-parameters-mainnet.json
1 change: 1 addition & 0 deletions src/base/convex-base.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ library
cardano-ledger-shelley,
cardano-ledger-babbage,
cardano-ledger-alonzo,
cardano-ledger-conway,

ouroboros-consensus,
ouroboros-consensus-cardano,
Expand Down
111 changes: 57 additions & 54 deletions src/base/lib/Convex/BuildTx.hs

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions src/base/lib/Convex/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module Convex.Class(
) where

import qualified Cardano.Api as C
import Cardano.Api.Shelley (BabbageEra,
import Cardano.Api.Shelley (ConwayEra,
EraHistory (..),
Hash,
HashableScriptData,
Expand Down Expand Up @@ -151,9 +151,9 @@ import Test.QuickCheck.Monadic (PropertyM)
-}
class Monad m => MonadBlockchain m where
-- see note Note [sendTx Failure]
sendTx :: Tx BabbageEra -> m (Either SendTxFailed TxId) -- ^ Submit a transaction to the network
utxoByTxIn :: Set C.TxIn -> m (C.UTxO C.BabbageEra) -- ^ Resolve tx inputs
queryProtocolParameters :: m (LedgerProtocolParameters C.BabbageEra) -- ^ Get the protocol parameters
sendTx :: Tx ConwayEra -> m (Either SendTxFailed TxId) -- ^ Submit a transaction to the network
utxoByTxIn :: Set C.TxIn -> m (C.UTxO C.ConwayEra) -- ^ Resolve tx inputs
queryProtocolParameters :: m (LedgerProtocolParameters C.ConwayEra) -- ^ Get the protocol parameters
queryStakeAddresses :: Set C.StakeCredential -> NetworkId -> m (Map C.StakeAddress C.Quantity, Map C.StakeAddress PoolId) -- ^ Get stake rewards
queryStakePools :: m (Set PoolId) -- ^ Get the stake pools
querySystemStart :: m SystemStart
Expand All @@ -166,7 +166,7 @@ class Monad m => MonadBlockchain m where
{-| Try sending the transaction to the node, failing with 'error' if 'sendTx'
was not successful.
-}
trySendTx :: MonadBlockchain m => Tx BabbageEra -> m TxId
trySendTx :: MonadBlockchain m => Tx ConwayEra -> m TxId
trySendTx = fmap (either (error . show) id) . sendTx

deriving newtype instance MonadBlockchain m => MonadBlockchain (MonadLogIgnoreT m)
Expand Down Expand Up @@ -227,7 +227,7 @@ instance MonadBlockchain m => MonadBlockchain (LazyState.StateT e m) where
networkId = lift networkId

-- | Look up a single UTxO
singleUTxO :: MonadBlockchain m => C.TxIn -> m (Maybe (C.TxOut C.CtxUTxO C.BabbageEra))
singleUTxO :: MonadBlockchain m => C.TxIn -> m (Maybe (C.TxOut C.CtxUTxO C.ConwayEra))
singleUTxO txi = utxoByTxIn (Set.singleton txi) >>= \case
C.UTxO (Map.toList -> [(_, o)]) -> pure (Just o)
_ -> pure Nothing
Expand All @@ -250,7 +250,7 @@ instance Pretty SendTxFailed where
pretty (SendTxFailed msg) = "sendTx: Submission failed:" <+> pretty msg

data ExUnitsError =
Phase1Error (C.TransactionValidityError BabbageEra)
Phase1Error (C.TransactionValidityError ConwayEra)
| Phase2Error C.ScriptExecutionError
deriving (Show)

Expand All @@ -270,7 +270,7 @@ data MockChainState =
{ mcsEnv :: MempoolEnv ERA
, mcsPoolState :: MempoolState ERA
, mcsTransactions :: [(Validated (Core.Tx ERA), [PlutusWithContext StandardCrypto])] -- ^ Transactions that were submitted to the mockchain and validated
, mcsFailedTransactions :: [(Tx BabbageEra, ValidationError)] -- ^ Transactions that were submitted to the mockchain, but failed with a validation error
, mcsFailedTransactions :: [(Tx ConwayEra, ValidationError)] -- ^ Transactions that were submitted to the mockchain, but failed with a validation error
, mcsDatums :: Map (Hash ScriptData) HashableScriptData
}

Expand Down Expand Up @@ -357,8 +357,8 @@ setUtxo :: MonadMockchain m => UTxO ERA -> m ()
setUtxo u = modifyUtxo (const (u, ()))

{-| Return all Tx's from the ledger state -}
getTxs :: MonadMockchain m => m [C.Tx C.BabbageEra] -- [Core.Tx ERA]
getTxs = getMockChainState <&> view (transactions . traverse . _1 . to ((: []) . C.ShelleyTx C.ShelleyBasedEraBabbage . extractTx))
getTxs :: MonadMockchain m => m [C.Tx C.ConwayEra]
getTxs = getMockChainState <&> view (transactions . traverse . _1 . to ((: []) . C.ShelleyTx C.ShelleyBasedEraConway . extractTx))

{-| Return all Tx's from the ledger state -}

Expand All @@ -371,7 +371,7 @@ setPOSIXTime tm =
{-| Change the clock so that the current slot time is within the given validity range.
This MAY move the clock backwards!
-}
setTimeToValidRange :: MonadMockchain m => (C.TxValidityLowerBound C.BabbageEra, C.TxValidityUpperBound C.BabbageEra) -> m ()
setTimeToValidRange :: MonadMockchain m => (C.TxValidityLowerBound C.ConwayEra, C.TxValidityUpperBound C.ConwayEra) -> m ()
setTimeToValidRange = \case
(C.TxValidityLowerBound _ lowerSlot, _) -> setSlot lowerSlot
(_, C.TxValidityUpperBound _ (Just upperSlot)) -> setSlot (pred upperSlot)
Expand Down Expand Up @@ -509,7 +509,7 @@ instance (MonadLog m, MonadIO m) => MonadBlockchain (MonadBlockchainCardanoNodeT
sendTx tx = MonadBlockchainCardanoNodeT $ do
let txId = C.getTxId (C.getTxBody tx)
info <- ask
result <- liftIO (C.submitTxToNodeLocal info (C.TxInMode C.ShelleyBasedEraBabbage tx))
result <- liftIO (C.submitTxToNodeLocal info (C.TxInMode C.ShelleyBasedEraConway tx))
case result of
SubmitSuccess -> do
logInfoS ("sendTx: Submitted " <> show txId)
Expand All @@ -520,16 +520,16 @@ instance (MonadLog m, MonadIO m) => MonadBlockchain (MonadBlockchainCardanoNodeT
pure (Left msg)

utxoByTxIn txIns =
runQuery' (C.QueryInEra (C.QueryInShelleyBasedEra C.ShelleyBasedEraBabbage (C.QueryUTxO (C.QueryUTxOByTxIn txIns))))
runQuery' (C.QueryInEra (C.QueryInShelleyBasedEra C.ShelleyBasedEraConway (C.QueryUTxO (C.QueryUTxOByTxIn txIns))))

queryProtocolParameters = do
LedgerProtocolParameters <$> runQuery' (C.QueryInEra (C.QueryInShelleyBasedEra C.ShelleyBasedEraBabbage C.QueryProtocolParameters))
LedgerProtocolParameters <$> runQuery' (C.QueryInEra (C.QueryInShelleyBasedEra C.ShelleyBasedEraConway C.QueryProtocolParameters))

queryStakeAddresses creds nid =
first (fmap C.lovelaceToQuantity) <$> runQuery' (C.QueryInEra (C.QueryInShelleyBasedEra C.ShelleyBasedEraBabbage (C.QueryStakeAddresses creds nid)))
first (fmap C.lovelaceToQuantity) <$> runQuery' (C.QueryInEra (C.QueryInShelleyBasedEra C.ShelleyBasedEraConway (C.QueryStakeAddresses creds nid)))

queryStakePools =
runQuery' (C.QueryInEra (C.QueryInShelleyBasedEra C.ShelleyBasedEraBabbage C.QueryStakePools))
runQuery' (C.QueryInEra (C.QueryInShelleyBasedEra C.ShelleyBasedEraConway C.QueryStakePools))

querySystemStart = runQuery C.QuerySystemStart

Expand Down
14 changes: 7 additions & 7 deletions src/base/lib/Convex/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ module Convex.Constants(
lessRecent
) where

import Cardano.Api (AsType (AsHash), BlockHeader,
ChainPoint (..))
import qualified Cardano.Api as CAPI
import Cardano.Ledger.Babbage (BabbageEra)
import Cardano.Ledger.Crypto (StandardCrypto)
import Cardano.Api (AsType (AsHash), BlockHeader,
ChainPoint (..))
import qualified Cardano.Api as CAPI
import Cardano.Ledger.Conway (ConwayEra)
import Cardano.Ledger.Crypto (StandardCrypto)

import Data.Proxy (Proxy (..))
import Data.Proxy (Proxy (..))

-- | Current era
type ERA = BabbageEra StandardCrypto
type ERA = ConwayEra StandardCrypto

-- | Start of the Alonzo era on mainnet.
-- https://explorer.cardano.org/en/block?id=8959c0323b94cc670afe44222ab8b4e72cfcad3b5ab665f334bbe642dc6e9ef4
Expand Down
99 changes: 30 additions & 69 deletions src/base/lib/Convex/NodeParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,41 @@ module Convex.NodeParams(
slotLength,
pParams,

-- * Lenses for @ProtocolParameters@
-- See https://input-output-hk.github.io/cardano-node/cardano-api/lib/Cardano-Api-Shelley.html#t:ProtocolParameters
-- for an explanation of the fields
protocolVersion,
decentralization,
extraPraosEntropy,
maxBlockHeaderSize,
maxBlockBodySize,
maxTxSize,
txFeeFixed,
txFeeFerByte,
minUTxOValue,
stakeAddressDeposit,
stakePoolDeposit,
minPoolCost,
poolRetireMaxEpoch,
stakePoolTargetNum,
poolPledgeInfluence,
monetaryExpansion,
treasuryCut,
costModels,
prices,
maxTxExUnits,
maxBlockExUnits,
maxValueSize,
collateralPercent,
maxCollateralInputs,
uTxOCostPerByte,
-- * Lenses for @ProtocolParameters@, re-exported from cardano-ledger.
-- See 'Cardano.Api.Ledger' for an explanation of the fields and a full list
L.ppProtocolVersionL,
L.hkdMaxBHSizeL,
L.hkdMaxBBSizeL,
L.hkdMaxTxSizeL,
L.hkdMinFeeAL,
L.hkdMinFeeBL,
L.hkdPoolDepositL,
L.hkdPricesL,
L.hkdMaxTxExUnitsL,
L.hkdMaxBlockExUnitsL,
L.hkdMaxValSizeL,
L.hkdCollateralPercentageL,
L.hkdMaxCollateralInputsL,
L.hkdMinPoolCostL,
L.hkdCostModelsL
) where

import Cardano.Api (BabbageEra)
import Cardano.Api.Shelley (EraHistory,
LedgerProtocolParameters (..),
NetworkId (..), PoolId,
ProtocolParameters (..))
import Cardano.Ledger.Babbage (Babbage)
import Cardano.Ledger.Core (PParams)
import Cardano.Slotting.Time (SlotLength, SystemStart)
import Control.Lens.TH (makeLensesFor)
import Data.Set as Set (Set)
import Cardano.Api (ConwayEra)
import Cardano.Api.Ledger (PParams)
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley (EraHistory,
LedgerProtocolParameters (..),
NetworkId (..), PoolId)
import qualified Cardano.Ledger.Alonzo.PParams as L
import Cardano.Slotting.Time (SlotLength, SystemStart)
import Control.Lens.TH (makeLensesFor)
import Data.Set as Set (Set)
import Ouroboros.Consensus.Shelley.Eras (StandardConway)

data NodeParams =
NodeParams
{ npNetworkId :: NetworkId
, npProtocolParameters :: LedgerProtocolParameters BabbageEra
, npProtocolParameters :: LedgerProtocolParameters ConwayEra
, npSystemStart :: SystemStart
, npEraHistory :: EraHistory
, npStakePools :: Set PoolId
Expand All @@ -77,36 +67,7 @@ makeLensesFor
[ ("unLedgerProtocolParameters", "protocolParameters")
] ''LedgerProtocolParameters

makeLensesFor
[ ("protocolParamProtocolVersion", "protocolVersion")
, ("protocolParamDecentralization", "decentralization")
, ("protocolParamExtraPraosEntropy", "extraPraosEntropy")
, ("protocolParamMaxBlockHeaderSize", "maxBlockHeaderSize")
, ("protocolParamMaxBlockBodySize", "maxBlockBodySize")
, ("protocolParamMaxTxSize", "maxTxSize")
, ("protocolParamTxFeeFixed", "txFeeFixed")
, ("protocolParamTxFeePerByte", "txFeeFerByte")
, ("protocolParamMinUTxOValue", "minUTxOValue")
, ("protocolParamStakeAddressDeposit", "stakeAddressDeposit")
, ("protocolParamStakePoolDeposit", "stakePoolDeposit")
, ("protocolParamMinPoolCost", "minPoolCost")
, ("protocolParamPoolRetireMaxEpoch", "poolRetireMaxEpoch")
, ("protocolParamStakePoolTargetNum", "stakePoolTargetNum")
, ("protocolParamPoolPledgeInfluence", "poolPledgeInfluence")
, ("protocolParamMonetaryExpansion", "monetaryExpansion")
, ("protocolParamTreasuryCut", "treasuryCut")
, ("protocolParamUTxOCostPerWord", "uTxOCostPerWord")
, ("protocolParamCostModels", "costModels")
, ("protocolParamPrices", "prices")
, ("protocolParamMaxTxExUnits", "maxTxExUnits")
, ("protocolParamMaxBlockExUnits", "maxBlockExUnits")
, ("protocolParamMaxValueSize", "maxValueSize")
, ("protocolParamCollateralPercent", "collateralPercent")
, ("protocolParamMaxCollateralInputs", "maxCollateralInputs")
, ("protocolParamUTxOCostPerByte", "uTxOCostPerByte")
] ''ProtocolParameters

-- | Convert `Params` to cardano-ledger `PParams`
pParams :: NodeParams -> PParams Babbage
pParams :: NodeParams -> PParams StandardConway
pParams NodeParams { npProtocolParameters } = case npProtocolParameters of
LedgerProtocolParameters p -> p
10 changes: 5 additions & 5 deletions src/base/lib/Convex/NodeQueries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import qualified Ouroboros.Consensus.Cardano.CanHardFork as Consensus
import qualified Ouroboros.Consensus.HardFork.Combinator as Consensus
import qualified Ouroboros.Consensus.HardFork.Combinator.AcrossEras as HFC
import qualified Ouroboros.Consensus.HardFork.Combinator.Basics as HFC
import Ouroboros.Consensus.Shelley.Eras (StandardBabbage)
import Ouroboros.Consensus.Shelley.Eras (StandardConway)
import qualified Ouroboros.Network.Protocol.LocalStateQuery.Type as T

{-| Load the node config file and create 'LocalNodeConnectInfo' and 'Env' values that can be used to talk to the node.
Expand Down Expand Up @@ -103,7 +103,7 @@ queryTip = queryLocalState CAPI.QueryChainPoint
queryStakePools :: LocalNodeConnectInfo -> IO (Set PoolId)
queryStakePools connectInfo = do
result <- queryLocalState
(CAPI.QueryInEra (CAPI.QueryInShelleyBasedEra CAPI.ShelleyBasedEraBabbage CAPI.QueryStakePools))
(CAPI.QueryInEra (CAPI.QueryInShelleyBasedEra CAPI.ShelleyBasedEraConway CAPI.QueryStakePools))
connectInfo
case result of
Left err -> do
Expand All @@ -113,7 +113,7 @@ queryStakePools connectInfo = do
queryStakeAddresses :: LocalNodeConnectInfo -> Set StakeCredential -> NetworkId -> IO (Map StakeAddress Quantity, Map StakeAddress PoolId)
queryStakeAddresses info creds nid = do
result <- queryLocalState
(CAPI.QueryInEra (CAPI.QueryInShelleyBasedEra CAPI.ShelleyBasedEraBabbage (CAPI.QueryStakeAddresses creds nid)))
(CAPI.QueryInEra (CAPI.QueryInShelleyBasedEra CAPI.ShelleyBasedEraConway (CAPI.QueryStakeAddresses creds nid)))
info
case result of
Left err -> do
Expand All @@ -129,9 +129,9 @@ queryLocalState query connectInfo = do
Right result -> pure result

-- | Get the protocol parameters from the local cardano node
queryProtocolParameters :: LocalNodeConnectInfo -> IO (PParams StandardBabbage)
queryProtocolParameters :: LocalNodeConnectInfo -> IO (PParams StandardConway)
queryProtocolParameters connectInfo = do
result <- queryLocalState (CAPI.QueryInEra (CAPI.QueryInShelleyBasedEra CAPI.ShelleyBasedEraBabbage CAPI.QueryProtocolParameters)) connectInfo
result <- queryLocalState (CAPI.QueryInEra (CAPI.QueryInShelleyBasedEra CAPI.ShelleyBasedEraConway CAPI.QueryProtocolParameters)) connectInfo
case result of
Left err -> do
fail ("queryProtocolParameters: failed with: " <> show err)
Expand Down
16 changes: 8 additions & 8 deletions src/base/lib/Convex/PlutusLedger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,19 @@ unTransStakeAddressReference (Just (PV1.StakingHash credential)) =
unTransStakeAddressReference (Just (PV1.StakingPtr slotNo txIx ptrIx)) =
Right (C.StakeAddressByPointer (C.StakeAddressPointer (Ptr (C.SlotNo $ fromIntegral slotNo) (TxIx $ fromIntegral txIx) (CertIx $ fromIntegral ptrIx))))

unTransAddressInEra :: C.NetworkId -> PV1.Address -> Either C.SerialiseAsRawBytesError (C.AddressInEra C.BabbageEra)
unTransAddressInEra :: C.NetworkId -> PV1.Address -> Either C.SerialiseAsRawBytesError (C.AddressInEra C.ConwayEra)
unTransAddressInEra networkId (PV1.Address cred staking) =
C.AddressInEra (C.ShelleyAddressInEra C.ShelleyBasedEraBabbage) <$>
C.AddressInEra (C.ShelleyAddressInEra C.ShelleyBasedEraConway) <$>
(C.makeShelleyAddress networkId
<$> unTransCredential cred
<*> unTransStakeAddressReference staking
)

-- | @cardano-api@ address to @plutus@ address. Returns 'Nothing' for
-- | byron addresses.
transAddressInEra :: C.AddressInEra C.BabbageEra -> Maybe PV1.Address
transAddressInEra :: C.AddressInEra C.ConwayEra -> Maybe PV1.Address
transAddressInEra = \case
C.AddressInEra (C.ShelleyAddressInEra C.ShelleyBasedEraBabbage) (C.ShelleyAddress _ p s) ->
C.AddressInEra (C.ShelleyAddressInEra C.ShelleyBasedEraConway) (C.ShelleyAddress _ p s) ->
Just $ PV1.Address
(transCredential $ C.fromShelleyPaymentCredential p)
(transStakeAddressReference $ C.fromShelleyStakeReference s)
Expand All @@ -215,8 +215,8 @@ transPOSIXTime posixTimeSeconds = PV1.POSIXTime (floor @Rational (1000 * realToF
unTransPOSIXTime :: PV1.POSIXTime -> POSIXTime
unTransPOSIXTime (PV1.POSIXTime pt) = realToFrac @Rational $ fromIntegral pt / 1000

unTransTxOutValue :: PV1.Value -> Either C.SerialiseAsRawBytesError (C.TxOutValue C.BabbageEra)
unTransTxOutValue value = C.TxOutValueShelleyBased C.ShelleyBasedEraBabbage . C.toMaryValue <$> unTransValue value
unTransTxOutValue :: PV1.Value -> Either C.SerialiseAsRawBytesError (C.TxOutValue C.ConwayEra)
unTransTxOutValue value = C.TxOutValueShelleyBased C.ShelleyBasedEraConway . C.toMaryValue <$> unTransValue value

unTransValue :: PV1.Value -> Either C.SerialiseAsRawBytesError C.Value
unTransValue =
Expand Down Expand Up @@ -244,5 +244,5 @@ unTransScriptDataHash :: P.DatumHash -> Either C.SerialiseAsRawBytesError (C.Has
unTransScriptDataHash (P.DatumHash bs) =
C.deserialiseFromRawBytes (C.AsHash C.AsScriptData) (PlutusTx.fromBuiltin bs)

unTransTxOutDatumHash :: P.DatumHash -> Either C.SerialiseAsRawBytesError (C.TxOutDatum ctx C.BabbageEra)
unTransTxOutDatumHash datumHash = C.TxOutDatumHash C.AlonzoEraOnwardsBabbage <$> unTransScriptDataHash datumHash
unTransTxOutDatumHash :: P.DatumHash -> Either C.SerialiseAsRawBytesError (C.TxOutDatum ctx C.ConwayEra)
unTransTxOutDatumHash datumHash = C.TxOutDatumHash C.AlonzoEraOnwardsConway <$> unTransScriptDataHash datumHash
Loading
Loading