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

Add Message::is_maybe_writable #35340

Merged
merged 3 commits into from
Feb 29, 2024

Conversation

jstarry
Copy link
Member

@jstarry jstarry commented Feb 28, 2024

Problem

After adopting a dynamic set of reserved account keys which are not allowed to be writable by transactions, it will not longer be possible to statically determine if a legacy message's accounts are writable or not. This is similar to how the accounts in versioned txs (which make use of address lookup tables) also can't be statically determined to be writable or not until the addresses are loaded from lookup tables. Versioned transaction messages expose a is_maybe_writable method for this reason.

There are a few places where the dynamic set of reserved account keys will not be available:

  1. Determining if tx is a valid nonced tx or not in the RPC client
  2. Printing transactions in CLI
  3. Transaction parsing in the RPC server

Summary of Changes

Add an is_maybe_writable method to Message which current has the same signature as is_writable. After #34901, Message::is_writable will be changed to accept an additional parameter for the dynamic set of reserved account keys.

Change the implementation of uses_durable_nonce to no longer check whether the nonce account is writable. That method should never have added that validity check in the first place.

Fixes #

Copy link

codecov bot commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 94.59459% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 81.7%. Comparing base (6ee3bb9) to head (f0cf45e).
Report is 15 commits behind head on master.

❗ Current head f0cf45e differs from pull request most recent head 36f958c. Consider uploading reports for the commit 36f958c to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #35340   +/-   ##
=======================================
  Coverage    81.7%    81.7%           
=======================================
  Files         834      834           
  Lines      224299   224307    +8     
=======================================
+ Hits       183361   183376   +15     
+ Misses      40938    40931    -7     

Copy link
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

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

Had some thoughts about naming and comments

sdk/program/src/message/legacy.rs Show resolved Hide resolved
@@ -1074,7 +1074,7 @@ impl Transaction {
}
}

pub fn uses_durable_nonce(tx: &Transaction) -> Option<&CompiledInstruction> {
pub fn maybe_uses_durable_nonce(tx: &Transaction) -> Option<&CompiledInstruction> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about this one more, I wonder if we can come up with a more descriptive fn name; the returned ix definitely does use durable nonce but the nonce account may not be writable.
Also, I quibble with "uses" in the first place, since this is a method that returns the instruction, not a bool.
Super wordy, but what about try_get_durable_nonce_instruction? Sort of ignores the "maybe writable" part

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it definitely looks like it's using a durable nonce but in the context of the Solana runtime, a tx is only considered to be using a durable nonce if it's a "valid" durable nonce which requires the nonce account to be writable. Maybe a name with "valid" in it would be more clear?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, fair. I'm open to adding "valid" somehow

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually I think I was focusing too much on the validity... a nonce is also only valid if the transaction's recent blockhash is correct. This method should probably not be doing the writable check at all.

I'm inclined to go with your suggestion of try_get_durable_nonce_instruction but I will add it as an alias and deprecate the original function because I really shouldn't have introduced that breaking change in the first place.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok actually I think I'm going to just leave everything as is but take out the is-writable check from this function

@@ -189,7 +189,7 @@ impl VersionedTransaction {
/// instruction. Since dynamically loaded addresses can't have write locks
/// demoted without loading addresses, this shouldn't be used in the
/// runtime.
pub fn uses_durable_nonce(&self) -> bool {
pub fn maybe_uses_durable_nonce(&self) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here about the fact that it definitely uses durable nonce, just is maybe writable. I haven't thought of a better option for this one, though.

CriesofCarrots
CriesofCarrots previously approved these changes Feb 29, 2024
Copy link
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

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

Nice, this feels better.
(I still think transaction::uses_durable_nonce is misnamed, but that's a thing for a different day)

@jstarry jstarry added the automerge Merge this Pull Request automatically once CI passes label Feb 29, 2024
Copy link
Contributor

mergify bot commented Feb 29, 2024

automerge label removed due to a CI failure

@mergify mergify bot removed the automerge Merge this Pull Request automatically once CI passes label Feb 29, 2024
@jstarry jstarry added the automerge Merge this Pull Request automatically once CI passes label Feb 29, 2024
Copy link
Contributor

mergify bot commented Feb 29, 2024

automerge label removed due to a CI failure

@mergify mergify bot removed the automerge Merge this Pull Request automatically once CI passes label Feb 29, 2024
@jstarry
Copy link
Member Author

jstarry commented Feb 29, 2024

@CriesofCarrots I just removed some tests that were checking for writable condition in uses_durable_nonce. Can you give another 👍🏻 please?

@jstarry jstarry merged commit c9c2fbb into solana-labs:master Feb 29, 2024
43 of 45 checks passed
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.

2 participants