Skip to content

Commit

Permalink
Merge pull request #382 from input-output-hk/jordan/remove-byron-tx
Browse files Browse the repository at this point in the history
Remove ByronTx
  • Loading branch information
Jimbo4350 authored Nov 28, 2023
2 parents c877137 + 72cbddf commit 8561b74
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 309 deletions.
1 change: 0 additions & 1 deletion cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ library internal
Cardano.Api.Eon.AllegraEraOnwards
Cardano.Api.Eon.AlonzoEraOnwards
Cardano.Api.Eon.BabbageEraOnwards
Cardano.Api.Eon.ByronEraOnly
Cardano.Api.Eon.ByronToAlonzoEra
Cardano.Api.Eon.ConwayEraOnwards
Cardano.Api.Eon.MaryEraOnwards
Expand Down
16 changes: 2 additions & 14 deletions cardano-api/gen/Test/Gen/Cardano/Api/Byron.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,23 @@ import Test.Tasty.Hedgehog

prop_byron_roundtrip_txbody_CBOR :: Property
prop_byron_roundtrip_txbody_CBOR = property $ do
let byron = ByronEra
x <- forAll $ makeSignedByronTransaction [] <$> genTxBodyByron
tripping (ByronTx ByronEraOnlyByron x) (serialiseTxLedgerCddl byron) deserialiseByronTxCddl


prop_byron_roundtrip_tx_CBOR :: Property
prop_byron_roundtrip_tx_CBOR = property $ do
let byron = ByronEra
x <- forAll genTxByron
cardanoEraConstraints byron $ trippingCbor (proxyToAsType Proxy) x

tripping x serializeByronTx deserialiseByronTxCddl

prop_byron_roundtrip_witness_CBOR :: Property
prop_byron_roundtrip_witness_CBOR = property $ do
let byron = ByronEra
x <- forAll genByronKeyWitness
cardanoEraConstraints byron $ trippingCbor (AsKeyWitness (proxyToAsType Proxy)) x


prop_byron_roundtrip_Tx_Cddl :: Property
prop_byron_roundtrip_Tx_Cddl = property $ do
let byron = ByronEra
x <- forAll genTxByron
tripping x (serialiseTxLedgerCddl byron) deserialiseByronTxCddl
tripping x serializeByronTx deserialiseByronTxCddl

tests :: TestTree
tests = testGroup "Test.Gen.Cardano.Api.Byron"
[ testProperty "Byron roundtrip txbody CBOR" prop_byron_roundtrip_txbody_CBOR
, testProperty "Byron roundtrip tx certificate CBOR" prop_byron_roundtrip_tx_CBOR
, testProperty "Byron roundtrip witness CBOR" prop_byron_roundtrip_witness_CBOR
, testProperty "Byron roundtrip tx CBOR" prop_byron_roundtrip_Tx_Cddl
]
Expand Down
34 changes: 13 additions & 21 deletions cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ module Test.Gen.Cardano.Api.Typed

