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

Construct tx for multisig wallet #3378

Merged
merged 27 commits into from
Jul 26, 2022

Conversation

paweljakubas
Copy link
Contributor

@paweljakubas paweljakubas commented Jul 7, 2022

The work was realized in three areas:

  1. On api level, the constructSharedTx was added in core's api level. Also swagger was updated accordingly.
    On api's server level the simplest (without delegation or minting support) impl was chosen. The error outlawing calling this endpoint was introduced when shared wallet is in pending state. Also transaction integration test suite was added

  2. The shared wallet state was extended. When the wallet is in active state now both external and internal pools are available. Also PendingIxs was added there. Those three things are now encapsulated in SharedAddressPools abstraction. So the accounting logic is like with shelley's wallet. In order to achieve that SharedAddressPool abstraction was generalized to account for chain type parameter. As previously active state has only external shared address pool, the change to have two more things had significant ripple effects down to DB layer. It also affected core unit testing. As deriveAddressPublicKey from cardano-addresses was assuming external chain only, the prerequisite for this PR is Extend payment share key derivation IntersectMBO/cardano-addresses#191 that enabled also derivation for internal chain.

Moreover, GenChange interface impl was added, also impl of constructAddressFromIx was changed, the same for isShared impl.

  1. constructSharedTransaction was added in Cardano.Wallet. constructTransaction wallet therein could not be used as it sets reward account in a way that is not enough for shared wallets, also it outlawsnon-shelly style wallets. For shared wallets delegation credential could be both keyhash (like for shelley) or script hash - at this moment key hash solution based on accXPub of wallet and ix=0 was added. In next PRs we will return to this subject.

Comments

Issue Number

adp-1623

@paweljakubas paweljakubas self-assigned this Jul 7, 2022
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-1623/construct-decode-tx-multisig branch from 6b61367 to f026f64 Compare July 7, 2022 15:45
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-1623/construct-decode-tx-multisig branch from f026f64 to e476ff6 Compare July 8, 2022 14:05
@paweljakubas paweljakubas marked this pull request as ready for review July 8, 2022 14:05
/shared-wallets/{walletId}/transactions-construct:
post:
operationId: constructSharedTransaction
tags: ["Transactions New"]
Copy link
Contributor

@piotr-iohk piotr-iohk Jul 8, 2022

Choose a reason for hiding this comment

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

This should go rather into 'Shared Transactions' under 'Shelley (Shared Wallets)'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

description: |
<p align="right">status: <strong>under development</strong></p>

