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

Reuse balance transaction in construct transaction #3553

Conversation

paweljakubas
Copy link
Contributor

@paweljakubas paweljakubas commented Oct 26, 2022

  • Added PreSelection along side SelectionOf
  • Enabled mkUnsignedTx to use either PreSelection or SelectionOf
  • constructTransaction produces "no-inputs/no-fee" sealed tx using mkUnsignedTx
  • constructTransaction uses balanceTransaction to add inputs and fees
  • coin selection and fee are retrieved from decodeTransaction
  • checking all integration tests
  • adding dummyTxIn as node does not allow producing no-inputs txs at the moment

Comments

Issue Number

adp-2257

@paweljakubas paweljakubas self-assigned this Oct 26, 2022
@paweljakubas paweljakubas changed the title Paweljakubas/adp 2257/reuse balance transaction in construct transaction Reuse balance transaction in construct transaction Oct 26, 2022
@paweljakubas paweljakubas marked this pull request as ready for review October 28, 2022 13:24
@jonathanknowles
Copy link
Member

jonathanknowles commented Nov 1, 2022

Hi @paweljakubas!

EDIT: I've rebased the branch on master and fixed the warnings (for now).


It seems this branch currently doesn't build:

https://buildkite.com/input-output-hk/cardano-wallet/builds/22055#01841a4d-940e-4db4-a23b-03e048a26afa

There's also a (small) conflict with master. Perhaps we could kill two birds with one stone here: Would you be able to rebase the branch on top of master, and fix the build errors and warnings? 🙏🏻

Many thanks!

Jonathan

@jonathanknowles jonathanknowles force-pushed the paweljakubas/adp-2257/reuse-balance-transaction-in-construct-transaction branch 2 times, most recently from 615178a to 92de589 Compare November 2, 2022 07:26
@jonathanknowles
Copy link
Member

bors try

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

iohk-bors bot commented Nov 2, 2022

try

Build failed:

Failed as expected with balance_tx_zero_ada_output:

         , Left
             ( ClientError
                 ( Object
                     ( fromList
                         [
                             ( "code"
                             , String "balance_tx_zero_ada_output"
                             )
                         ,
                             ( "message"
                             , String "I don't currently support balancing transactions containing one or more zero-ada outputs. In the future I might be able to increase the values to the minimum allowed ada value."
                             )
                         ]
                     )
                 )
             )
         )
       expected: Status {
                   statusCode = 202,
                   statusMessage = "Accepted"
                 }
        but got: Status {
                   statusCode = 501,
                   statusMessage = "Not Implemented"
                 }

  To rerun use: --match "/API Specifications/NEW_SHELLEY_TRANSACTIONS/TRANS_NEW_CREATE_10h - Minting assets without timelock to foreign address/"

After the work for ADP-2347 (Support increasing zero-ada outputs to minimum in balanceTx) has been merged into master, we can rebase this PR on top of that.

@jonathanknowles jonathanknowles force-pushed the paweljakubas/adp-2257/reuse-balance-transaction-in-construct-transaction branch 2 times, most recently from 8598029 to 7226abe Compare November 3, 2022 05:54
@jonathanknowles jonathanknowles mentioned this pull request Nov 3, 2022
@@ -2534,7 +2534,7 @@ constructTransaction
-> WalletId
-> Cardano.AnyCardanoEra
-> TransactionCtx
-> SelectionOf TxOut
-> Either PreSelection (SelectionOf TxOut)
Copy link
Member

@jonathanknowles jonathanknowles Nov 3, 2022

Choose a reason for hiding this comment

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

Hi @paweljakubas

I'm a bit confused about why this argument needs to be of type Either PreSelection Selection.

Is there a good reason for this? (Perhaps preparing for the future?)

AFAICT, this function is only ever called with Left PreSelection, so we could just simplify the argument type to PreSelection.

See the following commit, which still compiles: 262b7b9.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi @jonathanknowles indeed. PreSelection was introduced as the intention was to construct tx WITHOUT inputs and SelectionOf has NonEmpty of inputs. But when I proceeded then it turn out that node does not accept constructing tx with empty inputs. Hence this dummyInput hack. But, node intends to lift this restriction in coming version of node, so I intended to stick to differentiating PreSelection and SelectionOf.

@Anviking Anviking force-pushed the paweljakubas/adp-2257/reuse-balance-transaction-in-construct-transaction branch from f154f16 to eb72775 Compare November 8, 2022 19:02
@Anviking Anviking changed the base branch from master to anviking/ADP-2347/balanceTx-minAda November 8, 2022 19:03
@Anviking
Copy link
Member

