From 2f8594032695b207ae3d654d38c1fc5c1da87f11 Mon Sep 17 00:00:00 2001 From: Tyera Date: Tue, 2 Jul 2024 16:19:53 -0600 Subject: [PATCH] Remove deprecated symbols from solana-program (#1958) * Remove SLOT_MS * Remove deprecated Pubkey methods * Remove deprecated info! macro * Delete deprecated and dangling borsh 0.9 module * Remove deprecated UpgradeableLoaderState methods * Remove FeeCalculator deprecated method * Remove deprecated Instruction ctor * Remove deprecated legacy-message methods (deprecated in v1.9) --- sdk/program/src/borsh0_9.rs | 44 ----------- sdk/program/src/bpf_loader_upgradeable.rs | 54 -------------- sdk/program/src/clock.rs | 4 - sdk/program/src/fee_calculator.rs | 91 +---------------------- sdk/program/src/instruction.rs | 8 -- sdk/program/src/log.rs | 18 ----- sdk/program/src/message/legacy.rs | 53 ------------- sdk/program/src/pubkey.rs | 15 ---- 8 files changed, 2 insertions(+), 285 deletions(-) delete mode 100644 sdk/program/src/borsh0_9.rs diff --git a/sdk/program/src/borsh0_9.rs b/sdk/program/src/borsh0_9.rs deleted file mode 100644 index d7d1e97013f898..00000000000000 --- a/sdk/program/src/borsh0_9.rs +++ /dev/null @@ -1,44 +0,0 @@ -#![allow(clippy::arithmetic_side_effects)] -//! Utilities for the [borsh] serialization format, version 0.9. -//! -//! This file is provided for backwards compatibility with types that still use -//! borsh 0.9, even though this crate canonically uses borsh 0.10. -//! -//! [borsh]: https://borsh.io/ -use { - crate::borsh::{ - impl_get_instance_packed_len, impl_get_packed_len_v0, impl_try_from_slice_unchecked, - }, - borsh0_9::maybestd::io, -}; - -impl_get_packed_len_v0!( - borsh0_9, - #[deprecated( - since = "1.17.0", - note = "Please upgrade to Borsh 1.X and use `borsh1::get_packed_len` instead" - )] -); -impl_try_from_slice_unchecked!( - borsh0_9, - io, - #[deprecated( - since = "1.17.0", - note = "Please upgrade to Borsh 1.X and use `borsh1::try_from_slice_unchecked` instead" - )] -); -impl_get_instance_packed_len!( - borsh0_9, - io, - #[deprecated( - since = "1.17.0", - note = "Please upgrade to Borsh 1.X and use `borsh1::get_instance_packed_len` instead" - )] -); - -#[cfg(test)] -#[allow(deprecated)] -mod tests { - use {crate::borsh::impl_tests, borsh0_9::maybestd::io}; - impl_tests!(borsh0_9, io); -} diff --git a/sdk/program/src/bpf_loader_upgradeable.rs b/sdk/program/src/bpf_loader_upgradeable.rs index d0f95ffe166db5..82e9292fde2429 100644 --- a/sdk/program/src/bpf_loader_upgradeable.rs +++ b/sdk/program/src/bpf_loader_upgradeable.rs @@ -82,42 +82,6 @@ impl UpgradeableLoaderState { pub const fn size_of_programdata(program_len: usize) -> usize { Self::size_of_programdata_metadata().saturating_add(program_len) } - - /// Length of a Buffer account's data. - #[deprecated(since = "1.11.0", note = "Please use `size_of_buffer` instead")] - pub fn buffer_len(program_len: usize) -> Result { - Ok(Self::size_of_buffer(program_len)) - } - - /// Offset into the Buffer account's data of the program bits. - #[deprecated( - since = "1.11.0", - note = "Please use `size_of_buffer_metadata` instead" - )] - pub fn buffer_data_offset() -> Result { - Ok(Self::size_of_buffer_metadata()) - } - - /// Length of a Program account's data. - #[deprecated(since = "1.11.0", note = "Please use `size_of_program` instead")] - pub fn program_len() -> Result { - Ok(Self::size_of_program()) - } - - /// Length of a ProgramData account's data. - #[deprecated(since = "1.11.0", note = "Please use `size_of_programdata` instead")] - pub fn programdata_len(program_len: usize) -> Result { - Ok(Self::size_of_programdata(program_len)) - } - - /// Offset into the ProgramData account's data of the program bits. - #[deprecated( - since = "1.11.0", - note = "Please use `size_of_programdata_metadata` instead" - )] - pub fn programdata_data_offset() -> Result { - Ok(Self::size_of_programdata_metadata()) - } } /// Returns the program data address for a program ID @@ -425,24 +389,6 @@ mod tests { assert_eq!(UpgradeableLoaderState::size_of_program() as u64, size); } - #[test] - #[allow(deprecated)] - fn test_account_lengths() { - assert_eq!( - 4, - serialized_size(&UpgradeableLoaderState::Uninitialized).unwrap() - ); - assert_eq!(36, UpgradeableLoaderState::program_len().unwrap()); - assert_eq!( - 45, - UpgradeableLoaderState::programdata_data_offset().unwrap() - ); - assert_eq!( - 45 + 42, - UpgradeableLoaderState::programdata_len(42).unwrap() - ); - } - fn assert_is_instruction( is_instruction_fn: F, expected_instruction: UpgradeableLoaderInstruction, diff --git a/sdk/program/src/clock.rs b/sdk/program/src/clock.rs index e19c4c84486ced..5cf609d3000c26 100644 --- a/sdk/program/src/clock.rs +++ b/sdk/program/src/clock.rs @@ -33,10 +33,6 @@ static_assertions::const_assert_eq!(MS_PER_TICK, 6); /// The number of milliseconds per tick (6). pub const MS_PER_TICK: u64 = 1000 / DEFAULT_TICKS_PER_SECOND; -#[deprecated(since = "1.15.0", note = "Please use DEFAULT_MS_PER_SLOT instead")] -/// The expected duration of a slot (400 milliseconds). -pub const SLOT_MS: u64 = DEFAULT_MS_PER_SLOT; - // At 160 ticks/s, 64 ticks per slot implies that leader rotation and voting will happen // every 400 ms. A fast voting cadence ensures faster finality and convergence pub const DEFAULT_TICKS_PER_SLOT: u64 = 64; diff --git a/sdk/program/src/fee_calculator.rs b/sdk/program/src/fee_calculator.rs index 361e00c98b6b47..5d753e4acaed3a 100644 --- a/sdk/program/src/fee_calculator.rs +++ b/sdk/program/src/fee_calculator.rs @@ -1,10 +1,7 @@ //! Calculation of transaction fees. #![allow(clippy::arithmetic_side_effects)] -use { - crate::{clock::DEFAULT_MS_PER_SLOT, ed25519_program, message::Message, secp256k1_program}, - log::*, -}; +use {crate::clock::DEFAULT_MS_PER_SLOT, log::*}; #[repr(C)] #[cfg_attr(feature = "frozen-abi", derive(AbiExample))] @@ -24,29 +21,6 @@ impl FeeCalculator { lamports_per_signature, } } - - #[deprecated( - since = "1.9.0", - note = "Please do not use, will no longer be available in the future" - )] - pub fn calculate_fee(&self, message: &Message) -> u64 { - let mut num_signatures: u64 = 0; - for instruction in &message.instructions { - let program_index = instruction.program_id_index as usize; - // Message may not be sanitized here - if program_index < message.account_keys.len() { - let id = message.account_keys[program_index]; - if (secp256k1_program::check_id(&id) || ed25519_program::check_id(&id)) - && !instruction.data.is_empty() - { - num_signatures += instruction.data[0] as u64; - } - } - } - - self.lamports_per_signature - * (u64::from(message.header.num_required_signatures) + num_signatures) - } } #[cfg_attr(feature = "frozen-abi", derive(AbiExample))] @@ -188,10 +162,7 @@ impl FeeRateGovernor { #[cfg(test)] mod tests { - use { - super::*, - crate::{pubkey::Pubkey, system_instruction}, - }; + use super::*; #[test] fn test_fee_rate_governor_burn() { @@ -205,64 +176,6 @@ mod tests { assert_eq!(fee_rate_governor.burn(2), (0, 2)); } - #[test] - #[allow(deprecated)] - fn test_fee_calculator_calculate_fee() { - // Default: no fee. - let message = Message::default(); - assert_eq!(FeeCalculator::default().calculate_fee(&message), 0); - - // No signature, no fee. - assert_eq!(FeeCalculator::new(1).calculate_fee(&message), 0); - - // One signature, a fee. - let pubkey0 = Pubkey::from([0; 32]); - let pubkey1 = Pubkey::from([1; 32]); - let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1); - let message = Message::new(&[ix0], Some(&pubkey0)); - assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 2); - - // Two signatures, double the fee. - let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1); - let ix1 = system_instruction::transfer(&pubkey1, &pubkey0, 1); - let message = Message::new(&[ix0, ix1], Some(&pubkey0)); - assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 4); - } - - #[test] - #[allow(deprecated)] - fn test_fee_calculator_calculate_fee_secp256k1() { - use crate::instruction::Instruction; - let pubkey0 = Pubkey::from([0; 32]); - let pubkey1 = Pubkey::from([1; 32]); - let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1); - let mut secp_instruction = Instruction { - program_id: crate::secp256k1_program::id(), - accounts: vec![], - data: vec![], - }; - let mut secp_instruction2 = Instruction { - program_id: crate::secp256k1_program::id(), - accounts: vec![], - data: vec![1], - }; - - let message = Message::new( - &[ - ix0.clone(), - secp_instruction.clone(), - secp_instruction2.clone(), - ], - Some(&pubkey0), - ); - assert_eq!(FeeCalculator::new(1).calculate_fee(&message), 2); - - secp_instruction.data = vec![0]; - secp_instruction2.data = vec![10]; - let message = Message::new(&[ix0, secp_instruction, secp_instruction2], Some(&pubkey0)); - assert_eq!(FeeCalculator::new(1).calculate_fee(&message), 11); - } - #[test] fn test_fee_rate_governor_derived_default() { solana_logger::setup(); diff --git a/sdk/program/src/instruction.rs b/sdk/program/src/instruction.rs index 2e63a29ad56c2e..56d34d7beb410e 100644 --- a/sdk/program/src/instruction.rs +++ b/sdk/program/src/instruction.rs @@ -518,14 +518,6 @@ impl Instruction { data: data.to_vec(), } } - - #[deprecated( - since = "1.6.0", - note = "Please use another Instruction constructor instead, such as `Instruction::new_with_borsh`" - )] - pub fn new(program_id: Pubkey, data: &T, accounts: Vec) -> Self { - Self::new_with_bincode(program_id, data, accounts) - } } /// Addition that returns [`InstructionError::InsufficientFunds`] on overflow. diff --git a/sdk/program/src/log.rs b/sdk/program/src/log.rs index 4f3463f8dc1201..5febb4dbc5ad64 100644 --- a/sdk/program/src/log.rs +++ b/sdk/program/src/log.rs @@ -35,24 +35,6 @@ use crate::account_info::AccountInfo; -/// Print a message to the log. -#[macro_export] -#[deprecated(since = "1.4.14", note = "Please use `msg` macro instead")] -macro_rules! info { - ($msg:expr) => { - $crate::log::sol_log($msg) - }; - ($arg1:expr, $arg2:expr, $arg3:expr, $arg4:expr, $arg5:expr) => { - $crate::log::sol_log_64( - $arg1 as u64, - $arg2 as u64, - $arg3 as u64, - $arg4 as u64, - $arg5 as u64, - ) - }; -} - /// Print a message to the log. /// /// Supports simple strings as well as Rust [format strings][fs]. When passed a diff --git a/sdk/program/src/message/legacy.rs b/sdk/program/src/message/legacy.rs index 5f5e808f90cfea..502a9ccd351ba4 100644 --- a/sdk/program/src/message/legacy.rs +++ b/sdk/program/src/message/legacy.rs @@ -662,29 +662,6 @@ impl Message { i < self.header.num_required_signatures as usize } - #[deprecated] - pub fn get_account_keys_by_lock_type(&self) -> (Vec<&Pubkey>, Vec<&Pubkey>) { - let mut writable_keys = vec![]; - let mut readonly_keys = vec![]; - for (i, key) in self.account_keys.iter().enumerate() { - if self.is_maybe_writable(i, None) { - writable_keys.push(key); - } else { - readonly_keys.push(key); - } - } - (writable_keys, readonly_keys) - } - - #[deprecated] - pub fn deserialize_instruction( - index: usize, - data: &[u8], - ) -> Result { - #[allow(deprecated)] - sysvar::instructions::load_instruction_at(index, data) - } - pub fn signer_keys(&self) -> Vec<&Pubkey> { // Clamp in case we're working on un-`sanitize()`ed input let last_key = self @@ -907,36 +884,6 @@ mod tests { assert!(!message.is_account_maybe_reserved(2, None)); } - #[test] - fn test_get_account_keys_by_lock_type() { - let program_id = Pubkey::default(); - let id0 = Pubkey::new_unique(); - let id1 = Pubkey::new_unique(); - let id2 = Pubkey::new_unique(); - let id3 = Pubkey::new_unique(); - let message = Message::new( - &[ - Instruction::new_with_bincode(program_id, &0, vec![AccountMeta::new(id0, false)]), - Instruction::new_with_bincode(program_id, &0, vec![AccountMeta::new(id1, true)]), - Instruction::new_with_bincode( - program_id, - &0, - vec![AccountMeta::new_readonly(id2, false)], - ), - Instruction::new_with_bincode( - program_id, - &0, - vec![AccountMeta::new_readonly(id3, true)], - ), - ], - Some(&id1), - ); - assert_eq!( - message.get_account_keys_by_lock_type(), - (vec![&id1, &id0], vec![&id3, &program_id, &id2]) - ); - } - #[test] fn test_program_ids() { let key0 = Pubkey::new_unique(); diff --git a/sdk/program/src/pubkey.rs b/sdk/program/src/pubkey.rs index 206efd18f41e8e..bbf987341fbd8a 100644 --- a/sdk/program/src/pubkey.rs +++ b/sdk/program/src/pubkey.rs @@ -180,25 +180,10 @@ pub fn bytes_are_curve_point>(_bytes: T) -> bool { } impl Pubkey { - #[deprecated( - since = "1.14.14", - note = "Please use 'Pubkey::from' or 'Pubkey::try_from' instead" - )] - pub fn new(pubkey_vec: &[u8]) -> Self { - Self::try_from(pubkey_vec).expect("Slice must be the same length as a Pubkey") - } - pub const fn new_from_array(pubkey_array: [u8; 32]) -> Self { Self(pubkey_array) } - #[deprecated(since = "1.3.9", note = "Please use 'Pubkey::new_unique' instead")] - #[cfg(not(target_os = "solana"))] - pub fn new_rand() -> Self { - // Consider removing Pubkey::new_rand() entirely in the v1.5 or v1.6 timeframe - Pubkey::from(rand::random::<[u8; 32]>()) - } - /// unique Pubkey for tests and benchmarks. pub fn new_unique() -> Self { use crate::atomic_u64::AtomicU64;