solana-labs / solana-web3.js

Solana JavaScript SDK
https://solana-labs.github.io/solana-web3.js
MIT License
1.97k stars 792 forks source link

lastValidBlockHeight property for VersionedTransaction #2825

Closed AlexRubik closed 2 weeks ago

AlexRubik commented 2 weeks ago

Motivation

I want to prevent a versioned transaction from landing too late.

If I understand the docs correctly, this feature already exists on legacy transactions. It's the lastValidBlockHeight property.

Could we look into adding this to versioned transactions also? Thanks! https://solana-labs.github.io/solana-web3.js/classes/VersionedTransaction.html

steveluscher commented 2 weeks ago

You are correct that lastValidBlockHeight exists on Transaction, but that's actually an anti-pattern.

The thing is, the last block height for which a blockhash is valid is neither encoded in a transaction (it's nowhere in the bytes) nor is it even resolvable from a transaction (there's no call you can make to ask ‘until which blockheight is this blockhash valid?’). In short, it doesn't belong on transactions.

The lastValidBlockHeight is a property of you-having-fetched-the-blockhash. You should save it for use in transaction confirmation. If you obtained the blockhash from somewhere else, that somewhere else should also vend the lastValidBlockHeight. If neither of those is the case, and you're really desperate to know when the blockhash expires, you can fetch the SysvarRecentB1ockHashes11111111111111111111 account, figure out the position at which your blockhash sits, and infer how many blocks it has to go before it falls off the end.

github-actions[bot] commented 1 week ago

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