From 2b1163d40fc6ee9b11dc9e3f3d39ea170ba16456 Mon Sep 17 00:00:00 2001 From: Alexey Kuleshevich Date: Wed, 23 Oct 2024 12:09:16 -0600 Subject: [PATCH 1/3] Adjust semantics of `ConwayWdrlNotDelegatedToDRep` Previous semantics did not allow to withdraw rewards and deregister in the same transaction, because deregistration would effectively clear out delegation to a DRep, thus preventing withdrawals --- eras/conway/impl/CHANGELOG.md | 4 ++++ .../src/Cardano/Ledger/Conway/Rules/Ledger.hs | 24 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/eras/conway/impl/CHANGELOG.md b/eras/conway/impl/CHANGELOG.md index e2ccac17fa3..981edf83813 100644 --- a/eras/conway/impl/CHANGELOG.md +++ b/eras/conway/impl/CHANGELOG.md @@ -8,6 +8,10 @@ * Add `whenBootstrap` +## 1.17.2.0 + +* Change the state used for `ConwayWdrlNotDelegatedToDRep` predicate failure checking + ## 1.17.1.0 * Add `processDelegation` diff --git a/eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Ledger.hs b/eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Ledger.hs index 38104e0fac6..a254316d5ef 100644 --- a/eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Ledger.hs +++ b/eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Ledger.hs @@ -417,17 +417,15 @@ ledgerTransition = do committee = govState ^. committeeGovStateL proposals = govState ^. proposalsGovStateL committeeProposals = proposalsWithPurpose grCommitteeL proposals - certStateAfterCERTS <- - trans @(EraRule "CERTS" era) $ - TRC - ( CertsEnv tx pp slot currentEpoch committee committeeProposals - , certState - , StrictSeq.fromStrict $ txBody ^. certsTxBodyL - ) - -- Starting with version 10, we don't allow withdrawals into RewardAcounts that are KeyHashes and not delegated to Dreps + -- Starting with version 10, we don't allow withdrawals into RewardAcounts that are + -- KeyHashes and not delegated to Dreps. + -- + -- We also need to make sure we are using the certState before certificates are applied, + -- because otherwise it would not be possible to unregister a reward account and withdraw + -- all funds from it in the same transaction. unless (HF.bootstrapPhase (pp ^. ppProtocolVersionL)) $ do - let dUnified = dsUnified $ certDState certStateAfterCERTS + let dUnified = dsUnified $ certDState certState wdrls = unWithdrawals $ tx ^. bodyTxL . withdrawalsTxBodyL delegatedAddrs = DRepUView dUnified wdrlsKeyHashes = @@ -437,6 +435,14 @@ ledgerTransition = do Set.filter (not . (`UMap.member` delegatedAddrs) . KeyHashObj) wdrlsKeyHashes failOnNonEmpty nonExistentDelegations ConwayWdrlNotDelegatedToDRep + certStateAfterCERTS <- + trans @(EraRule "CERTS" era) $ + TRC + ( CertsEnv tx pp slot currentEpoch committee committeeProposals + , certState + , StrictSeq.fromStrict $ txBody ^. certsTxBodyL + ) + -- Votes and proposals from signal tx let govSignal = GovSignal From 946ec12cc3775992f2c2176e3772879a350165ca Mon Sep 17 00:00:00 2001 From: Alexey Kuleshevich Date: Wed, 23 Oct 2024 13:00:58 -0600 Subject: [PATCH 2/3] Add a test case for recent changeof ConwayWdrlNotDelegatedToDRep semantics: #4715 --- .../Cardano/Ledger/Conway/Imp/LedgerSpec.hs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/LedgerSpec.hs b/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/LedgerSpec.hs index 96d15058ffe..4bc88d0a3a7 100644 --- a/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/LedgerSpec.hs +++ b/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/LedgerSpec.hs @@ -118,6 +118,31 @@ spec = do ifBootstrap (submitTx_ tx >> (lookupReward cred `shouldReturn` mempty)) $ do submitFailingTx tx [injectFailure $ ConwayWdrlNotDelegatedToDRep [kh]] + it "Withdraw and unregister staking credential in the same transaction" $ do + refund <- getsNES $ nesEsL . curPParamsEpochStateL . ppKeyDepositL + kh <- freshKeyHash + let cred = KeyHashObj kh + ra <- registerStakeCredential cred + Positive newDeposit <- arbitrary + modifyPParams $ \pp -> + pp + & ppGovActionLifetimeL .~ EpochInterval 2 + & ppKeyDepositL .~ Coin newDeposit + + submitAndExpireProposalToMakeReward cred + reward <- lookupReward cred + + (drep, _, _) <- setupSingleDRep 1_000_000 + + _ <- delegateToDRep cred (Coin 1_000_000) (DRepCredential drep) + + let tx = + mkBasicTx $ + mkBasicTxBody + & certsTxBodyL .~ [UnRegDepositTxCert cred refund] + & (withdrawalsTxBodyL .~ Withdrawals [(ra, reward)]) + submitTx_ tx + it "Withdraw from a key delegated to an expired DRep" $ do modifyPParams $ \pp -> pp From 2fd3a764b668cadb7996530b88614f85938005b9 Mon Sep 17 00:00:00 2001 From: Alexey Kuleshevich Date: Wed, 23 Oct 2024 13:02:04 -0600 Subject: [PATCH 3/3] Fix using a wrong deposit for stake pools in the ImpSpec --- .../shelley/impl/testlib/Test/Cardano/Ledger/Shelley/ImpTest.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/ImpTest.hs b/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/ImpTest.hs index dccf1d91299..5bb9df08989 100644 --- a/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/ImpTest.hs +++ b/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/ImpTest.hs @@ -685,7 +685,7 @@ instance & ppMaxBBSizeL .~ 65536 & ppMaxTxSizeL .~ 16384 & ppKeyDepositL .~ Coin 2_000_000 - & ppKeyDepositL .~ Coin 500_000_000 + & ppPoolDepositL .~ Coin 500_000_000 & ppEMaxL .~ EpochInterval 18 & ppNOptL .~ 150 & ppA0L .~ (3 %! 10)