Anviking commented Nov 8, 2022

bors try

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

iohk-bors bot commented Nov 8, 2022

try

Build failed:

@Unisay Unisay force-pushed the paweljakubas/adp-2257/reuse-balance-transaction-in-construct-transaction branch from eb72775 to 6b1f160 Compare November 10, 2022 11:02
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 10, 2022

👎 Rejected by too few approved reviews

@Anviking Anviking force-pushed the anviking/ADP-2347/balanceTx-minAda branch 3 times, most recently from d9a6ee6 to 86448bd Compare November 14, 2022 14:54
@Unisay
Copy link
Contributor

Unisay commented Nov 14, 2022

I am taking over this branch

@Unisay Unisay force-pushed the paweljakubas/adp-2257/reuse-balance-transaction-in-construct-transaction branch from 6b1f160 to ab4539e Compare November 15, 2022 08:13
@Anviking Anviking force-pushed the anviking/ADP-2347/balanceTx-minAda branch from e903498 to b38c399 Compare November 15, 2022 11:33
Anviking and others added 22 commits November 21, 2022 15:48
Use `LambdaCase` instead of repeating patterns.
Use `Coin.fromQuantity` instead of `fromIntegral`.
This removes the incomplete pattern match warnings.
The function `Cardano.Wallet.constructTransaction` is only ever called
with a `Left PreSelection`, and never called with a `Right Selection`.

Therefore, we can simplify the selection argument type from
`Either PreSelection Selection` to just `PreSelection`.
This helper type is only used by the `constructTransaction` and
`mkUnsignedTx` functions, and not used by anything within the
`CoinSelection` module hierarchy.
Without this change integration tests would fail e.g. where:

```pseudo-code
constructTx
  paymentTo addr1 (0 ada)

  |
  |
  V

Tx
  output: addr1 (1 ada) -- min ada, set automatically
  output: addr2 (9 ada) -- change
```

as we'd believe both outputs in the resuling tx were change -- neither
of them exists in the original output list.

If there are 'n' outputs in the original unbalanced tx, we will with
this commit instead judge that the first 'n' are "outputs" and that the
ones after that are all change. While this makes assumptions about how
balanceTx appends outputs, it is more importantly ressilient to outputs
being modified, like with the `increaseZeroAdaOutputs` feature.
@Unisay Unisay force-pushed the paweljakubas/adp-2257/reuse-balance-transaction-in-construct-transaction branch from 7e7a60b to 6473ee4 Compare November 21, 2022 15:39
@Unisay
Copy link
Contributor

Unisay commented Nov 21, 2022

bors merge

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 21, 2022

Build succeeded:

@iohk-bors iohk-bors bot merged commit 2363059 into master Nov 21, 2022
@iohk-bors iohk-bors bot deleted the paweljakubas/adp-2257/reuse-balance-transaction-in-construct-transaction branch November 21, 2022 19:48
WilliamKingNoel-Bot pushed a commit that referenced this pull request Nov 21, 2022
…ction r=Unisay a=paweljakubas <!-- Detail in a few bullet points the work accomplished in this PR. Before you submit, don't forget to: LICENSE README.md bors.toml cabal.project default.nix docker-compose.yml docs flake.lock flake.nix floskell.json hie-direnv.yaml lib nix prototypes release.nix reports scripts shell.nix specifications test touch.me.CI weeder.dhall 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. LICENSE README.md bors.toml cabal.project default.nix docker-compose.yml docs flake.lock flake.nix floskell.json hie-direnv.yaml lib nix prototypes release.nix reports scripts shell.nix specifications test touch.me.CI weeder.dhall 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. LICENSE README.md bors.toml cabal.project default.nix docker-compose.yml docs flake.lock flake.nix floskell.json hie-direnv.yaml lib nix prototypes release.nix reports scripts shell.nix specifications test touch.me.CI weeder.dhall 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] Added PreSelection along side SelectionOf - [x] Enabled mkUnsignedTx to use either PreSelection or SelectionOf - [x] constructTransaction produces "no-inputs/no-fee" sealed tx using mkUnsignedTx - [x] constructTransaction uses balanceTransaction to add inputs and fees - [x] coin selection and fee are retrieved from decodeTransaction - [x] checking all integration tests - [x] adding dummyTxIn as node does not allow producing no-inputs txs at the moment ### Comments <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number adp-2257
 
 <!-- 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: Johannes Lund <[email protected]> Co-authored-by: Jonathan Knowles <[email protected]> Co-authored-by: Yura Lazarev <[email protected]> Source commit: 2363059
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