Skip to content
Open
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: 2 additions & 0 deletions .github/workflows/actionlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
accept-flake-config = true
# Make the Nix environment available to next steps
- uses: rrbutani/use-nix-shell-action@v1
with:
flakes: nixpkgs#shellcheck,nixpkgs#actionlint

- name: actionlint
run: |
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/check-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ jobs:
extra_nix_config: |
accept-flake-config = true

- name: Check scriv fragments are correct
- uses: rrbutani/use-nix-shell-action@v1
if: steps.filter.outputs.cardano == 'true'
uses: rrbutani/use-nix-shell-action@v1
with:
script: cd cardano-testnet && scriv collect --version "CI-CHECK" --keep
flakes: nixpkgs#scriv
- name: Check scriv fragments are correct
if: steps.filter.outputs.cardano == 'true'
run: cd cardano-testnet && scriv collect --version "CI-CHECK" --keep

3 changes: 2 additions & 1 deletion .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ jobs:
with:
extra_nix_config: |
accept-flake-config = true
# Make the Nix environment available to next steps
- uses: rrbutani/use-nix-shell-action@v1
with:
flakes: nixpkgs#shellcheck
- name: shellcheck
run: |
for file in $(git ls-files "*.sh")
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ cardano-tracer/cardano-tracer-test
.idea/

.codex

.serena/
8 changes: 4 additions & 4 deletions bench/plutus-scripts-bench/plutus-scripts-bench.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ library
-- IOG dependencies
--------------------------
build-depends:
, cardano-api ^>=11.0
, plutus-ledger-api ^>=1.63
, plutus-tx ^>=1.63
, plutus-tx-plugin ^>=1.63
, cardano-api ^>=11.3
, plutus-ledger-api ^>=1.65
, plutus-tx ^>=1.65
, plutus-tx-plugin ^>=1.65

------------------------
-- Non-IOG dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

module Cardano.Benchmarking.GeneratorTx.SizedMetadata
where

import Cardano.Api

import Cardano.Ledger.BaseTypes (maybeToStrictMaybe)
import qualified Cardano.Ledger.Core as L
import Cardano.TxGenerator.Utils

import Prelude
Expand All @@ -16,6 +19,7 @@ import qualified Data.ByteString as BS
import Data.Function ((&))
import qualified Data.Map.Strict as Map
import Data.Word (Word64)
import Lens.Micro ((.~), (^.))


maxMapSize :: Int
Expand Down Expand Up @@ -53,7 +57,7 @@ prop_mapCostsMary = measureMapCosts AsMaryEra == assumeMapCosts AsMaryE
prop_mapCostsAlonzo = measureMapCosts AsAlonzoEra == assumeMapCosts AsAlonzoEra
prop_mapCostsBabbage = measureMapCosts AsBabbageEra == assumeMapCosts AsBabbageEra
prop_mapCostsConway = measureMapCosts AsConwayEra == assumeMapCosts AsConwayEra
prop_mapCostsDijkstra = measureMapCosts AsDijkstraEra == assumeMapCosts AsDijkstraEra
prop_mapCostsDijkstra = measureMapCosts AsDijkstraEra == assumeMapCosts AsDijkstraEra

