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

Undelegate with existing rewards #3119

Merged
merged 6 commits into from
Feb 14, 2022

Conversation

Anviking
Copy link
Member

@Anviking Anviking commented Feb 10, 2022

Old workflow:

  • Automatically withdraw rewards when quitting (both for HW and normal wallets)

New workflow (constructTransaction):

  • Don't fail with ErrNonNullRewards if "withdrawal": "self" is set when quitting

Comments

cabal v2-test cardano-wallet:integration --test-option=-j --test-option="10" --test-option="--match" --test-option "quit with rewards"

Before fix
    TRANS_NEW_QUIT_02a - Cannot quit with rewards without explicit withdrawal (51966ms)
    TRANS_NEW_QUIT_02b - Can quit with rewards with explicit withdrawal FAILED [1] (51967ms)
  SHELLEY_STAKE_POOLS
    STAKE_POOLS_QUIT_03 - Can quit with rewards FAILED [2] (51966ms)

Failures:

  src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs:2597:24:
  1) API Specifications, NEW_SHELLEY_TRANSACTIONS, TRANS_NEW_QUIT_02b - Can quit with rewards with explicit withdrawal
       uncaught exception: ErrorCall
       getFromResponse failed to get item
       CallStack (from HasCallStack):
         error, called at src/Test/Integration/Framework/DSL.hs:2034:16 in cardano-wallet-core-integration-2022.1.18-inplace:Test.Integration.Framework.DSL
         getFromResponse, called at src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs:2597:24 in cardano-wallet-core-integration-2022.1.18-inplace:Test.Integration.Scenario.API.Shelley.TransactionsNew

  To rerun use: --match "/API Specifications/NEW_SHELLEY_TRANSACTIONS/TRANS_NEW_QUIT_02b - Can quit with rewards with explicit withdrawal/"

  src/Test/Integration/Scenario/API/Shelley/StakePools.hs:537:15:
  2) API Specifications, SHELLEY_STAKE_POOLS, STAKE_POOLS_QUIT_03 - Can quit with rewards
       From the following response: Left
           ( ClientError
               ( Object
                   ( fromList
                       [
                           ( "code"
                           , String "non_null_rewards"
                           )
                       ,
                           ( "message"
                           , String "It seems that you're trying to retire from delegation although you've unspoiled rewards in your rewards account! Make sure to withdraw your 1000000.000000 lovelace first."
                           )
                       ]
                   )
               )
           )
       While verifying value:
         ( Status
             { statusCode = 403
             , statusMessage = "Forbidden"
             }
         , Left
             ( ClientError
                 ( Object
                     ( fromList
                         [
                             ( "code"
                             , String "non_null_rewards"
                             )
                         ,
                             ( "message"
                             , String "It seems that you're trying to retire from delegation although you've unspoiled rewards in your rewards account! Make sure to withdraw your 1000000.000000 lovelace first."
                             )
                         ]
                     )
                 )
             )
         )
       expected: Status {statusCode = 202, statusMessage = "Accepted"}
        but got: Status {statusCode = 403, statusMessage = "Forbidden"}

  To rerun use: --match "/API Specifications/SHELLEY_STAKE_POOLS/STAKE_POOLS_QUIT_03 - Can quit with rewards/"

Randomized with seed 1670117879

Finished in 52.0220 seconds, used 10.2823 seconds of CPU time
3 examples, 2 failures

After fixes:

    TRANS_NEW_QUIT_02a - Cannot quit with rewards without explicit withdrawal (51666ms)
    TRANS_NEW_QUIT_02b - Can quit with rewards with explicit withdrawal (51975ms)
  SHELLEY_STAKE_POOLS
    STAKE_POOLS_QUIT_03 - Can quit with rewards (51975ms)

Issue Number

ADP-1067

@Anviking Anviking self-assigned this Feb 10, 2022
@Anviking Anviking force-pushed the anviking/ADP-1067/undelegateWithExistingRewards branch 3 times, most recently from 4cef1e8 to 9ec842c Compare February 10, 2022 19:36
@Anviking Anviking marked this pull request as ready for review February 10, 2022 19:45
@paweljakubas
Copy link
Contributor

what about adding :

                , expectField #depositReturned (`shouldBe` Quantity 1000000)
                , expectField #depositTaken (`shouldBe` Quantity 0)

to both StakePools and TransactionNew tests?

