diff --git a/eras/allegra/impl/src/Cardano/Ledger/Allegra/Tx.hs b/eras/allegra/impl/src/Cardano/Ledger/Allegra/Tx.hs index 23da633d776..525c91b1024 100644 --- a/eras/allegra/impl/src/Cardano/Ledger/Allegra/Tx.hs +++ b/eras/allegra/impl/src/Cardano/Ledger/Allegra/Tx.hs @@ -59,6 +59,9 @@ instance Crypto c => EraTx (AllegraEra c) where sizeTxF = sizeShelleyTxF {-# INLINE sizeTxF #-} + wireSizeTxF = sizeShelleyTxF + {-# INLINE wireSizeTxF #-} + validateNativeScript = validateTimelock {-# INLINE validateNativeScript #-} diff --git a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Tx.hs b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Tx.hs index 52ea88c6c00..1ed960de068 100644 --- a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Tx.hs +++ b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Tx.hs @@ -186,9 +186,12 @@ instance Crypto c => EraTx (AlonzoEra c) where auxDataTxL = auxDataAlonzoTxL {-# INLINE auxDataTxL #-} - sizeTxF = sizeAlonzoTxF + sizeTxF = sizeAlonzoTxF toCBORForSizeComputation {-# INLINE sizeTxF #-} + wireSizeTxF = sizeAlonzoTxf toCBOR + {-# INLINE wireSizeTxF #-} + validateNativeScript = validateTimelock {-# INLINE validateNativeScript #-} @@ -236,13 +239,18 @@ auxDataAlonzoTxL = lens auxiliaryData (\tx txTxAuxData -> tx {auxiliaryData = tx {-# INLINEABLE auxDataAlonzoTxL #-} -- | txsize computes the length of the serialised bytes -sizeAlonzoTxF :: forall era. EraTx era => SimpleGetter (AlonzoTx era) Integer -sizeAlonzoTxF = +sizeAlonzoTxF :: + forall era. + EraTx era => + -- | encoding for CBOR size or mempool submission + (AlonzoTx era -> Encoding) -> + SimpleGetter (AlonzoTx era) Integer +sizeAlonzoTxF enc = to $ fromIntegral . LBS.length . serialize (eraProtVerLow @era) - . toCBORForSizeComputation + . enc {-# INLINEABLE sizeAlonzoTxF #-} isValidAlonzoTxL :: Lens' (AlonzoTx era) IsValid diff --git a/eras/babbage/impl/src/Cardano/Ledger/Babbage/Tx.hs b/eras/babbage/impl/src/Cardano/Ledger/Babbage/Tx.hs index 03180d62eeb..a297203a605 100644 --- a/eras/babbage/impl/src/Cardano/Ledger/Babbage/Tx.hs +++ b/eras/babbage/impl/src/Cardano/Ledger/Babbage/Tx.hs @@ -47,9 +47,12 @@ instance Crypto c => EraTx (BabbageEra c) where auxDataTxL = auxDataAlonzoTxL {-# INLINE auxDataTxL #-} - sizeTxF = sizeAlonzoTxF + sizeTxF = sizeAlonzoTxF X.toCBORForSizeComputation {-# INLINE sizeTxF #-} + wireSizeTxF = sizeAlonzoTxf toCBOR + {-# INLINE wireSizeTxF #-} + validateNativeScript = validateTimelock {-# INLINE validateNativeScript #-} diff --git a/eras/conway/impl/src/Cardano/Ledger/Conway/Tx.hs b/eras/conway/impl/src/Cardano/Ledger/Conway/Tx.hs index b44038cc36b..b0a8b49e89c 100644 --- a/eras/conway/impl/src/Cardano/Ledger/Conway/Tx.hs +++ b/eras/conway/impl/src/Cardano/Ledger/Conway/Tx.hs @@ -62,9 +62,12 @@ instance Crypto c => EraTx (ConwayEra c) where auxDataTxL = auxDataAlonzoTxL {-# INLINE auxDataTxL #-} - sizeTxF = sizeAlonzoTxF + sizeTxF = sizeAlonzoTxF toCBORForSizeComputation {-# INLINE sizeTxF #-} + wireSizeTxF = sizeAlonzoTxf toCBOR + {-# INLINE wireSizeTxF #-} + validateNativeScript = validateTimelock {-# INLINE validateNativeScript #-} diff --git a/eras/mary/impl/src/Cardano/Ledger/Mary/Tx.hs b/eras/mary/impl/src/Cardano/Ledger/Mary/Tx.hs index d9e166e9f52..50d812738e3 100644 --- a/eras/mary/impl/src/Cardano/Ledger/Mary/Tx.hs +++ b/eras/mary/impl/src/Cardano/Ledger/Mary/Tx.hs @@ -47,6 +47,9 @@ instance Crypto c => EraTx (MaryEra c) where sizeTxF = sizeShelleyTxF {-# INLINE sizeTxF #-} + wireSizeTxF = sizeShelleyTxF + {-# INLINE wireSizeTxF #-} + validateNativeScript = validateTimelock {-# INLINE validateNativeScript #-} diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Tx.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Tx.hs index baced876e01..f305502c4ed 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Tx.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Tx.hs @@ -164,7 +164,7 @@ auxDataShelleyTxL = {-# INLINEABLE auxDataShelleyTxL #-} -- | Size getter for `ShelleyTx`. -sizeShelleyTxF :: Era era => SimpleGetter (ShelleyTx era) Integer +sizeShelleyTxF :: (Era era, Num b) => SimpleGetter (ShelleyTx era) b sizeShelleyTxF = to (\(TxConstr (Memo _ bytes)) -> fromIntegral $ SBS.length bytes) {-# INLINEABLE sizeShelleyTxF #-} @@ -200,6 +200,9 @@ instance Crypto c => EraTx (ShelleyEra c) where sizeTxF = sizeShelleyTxF {-# INLINE sizeTxF #-} + wireSizeTxF = sizeShelleyTxF + {-# INLINE wireSizeTxF #-} + validateNativeScript = validateMultiSig {-# INLINE validateNativeScript #-} diff --git a/libs/cardano-ledger-core/CHANGELOG.md b/libs/cardano-ledger-core/CHANGELOG.md index b2f6108b2c4..3a51b5b72da 100644 --- a/libs/cardano-ledger-core/CHANGELOG.md +++ b/libs/cardano-ledger-core/CHANGELOG.md @@ -1,5 +1,9 @@ # Version history for `cardano-ledger-core` +## 1.14.2.0 + +* Add `wireSizeTxF` to `EraTx` class + ## 1.14.1.0 ### `testlib` diff --git a/libs/cardano-ledger-core/cardano-ledger-core.cabal b/libs/cardano-ledger-core/cardano-ledger-core.cabal index bb33f7badc3..b0d569a141d 100644 --- a/libs/cardano-ledger-core/cardano-ledger-core.cabal +++ b/libs/cardano-ledger-core/cardano-ledger-core.cabal @@ -1,6 +1,6 @@ cabal-version: 3.0 name: cardano-ledger-core -version: 1.14.1.0 +version: 1.14.2.0 license: Apache-2.0 maintainer: operations@iohk.io author: IOHK diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/Core.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/Core.hs index e2fe27b18a9..96b3eb51016 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/Core.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/Core.hs @@ -118,7 +118,7 @@ import Data.Maybe.Strict (StrictMaybe) import Data.Sequence.Strict (StrictSeq) import Data.Set (Set) import Data.Void (Void) -import Data.Word (Word64) +import Data.Word (Word32, Word64) import GHC.Stack (HasCallStack) import Lens.Micro import NoThunks.Class (NoThunks) @@ -153,8 +153,12 @@ class auxDataTxL :: Lens' (Tx era) (StrictMaybe (AuxiliaryData era)) + -- | For estimations of impact on block space sizeTxF :: SimpleGetter (Tx era) Integer + -- | For end use by eg. diffusion layer in transaction submission protocol + wireSizeTxF :: SimpleGetter (Tx era) Word32 + -- | Using information from the transaction validate the supplied native script. validateNativeScript :: Tx era -> NativeScript era -> Bool