assumeMapCosts :: forall era . IsShelleyBasedEra era => AsType era -> [Int]
assumeMapCosts _proxy = stepFunction [
Expand Down Expand Up @@ -113,21 +117,25 @@ measureBSCosts era = map (metadataSize era . Just . bsMetadata) [0..maxBSSize]
metadataSize :: forall era . IsShelleyBasedEra era => AsType era -> Maybe TxMetadata -> Int
metadataSize p m = dummyTxSize p m - dummyTxSize p Nothing

dummyTxSizeInEra :: IsShelleyBasedEra era => TxMetadataInEra era -> Int
dummyTxSizeInEra metadata = case createTransactionBody shelleyBasedEra dummyTx of
Right b -> BS.length $ serialiseToCBOR b
Left err -> error $ "metaDataSize " ++ show err
dummyTxSizeInEra :: forall era. IsShelleyBasedEra era => TxMetadataInEra era -> Int
dummyTxSizeInEra metadata =
BS.length $ serialiseToCBOR dummyTx
where
dummyTx = defaultTxBodyContent shelleyBasedEra
& setTxIns
[ ( mkTxIn "dbaff4e270cfb55612d9e2ac4658a27c79da4a5271c6f90853042d1403733810#0"
, BuildTxWith $ KeyWitness KeyWitnessForSpending
)
]
& setTxFee (mkTxFee 0)
& setTxValidityLowerBound TxValidityNoLowerBound
& setTxValidityUpperBound (mkTxValidityUpperBound 0)
& setTxMetadata metadata
sbe = shelleyBasedEra @era
txInputs =
[ ( mkTxIn "dbaff4e270cfb55612d9e2ac4658a27c79da4a5271c6f90853042d1403733810#0"
, BuildTxWith $ KeyWitness KeyWitnessForSpending
)
]
txAuxData = toAuxiliaryData sbe metadata TxAuxScriptsNone
ledgerTxBody =
mkCommonTxBody sbe txInputs [] (mkTxFee 0) TxWithdrawalsNone txAuxData
& invalidHereAfterTxBodyL sbe .~ convValidityUpperBound sbe (mkTxValidityUpperBound 0)
dummyTx :: Tx era
dummyTx = shelleyBasedEraConstraints sbe $
ShelleyTx sbe $
L.mkBasicTx (ledgerTxBody ^. txBodyL)
& L.auxDataTxL .~ maybeToStrictMaybe txAuxData

dummyTxSize :: forall era . IsShelleyBasedEra era => AsType era -> Maybe TxMetadata -> Int
dummyTxSize _p m = (dummyTxSizeInEra @era) $ metadataInEra m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
fail (T.unpack err)
let (stillUnacked, acked) = L.splitAtEnd ack unAcked
let newStats = stats { stsAcked = stsAcked stats + Ack ack }
traceWith bmtr $ SubmissionClientDiscardAcknowledged (getTxId . getTxBody <$> acked)
traceWith bmtr $ SubmissionClientDiscardAcknowledged (txIdFromTx <$> acked)
return (txSource, UnAcked stillUnacked, newStats)

queueNewTxs :: [Tx era] -> LocalState era -> LocalState era
Expand Down Expand Up @@ -135,8 +135,8 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
let stateC@(_, UnAcked outs , stats) = queueNewTxs newTxs stateB

traceWith tr $ idListTrace (ToAnnce newTxs) blocking
traceWith bmtr $ SubmissionClientReplyTxIds (getTxId . getTxBody <$> newTxs)
traceWith bmtr $ SubmissionClientUnAcked (getTxId . getTxBody <$> outs)
traceWith bmtr $ SubmissionClientReplyTxIds (txIdFromTx <$> newTxs)
traceWith bmtr $ SubmissionClientUnAcked (txIdFromTx <$> outs)

case blocking of
SingBlocking -> case NE.nonEmpty newTxs of
Expand All @@ -160,12 +160,12 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
reqTxIds = fmap fromGenTxId txIds
traceWith tr $ ReqTxs (length reqTxIds)
let UnAcked ua = unAcked
uaIds = getTxId . getTxBody <$> ua
(toSend, _retained) = L.partition ((`L.elem` reqTxIds) . getTxId . getTxBody) ua
uaIds = txIdFromTx <$> ua
(toSend, _retained) = L.partition ((`L.elem` reqTxIds) . txIdFromTx) ua
missIds = reqTxIds L.\\ uaIds

traceWith tr $ TxList (length toSend)
traceWith bmtr $ SubmissionClientUnAcked (getTxId . getTxBody <$> ua)
traceWith bmtr $ SubmissionClientUnAcked (txIdFromTx <$> ua)
traceWith bmtr $ TraceBenchTxSubServReq reqTxIds
unless (L.null missIds) $
traceWith bmtr $ TraceBenchTxSubServUnav missIds
Expand Down Expand Up @@ -195,6 +195,10 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
fromGenTxId (Block.GenTxIdConway (Mempool.ShelleyTxId i)) = fromShelleyTxId i
fromGenTxId _ = error "TODO: fix incomplete match"

txIdFromTx :: Tx era -> TxId
txIdFromTx (ShelleyTx sbe tx) =
shelleyBasedEraConstraints sbe $ fromShelleyTxId $ Ledger.txIdTxBody (tx ^. Ledger.bodyTxL)

tokIsBlocking :: SingBlockingStyle a -> Bool
tokIsBlocking = \case
SingBlocking -> True
Expand Down
11 changes: 7 additions & 4 deletions bench/tx-generator/src/Cardano/Benchmarking/Script/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Cardano.Benchmarking.Version as Version
import Cardano.Benchmarking.Wallet as Wallet
import qualified Cardano.Ledger.Coin as L
import qualified Cardano.Ledger.Core as Ledger
import Cardano.Ledger.Tools (estimateMinFeeTx)
import Cardano.Logging hiding (LocalSocket)
import Cardano.TxGenerator.Fund as Fund
import qualified Cardano.TxGenerator.FundQueue as FundQueue
Expand Down Expand Up @@ -353,10 +354,12 @@ evalGenerator generator txParams@TxGenTxParams{txParamFee = fee} era = do
Right tx -> do
let
txSize = txSizeInBytes tx
txFeeEstimate = case toLedgerPParams shelleyBasedEra protocolParameters of
Left{} -> Nothing
Right ledgerPParams -> Just $
evaluateTransactionFee shelleyBasedEra ledgerPParams (getTxBody tx) (fromIntegral $ inputs + 1) 0 0 -- 1 key witness per tx input + 1 collateral
txFeeEstimate = case tx of
ShelleyTx sbe ledgerTx -> shelleyBasedEraConstraints sbe $
case toLedgerPParams sbe protocolParameters of
Left{} -> Nothing
Right ledgerPParams -> Just $
estimateMinFeeTx ledgerPParams ledgerTx (inputs + 1) 0 0 -- 1 key witness per tx input + 1 collateral
traceDebug $ "Projected Tx size in bytes: " ++ show txSize
traceDebug $ "Projected Tx fee in Coin: " ++ show txFeeEstimate
-- TODO: possibly emit a warning when (Just txFeeEstimate) is lower than specified by config in TxGenTxParams.txFee
Expand Down
41 changes: 28 additions & 13 deletions bench/tx-generator/src/Cardano/TxGenerator/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}