Currently fails with: src/Test/Integration/Scenario/API/Shelley/StakePools.hs:537:15:
  1) API Specifications, SHELLEY_STAKE_POOLS, STAKE_POOLS_QUIT_xx - Can quit with rewards expected: Status {statusCode = 202, statusMessage = "Accepted"} but
     got: Status {statusCode = 403, statusMessage = "Forbidden"}

       from the following response: Left (DecodeFailure "Error in $: parsing Cardano.Wallet.Api.Types.ApiTransaction(ApiTransaction) failed, key \"id\" not
       found: Response {responseStatus = Status {statusCode = 403, statusMessage = \"Forbidden\"}, responseVersion = HTTP/1.1, responseHeaders =
       [(\"Transfer-Encoding\",\"chunked\"),(\"Date\",\"Fri, 06 Aug 2021 13:21:52
       GMT\"),(\"Server\",\"Warp/3.3.17\"),(\"Content-Type\",\"application/json;charset=utf-8\")], responseBody =
       \"{\\\"code\\\":\\\"non_null_rewards\\\",\\\"message\\\":\\\"It seems that you're trying to retire from delegation although you've unspoiled rewards in
       your rewards account! Make sure to withdraw your 1000000000000 lovelace first.\\\"}\", responseCookieJar = CJ {expose = []}, responseClose' =
       ResponseClose}")

       While verifying value: ( Status { statusCode = 403 , statusMessage = "Forbidden" } , Left ( DecodeFailure "Error in $: parsing
       Cardano.Wallet.Api.Types.ApiTransaction(ApiTransaction) failed, key "id" not found: Response {responseStatus = Status {statusCode = 403, statusMessage =
       "Forbidden"}, responseVersion = HTTP/1.1, responseHeaders = [("Transfer-Encoding","chunked"),("Date","Fri, 06 Aug 2021 13:21:52
       GMT"),("Server","Warp/3.3.17"),("Content-Type","application/json;charset=utf-8")], responseBody = "{\"code\":\"non_null_rewards\",\"message\":\"It seems
       that you're trying to retire from delegation although you've unspoiled rewards in your rewards account! Make sure to withdraw your 1000000000000 lovelace
       first.\"}", responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose}" ))
@Anviking Anviking force-pushed the anviking/ADP-1067/undelegateWithExistingRewards branch from 9ec842c to c1aa000 Compare February 11, 2022 17:54
@Anviking
Copy link
Member Author

what about adding :

@paweljakubas Done, and I found something interesting:

        quitStakePool @n ctx (w, fixturePassphrase) >>= flip verify
            [ expectResponseCode HTTP.status202
            , expectField #depositTaken (`shouldBe` (Quantity 0))
            , expectField #depositReturned
                (`shouldBe` (Quantity 0))
                    -- FIXME: We would expect 1000000 here;
                    -- seems like a bug!

I pushed a fix to the reclaimIfAny calculation (which didn't seem to care about withdrawals)... let's see if everything is still green.

WithdrawalSelf {} -> return ()
_
| rewards == Coin 0 -> return ()
| otherwise -> Left $ ErrNonNullRewards rewards
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

let unsignedTx2 = getFromResponse #transaction rUnsignedTx2
verify rUnsignedTx2
[ expectField (#coinSelection . #depositsReturned)
(`shouldBe` [Quantity 1000000])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

ctx (Link.listStakePools arbitraryStake) Empty
joinStakePool @n ctx pool (w, fixturePassphrase) >>= flip verify
[ expectResponseCode HTTP.status202
, expectField #depositTaken (`shouldBe` (Quantity 0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, shouldn't this be Quantity depositAmt ?

Copy link
Member Author

@Anviking Anviking Feb 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the fixture rewardWallets which already have registered stake keys. Added a comment to the other test, but can add one here as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aha, ok. so this is shelley wallet with gathered some rewards 👍 (---> rewardWallet rather than fixtureWallet). And we do it in order not to wait. Then here we are really rejoining.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I was expecting the flow more like in suite STAKE_POOLS_JOIN_04 - Rewards accumulate

BTW. you need to correct there :

652         -- Can't quite if unspoiled rewards.                                                                                                                                                                   
653         quitStakePool @n ctx (w, fixturePassphrase) >>= flip verify                                                                                                                                            
654             [ expectResponseCode HTTP.status403                                                                                                                                                                
655             , expectErrorMessage errMsg403NonNullReward                                                                                                                                                        
656             ]    

No anymore valid after your change.

depositValue
else
0
| otherwise = 0

totalInWithoutFee :: Natural
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, this was redundant if we take into account withdrawals 👍 And the name was misleading

Copy link
Contributor

@paweljakubas paweljakubas Feb 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now thinking about this. we want to detect quitting and receiving deposit back. Shouldn't we have instead totalIn

    totalInWithoutWdrl
        = sum (txOutValue <$> mapMaybe snd (tx ^. #txInputs))

in the end? We are not after detecting direction here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all test passes, so you are right 😅

@@ -459,8 +462,12 @@ prop_guardQuitJoin (NonEmpty knownPoolsList) dlg rewards =
knownPools dlg (last knownPoolsList) noRetirementPlanned
=== Right ()
Left W.ErrNonNullRewards{} ->
label "ErrNonNullRewards"
(property $ rewards /= 0)
label "ErrNonNullRewards" $
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Copy link
Contributor

@paweljakubas paweljakubas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except https://github.com/input-output-hk/cardano-wallet/pull/3119/files#r804961464
It is not forbidden anymore. I was expecting the flow more like in STAKE_POOLS_JOIN_04 - Rewards accumulate but you used rewardWallet . Kinda surprised here. I understand we have wallet with rewards, but still at first I thought when joining I will see depositTaken > 0. Of course, we cannot deregister stake credential without taking rewards home, so when we have rewards to be taken it implies we are staking ...
I checked locally

stack test --ta '-m "TRANS_NEW"' cardano-wallet:integration   OK
stack test --ta '-m "STAKE_POOLS"' cardano-wallet:integration  only STAKE_POOLS_JOIN_04 - Rewards accumulate fails for the obvious reason

@Anviking
Copy link
Member Author

bors try

iohk-bors bot added a commit that referenced this pull request Feb 14, 2022
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Feb 14, 2022

try

Build succeeded:

@Anviking Anviking merged commit f56e469 into master Feb 14, 2022
@Anviking Anviking deleted the anviking/ADP-1067/undelegateWithExistingRewards branch February 14, 2022 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants