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

txnbuild: Reenable Multiplexed strkeys (SEP23 M-addresses) behind flags #3527

Merged
merged 22 commits into from
Apr 14, 2021

Conversation

2opremio
Copy link
Contributor

@2opremio 2opremio commented Apr 6, 2021

Fixes #3490

This is an initial RFC draft a PR to re-introduce Multiplexed addresses in txnbuild, considering all the requirements from #3490 .

My main criteria for this proposal has been that no user should be enabling M-addresss unknowingly, either for new or existing code. For that reason:

  • New public functions/methods enabling SEP23 state so explicitly in their name
  • Existing public functions/methods keep their name and enable SEP23 through explicit options

Key changes:

  1. the txnbuild.Operation interface now adds a withMuxedAccount parameter to most of its methods:
    type Operation interface {
	BuildXDR(withMuxedAccounts bool) (xdr.Operation, error)
	FromXDR(xdrOp xdr.Operation, withMuxedAccounts bool) error
	Validate(withMuxedAccounts bool) error
	GetSourceAccount() string
}

For now, only txnbuild.AccountMerge supports the extended interface.

  1. NewTransaction(), TransactionFromXDR() and NewFeeBumpTransaction() now accept an option to enable SEP23, while keeping backwards compatibility

TODO:

@2opremio 2opremio requested review from leighmcculloch, tomerweller and a team April 6, 2021 14:11
txnbuild/transaction.go Outdated Show resolved Hide resolved
txnbuild/transaction.go Outdated Show resolved Hide resolved
txnbuild/operation.go Outdated Show resolved Hide resolved
strkey/main.go Outdated Show resolved Hide resolved
txnbuild/account_merge.go Outdated Show resolved Hide resolved
txnbuild/operation.go Outdated Show resolved Hide resolved
txnbuild/account_merge.go Outdated Show resolved Hide resolved
@2opremio
Copy link
Contributor Author

2opremio commented Apr 9, 2021

@tamirms Operation-tests (which are cooking) and #3527 (comment) aside, this is ready for review. PTAL while I am on it so that we can reach the release quicker.

Same for @bartekn (but I know he is off today :) ).

strkey/main.go Outdated Show resolved Hide resolved
txnbuild/clawback.go Outdated Show resolved Hide resolved
result, ok := xdrOp.Body.GetPathPaymentStrictReceiveOp()
if !ok {
return errors.New("error parsing path_payment operation from xdr")
}

