From 860ecd6572bdbad01cf88fcaf4a387fc4d019a93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Tue, 19 Apr 2022 17:11:04 +0200 Subject: [PATCH] Deprecate `KeyedAccount` and `StackFrame` (#24480) * Marks KeyedAccount as deprecated. * Marks StackFrame as deprecated. --- program-runtime/src/invoke_context.rs | 17 +++++++++- sdk/src/keyed_account.rs | 48 +++------------------------ 2 files changed, 21 insertions(+), 44 deletions(-) diff --git a/program-runtime/src/invoke_context.rs b/program-runtime/src/invoke_context.rs index a416f7454..9cfb3605b 100644 --- a/program-runtime/src/invoke_context.rs +++ b/program-runtime/src/invoke_context.rs @@ -1,3 +1,5 @@ +#[allow(deprecated)] +use solana_sdk::keyed_account::{create_keyed_accounts_unified, KeyedAccount}; use { crate::{ accounts_data_meter::AccountsDataMeter, @@ -20,7 +22,6 @@ use { }, hash::Hash, instruction::{AccountMeta, Instruction, InstructionError}, - keyed_account::{create_keyed_accounts_unified, KeyedAccount}, native_loader, pubkey::Pubkey, rent::Rent, @@ -172,12 +173,18 @@ impl fmt::Display for AllocErr { } } +#[deprecated( + since = "1.11.0", + note = "Please use InstructionContext instead of StackFrame" +)] +#[allow(deprecated)] pub struct StackFrame<'a> { pub number_of_program_accounts: usize, pub keyed_accounts: Vec>, pub keyed_accounts_range: std::ops::Range, } +#[allow(deprecated)] impl<'a> StackFrame<'a> { pub fn new(number_of_program_accounts: usize, keyed_accounts: Vec>) -> Self { let keyed_accounts_range = std::ops::Range { @@ -200,6 +207,7 @@ impl<'a> StackFrame<'a> { pub struct InvokeContext<'a> { pub transaction_context: &'a mut TransactionContext, + #[allow(deprecated)] invoke_stack: Vec>, rent: Rent, pre_accounts: Vec, @@ -411,6 +419,7 @@ impl<'a> InvokeContext<'a> { } // Create the KeyedAccounts that will be passed to the program + #[allow(deprecated)] let keyed_accounts = program_indices .iter() .map(|account_index| { @@ -436,6 +445,7 @@ impl<'a> InvokeContext<'a> { .collect::, InstructionError>>()?; // Unsafe will be removed together with the keyed_accounts + #[allow(deprecated)] self.invoke_stack.push(StackFrame::new( program_indices.len(), create_keyed_accounts_unified(unsafe { @@ -996,6 +1006,11 @@ impl<'a> InvokeContext<'a> { Err(InstructionError::UnsupportedProgramId) } + #[deprecated( + since = "1.11.0", + note = "Please use BorrowedAccount instead of KeyedAccount" + )] + #[allow(deprecated)] /// Get the list of keyed accounts including the chain of program accounts pub fn get_keyed_accounts(&self) -> Result<&[KeyedAccount], InstructionError> { self.invoke_stack diff --git a/sdk/src/keyed_account.rs b/sdk/src/keyed_account.rs index 20d555430..f21876dda 100644 --- a/sdk/src/keyed_account.rs +++ b/sdk/src/keyed_account.rs @@ -1,3 +1,8 @@ +#![deprecated( + since = "1.11.0", + note = "Please use BorrowedAccount instead of KeyedAccount" +)] +#![allow(deprecated)] use { crate::{ account::{AccountSharedData, ReadableAccount}, @@ -251,46 +256,3 @@ where self.try_account_ref_mut()?.set_state(state) } } - -#[cfg(test)] -mod tests { - use { - super::*, - crate::{ - account::{create_account_for_test, from_account, to_account}, - pubkey::Pubkey, - sysvar::Sysvar, - }, - }; - - #[repr(C)] - #[derive(Serialize, Deserialize, Debug, Default, PartialEq)] - struct TestSysvar { - something: Pubkey, - } - crate::declare_id!("TestSysvar111111111111111111111111111111111"); - impl solana_program::sysvar::SysvarId for TestSysvar { - fn id() -> crate::pubkey::Pubkey { - id() - } - fn check_id(pubkey: &crate::pubkey::Pubkey) -> bool { - check_id(pubkey) - } - } - impl Sysvar for TestSysvar {} - - #[test] - fn test_sysvar_keyed_account_to_from() { - let test_sysvar = TestSysvar::default(); - let key = crate::keyed_account::tests::id(); - - let account = create_account_for_test(&test_sysvar); - let test_sysvar = from_account::(&account).unwrap(); - assert_eq!(test_sysvar, TestSysvar::default()); - - let mut account = AccountSharedData::new(42, TestSysvar::size_of(), &key); - to_account(&test_sysvar, &mut account).unwrap(); - let test_sysvar = from_account::(&account).unwrap(); - assert_eq!(test_sysvar, TestSysvar::default()); - } -}