Create a transaction to be signed from the shared wallet.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be for adding an additional note here explicitely which elements of construct we are expecting to work with a ⚠️. (That's because rendered API doc shows all elements of request body ApiConstructTransactionData which might suggest all of them work)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

let amt = 10 * minUTxOValue (_mainEra ctx)
fundSharedWallet ctx amt walShared
where
fundSharedWallet ctx amt walShared = do
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be quite useful to introduce fixtureSharedWallet mechanism (just like we have for fixtureWallet). That would be quite handy for testing transactions, as we're going to have more tests like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it is good idea. I plan to do it in next PR just not to bloat this one

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 have done it in the current PR

errMsg403SharedWalletPending :: String
errMsg403SharedWalletPending = unwords
[ "Transaction for a shared wallet should not be tried for"
, "a pending shared wallet. Make the wallet active before sending"
Copy link
Contributor

@piotr-iohk piotr-iohk Jul 11, 2022

Choose a reason for hiding this comment

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

The visible status of such wallet is actually:

  "state": {
    "status": "incomplete"
  }

So maybe something like:

"I cannot construct transaction for a shared wallet that is in 'incomplete' state. Please update your wallet accordingly with 'PATCH /shared-wallets/{walletId}/payment-script-template' or 'PATCH /shared-wallets/{walletId}/delegation-script-template' to make it applicable for constructing transaction."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

(Link.createUnsignedTransaction @'Shared wal) Default metadata
verify rTx
[ expectResponseCode HTTP.status403
, expectErrorMessage errMsg403EmptyUTxO
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok for the empty wallet, but we're missing test for constructing tx from wallet with funds.

Actually, it seems the case of non-empty wallet there is an unexpected 403:

$ curl -X POST http://localhost:8090/v2/shared-wallets/e173d884b4300c7450b6a7774fd4055bf3547eac/transactions-construct \
 -d '{"payments":[{"address":"addr_test1xz0fh48l3rv4tgs32e767ax60rdncf3ydfgtgxt3u83staue0pjynxnypmrzetew4nmwq4yapd3cc85qc9fg6gva66psrh402e",
                   "amount":{"quantity":10000000,"unit":"lovelace"}}]}' \
-H "Content-Type: application/json" | jq

{
  "code": "invalid_wallet_type",
  "message": "It is regrettable but you've just attempted an operation that is invalid for this type of wallet. Only new 'Shelley' wallets can do something with rewards and this one isn't."
}

Copy link
Contributor Author

@paweljakubas paweljakubas Jul 12, 2022

Choose a reason for hiding this comment

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

I know, I needed to add special mutable account treatment for shared wallet to deal with that.

@paweljakubas paweljakubas force-pushed the paweljakubas/adp-1623/construct-decode-tx-multisig branch from dfde761 to 6892586 Compare July 12, 2022 13:53
@paweljakubas paweljakubas changed the title Construct tx for multisig multisig Construct tx for multisig wallet Jul 12, 2022
@paweljakubas paweljakubas requested a review from piotr-iohk July 12, 2022 14:20
fundSharedWallet ctx amt walShared

rTx2 <- request @(ApiConstructTransaction n) ctx
(Link.createUnsignedTransaction @'Shared wal) Default metadata
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice actually to demonstrate in the integration tests all that we expect to work is working, i.e. constructing:

  • single output tx
  • multi ouput tx
  • multi assets tx
  • metadata
  • use of validity intervals

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds reasonable. I have added testing for all cases except multi assets tx as this topic will require separate treatment and ticket. I also added fixtureSharedWallet as you requested in early comment

@paweljakubas paweljakubas force-pushed the paweljakubas/adp-1623/construct-decode-tx-multisig branch from 16aa0d6 to 9532b60 Compare July 14, 2022 14:07
@paweljakubas paweljakubas requested a review from piotr-iohk July 14, 2022 14:10
@paweljakubas paweljakubas mentioned this pull request Jul 19, 2022
2 tasks
Copy link
Contributor

@HeinrichApfelmus HeinrichApfelmus left a comment

Choose a reason for hiding this comment

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

First round of review. Looks mostly good! 😊 However, a couple of points:

One point that needs to be fixed:

  • PendingIxs need to be part of the Prologue — similar to how SeqState does it. (Yes, this means that there could be a subtle problem with the pending txs when a rollback happens, they are not part of the checkpoints. However, this problem has always been present in the SeqState; this is not the right moment to fix it.)

Two points that I think should be fixed:

  • I believe that we can statically set k ~ SharedKey and get rid of the dynamic error for constructSharedTransaction.
  • Avoid code duplication for PendingIxs, specially for the implementation of nextChangeIndex, by extracting the common functions into a separate module (suggestions in comments).

One point that would be nice to address, but is not blocking:

  • Accumulate less logic in Cardano.Wallet.Api.Server — move coin selection logic to Cardano.Wallet instead.

Looking forward to second round of review. Happy to discuss in person as well.

(I have looked at almost all files, but not the integration tests.)

lib/shelley/src/Cardano/Wallet/Shelley/Api/Server.hs Outdated Show resolved Hide resolved
lib/core/src/Cardano/Wallet/Api/Server.hs Outdated Show resolved Hide resolved
lib/core/src/Cardano/Wallet/Api/Server.hs Outdated Show resolved Hide resolved
lib/core/src/Cardano/Wallet/Api/Server.hs Outdated Show resolved Hide resolved
lib/core/src/Cardano/Wallet.hs Outdated Show resolved Hide resolved
lib/core/src/Cardano/Wallet/DB/Store/Checkpoints.hs Outdated Show resolved Hide resolved
lib/core/src/Cardano/Wallet/Address/Book.hs Outdated Show resolved Hide resolved
lib/core/src/Cardano/Wallet/Address/Book.hs Outdated Show resolved Hide resolved
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-1623/construct-decode-tx-multisig branch from 9532b60 to 1ce7652 Compare July 26, 2022 12:27
Copy link
Contributor

@HeinrichApfelmus HeinrichApfelmus left a comment

Choose a reason for hiding this comment

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

Looks good to me now! 😊 Only minor issues with indentation remaining.

Comment on lines 616 to 618
Shared.pendingIxsFromList . fromRes <$> selectList
[SharedStatePendingWalletId ==. wid]
[Desc SharedStatePendingIxIndex]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Shared.pendingIxsFromList . fromRes <$> selectList
[SharedStatePendingWalletId ==. wid]
[Desc SharedStatePendingIxIndex]
Shared.pendingIxsFromList . fromRes <$> selectList
[SharedStatePendingWalletId ==. wid]
[Desc SharedStatePendingIxIndex]

(Indentation for clarity.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines +623 to +625
extAddrMap <- loadAddresses @'UtxoExternal
intAddrMap <- loadAddresses @'UtxoInternal
pure $ SharedDiscoveries extAddrMap intAddrMap
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
extAddrMap <- loadAddresses @'UtxoExternal
intAddrMap <- loadAddresses @'UtxoInternal
pure $ SharedDiscoveries extAddrMap intAddrMap
extAddrMap <- loadAddresses @'UtxoExternal
intAddrMap <- loadAddresses @'UtxoInternal
pure $ SharedDiscoveries extAddrMap intAddrMap

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

-------------------------------------------------------------------------------}

-- | An ordered set of pending indexes. This keep track of indexes used
newtype PendingIxs = PendingIxs
Copy link
Contributor

Choose a reason for hiding this comment

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

let's say I will do it in the next PR

That works for me! Feel free to make a separate PR just for this refactoring move — that will make it much easier to review.

@paweljakubas
Copy link
Contributor Author

bors r+

iohk-bors bot added a commit that referenced this pull request Jul 26, 2022
3378: Construct tx for multisig wallet 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.
-->

The work was realized in three areas:
1. On api level, the constructSharedTx was added in core's api level. Also swagger was updated accordingly.
    On api's server level the simplest (without delegation or minting support) impl was chosen. The error outlawing calling this endpoint was introduced when shared wallet is in pending state. Also transaction integration test suite was added 

2. The shared wallet state was extended. When the wallet is in active state now both external and internal pools are available. Also `PendingIxs` was added there. Those three things are now encapsulated in `SharedAddressPools` abstraction. So the accounting logic is like with shelley's wallet. In order to achieve that `SharedAddressPool` abstraction was generalized to account for chain type parameter. As previously active state has only external shared address pool, the change to have two more things had significant ripple effects down to DB layer. It also affected core unit testing. As `deriveAddressPublicKey` from cardano-addresses was assuming external chain only, the prerequisite for this PR is IntersectMBO/cardano-addresses#191 that enabled also derivation for internal chain.

Moreover, `GenChange` interface impl was added, also impl of `constructAddressFromIx` was changed, the same for `isShared` impl.   

3. `constructSharedTransaction` was added in `Cardano.Wallet`. `constructTransaction` wallet therein could not be used as it sets reward account in a way that is not enough for shared wallets, also it outlawsnon-shelly style wallets. For shared wallets delegation credential could be both keyhash (like for shelley) or script hash - at this moment key hash solution based on accXPub of wallet and ix=0 was added. In next PRs we will return to this subject. 
 
### Comments

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

### Issue Number

adp-1623

<!-- 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 Jul 26, 2022

Build failed:

  src/Test/Integration/Scenario/API/Shared/Addresses.hs:86:9: 
  1) API Specifications, SHARED_ADDRESSES, SHARED_ADDRESSES_LIST_01 - Can list known addresses on a default wallet
       expected: 20
        but got: 40

@paweljakubas
Copy link
Contributor Author

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jul 26, 2022

Build succeeded:

@iohk-bors iohk-bors bot merged commit ea35080 into master Jul 26, 2022
@iohk-bors iohk-bors bot deleted the paweljakubas/adp-1623/construct-decode-tx-multisig branch July 26, 2022 16:34
WilliamKingNoel-Bot pushed a commit that referenced this pull request Jul 26, 2022
iohk-bors bot added a commit that referenced this pull request Jul 29, 2022
3412: PendingIxs refactoring and decode tx shared wallets 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] I have introduced `PendingIxs` in `AddressDerivation` and reused it in both sequential and shared mode 
- [x]  I have implemented endpoint for decode tx for multisig working for all cases supported for construct tx
as in #3378
- [x]  I have added integration tests