import Cardano.Api hiding (txIns)
import qualified Cardano.Api as Api
import Cardano.Api.Byron (KeyWitness (ByronKeyWitness), Tx (ByronTx),
import Cardano.Api.Byron (KeyWitness (ByronKeyWitness),
WitnessNetworkIdOrByronAddress (..))
import qualified Cardano.Api.Byron as Byron
import Cardano.Api.Eon.AllegraEraOnwards (allegraEraOnwardsToShelleyBasedEra)
import Cardano.Api.Error
import qualified Cardano.Api.Ledger as L
Expand Down Expand Up @@ -544,14 +545,9 @@ genTxValidityLowerBound =
(\w -> TxValidityLowerBound w <$> genTtl)

-- TODO: Accept a range for generating ttl.
genTxValidityUpperBound :: CardanoEra era -> Gen (TxValidityUpperBound era)
genTxValidityUpperBound era =
forEraInEon era
( forEraInEon era
(error "genTxValidityUpperBound: unexpected era support combination")
(pure . TxValidityNoUpperBound)
)
(\w -> TxValidityUpperBound w <$> Gen.maybe genTtl)
genTxValidityUpperBound :: ShelleyBasedEra era -> Gen (TxValidityUpperBound era)
genTxValidityUpperBound sbe =
TxValidityUpperBound sbe <$> Gen.maybe genTtl

genTxMetadataInEra :: CardanoEra era -> Gen (TxMetadataInEra era)
genTxMetadataInEra =
Expand Down Expand Up @@ -643,9 +639,9 @@ genTxBodyContent sbe = do
txOuts <- Gen.list (Range.constant 1 10) (genTxOutTxContext sbe)
txTotalCollateral <- genTxTotalCollateral era
txReturnCollateral <- genTxReturnCollateral sbe
txFee <- genTxFee era
txFee <- genTxFee sbe
txValidityLowerBound <- genTxValidityLowerBound era
txValidityUpperBound <- genTxValidityUpperBound era
txValidityUpperBound <- genTxValidityUpperBound sbe
txMetadata <- genTxMetadataInEra era
txAuxScripts <- genTxAuxScripts sbe
let txExtraKeyWits = TxExtraKeyWitnessesNone --TODO: Alonzo era: Generate witness key hashes
Expand Down Expand Up @@ -709,21 +705,17 @@ genTxTotalCollateral =
(pure TxTotalCollateralNone)
(\w -> TxTotalCollateral w <$> genPositiveLovelace)

genTxFee :: CardanoEra era -> Gen (TxFee era)
genTxFee =
caseByronOrShelleyBasedEra
(pure . TxFeeImplicit)
(\w -> TxFeeExplicit w <$> genLovelace)
genTxFee :: ShelleyBasedEra era -> Gen (TxFee era)
genTxFee w = TxFeeExplicit w <$> genLovelace

genAddressInEraByron :: Gen (AddressInEra ByronEra)
genAddressInEraByron = byronAddressInEra <$> genAddressByron

genTxByron :: Gen (Tx ByronEra)
genTxByron :: Gen (Byron.ATxAux ByteString)
genTxByron = do
tx <- makeSignedByronTransaction
<$> genWitnessesByron
<*> genTxBodyByron
return $ ByronTx ByronEraOnlyByron tx
makeSignedByronTransaction
<$> genWitnessesByron
<*> genTxBodyByron

genTxOutValueByron :: Gen (TxOutValue ByronEra)
genTxOutValueByron = TxOutValueByron <$> genPositiveLovelace
Expand Down
16 changes: 4 additions & 12 deletions cardano-api/internal/Cardano/Api/Block.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ module Cardano.Api.Block (
makeChainTip,
) where

import Cardano.Api.Eon.ByronEraOnly
import Cardano.Api.Eon.ShelleyBasedEra
import Cardano.Api.Eras
import Cardano.Api.Hash
Expand All @@ -60,8 +59,6 @@ import Cardano.Api.SerialiseRaw
import Cardano.Api.SerialiseUsing
import Cardano.Api.Tx

import qualified Cardano.Chain.Block as Byron
import qualified Cardano.Chain.UTxO as Byron
import qualified Cardano.Crypto.Hash.Class as Crypto
import qualified Cardano.Crypto.Hashing
import qualified Cardano.Ledger.Api as L
Expand Down Expand Up @@ -159,15 +156,10 @@ instance Show (Block era) where

getBlockTxs :: forall era . Block era -> [Tx era]
getBlockTxs = \case
ByronBlock Consensus.ByronBlock { Consensus.byronBlockRaw } ->
case byronBlockRaw of
Byron.ABOBBoundary{} -> [] -- no txs in EBBs
Byron.ABOBBlock Byron.ABlock {
Byron.blockBody =
Byron.ABody {
Byron.bodyTxPayload = Byron.ATxPayload txs
}
} -> map (ByronTx ByronEraOnlyByron) txs
-- In the context of foldBlocks we don't care about the Byron era.
-- Testing leans on ledger events which is a Shelley onwards feature.
ByronBlock Consensus.ByronBlock{} -> []

ShelleyBlock sbe Consensus.ShelleyBlock{Consensus.shelleyBlockRaw} ->
shelleyBasedEraConstraints sbe $
getShelleyBlockTxs sbe shelleyBlockRaw
Expand Down
55 changes: 0 additions & 55 deletions cardano-api/internal/Cardano/Api/Eon/ByronEraOnly.hs

This file was deleted.

22 changes: 6 additions & 16 deletions cardano-api/internal/Cardano/Api/Eras/Case.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
Expand All @@ -16,10 +15,6 @@ module Cardano.Api.Eras.Case
, caseShelleyToAlonzoOrBabbageEraOnwards
, caseShelleyToBabbageOrConwayEraOnwards

-- Proofs
, noByronEraInShelleyBasedEra
, disjointByronEraOnlyAndShelleyBasedEra

-- Conversions
, shelleyToAlonzoEraToShelleyToBabbageEra
, alonzoEraOnwardsToMaryEraOnwards
Expand All @@ -30,7 +25,6 @@ module Cardano.Api.Eras.Case
import Cardano.Api.Eon.AllegraEraOnwards
import Cardano.Api.Eon.AlonzoEraOnwards
import Cardano.Api.Eon.BabbageEraOnwards
import Cardano.Api.Eon.ByronEraOnly
import Cardano.Api.Eon.ByronToAlonzoEra
import Cardano.Api.Eon.ConwayEraOnwards
import Cardano.Api.Eon.MaryEraOnwards
Expand All @@ -42,14 +36,17 @@ import Cardano.Api.Eon.ShelleyToBabbageEra
import Cardano.Api.Eon.ShelleyToMaryEra
import Cardano.Api.Eras.Core

-- | @caseByronOrShelleyBasedEra f g era@ applies @f@ to byron and @g@ to other eras.
-- | @caseByronOrShelleyBasedEra f g era@ returns @f@ in Byron and applies @g@ to Shelley-based eras.
caseByronOrShelleyBasedEra :: ()
=> (ByronEraOnly era -> a)
=> a
-> (ShelleyBasedEraConstraints era => ShelleyBasedEra era -> a)
-> CardanoEra era
-> a
caseByronOrShelleyBasedEra l r = \case
ByronEra -> l ByronEraOnlyByron
ByronEra -> l -- We no longer provide the witness because Byron is isolated.
-- This function will be deleted shortly after build-raw --byron-era is
-- deprecated in cardano-cli

ShelleyEra -> r ShelleyBasedEraShelley
AllegraEra -> r ShelleyBasedEraAllegra
MaryEra -> r ShelleyBasedEraMary
Expand Down Expand Up @@ -148,13 +145,6 @@ caseShelleyToBabbageOrConwayEraOnwards l r = \case
ShelleyBasedEraBabbage -> l ShelleyToBabbageEraBabbage
ShelleyBasedEraConway -> r ConwayEraOnwardsConway

{-# DEPRECATED noByronEraInShelleyBasedEra "Use disjointByronEraOnlyAndShelleyBasedEra instead" #-}
noByronEraInShelleyBasedEra :: ShelleyBasedEra era -> ByronEraOnly era -> a
noByronEraInShelleyBasedEra = flip disjointByronEraOnlyAndShelleyBasedEra

disjointByronEraOnlyAndShelleyBasedEra :: ByronEraOnly era -> ShelleyBasedEra era -> a
disjointByronEraOnlyAndShelleyBasedEra ByronEraOnlyByron sbe = case sbe of {}

shelleyToAlonzoEraToShelleyToBabbageEra :: ()
=> ShelleyToAlonzoEra era
-> ShelleyToBabbageEra era
Expand Down
15 changes: 0 additions & 15 deletions cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ module Cardano.Api.Fees (
import Cardano.Api.Address
import Cardano.Api.Certificate
import Cardano.Api.Eon.BabbageEraOnwards
import Cardano.Api.Eon.ByronEraOnly
import Cardano.Api.Eon.MaryEraOnwards
import Cardano.Api.Eon.ShelleyBasedEra
import Cardano.Api.Eras.Case
Expand Down Expand Up @@ -118,9 +117,6 @@ transactionFee sbe txFeeFixed txFeePerByte tx =
case tx of
ShelleyTx _ tx' ->
let x = shelleyBasedEraConstraints sbe $ tx' ^. L.sizeTxF in Lovelace (a * x + b)
--TODO: This can be made to work for Byron txs too.
ByronTx ByronEraOnlyByron _ -> case sbe of {}

{-# DEPRECATED transactionFee "Use 'evaluateTransactionFee' instead" #-}

--TODO: in the Byron case the per-byte is non-integral, would need different
Expand All @@ -146,9 +142,6 @@ estimateTransactionFee :: ()
-> Int -- ^ The number of extra Byron key witnesses
-> Lovelace
estimateTransactionFee sbe nw txFeeFixed txFeePerByte = \case
-- TODO: This can be made to work for Byron txs too.
ByronTx ByronEraOnlyByron _ ->
case sbe of {}
ShelleyTx era tx ->
let Lovelace baseFee = transactionFee sbe txFeeFixed txFeePerByte (ShelleyTx era tx)
in \nInputs nOutputs nShelleyKeyWitnesses nByronKeyWitnesses ->
Expand Down Expand Up @@ -217,7 +210,6 @@ evaluateTransactionFee _ _ _ _ byronwitcount | byronwitcount > 0 =
evaluateTransactionFee sbe pp txbody keywitcount _byronwitcount =
shelleyBasedEraConstraints sbe $
case makeSignedTransaction' (shelleyBasedToCardanoEra sbe) [] txbody of
ByronTx w _ -> disjointByronEraOnlyAndShelleyBasedEra w sbe
ShelleyTx _ tx -> fromShelleyLovelace $ Ledger.evaluateTransactionFee pp tx keywitcount

-- | Give an approximate count of the number of key witnesses (i.e. signatures)
Expand Down Expand Up @@ -478,14 +470,7 @@ evaluateTransactionExecutionUnits :: forall era. ()
(Map ScriptWitnessIndex (Either ScriptExecutionError ExecutionUnits))
evaluateTransactionExecutionUnits era systemstart epochInfo pp utxo txbody =
case makeSignedTransaction' era [] txbody of
ByronTx {} -> evalPreAlonzo
ShelleyTx sbe tx' -> evaluateTransactionExecutionUnitsShelley sbe systemstart epochInfo pp utxo tx'
where
-- | Pre-Alonzo eras do not support languages with execution unit accounting.
evalPreAlonzo :: Either TransactionValidityError
(Map ScriptWitnessIndex
(Either ScriptExecutionError ExecutionUnits))
evalPreAlonzo = Right Map.empty

evaluateTransactionExecutionUnitsShelley :: forall era. ()
=> ShelleyBasedEra era
Expand Down
7 changes: 1 addition & 6 deletions cardano-api/internal/Cardano/Api/IPC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ module Cardano.Api.IPC (
) where

import Cardano.Api.Block
import Cardano.Api.Eras
import Cardano.Api.HasTypeProxy
import Cardano.Api.InMode
import Cardano.Api.IO
Expand Down Expand Up @@ -631,11 +630,7 @@ instance ToJSON LocalTxMonitoringResult where
]
where
txId = case txInMode of
Just (TxInMode e tx) ->
case e of
-- NB: Local tx protocol is not possible in the Byron era
ByronEra -> error "ToJSON LocalTxMonitoringResult: Byron era not supported"
_ -> Just $ getTxId $ getTxBody tx
Just (TxInMode _ tx) -> Just $ getTxId $ getTxBody tx
-- TODO: support fetching the ID of a Byron Era transaction
_ -> Nothing
LocalTxMonitoringMempoolSizeAndCapacity mempool slot ->
Expand Down
Loading

0 comments on commit 8561b74

Please sign in to comment.