-
Notifications
You must be signed in to change notification settings - Fork 37
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
Strip the TransactionMessageWithDurableNonceLifetime type when prepending instructions to a TransactionMessage #193
Conversation
…ding instructions to a TransactionMessage
🦋 Changeset detectedLatest commit: 08c0c77 The changes in this PR will be included in the next version bump. This PR includes changesets to release 39 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
BundleMonUnchanged files (127)
No change in files bundle size Final result: ✅ View report in BundleMon website ➡️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem
It's possible to create a
CompilableTransactionMessage
that actually is not. Take a valid durable nonce transaction message, and prepend any instruction with no accounts. This will remain aCompilableTransactionMessage
, since prepending doesn't change the type, but when you attempt to compile it it'll throw an error trying to read accounts from the first instruction, which it expects to be a durable nonce advance instruction but is not.See compile code:
kit/packages/transactions/src/compile-transaction.ts
Lines 42 to 52 in 0ffbfb6
Summary of Changes
While we could add error checking to that compile code, the root cause is that
prependTransactionMessageInstruction(s)
should never return aTransactionMessageWithDurableNonceLifetime
. This PR modifies the types so that theTransactionMessageWithDurableNonceLifetime
is stripped if present on the input type.This means that the returned transaction is no longer a
CompilableTransactionMessage
if it was previously aTransactionMessageWithDurableNonceLifetime
, and you'll correctly get a type error if you attempt to compile it.This does not fix the bad error message if you eg cast such an invalid message to
TransactionMessageWithDurableNonceLifetime
, so we might still decide to add runtime checks and errors. But since we've generally preferred type errors when possible, I think this is the best fix for now.Addresses #187