Skip to content

Commit

Permalink
v2.0: Remove deprecated symbols from solana-program (backport of #1958)…
Browse files Browse the repository at this point in the history
… (#1977)

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)

(cherry picked from commit 2f85940)

Co-authored-by: Tyera <tyera@anza.xyz>
  • Loading branch information
mergify[bot] and CriesofCarrots authored Jul 3, 2024
1 parent b939e17 commit 262706a
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 285 deletions.
44 changes: 0 additions & 44 deletions sdk/program/src/borsh0_9.rs

This file was deleted.

54 changes: 0 additions & 54 deletions sdk/program/src/bpf_loader_upgradeable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize, InstructionError> {
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<usize, InstructionError> {
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<usize, InstructionError> {
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<usize, InstructionError> {
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<usize, InstructionError> {
Ok(Self::size_of_programdata_metadata())
}
}

/// Returns the program data address for a program ID
Expand Down Expand Up @@ -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<F>(
is_instruction_fn: F,
expected_instruction: UpgradeableLoaderInstruction,
Expand Down
4 changes: 0 additions & 4 deletions sdk/program/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
91 changes: 2 additions & 89 deletions sdk/program/src/fee_calculator.rs
Original file line number Diff line number Diff line change
@@ -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))]
Expand All @@ -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))]
Expand Down Expand Up @@ -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() {
Expand All @@ -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();
Expand Down
8 changes: 0 additions & 8 deletions sdk/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,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<T: Serialize>(program_id: Pubkey, data: &T, accounts: Vec<AccountMeta>) -> Self {
Self::new_with_bincode(program_id, data, accounts)
}
}

/// Addition that returns [`InstructionError::InsufficientFunds`] on overflow.
Expand Down
18 changes: 0 additions & 18 deletions sdk/program/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 0 additions & 53 deletions sdk/program/src/message/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Instruction, SanitizeError> {
#[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
Expand Down Expand Up @@ -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();
Expand Down
15 changes: 0 additions & 15 deletions sdk/program/src/pubkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,25 +180,10 @@ pub fn bytes_are_curve_point<T: AsRef<[u8]>>(_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;
Expand Down

0 comments on commit 262706a

Please sign in to comment.