Skip to content

Commit

Permalink
Fix getRegTxCert and getUnRegTxCert definitions in Conway
Browse files Browse the repository at this point in the history
keeping the manifestation of the problem for protocol 9
  • Loading branch information
teodanciu committed Sep 13, 2024
1 parent 76fcc22 commit 7539293
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions eras/conway/impl/src/Cardano/Ledger/Conway/TxCert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ instance Crypto c => EraTxCert (ConwayEra c) where
instance Crypto c => ShelleyEraTxCert (ConwayEra c) where
mkRegTxCert c = ConwayTxCertDeleg $ ConwayRegCert c SNothing

getRegTxCert (ConwayTxCertDeleg (ConwayRegCert c _)) = Just c
getRegTxCert (ConwayTxCertDeleg (ConwayRegCert c SNothing)) = Just c
getRegTxCert _ = Nothing

mkUnRegTxCert c = ConwayTxCertDeleg $ ConwayUnRegCert c SNothing

getUnRegTxCert (ConwayTxCertDeleg (ConwayUnRegCert c _)) = Just c
getUnRegTxCert (ConwayTxCertDeleg (ConwayUnRegCert c SNothing)) = Just c
getUnRegTxCert _ = Nothing

mkDelegStakeTxCert c kh = ConwayTxCertDeleg $ ConwayDelegCert c (DelegStake kh)
Expand Down
17 changes: 14 additions & 3 deletions eras/conway/impl/src/Cardano/Ledger/Conway/TxInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ import Cardano.Ledger.Plutus.TxInfo (
import qualified Cardano.Ledger.Plutus.TxInfo as TxInfo
import Cardano.Ledger.PoolParams
import Cardano.Ledger.SafeHash (hashAnnotated)
import qualified Cardano.Ledger.Shelley.HardForks as HF (bootstrapPhase)
import Cardano.Ledger.TxIn (TxId (..), TxIn (..))
import Cardano.Ledger.UTxO (UTxO)
import Control.Arrow (ArrowChoice (..))
Expand Down Expand Up @@ -486,8 +487,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.
transTxCert :: ConwayEraTxCert era => ProtVer -> TxCert era -> PV3.TxCert
transTxCert _pv = \case
transTxCert pv = \case
RegPoolTxCert PoolParams {ppId, ppVrf} ->
PV3.TxCertPoolRegister (transKeyHash ppId) (PV3.PubKeyHash (PV3.toBuiltin (hashToBytes ppVrf)))
RetirePoolTxCert poolId retireEpochNo ->
Expand All @@ -497,9 +502,15 @@ transTxCert _pv = \case
UnRegTxCert stakeCred ->
PV3.TxCertUnRegStaking (transCred stakeCred) Nothing
RegDepositTxCert stakeCred deposit ->
PV3.TxCertRegStaking (transCred stakeCred) (Just (transCoinToLovelace deposit))
let transDeposit
| HF.bootstrapPhase pv = Nothing
| otherwise = Just (transCoinToLovelace deposit)
in PV3.TxCertRegStaking (transCred stakeCred) transDeposit
UnRegDepositTxCert stakeCred refund ->
PV3.TxCertUnRegStaking (transCred stakeCred) (Just (transCoinToLovelace refund))
let transRefund
| HF.bootstrapPhase pv = Nothing
| otherwise = Just (transCoinToLovelace refund)
in PV3.TxCertUnRegStaking (transCred stakeCred) transRefund
DelegTxCert stakeCred delegatee ->
PV3.TxCertDelegStaking (transCred stakeCred) (transDelegatee delegatee)
RegDepositDelegTxCert stakeCred delegatee deposit ->
Expand Down

0 comments on commit 7539293

Please sign in to comment.