### Comments

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

### Issue Number
adp-2008

<!-- 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]>
iohk-bors bot added a commit that referenced this pull request Jul 29, 2022
3412: PendingIxs refactoring and decode tx shared wallets 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] I have introduced `PendingIxs` in `AddressDerivation` and reused it in both sequential and shared mode 
- [x]  I have implemented endpoint for decode tx for multisig working for all cases supported for construct tx
as in #3378
- [x]  I have added integration tests

### Comments

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

### Issue Number
adp-2008

<!-- 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]>
iohk-bors bot added a commit that referenced this pull request Jul 29, 2022
3412: PendingIxs refactoring and decode tx shared wallets 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] I have introduced `PendingIxs` in `AddressDerivation` and reused it in both sequential and shared mode 
- [x]  I have implemented endpoint for decode tx for multisig working for all cases supported for construct tx
as in #3378
- [x]  I have added integration tests

### Comments

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

### Issue Number
adp-2008

<!-- 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]>
iohk-bors bot added a commit that referenced this pull request Aug 1, 2022
3412: PendingIxs refactoring and decode tx shared wallets 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] I have introduced `PendingIxs` in `AddressDerivation` and reused it in both sequential and shared mode 
- [x]  I have implemented endpoint for decode tx for multisig working for all cases supported for construct tx
as in #3378
- [x]  I have added integration tests

### Comments

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

### Issue Number
adp-2008

<!-- 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]>
iohk-bors bot added a commit that referenced this pull request Aug 1, 2022
3412: PendingIxs refactoring and decode tx shared wallets 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] I have introduced `PendingIxs` in `AddressDerivation` and reused it in both sequential and shared mode 
- [x]  I have implemented endpoint for decode tx for multisig working for all cases supported for construct tx
as in #3378
- [x]  I have added integration tests

### Comments

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

### Issue Number
adp-2008

<!-- 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]>
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.

3 participants