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: Remove TxEnvelope() functions from txnbuild #3377

Merged
merged 2 commits into from
Feb 1, 2021

Conversation

tamirms
Copy link
Contributor

@tamirms tamirms commented Jan 28, 2021

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

Remove TxEnvelope() from Transaction and FeeBumpTransaction. Now ToXDR() is the only function which produces XDR transaction envelopes.

Why

It simplifies the API to just have one function which produces an XDR transaction envelope. Although it would be nice to have immutable transaction envelopes, the inconvenience of checking the error result might outweigh the benefit. Given that the Signatures() and Operations() functions assume the caller will not modify the returned slice, I think it is ok for us to be consistent and hold the same assumption in ToXDR().

Known limitations

[N/A]

@cla-bot cla-bot bot added the cla: yes label Jan 28, 2021
@tamirms tamirms changed the base branch from master to release-txnbuild-v6.0.0 January 28, 2021 12:44
@tamirms tamirms force-pushed the remove-tx-envelope branch from 7e2b9c6 to 4fd2ccc Compare January 28, 2021 12:45
@tamirms tamirms requested review from leighmcculloch, marcelosalloum and a team January 28, 2021 12:51
@tamirms tamirms marked this pull request as ready for review January 28, 2021 12:52
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.

I think reducing the number of functions that return the same thing, and therefore reducing the API, is good.

I think returning a transaction envelope that shouldn't be modified by the caller is also okay. As you say this API already does this in multiple places.

I think the errorless panic function is okay, because as far as I can tell the SDK doesn't allow the panic case to occur unless there was a logical bug in the SDK because parsing an XDR containing and unknown envelope type would error earlier, and the code won't allow constructing a transaction with other envelope types.

I left comments inline containin a question (❓) and suggestion (💡). Regardless this looks 👍🏻. I defer to @stellar/horizon-committers.

Comment on lines 310 to 315
env.V1 = new(xdr.TransactionV1Envelope)
*env.V1 = *t.envelope.V1
env.V1.Signatures = t.signatures
case xdr.EnvelopeTypeEnvelopeTypeTxV0:
env.V0 = new(xdr.TransactionV0Envelope)
*env.V0 = *t.envelope.V0
Copy link
Member

Choose a reason for hiding this comment

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

❓ Why does this change include copying the V0 and V1 to itself? The signatures aren't copied, or the original envelope object. If the function says it returns an object that shouldn't be modified I don't think you need to do this copy.

Comment on lines 310 to 315
env.V1 = new(xdr.TransactionV1Envelope)
*env.V1 = *t.envelope.V1
env.V1.Signatures = t.signatures
case xdr.EnvelopeTypeEnvelopeTypeTxV0:
env.V0 = new(xdr.TransactionV0Envelope)
*env.V0 = *t.envelope.V0
Copy link
Member

Choose a reason for hiding this comment

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

💡 We might want to consider storing signatures directly on the envelope at the time the signatures are added. In multiple places we set them lazily on the envelope which I don't think is particularly intuitive. If we set them upfront functions like ToXDR would simply be:

return t.envelope

@@ -260,18 +246,36 @@ func (t *Transaction) HashHex(network string) (string, error) {
return hashHex(t.envelope, network)
}

func (t *Transaction) clone(signatures []xdr.DecoratedSignature) *Transaction {
Copy link
Contributor

Choose a reason for hiding this comment

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

This may be OK but this function does not clone objects behind pointers. The removed cloneEnvelope did so, so it's worth checking if any assumptions were not broken by this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Transaction never modifies the transaction envelope and when ToXDR() returns the transaction envelope we assume the caller will not modify the transaction envelope

@tamirms tamirms merged commit c56bd76 into stellar:release-txnbuild-v6.0.0 Feb 1, 2021
@tamirms tamirms deleted the remove-tx-envelope branch February 1, 2021 20:19
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