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

Handle reclaims in get transaction #3104

Merged
merged 12 commits into from
Feb 11, 2022

Conversation

paweljakubas
Copy link
Contributor

@paweljakubas paweljakubas commented Feb 3, 2022

  • Update of ApiTransaction to include depositTaken and depositReturned
  • adding of integration tests showing the case for joining/rejoining and quitting
  • update core unit tests and swagger

Comments

Issue Number

adp-460
adp-1402

@paweljakubas paweljakubas self-assigned this Feb 3, 2022
Copy link
Member

@Anviking Anviking left a comment

Choose a reason for hiding this comment

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

lgtm

Also adding a returned deposit check for quitting in the old workflow would be nice

I.e. here lib/core-integration/src/Test/Integration/Scenario/API/Shelley/StakePools.hs:395

       -- Quit delegation altogether.
        rq <- quitStakePool @n ctx (src, fixturePassphrase)
        verify rq
            -- pending tx for quitting pool is initially outgoing
            -- because there is a fee for this tx
            [ expectResponseCode HTTP.status202
            , expectField (#status . #getApiT) (`shouldBe` Pending)
            , expectField (#direction . #getApiT) (`shouldBe` Incoming)
            ]

Comment on lines 3396 to 3463
reclaimIfAny :: Natural
reclaimIfAny
| tx ^. (#txMeta . #direction) == W.Outgoing =
if totalIn < totalOut
then totalOut - totalIn
else 0
| otherwise = 0
Copy link
Member

Choose a reason for hiding this comment

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

This looked odd to me at first, but I guess it is correct, as the ins, outs and withdrawals include both ours and foreign.

@piotr-iohk
Copy link
Contributor

@paweljakubas I see an issue:

  1. When doing quit using Construct->sign->submit flow then:
  • while tx is pending then GET /transactions/ID shows deposit_returned = 2A ✔️
  • but when tx is in_ledger then GET /transactions/ID shows deposit_returned = 0 ❌
  1. When doing old quit pool DELETE /stake-pools/*/wallets/{walletId} then:
  • while tx is pending then GET /transactions/ID shows deposit_returned = 0 ❌
  • and when tx is in_ledger then GET /transactions/ID shows deposit_returned = 0 ❌

I've added checks to illustrate this to repective tests:

  1. TRANS_NEW_JOIN_01a
  2. STAKE_POOLS_JOIN_01rewards

@paweljakubas paweljakubas force-pushed the paweljakubas/adp-460/handle-reclaims-in-get-history-tx branch from cd5f9db to 29c2adf Compare February 8, 2022 14:08
@paweljakubas
Copy link
Contributor Author

paweljakubas commented Feb 8, 2022

@piotr-iohk @Anviking now all checks in tests added by Piotr passes. the problem was solved by:

  • different formula for detecting reclaim- I made extensive comment in the code about rationale here
  • now reclaim can only be for Incoming
  • in old tx flow Incoming was when pending/inLedger
  • in new tx flow Incoming was only for inLedger so I made sure it is also for Pending. In order to do it I needed to bolster submitTransaction, and its tx context.

@paweljakubas paweljakubas force-pushed the paweljakubas/adp-460/handle-reclaims-in-get-history-tx branch from 29c2adf to e6d6643 Compare February 8, 2022 14:15
Comment on lines 2146 to 2149
dir = if (txCtx ^. #txDelegationAction) == Just Quit then
Incoming
else
Outgoing
Copy link
Member

Choose a reason for hiding this comment

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

Everything TxMeta-related seems so complicated, and I don't grasp the full picture, but this change might interplay with the rollback logic

https://github.com/input-output-hk/cardano-wallet/blob/13a6c0b2c865092011ca0bc8c5ee2e7d7194365b/lib/core/src/Cardano/Wallet/DB/Sqlite.hs#L670-L673

It seems a pending Quit tx could be deleted on rollback. I'm not sure if it also stops the wallet from trying to re-submit it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I bet it is not going to destroy anything as for OLD tx workflow Incoming was for both Pending/InLedger. We had Outcoming -> Incoming for new tx workflow though. and now we have the transition/directions as for old tx workflow

Copy link
Member

Choose a reason for hiding this comment

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

Fair, the old tx workflow should also be able to produce pending incoming txs through this logic.

I still suspect this could be a problem, but unrelated to this PR.

@piotr-iohk
Copy link
Contributor

@paweljakubas I'm getting issues (arithmetic underflow in the log) when doing list transactions for my wallets on testnet on this branch:

$ curl -vX GET http://localhost:8090/v2/wallets/1ceb45b37a94c7022837b5ca14045f11a5927c65/transactions
Note: Unnecessary use of -X or --request, GET is already inferred.
*   Trying 127.0.0.1:8090...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8090 (#0)
> GET /v2/wallets/1ceb45b37a94c7022837b5ca14045f11a5927c65/transactions HTTP/1.1
> Host: localhost:8090
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server

in the wallet.log there is:

[RequestId 15] [GET] /v2/wallets/1ceb45b37a94c7022837b5ca14045f11a5927c65/transactions
arithmetic underflow

@paweljakubas
Copy link
Contributor Author

paweljakubas commented Feb 8, 2022

I see this also in integration tests when running
$ stack test --ta '-m "TRANS_LIST"' cardano-wallet:integration

arithmetic underflow
    TRANS_LIST_03 - Can order results FAILED [1] (13428ms)

CLI Specifications, SHELLEY_CLI_TRANSACTIONS, TRANS_LIST_03 - Can order results

I bet I need to make sure not to substract bigger natural from smaller one in reclaimIfAny

@paweljakubas
Copy link
Contributor Author

@piotr-iohk indeed, my hypothesis was right. I needed one more check in reclaimIfAny. Now the test passes. Could you kindly confirm?

@@ -2142,9 +2143,13 @@ mkTxMetaWithoutSel blockHeader wState txCtx inps outs =
w@WithdrawalSelf{} -> Coin.add (withdrawalToCoin w)
WithdrawalExternal{} -> Prelude.id
NoWithdrawal -> Prelude.id
dir = if (txCtx ^. #txDelegationAction) == Just Quit then
Copy link
Member

Choose a reason for hiding this comment

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

This logic is called from submitTransaction, where the user could submit any kind of (wallet-related) transaction.

Defining the direction this way might work for txs from constructTransaction, but with balanceTransaction it would quickly break.

What was the reason we can't use mkTxMeta instead of constructTxMeta? (which itself is duplicated with logic in Primitive.Model)

Copy link
Contributor Author

@paweljakubas paweljakubas Feb 9, 2022

Choose a reason for hiding this comment

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

well, we are not doing selection when submitting, we are decoding what is inside tx cbor to be sent. hence we do not use, mkTxMeta. But, we can resign from dir and compare amtInps and amtOuts to determine direction. Now it should survive balanceTransaction step (or at least we will not deteriorate situation in the context what was before this PR). I have refactored constructTxMeta and found a bug in submitTransaction. And simplified the things. And locally it is green
---> see the last commit

@paweljakubas paweljakubas force-pushed the paweljakubas/adp-460/handle-reclaims-in-get-history-tx branch from fbf3708 to fdf53da Compare February 9, 2022 18:01
@paweljakubas
Copy link
Contributor Author

bors r+

iohk-bors bot added a commit that referenced this pull request Feb 9, 2022
3104: Handle reclaims in get transaction r=paweljakubas a=paweljakubas

<!--
Detail in a few bullet points the work accomplished in this PR.

Before you submit, don't forget to:

* Make sure the GitHub PR fields are correct:
   ✓ Set a good Title for your PR.
   ✓ Assign yourself to the PR.
   ✓ Assign one or more reviewer(s).
   ✓ Link to a Jira issue, and/or other GitHub issues or PRs.
   ✓ In the PR description delete any empty sections
     and all text commented in <!--, so that this text does not appear
     in merge commit messages.

* Don't waste reviewers' time:
   ✓ If it's a draft, select the Create Draft PR option.
   ✓ Self-review your changes to make sure nothing unexpected slipped through.

* Try to make your intent clear:
   ✓ Write a good Description that explains what this PR is meant to do.
   ✓ Jira will detect and link to this PR once created, but you can also
     link this PR in the description of the corresponding Jira ticket.
   ✓ Highlight what Testing you have done.
   ✓ Acknowledge any changes required to the Documentation.
-->


- [x] Update of `ApiTransaction` to include `depositTaken` and `depositReturned`
- [x] adding of integration tests showing the case for joining/rejoining and quitting
- [x] update core unit tests and swagger

### Comments

<!-- Additional comments, links, or screenshots to attach, if any. -->

### Issue Number

<!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles.
  Note: Jira issues of the form ADP- will be auto-linked. -->


Co-authored-by: Pawel Jakubas <[email protected]>
Co-authored-by: Piotr Stachyra <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Feb 9, 2022

Build failed:

#expected (hlint)

@paweljakubas
Copy link
Contributor Author

bors r+

iohk-bors bot added a commit that referenced this pull request Feb 9, 2022
3104: Handle reclaims in get transaction r=paweljakubas a=paweljakubas

<!--
Detail in a few bullet points the work accomplished in this PR.

Before you submit, don't forget to:

* Make sure the GitHub PR fields are correct:
   ✓ Set a good Title for your PR.
   ✓ Assign yourself to the PR.
   ✓ Assign one or more reviewer(s).
   ✓ Link to a Jira issue, and/or other GitHub issues or PRs.
   ✓ In the PR description delete any empty sections
     and all text commented in <!--, so that this text does not appear
     in merge commit messages.

* Don't waste reviewers' time:
   ✓ If it's a draft, select the Create Draft PR option.
   ✓ Self-review your changes to make sure nothing unexpected slipped through.

* Try to make your intent clear:
   ✓ Write a good Description that explains what this PR is meant to do.
   ✓ Jira will detect and link to this PR once created, but you can also
     link this PR in the description of the corresponding Jira ticket.
   ✓ Highlight what Testing you have done.
   ✓ Acknowledge any changes required to the Documentation.
-->


- [x] Update of `ApiTransaction` to include `depositTaken` and `depositReturned`
- [x] adding of integration tests showing the case for joining/rejoining and quitting
- [x] update core unit tests and swagger

### Comments

<!-- Additional comments, links, or screenshots to attach, if any. -->

### Issue Number

<!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles.
  Note: Jira issues of the form ADP- will be auto-linked. -->


Co-authored-by: Pawel Jakubas <[email protected]>
Co-authored-by: Piotr Stachyra <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Feb 9, 2022

Build failed:

  test/unit/Cardano/Wallet/Api/ServerSpec.hs:141:5: 
  1) Cardano.Wallet.Api.Server, API Server, handles bad host name
       uncaught exception: IOException of type UserError
       user error (Network.Socket.gai_strerror not supported: 11002)

  To rerun use: --match "/Cardano.Wallet.Api.Server/API Server/handles bad host name/"

Randomized with seed 406019484

#3121

@paweljakubas
Copy link
Contributor Author

bors r+

iohk-bors bot added a commit that referenced this pull request Feb 10, 2022
3104: Handle reclaims in get transaction r=paweljakubas a=paweljakubas

<!--
Detail in a few bullet points the work accomplished in this PR.

Before you submit, don't forget to:

* Make sure the GitHub PR fields are correct:
   ✓ Set a good Title for your PR.
   ✓ Assign yourself to the PR.
   ✓ Assign one or more reviewer(s).
   ✓ Link to a Jira issue, and/or other GitHub issues or PRs.
   ✓ In the PR description delete any empty sections
     and all text commented in <!--, so that this text does not appear
     in merge commit messages.

* Don't waste reviewers' time:
   ✓ If it's a draft, select the Create Draft PR option.
   ✓ Self-review your changes to make sure nothing unexpected slipped through.

* Try to make your intent clear:
   ✓ Write a good Description that explains what this PR is meant to do.
   ✓ Jira will detect and link to this PR once created, but you can also
     link this PR in the description of the corresponding Jira ticket.
   ✓ Highlight what Testing you have done.
   ✓ Acknowledge any changes required to the Documentation.
-->


- [x] Update of `ApiTransaction` to include `depositTaken` and `depositReturned`
- [x] adding of integration tests showing the case for joining/rejoining and quitting
- [x] update core unit tests and swagger

### Comments

<!-- Additional comments, links, or screenshots to attach, if any. -->

### Issue Number
adp-460
adp-1402


<!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles.
  Note: Jira issues of the form ADP- will be auto-linked. -->


Co-authored-by: Pawel Jakubas <[email protected]>
Co-authored-by: Piotr Stachyra <[email protected]>
@piotr-iohk
Copy link
Contributor

adp-1402 situation seems to be fixed also. 🎉

It would be nice to have a property/unit test for that (integration or e2e is not really viable because most lakely it'd cause race conditions), but as far as I understand there's no way currently to have an automated test, so manual check has to be enough.

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Feb 10, 2022

Build failed:

Failures:
 
  src/Test/Integration/Scenario/CLI/Shelley/Transactions.hs:244:59: 
  1) CLI Specifications, SHELLEY_CLI_TRANSACTIONS, TRANS_CREATE_06 - Invalid amount, 1.5
       uncaught exception: IOException of type ResourceVanished
       fd:106: hFlush: resource vanished (Broken pipe)
 
  To rerun use: --match "/CLI Specifications/SHELLEY_CLI_TRANSACTIONS/TRANS_CREATE_06 - Invalid amount/1.5/"
 
Randomized with seed 2108903879
 
Finished in 960.1969 seconds, used 844.4028 seconds of CPU time
898 examples, 1 failure, 41 pending

#2855

@paweljakubas paweljakubas force-pushed the paweljakubas/adp-460/handle-reclaims-in-get-history-tx branch from 994c5a5 to 8489261 Compare February 10, 2022 12:17
@paweljakubas
Copy link
Contributor Author

bors r+

iohk-bors bot added a commit that referenced this pull request Feb 10, 2022
3104: Handle reclaims in get transaction r=paweljakubas a=paweljakubas

<!--
Detail in a few bullet points the work accomplished in this PR.

Before you submit, don't forget to:

* Make sure the GitHub PR fields are correct:
   ✓ Set a good Title for your PR.
   ✓ Assign yourself to the PR.
   ✓ Assign one or more reviewer(s).
   ✓ Link to a Jira issue, and/or other GitHub issues or PRs.
   ✓ In the PR description delete any empty sections
     and all text commented in <!--, so that this text does not appear
     in merge commit messages.

* Don't waste reviewers' time:
   ✓ If it's a draft, select the Create Draft PR option.
   ✓ Self-review your changes to make sure nothing unexpected slipped through.

* Try to make your intent clear:
   ✓ Write a good Description that explains what this PR is meant to do.
   ✓ Jira will detect and link to this PR once created, but you can also
     link this PR in the description of the corresponding Jira ticket.
   ✓ Highlight what Testing you have done.
   ✓ Acknowledge any changes required to the Documentation.
-->


- [x] Update of `ApiTransaction` to include `depositTaken` and `depositReturned`
- [x] adding of integration tests showing the case for joining/rejoining and quitting
- [x] update core unit tests and swagger

### Comments

<!-- Additional comments, links, or screenshots to attach, if any. -->

### Issue Number
adp-460
adp-1402


<!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles.
  Note: Jira issues of the form ADP- will be auto-linked. -->


Co-authored-by: Pawel Jakubas <[email protected]>
Co-authored-by: Piotr Stachyra <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Feb 10, 2022

Timed out.

@paweljakubas
Copy link
Contributor Author

bors retry

iohk-bors bot added a commit that referenced this pull request Feb 10, 2022
3104: Handle reclaims in get transaction r=paweljakubas a=paweljakubas

<!--
Detail in a few bullet points the work accomplished in this PR.

Before you submit, don't forget to:

* Make sure the GitHub PR fields are correct:
   ✓ Set a good Title for your PR.
   ✓ Assign yourself to the PR.
   ✓ Assign one or more reviewer(s).
   ✓ Link to a Jira issue, and/or other GitHub issues or PRs.
   ✓ In the PR description delete any empty sections
     and all text commented in <!--, so that this text does not appear
     in merge commit messages.

* Don't waste reviewers' time:
   ✓ If it's a draft, select the Create Draft PR option.
   ✓ Self-review your changes to make sure nothing unexpected slipped through.

* Try to make your intent clear:
   ✓ Write a good Description that explains what this PR is meant to do.
   ✓ Jira will detect and link to this PR once created, but you can also
     link this PR in the description of the corresponding Jira ticket.
   ✓ Highlight what Testing you have done.
   ✓ Acknowledge any changes required to the Documentation.
-->


- [x] Update of `ApiTransaction` to include `depositTaken` and `depositReturned`
- [x] adding of integration tests showing the case for joining/rejoining and quitting
- [x] update core unit tests and swagger

### Comments

<!-- Additional comments, links, or screenshots to attach, if any. -->

### Issue Number
adp-460
adp-1402


<!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles.
  Note: Jira issues of the form ADP- will be auto-linked. -->


Co-authored-by: Pawel Jakubas <[email protected]>
Co-authored-by: Piotr Stachyra <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Feb 11, 2022

Timed out.

@paweljakubas paweljakubas force-pushed the paweljakubas/adp-460/handle-reclaims-in-get-history-tx branch from 8489261 to 9670f61 Compare February 11, 2022 08:03
@paweljakubas
Copy link
Contributor Author

bors r+

iohk-bors bot added a commit that referenced this pull request Feb 11, 2022
3104: Handle reclaims in get transaction r=paweljakubas a=paweljakubas

<!--
Detail in a few bullet points the work accomplished in this PR.

Before you submit, don't forget to:

* Make sure the GitHub PR fields are correct:
   ✓ Set a good Title for your PR.
   ✓ Assign yourself to the PR.
   ✓ Assign one or more reviewer(s).
   ✓ Link to a Jira issue, and/or other GitHub issues or PRs.
   ✓ In the PR description delete any empty sections
     and all text commented in <!--, so that this text does not appear
     in merge commit messages.

* Don't waste reviewers' time:
   ✓ If it's a draft, select the Create Draft PR option.
   ✓ Self-review your changes to make sure nothing unexpected slipped through.

* Try to make your intent clear:
   ✓ Write a good Description that explains what this PR is meant to do.
   ✓ Jira will detect and link to this PR once created, but you can also
     link this PR in the description of the corresponding Jira ticket.
   ✓ Highlight what Testing you have done.
   ✓ Acknowledge any changes required to the Documentation.
-->


- [x] Update of `ApiTransaction` to include `depositTaken` and `depositReturned`
- [x] adding of integration tests showing the case for joining/rejoining and quitting
- [x] update core unit tests and swagger

### Comments

<!-- Additional comments, links, or screenshots to attach, if any. -->

### Issue Number
adp-460
adp-1402


<!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles.
  Note: Jira issues of the form ADP- will be auto-linked. -->


Co-authored-by: Pawel Jakubas <[email protected]>
Co-authored-by: Piotr Stachyra <[email protected]>
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-460/handle-reclaims-in-get-history-tx branch from 9670f61 to d5721da Compare February 11, 2022 11:48
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Feb 11, 2022

Canceled.

@paweljakubas paweljakubas force-pushed the paweljakubas/adp-460/handle-reclaims-in-get-history-tx branch from d5721da to 75c4ec3 Compare February 11, 2022 11:51
@rvl rvl enabled auto-merge (squash) February 11, 2022 11:54
@rvl rvl merged commit 28587b7 into master Feb 11, 2022
@rvl rvl deleted the paweljakubas/adp-460/handle-reclaims-in-get-history-tx branch February 11, 2022 12:09
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.

4 participants