{- HLINT ignore "Use map with tuple-section" -}

-- | This module provides means to secure funds that are given in genesis.
Expand All @@ -21,16 +22,20 @@ where
import Cardano.Api hiding (ShelleyGenesis)

import qualified Cardano.Ledger.Coin as L
import qualified Cardano.Ledger.Core as Ledger
import Cardano.Ledger.Keys.WitVKey (WitVKey (WitVKey))
import Cardano.Ledger.Shelley.API (Addr (..))
import Cardano.TxGenerator.Fund
import Cardano.TxGenerator.Types
import Cardano.TxGenerator.Utils
import Ouroboros.Consensus.Shelley.Node (validateGenesis)

import Data.Bifunctor (bimap, second)
import Data.Bifunctor (second)
import Data.Function ((&))
import Data.List (find)
import qualified Data.ListMap as ListMap (toList)
import qualified Data.Set as Set
import Lens.Micro ((.~), (^.))


genesisValidate :: ShelleyGenesis -> Either String ()
Expand Down Expand Up @@ -105,12 +110,16 @@ genesisExpenditure networkId inputKey addr value fee ttl outputKey
pseudoTxIn = genesisTxInput networkId inputKey

fund tx = FundInEra {
_fundTxIn = TxIn (getTxId $ getTxBody tx) (TxIx 0)
_fundTxIn = TxIn (txIdFromTx tx) (TxIx 0)
, _fundWitness = KeyWitness KeyWitnessForSpending
, _fundVal = value
, _fundSigningKey = Just outputKey
}

txIdFromTx :: Tx era -> TxId
txIdFromTx (ShelleyTx sbe' tx') =
shelleyBasedEraConstraints sbe' $ fromShelleyTxId $ Ledger.txIdTxBody (tx' ^. Ledger.bodyTxL)

mkGenesisTransaction :: forall era .
IsShelleyBasedEra era
=> SigningKey GenesisUTxOKey
Expand All @@ -119,18 +128,24 @@ mkGenesisTransaction :: forall era .
-> [TxIn]
-> [TxOut CtxTx era]
-> Either TxGenError (Tx era)
mkGenesisTransaction key ttl fee txins txouts
= bimap
ApiError
(\b -> signShelleyTransaction (shelleyBasedEra @era) b [WitnessGenesisUTxOKey key])
(createTransactionBody (shelleyBasedEra @era) txBodyContent)
mkGenesisTransaction key ttl fee txins txouts =
shelleyBasedEraConstraints sbe $
let txInputs = zip txins $ repeat $ BuildTxWith $ KeyWitness KeyWitnessForSpending
ledgerTxBody =
mkCommonTxBody sbe txInputs txouts (mkTxFee fee) TxWithdrawalsNone Nothing
& invalidHereAfterTxBodyL sbe .~ convValidityUpperBound sbe (mkTxValidityUpperBound ttl)
rawBody = ledgerTxBody ^. txBodyL
unsignedLedgerTx = Ledger.mkBasicTx rawBody
txHash = Ledger.extractHash $ Ledger.hashAnnotated rawBody
shelleySigningKey = toShelleySigningKey (WitnessGenesisUTxOKey key)
witVKey = WitVKey
(getShelleyKeyWitnessVerificationKey shelleySigningKey)
(makeShelleySignature txHash shelleySigningKey)
signedLedgerTx = unsignedLedgerTx
& Ledger.witsTxL .~ (Ledger.mkBasicTxWits & Ledger.addrTxWitsL .~ Set.singleton witVKey)
in Right $ ShelleyTx sbe signedLedgerTx
where
txBodyContent = defaultTxBodyContent shelleyBasedEra
& setTxIns (zip txins $ repeat $ BuildTxWith $ KeyWitness KeyWitnessForSpending)
& setTxOuts txouts
& setTxFee (mkTxFee fee)
& setTxValidityLowerBound TxValidityNoLowerBound
& setTxValidityUpperBound (mkTxValidityUpperBound ttl)
sbe = shelleyBasedEra @era

