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

Refactor transaction-confirmation to use new transaction lifetimes #2485

Merged
merged 3 commits into from
Apr 18, 2024

Conversation

mcintyre94
Copy link
Collaborator

@mcintyre94 mcintyre94 commented Apr 15, 2024

This PR refactors transaction-confirmation to take NewTransaction & {lifetimeConstraint: ...} as input. This removes the dependency on the old transaction model.

  • The new Transaction blockhash lifetime has lastValidBlockHeight added
  • The new Transaction durable nonce lifetime has nonceAccountAddress added. Previously this was pulled from the transaction's instructions, but we no longer have access to decompiled instructions when we have a signed Transaction object.

Note: I'm leaning away from providing a helper to assert on the lifetime of a NewTransaction if you don't know it, at least for now. It would require decompiling almost all of the transaction (up to its first instruction), and potentially fetching address lookup tables (if they're used for any of the accounts in the advance nonce instruction). At that point I don't think it provides much value over our existing functions to decompile (using either known address table lookups or an rpc). We can always add this later if we find we need to, it doesn't block anything.

Copy link

changeset-bot bot commented Apr 15, 2024

⚠️ No Changeset found

Latest commit: 3b2ee65

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@mcintyre94 mcintyre94 changed the title add lastValidBlockHeight to transaction blockhash lifetime Refactor transaction-confirmation to use new transaction lifetimes Apr 15, 2024
@mcintyre94 mcintyre94 marked this pull request as ready for review April 15, 2024 13:21
@mcintyre94 mcintyre94 force-pushed the keep-lifetime branch 2 times, most recently from 4c0aed8 to e24a32b Compare April 16, 2024 08:02
@mcintyre94 mcintyre94 force-pushed the tx-confirm-new branch 3 times, most recently from db247b0 to 3b6f6ee Compare April 16, 2024 08:18
@lorisleiva
Copy link
Collaborator

Could you remind me why we need the lifetimeConstraint to be on the NewTransaction type at all? Like where exactly is it used?

My other related question is: does this information already lives inside the compiled and encoded messageBytes property?

If so — and if the lifeConstraint is only used, say, when confirming a transaction — then, would it not make sense to decompile that information once there, instead of dragging these types everywhere with us?

@mcintyre94
Copy link
Collaborator Author

mcintyre94 commented Apr 16, 2024

I think it's only used for transaction confirmation, but I haven't exhausively worked through everything using transactions yet so I'm not 100% sure if there are any other places. I think any other use cases will be much smaller though.

It lives in messageBytes - sort of. It's a durable nonce transaction if the first instruction is a particular durable nonce instruction. Our check for that also includes a lookup for the accounts, so if you wanted to do it in full then you'd need to combine it with either known address lookup tables or an RPC to resolve them. The accounts in that instruction could be in address lookup tables.

So we could take a NewTransaction and add a lifetime to it when we need it. But I think probably one of the most common use cases in web3js is that you create a transaction (at some point adding a lifetime), send and confirm it. We'd be requiring you to add this decompile (or use a helper that does it for you) on that path, even though you had the transaction message with a known lifetime. It's better performance and better DX.

I think in practice most people would probably just cast to whatever lifetime they were using instead of using a helper that requires address lookup tables or an RPC and not care that much, so the DX is the bigger point I think.

I also think the downside here is limited because there's just not much you need to/can do with a Transaction.

@mcintyre94
Copy link
Collaborator Author

This PR has ended up pulling in most of #2487 because it broke send-transaction

@lorisleiva
Copy link
Collaborator

Gotcha, it sounds like — whilst technically the information is there — the process required to get 100% of the compiled information is not simple enough to justify decompiling on-demand when we need access to that information. I'm happy with that.

I just wanted to make sure we didn't end up with another version of our "we need to keep our data in sync with the compiled bytes" problem — which is the primary reason for this entire refactoring haha.

Base automatically changed from keep-lifetime to master April 16, 2024 12:17
@@ -23,7 +28,7 @@ interface SendAndConfirmDurableNonceTransactionConfig
'getNonceInvalidationPromise' | 'getRecentSignatureConfirmationPromise'
>,
) => Promise<void>;
transaction: IDurableNonceTransaction & SendableTransaction;
transaction: FullySignedTransaction & { lifetimeConstraint: TransactionDurableNonceLifetime };
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe Readonly<{...}> all of these?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea! I'll do this in an update to #2486 to avoid rebase conflicts there

Copy link
Collaborator

@steveluscher steveluscher left a comment

Choose a reason for hiding this comment

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

Added via Giphy

Copy link
Contributor

🎉 This PR is included in version 1.91.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link
Contributor

github-actions bot commented May 3, 2024

Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants