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

Remove no longer needed workarounds #4907

Merged
merged 4 commits into from
Feb 26, 2025
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
10 changes: 6 additions & 4 deletions eras/conway/impl/src/Cardano/Ledger/Conway/TxInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,12 @@ transTxBodyWithdrawals :: EraTxBody era => TxBody era -> PV3.Map PV3.Credential
transTxBodyWithdrawals txBody =
transMap transRewardAccount transCoinToLovelace (unWithdrawals $ txBody ^. withdrawalsTxBodyL)

-- | In version 9, a bug in `RegTxCert` and `UnRegTxCert` pattern definitions
-- was causing the deposit in `RegDepositTxCert` and `UnRegDepositTxCert` to be omitted.
-- We need to keep this behavior for version 9, so, now that the bug in the patterns has been fixed,
-- we are explicitly omitting the deposit in these cases.
-- | In protocol version 9, a bug in `RegTxCert` and `UnRegTxCert` pattern definitions was causing
-- the deposit in `RegDepositTxCert` and `UnRegDepositTxCert` to be omitted. We need to keep this
-- behavior for version 9, so, now that the bug in the patterns has been fixed, we are explicitly
-- omitting the deposit in these cases. It has been confirmed that this buggy behavior for protocol
-- version 9 has been exercised on Mainnet, therefore this conditional translation can never be
-- removed for Conway era (#4863)
transTxCert :: ConwayEraTxCert era => ProtVer -> TxCert era -> PV3.TxCert
transTxCert pv = \case
RegPoolTxCert PoolParams {ppId, ppVrf} ->
Expand Down
7 changes: 2 additions & 5 deletions eras/mary/impl/test/Test/Cardano/Ledger/Mary/ValueSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Test.Cardano.Data
import Test.Cardano.Ledger.Binary.RoundTrip (
roundTripCborExpectation,
roundTripCborFailureExpectation,
roundTripCborRangeExpectation,
roundTripCborRangeFailureExpectation,
)
import Test.Cardano.Ledger.Common
Expand All @@ -47,10 +46,8 @@ spec = do
context "Coin" $ do
prop "Non-negative Coin succeeds for all eras" $
\(NonNegative i) -> roundTripCborExpectation (Coin i)
prop "Negative Coin succeeds for pre-Conway" $
\(Negative i) -> roundTripCborRangeExpectation minBound (natVersion @8) (Coin i)
prop "Negative Coin fails to deserialise for Conway" $
\(Negative i) -> roundTripCborRangeFailureExpectation (natVersion @9) (natVersion @9) (Coin i)
prop "Negative Coin fails to deserialise for all eras" $
\(Negative i) -> roundTripCborRangeFailureExpectation (natVersion @0) maxBound (Coin i)
context "MultiAsset" $ do
prop "Non-zero-valued MultiAsset succeeds for all eras" $
roundTripCborExpectation @MultiAsset
Expand Down
32 changes: 5 additions & 27 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/TxWits.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import Cardano.Ledger.Core (
hashScript,
)
import Cardano.Ledger.Hashes (SafeToHash (..))
import Cardano.Ledger.Keys (BootstrapWitness, KeyRole (Witness), WitVKey (..), witVKeyHash)
import Cardano.Ledger.Keys (BootstrapWitness, KeyRole (Witness), WitVKey (..))
import Cardano.Ledger.MemoBytes (
EqRaw (..),
Mem,
Expand All @@ -77,7 +77,6 @@ import qualified Data.Map.Strict as Map
import qualified Data.MapExtras as Map (fromElems)
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
import GHC.Records ()
import Lens.Micro (Lens', (^.))
Expand Down Expand Up @@ -228,7 +227,7 @@ deriving via
instance
EraScript era => DecCBOR (Annotator (ShelleyTxWits era))

instance forall era. (EraScript era, DecCBOR (Script era)) => DecCBOR (ShelleyTxWitsRaw era) where
instance (EraScript era, DecCBOR (Script era)) => DecCBOR (ShelleyTxWitsRaw era) where
decCBOR =
decode $
SparseKeyed
Expand All @@ -238,31 +237,14 @@ instance forall era. (EraScript era, DecCBOR (Script era)) => DecCBOR (ShelleyTx
[]
where
witField :: Word -> Field (ShelleyTxWitsRaw era)
witField 0 =
field
(\x wits -> wits {addrWits' = x})
(D $ withIgnoreSigOrd <$> decodeList decCBOR)
witField 0 = field (\x wits -> wits {addrWits' = x}) From
witField 1 =
field
(\x wits -> wits {scriptWits' = x})
(D $ Map.fromElems (hashScript @era) <$> decodeList decCBOR)
witField 2 =
field
(\x wits -> wits {bootWits' = x})
(D $ Set.fromList <$> decodeList decCBOR)
witField 2 = field (\x wits -> wits {bootWits' = x}) From
witField n = field (\_ wits -> wits) (Invalid n)

-- | This type is only used to preserve the old buggy behavior where signature
-- was ignored in the `Ord` instance for `WitVKey`s.
newtype IgnoreSigOrd kr = IgnoreSigOrd {unIgnoreSigOrd :: WitVKey kr}
deriving (Eq)

withIgnoreSigOrd :: Typeable kr => [WitVKey kr] -> Set (WitVKey kr)
withIgnoreSigOrd = Set.map unIgnoreSigOrd . Set.fromList . fmap IgnoreSigOrd

instance Typeable kr => Ord (IgnoreSigOrd kr) where
compare (IgnoreSigOrd w1) (IgnoreSigOrd w2) = compare (witVKeyHash w1) (witVKeyHash w2)

decodeWits ::
forall era s.
EraScript era =>
Expand All @@ -280,11 +262,7 @@ decodeWits =
witField 0 =
fieldAA
(\x wits -> wits {addrWits' = x})
( D $
mapTraverseableDecoderA
(decodeList decCBOR)
withIgnoreSigOrd
)
(D $ mapTraverseableDecoderA (decodeList decCBOR) Set.fromList)
witField 1 =
fieldAA
(\x wits -> wits {scriptWits' = x})
Expand Down
10 changes: 1 addition & 9 deletions libs/cardano-ledger-core/src/Cardano/Ledger/Coin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ import Cardano.Ledger.Binary (
EncCBOR (..),
FromCBOR (..),
ToCBOR,
decodeInteger,
decodeWord64,
ifDecoderVersionAtLeast,
natVersion,
)
import qualified Cardano.Ledger.Binary.Plain as Plain
import Cardano.Ledger.Compactible
Expand Down Expand Up @@ -89,12 +86,7 @@ newtype Coin = Coin {unCoin :: Integer}
instance FromCBOR Coin where
fromCBOR = Coin . toInteger <$> Plain.decodeWord64

instance DecCBOR Coin where
decCBOR =
ifDecoderVersionAtLeast
(natVersion @9)
(Coin . fromIntegral <$> decodeWord64)
(Coin <$> decodeInteger)
instance DecCBOR Coin

newtype DeltaCoin = DeltaCoin Integer
deriving (Eq, Ord, Generic, Enum, NoThunks, HeapWords)
Expand Down