castKey :: SigningKey PaymentKey -> SigningKey GenesisUTxOKey
castKey (PaymentSigningKey skey) = GenesisUTxOSigningKey skey
52 changes: 34 additions & 18 deletions bench/tx-generator/src/Cardano/TxGenerator/Tx.hs
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}


module Cardano.TxGenerator.Tx
(module Cardano.TxGenerator.Tx)
where

import Cardano.Api hiding (txId)

import Cardano.Ledger.BaseTypes (maybeToStrictMaybe)
import qualified Cardano.Ledger.Coin as L
import qualified Cardano.Ledger.Core as Ledger
import Cardano.Ledger.Keys.WitVKey (WitVKey (WitVKey))
import Cardano.TxGenerator.Fund
import Cardano.TxGenerator.Types
import Cardano.TxGenerator.UTxO (ToUTxOList)

import Data.Bifunctor (bimap, second)
import Data.Bifunctor (second)
import qualified Data.ByteString as BS (length)
import Data.Function ((&))
import Data.Maybe (mapMaybe)
import qualified Data.Set as Set
import Lens.Micro ((.~), (^.))


-- | 'CreateAndStore' is meant to represent building a transaction
Expand Down Expand Up @@ -165,22 +170,33 @@ genTx :: forall era. ()
-> TxFee era
-> TxMetadataInEra era
-> TxGenerator era
genTx sbe ledgerParameters (collateral, collFunds) fee metadata inFunds outputs
= bimap
ApiError
(\b -> (signShelleyTransaction (shelleyBasedEra @era) b $ map WitnessPaymentKey allKeys, getTxId b))
(createTransactionBody (shelleyBasedEra @era) txBodyContent)
where
allKeys = mapMaybe getFundKey $ inFunds ++ collFunds
txBodyContent = defaultTxBodyContent sbe
& setTxIns (map (\f -> (getFundTxIn f, BuildTxWith $ getFundWitness f)) inFunds)
& setTxInsCollateral collateral
& setTxOuts outputs
& setTxFee fee
& setTxValidityLowerBound TxValidityNoLowerBound
& setTxValidityUpperBound (defaultTxValidityUpperBound sbe)
& setTxMetadata metadata
& setTxProtocolParams (BuildTxWith (Just ledgerParameters))
genTx sbe _ledgerParameters (collateral, collFunds) fee metadata inFunds outputs =
shelleyBasedEraConstraints sbe $ do
let allKeys = mapMaybe getFundKey $ inFunds ++ collFunds
setCollateral = case collateral of
TxInsCollateralNone -> id
TxInsCollateral eon _ -> collateralInputsTxBodyL eon .~ convCollateralTxIns collateral
txInputs = map (\f -> (getFundTxIn f, BuildTxWith $ getFundWitness f)) inFunds
txAuxData = toAuxiliaryData sbe metadata TxAuxScriptsNone
ledgerTxBody =
mkCommonTxBody sbe txInputs outputs fee TxWithdrawalsNone txAuxData
& invalidHereAfterTxBodyL sbe .~ convValidityUpperBound sbe (defaultTxValidityUpperBound sbe)
& setCollateral
rawBody = ledgerTxBody ^. txBodyL
unsignedLedgerTx = Ledger.mkBasicTx rawBody
txHash = Ledger.extractHash $ Ledger.hashAnnotated rawBody
witVKeys = Set.fromList
[ WitVKey
(getShelleyKeyWitnessVerificationKey sk)
(makeShelleySignature txHash sk)
| sk <- map (toShelleySigningKey . WitnessPaymentKey) allKeys
]
signedLedgerTx = unsignedLedgerTx
& Ledger.witsTxL .~ (Ledger.mkBasicTxWits & Ledger.addrTxWitsL .~ witVKeys)
& Ledger.auxDataTxL .~ maybeToStrictMaybe txAuxData
tx = ShelleyTx sbe signedLedgerTx
txId = fromShelleyTxId $ Ledger.txIdTxBody rawBody
Right (tx, txId)


txSizeInBytes :: forall era. IsShelleyBasedEra era =>
Expand Down
Loading
Loading