pp.SourceAccount = accountFromXDR(xdrOp.SourceAccount)
pp.SourceAccount = accountFromXDR(xdrOp.SourceAccount, withMuxedAccounts)
if withMuxedAccounts {
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 accountFromXDR can be used to assign to pp.Destination

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, because accountFromXDR() accepts nil values.

txnbuild/transaction.go Outdated Show resolved Hide resolved
Copy link
Member

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

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

Really exciting to see this rolling.

I left comments about a couple things I think we should change (❗).

If you're open, I also left some suggestions (💡) that are to do with how the API is changing for the user, and how I think we could make the API is easier to understand.

txnbuild/account_merge.go Outdated Show resolved Hide resolved
txnbuild/account_merge.go Outdated Show resolved Hide resolved
txnbuild/account_merge.go Outdated Show resolved Hide resolved
txnbuild/claim_claimable_balance.go Outdated Show resolved Hide resolved
txnbuild/transaction.go Outdated Show resolved Hide resolved
txnbuild/transaction.go Outdated Show resolved Hide resolved
xdr/muxed_account.go Show resolved Hide resolved
@2opremio 2opremio force-pushed the 3490-reenable-muptiplexed-addresses branch from ed74412 to 0a6beda Compare April 14, 2021 00:04
@2opremio
Copy link
Contributor Author

It took considerable effort (due to the lack of prior coverage) but all operations should now be tested.

This should be good to go. @tamirms @bartekn please take a final look.

xdr/muxed_account.go Outdated Show resolved Hide resolved
txnbuild/CHANGELOG.md Outdated Show resolved Hide resolved
@@ -13,10 +13,14 @@ type AccountMerge struct {
}

// BuildXDR for AccountMerge returns a fully configured XDR Operation.
func (am *AccountMerge) BuildXDR() (xdr.Operation, error) {
func (am *AccountMerge) BuildXDR(withMuxedAccounts bool) (xdr.Operation, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I know this PR has been reviewed multiple times but I have one (simple) idea how to improve the API. Passing bool value to methods can be misleading (user need to check the description of the method to understand what is the param). We can create additional extra methods for each method accepting withMuxedAccounts. BuildXDR as an example:

  • Change BuildXDR(withMuxedAccounts bool) (xdr.Operation, error) to buildXDR(withMuxedAccounts bool) (xdr.Operation, error)
  • BuildXDR() stays in a form before this PR. Calls buildXDR(false) internally.
  • A new BuildXDRWithMuxedAccounts() is added and calls buildXDR(true) internally.

Copy link
Contributor Author

@2opremio 2opremio Apr 14, 2021

Choose a reason for hiding this comment

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

@bartekn that's exactly what I implemented originally and I discarded after the design discussion. Please see 27a79c6#diff-0ef2e7d165d2f196939c937afadef91206823b0671f32120b265843fd291332aR15 and the issue body edit history (which originally presented the same design you suggested, symbol-naming aside).

We should be more cohesive when discussing designs (but that's for a retro discussion). The purpose of creating an early draft a week ago was exactly avoiding this type of situation.

I personally think this needs to go out (it's already late) but if @ire-and-curses thinks it's worth another rewrite, I will cave in and restore my original design.

Copy link
Contributor Author

@2opremio 2opremio Apr 14, 2021

Choose a reason for hiding this comment

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

@ire-and-curses In order to get more context on what happened:

  1. I originally proposed what @bartekn is proposing now (you can go through the edit history of the issue body and see it).
  2. @tamirms suggested using an internal boolean (appended to each operation struct) at txnbuild: Reenable Multiplexed strkeys (SEP23 M-addresses) behind flags #3527 (comment)
  3. We discarded it at txnbuild: Reenable Multiplexed strkeys (SEP23 M-addresses) behind flags #3527 (comment) and went for the design as it is now.
  4. I proceed to implement the design for all the operations.
  5. @leighmcculloch proposed yet another design modification at txnbuild: Reenable Multiplexed strkeys (SEP23 M-addresses) behind flags #3527 (comment) which I discarded.
  6. @bartekn suggests my original design.

Copy link
Member

Choose a reason for hiding this comment

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

  1. Profit??!!
    Let's discuss in team meeting today. I really want to get this out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We decided offline to keep it as it is. Thanks for the suggestion though @bartekn

@2opremio 2opremio merged commit a9f3903 into stellar:master Apr 14, 2021
@2opremio 2opremio deleted the 3490-reenable-muptiplexed-addresses branch April 14, 2021 20:12
Shaptic added a commit to stellar/js-stellar-base that referenced this pull request May 5, 2021
Feature summary:
- Operations updated to support muxed accounts:
  * Operation.sourceAccount
  * Payment.destination
  * PathPaymentStrictReceive.destination
  * PathPaymentStrictSend.destination
  * AccountMerge.destination
  * Transaction.sourceAccount
- M... addresses can be converted to & from their XDR representation easily
- Muxed accounts can be created & managed efficiently w/ helpers (MuxedAccount)
- Feature is hidden behind an opt-in flag (`withMuxing` boolean)

Limitations:
- The final missing implementation detail is adapting
  `FeeBumpTransaction.feeSource` to accept an M-address, but this will not (and
  _should not_) be a part of this pull request because it involves a breaking
  change.

  Currently, `TransactionBuilder.buildFeeBumpTransaction` takes `feeSource`
  typed to `Keypair`, which doesn't support M-addresses. Either Keypair will
  need to support M-addresses (unlikely, as this breaks abstraction barriers) or
  the type will need to change (likely), so this will be part of a breaking 6.0
  release.

  See #422.

More reading: 
 - CAP-27 (muxed account XDR), 
 - SEP-23 (M-addresses), 
 - stellar/stellar-protocol#617 (rollout plan)
 - stellar/go#3527 (Go SDK reference impl.)
Shaptic added a commit to stellar/js-stellar-base that referenced this pull request Aug 3, 2021
Feature summary:
- Operations updated to support muxed accounts:
  * Operation.sourceAccount
  * Payment.destination
  * PathPaymentStrictReceive.destination
  * PathPaymentStrictSend.destination
  * AccountMerge.destination
  * Transaction.sourceAccount
- M... addresses can be converted to & from their XDR representation easily
- Muxed accounts can be created & managed efficiently w/ helpers (MuxedAccount)
- Feature is hidden behind an opt-in flag (`withMuxing` boolean)

Limitations:
- The final missing implementation detail is adapting
  `FeeBumpTransaction.feeSource` to accept an M-address, but this will not (and
  _should not_) be a part of this pull request because it involves a breaking
  change.

  Currently, `TransactionBuilder.buildFeeBumpTransaction` takes `feeSource`
  typed to `Keypair`, which doesn't support M-addresses. Either Keypair will
  need to support M-addresses (unlikely, as this breaks abstraction barriers) or
  the type will need to change (likely), so this will be part of a breaking 6.0
  release.

  See #422.

More reading: 
 - CAP-27 (muxed account XDR), 
 - SEP-23 (M-addresses), 
 - stellar/stellar-protocol#617 (rollout plan)
 - stellar/go#3527 (Go SDK reference impl.)
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.

Feature Request (txnbuild): (Re-)implement multiplexed accounts in the SDK
6 participants