Skip to content

Commit

Permalink
Deprecate is_key_passed_to_program in favor of `is_instruction_acco…
Browse files Browse the repository at this point in the history
…unt` (#1374)

Deprecate is_key_passed_to_program in favor of is_instruction_account
  • Loading branch information
jstarry authored May 16, 2024
1 parent 228b2e5 commit 7474e47
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
10 changes: 5 additions & 5 deletions accounts-db/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,10 +729,10 @@ impl Accounts {
}
};

// Accounts that are invoked and also not passed to a program don't
// need to be stored because it's assumed to be impossible for a
// committable transaction to modify an invoked account if said
// account isn't passed to some program.
// Accounts that are invoked and also not passed as an instruction
// account to a program don't need to be stored because it's assumed
// to be impossible for a committable transaction to modify an
// invoked account if said account isn't passed to some program.
//
// Note that this assumption might not hold in the future after
// SIMD-0082 is implemented because we may decide to commit
Expand All @@ -742,7 +742,7 @@ impl Accounts {
// if they aren't passed to any programs (because they are mutated
// outside of the VM).
let is_storable_account = |message: &SanitizedMessage, key_index: usize| -> bool {
!message.is_invoked(key_index) || message.is_key_passed_to_program(key_index)
!message.is_invoked(key_index) || message.is_instruction_account(key_index)
};

let message = tx.message();
Expand Down
19 changes: 13 additions & 6 deletions sdk/program/src/message/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,14 @@ impl Message {
.collect()
}

#[deprecated(since = "2.0.0", note = "Please use `is_instruction_account` instead")]
pub fn is_key_passed_to_program(&self, key_index: usize) -> bool {
self.is_instruction_account(key_index)
}

/// Returns true if the account at the specified index is an account input
/// to some program instruction in this message.
pub fn is_instruction_account(&self, key_index: usize) -> bool {
if let Ok(key_index) = u8::try_from(key_index) {
self.instructions
.iter()
Expand All @@ -549,10 +556,10 @@ impl Message {

#[deprecated(
since = "2.0.0",
note = "Please use `is_key_called_as_program` and `is_key_passed_to_program` directly"
note = "Please use `is_key_called_as_program` and `is_instruction_account` directly"
)]
pub fn is_non_loader_key(&self, key_index: usize) -> bool {
!self.is_key_called_as_program(key_index) || self.is_key_passed_to_program(key_index)
!self.is_key_called_as_program(key_index) || self.is_instruction_account(key_index)
}

pub fn program_position(&self, index: usize) -> Option<usize> {
Expand Down Expand Up @@ -921,7 +928,7 @@ mod tests {
}

#[test]
fn test_is_key_passed_to_program() {
fn test_is_instruction_account() {
let key0 = Pubkey::new_unique();
let key1 = Pubkey::new_unique();
let loader2 = Pubkey::new_unique();
Expand All @@ -935,9 +942,9 @@ mod tests {
instructions,
);

assert!(message.is_key_passed_to_program(0));
assert!(message.is_key_passed_to_program(1));
assert!(!message.is_key_passed_to_program(2));
assert!(message.is_instruction_account(0));
assert!(message.is_instruction_account(1));
assert!(!message.is_instruction_account(2));
}

#[test]
Expand Down
11 changes: 9 additions & 2 deletions sdk/program/src/message/sanitized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,14 @@ impl SanitizedMessage {

/// Returns true if the account at the specified index is an input to some
/// program instruction in this message.
#[deprecated(since = "2.0.0", note = "Please use `is_instruction_account` instead")]
pub fn is_key_passed_to_program(&self, key_index: usize) -> bool {
self.is_instruction_account(key_index)
}

/// Returns true if the account at the specified index is an input to some
/// program instruction in this message.
pub fn is_instruction_account(&self, key_index: usize) -> bool {
if let Ok(key_index) = u8::try_from(key_index) {
self.instructions()
.iter()
Expand All @@ -245,10 +252,10 @@ impl SanitizedMessage {
/// program or, if invoked, is passed to a program.
#[deprecated(
since = "2.0.0",
note = "Please use `is_invoked` and `is_key_passed_to_program` instead"
note = "Please use `is_invoked` and `is_instruction_account` instead"
)]
pub fn is_non_loader_key(&self, key_index: usize) -> bool {
!self.is_invoked(key_index) || self.is_key_passed_to_program(key_index)
!self.is_invoked(key_index) || self.is_instruction_account(key_index)
}

/// Returns true if the account at the specified index is writable by the
Expand Down
9 changes: 7 additions & 2 deletions sdk/program/src/message/versions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,14 @@ impl VersionedMessage {
}
}

#[deprecated(since = "2.0.0", note = "Please use `is_instruction_account` instead")]
pub fn is_key_passed_to_program(&self, key_index: usize) -> bool {
self.is_instruction_account(key_index)
}

/// Returns true if the account at the specified index is an input to some
/// program instruction in this message.
fn is_key_passed_to_program(&self, key_index: usize) -> bool {
fn is_instruction_account(&self, key_index: usize) -> bool {
if let Ok(key_index) = u8::try_from(key_index) {
self.instructions()
.iter()
Expand All @@ -114,7 +119,7 @@ impl VersionedMessage {
/// Returns true if the account at the specified index is not invoked as a
/// program or, if invoked, is passed to a program.
pub fn is_non_loader_key(&self, key_index: usize) -> bool {
!self.is_invoked(key_index) || self.is_key_passed_to_program(key_index)
!self.is_invoked(key_index) || self.is_instruction_account(key_index)
}

pub fn recent_blockhash(&self) -> &Hash {
Expand Down

0 comments on commit 7474e47

Please sign in to comment.