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

generic get nonce and ix signers #2826

Merged
merged 7 commits into from
Sep 25, 2024
Merged

Conversation

apfitzge
Copy link

@apfitzge apfitzge commented Sep 3, 2024

Problem

  • Need getting nonce to be generic over tx trait (or using RuntimeTransaction cached value in future?)

Summary of Changes

  • implement get_durable_nonce and get_ix_signers for checking transaction
  • add tests

Fixes #

@apfitzge apfitzge changed the title generic get nonce and ix signers + tests generic get nonce and ix signers Sep 3, 2024
@@ -62,6 +62,7 @@ solana-loader-v4-program = { workspace = true }
solana-measure = { workspace = true }
solana-metrics = { workspace = true }
solana-perf = { workspace = true }
solana-program = { workspace = true }
Copy link
Author

Choose a reason for hiding this comment

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

limited_deserialize from sdk is a trick, the one from here is what we need

@apfitzge apfitzge marked this pull request as ready for review September 4, 2024 12:44
@apfitzge apfitzge self-assigned this Sep 4, 2024
}

#[test]
fn test_get_ix_signers() {
Copy link
Author

Choose a reason for hiding this comment

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

this test was copied from sdk and just modified to test the new generic fn

@@ -345,4 +408,273 @@ mod tests {
.check_and_load_message_nonce_account(&message, &bank.next_durable_nonce())
.is_none());
}

#[test]
fn test_get_durable_nonce() {
Copy link
Author

@apfitzge apfitzge Sep 4, 2024

Choose a reason for hiding this comment

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

afaict, there are no tests for the equivalent function in sdk. I did my best to cover the branches in logic.

Copy link

@tao-stones tao-stones left a comment

Choose a reason for hiding this comment

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

looks good overall. Will look into tests if you decided to keep these functions in bank, or move them out.

sdk/program/src/program_utils.rs Show resolved Hide resolved
@@ -184,6 +188,54 @@ impl Bank {
}
}

/// If the message uses a durable nonce, return the pubkey of the nonce account
fn get_durable_nonce(message: &impl SVMMessage) -> Option<&Pubkey> {

Choose a reason for hiding this comment

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

Would it be possible to make this, and get_is_signer(), functions extension of SVMMessage, or at least make them live outside of Bank - they don't need `bank anyway?

Copy link
Author

Choose a reason for hiding this comment

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

Moved functions and tests to a new mod inside runtime: svm_message_ext.

runtime/src/bank/check_transactions.rs Outdated Show resolved Hide resolved
tao-stones
tao-stones previously approved these changes Sep 6, 2024
Copy link

@tao-stones tao-stones left a comment

Choose a reason for hiding this comment

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

lgtm - just a nit and CI

runtime/src/lib.rs Outdated Show resolved Hide resolved
@@ -34,6 +34,7 @@ pub mod stake_weighted_timestamp;
pub mod stakes;
pub mod static_ids;
pub mod status_cache;
pub mod svm_message_ext;
Copy link

Choose a reason for hiding this comment

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

Can we keep these extensions in the svm-transaction crate? Even though these methods are used by the runtime, they're still useful in other contexts. Off chain clients may want to check if a transaction uses a durable nonce for example.

Copy link
Author

@apfitzge apfitzge Sep 10, 2024

Choose a reason for hiding this comment

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

It'd add a dependency on bincode in svm-transaction trait, which is undesirable.

When I talked with @buffalojoec about this we discussed creating a separate crate for derived behavior.
Not sure if we'd like to do that now, or wait until there's a larger set of derived behaviors.
Didn't feel right to create a new crate for 2 functions, but lmk if you feel that'd be more appropriate.

Choose a reason for hiding this comment

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

I'm definitely in favor of leaving it in runtime until it's needed off-chain, or creating a new crate. I also agree svm-transaction should be lightweight and basically only used to roll a custom transaction type beyond the ones provided by SDK, for interacting with the SVM API.

Copy link
Author

Choose a reason for hiding this comment

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

another option is to rework the implementation to avoid bincode - would be relatively straight-forward since all we use it for is to read a 4-byte discriminant.

Copy link
Author

Choose a reason for hiding this comment

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

@jstarry thoughts on which approach you think is best here?

Choose a reason for hiding this comment

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

Just adding one more point to supplement my argument for the runtime/new crate. Lmk if it's off-base.

Even though nonce management is split between runtime and SVM right now, the concept of a durable nonce is actually more pertinent to the runtime, when checking transaction age. There's an argument to be made for actually making the act of advancing the nonce during transaction execution a plugin that extends SVM, since not everyone will use nonces in other execution environments.

Anyway that's my perspective on it. I think we should keep the SVM crate composable and as light as possible, opening up custom behavior through plugins implemented elsewhere rather than bloat.

Copy link

Choose a reason for hiding this comment

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

I agree with @buffalojoec that this is a runtime concept and doesn't make sense for it to live in the svm transaction crate. I think it's going to all make much more sense when we have a "runtime transaction" abstraction

@@ -193,7 +193,7 @@ mod tests {
setup_nonce_with_bank,
},
solana_sdk::{
feature_set::FeatureSet, hash::Hash, message::Message, signature::Keypair,
self, feature_set::FeatureSet, hash::Hash, message::Message, signature::Keypair,

Choose a reason for hiding this comment

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

Do you want this self in here?

@@ -34,6 +34,7 @@ pub mod stake_weighted_timestamp;
pub mod stakes;
pub mod static_ids;
pub mod status_cache;
pub mod svm_message_ext;

Choose a reason for hiding this comment

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

nit: I don't feel strongly about this, but I suggest a different module name like nonce_extraction_utils (or better), to avoid this one day becoming a catch-all for SVM message extensions. Or maybe that's your intention..? 😅

@@ -34,6 +34,7 @@ pub mod stake_weighted_timestamp;
pub mod stakes;
pub mod static_ids;
pub mod status_cache;
pub mod svm_message_ext;

Choose a reason for hiding this comment

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

Just adding one more point to supplement my argument for the runtime/new crate. Lmk if it's off-base.

Even though nonce management is split between runtime and SVM right now, the concept of a durable nonce is actually more pertinent to the runtime, when checking transaction age. There's an argument to be made for actually making the act of advancing the nonce during transaction execution a plugin that extends SVM, since not everyone will use nonces in other execution environments.

Anyway that's my perspective on it. I think we should keep the SVM crate composable and as light as possible, opening up custom behavior through plugins implemented elsewhere rather than bloat.

@apfitzge
Copy link
Author

@buffalojoec think i hit all your comments now, forgot to ping friday!

@apfitzge apfitzge merged commit 56672cd into anza-xyz:master Sep 25, 2024
52 checks passed
@apfitzge apfitzge deleted the nonce_generic branch September 25, 2024 11:30
ray-kast pushed a commit to abklabs/agave that referenced this pull request Nov 27, 2024
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