Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 33 additions & 28 deletions account-decoder/src/parse_sysvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
use bincode::deserialize;
use bv::BitVec;
#[allow(deprecated)]
use solana_sdk::sysvar::recent_blockhashes::RecentBlockhashes;
use solana_sdk::sysvar::{fees::Fees, recent_blockhashes::RecentBlockhashes};
use solana_sdk::{
clock::{Clock, Epoch, Slot, UnixTimestamp},
epoch_schedule::EpochSchedule,
Expand All @@ -14,7 +14,7 @@ use solana_sdk::{
slot_hashes::SlotHashes,
slot_history::{self, SlotHistory},
stake_history::{StakeHistory, StakeHistoryEntry},
sysvar::{self, fees::Fees, rewards::Rewards},
sysvar::{self, rewards::Rewards},
};

pub fn parse_sysvar(data: &[u8], pubkey: &Pubkey) -> Result<SysvarAccountType, ParseAccountError> {
Expand Down Expand Up @@ -94,7 +94,9 @@ pub fn parse_sysvar(data: &[u8], pubkey: &Pubkey) -> Result<SysvarAccountType, P
pub enum SysvarAccountType {
Clock(UiClock),
EpochSchedule(EpochSchedule),
#[allow(deprecated)]
Fees(UiFees),
#[allow(deprecated)]
RecentBlockhashes(Vec<UiRecentBlockhashesEntry>),
Rent(UiRent),
Rewards(UiRewards),
Expand Down Expand Up @@ -130,6 +132,7 @@ impl From<Clock> for UiClock {
pub struct UiFees {
pub fee_calculator: UiFeeCalculator,
}
#[allow(deprecated)]
impl From<Fees> for UiFees {
fn from(fees: Fees) -> Self {
Self {
Expand Down Expand Up @@ -222,6 +225,8 @@ mod test {

#[test]
fn test_parse_sysvars() {
let hash = Hash::new(&[1; 32]);

let clock_sysvar = create_account_for_test(&Clock::default());
assert_eq!(
parse_sysvar(&clock_sysvar.data, &sysvar::clock::id()).unwrap(),
Expand All @@ -241,33 +246,33 @@ mod test {
SysvarAccountType::EpochSchedule(epoch_schedule),
);

let fees_sysvar = create_account_for_test(&Fees::default());
assert_eq!(
parse_sysvar(&fees_sysvar.data, &sysvar::fees::id()).unwrap(),
SysvarAccountType::Fees(UiFees::default()),
);

let hash = Hash::new(&[1; 32]);
let fee_calculator = FeeCalculator {
lamports_per_signature: 10,
};
#[allow(deprecated)]
let recent_blockhashes: RecentBlockhashes = vec![IterItem(0, &hash, &fee_calculator)]
.into_iter()
.collect();
let recent_blockhashes_sysvar = create_account_for_test(&recent_blockhashes);
assert_eq!(
parse_sysvar(
&recent_blockhashes_sysvar.data,
#[allow(deprecated)]
&sysvar::recent_blockhashes::id()
)
.unwrap(),
SysvarAccountType::RecentBlockhashes(vec![UiRecentBlockhashesEntry {
blockhash: hash.to_string(),
fee_calculator: fee_calculator.into(),
}]),
);
{
let fees_sysvar = create_account_for_test(&Fees::default());
assert_eq!(
parse_sysvar(&fees_sysvar.data, &sysvar::fees::id()).unwrap(),
SysvarAccountType::Fees(UiFees::default()),
);

let fee_calculator = FeeCalculator {
lamports_per_signature: 10,
};
let recent_blockhashes: RecentBlockhashes = vec![IterItem(0, &hash, &fee_calculator)]
.into_iter()
.collect();
let recent_blockhashes_sysvar = create_account_for_test(&recent_blockhashes);
assert_eq!(
parse_sysvar(
&recent_blockhashes_sysvar.data,
&sysvar::recent_blockhashes::id()
)
.unwrap(),
SysvarAccountType::RecentBlockhashes(vec![UiRecentBlockhashesEntry {
blockhash: hash.to_string(),
fee_calculator: fee_calculator.into(),
}]),
);
}

let rent = Rent {
lamports_per_byte_year: 10,
Expand Down
5 changes: 4 additions & 1 deletion program-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! The solana-program-test provides a BanksClient-based test framework BPF programs
#![allow(clippy::integer_arithmetic)]

#[allow(deprecated)]
use solana_sdk::sysvar::fees::Fees;
use {
async_trait::async_trait,
chrono_humanize::{Accuracy, HumanTime, Tense},
Expand Down Expand Up @@ -34,7 +36,7 @@ use {
signature::{Keypair, Signer},
sysvar::{
clock, epoch_schedule,
fees::{self, Fees},
fees::{self},
rent, Sysvar,
},
},
Expand Down Expand Up @@ -377,6 +379,7 @@ impl solana_sdk::program_stubs::SyscallStubs for SyscallStubs {
get_sysvar::<EpochSchedule>(&epoch_schedule::id(), var_addr)
}

#[allow(deprecated)]
fn sol_get_fees_sysvar(&self, var_addr: *mut u8) -> u64 {
get_sysvar::<Fees>(&fees::id(), var_addr)
}
Expand Down
33 changes: 15 additions & 18 deletions program-test/tests/sysvar.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
#[allow(deprecated)]
use solana_sdk::sysvar::fees::Fees;
use {
solana_program_test::{processor, ProgramTest},
solana_sdk::{
account_info::AccountInfo,
clock::Clock,
entrypoint::ProgramResult,
epoch_schedule::EpochSchedule,
fee_calculator::FeeCalculator,
instruction::Instruction,
msg,
pubkey::Pubkey,
rent::Rent,
signature::Signer,
sysvar::{fees::Fees, Sysvar},
account_info::AccountInfo, clock::Clock, entrypoint::ProgramResult,
epoch_schedule::EpochSchedule, fee_calculator::FeeCalculator, instruction::Instruction,
msg, pubkey::Pubkey, rent::Rent, signature::Signer, sysvar::Sysvar,
transaction::Transaction,
},
};
Expand All @@ -30,13 +24,16 @@ fn sysvar_getter_process_instruction(
let epoch_schedule = EpochSchedule::get()?;
assert_eq!(epoch_schedule, EpochSchedule::default());

let fees = Fees::get()?;
assert_eq!(
fees.fee_calculator,
FeeCalculator {
lamports_per_signature: 5000
}
);
#[allow(deprecated)]
{
let fees = Fees::get()?;
assert_eq!(
fees.fee_calculator,
FeeCalculator {
lamports_per_signature: 5000
}
);
}

let rent = Rent::get()?;
assert_eq!(rent, Rent::default());
Expand Down
5 changes: 3 additions & 2 deletions programs/bpf/rust/sysvar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

extern crate solana_program;
#[allow(deprecated)]
use solana_program::sysvar::recent_blockhashes::RecentBlockhashes;
use solana_program::sysvar::{fees::Fees, recent_blockhashes::RecentBlockhashes};
use solana_program::{
account_info::AccountInfo,
entrypoint,
Expand All @@ -12,7 +12,7 @@ use solana_program::{
program_error::ProgramError,
pubkey::Pubkey,
sysvar::{
self, clock::Clock, epoch_schedule::EpochSchedule, fees::Fees, instructions, rent::Rent,
self, clock::Clock, epoch_schedule::EpochSchedule, instructions, rent::Rent,
slot_hashes::SlotHashes, slot_history::SlotHistory, stake_history::StakeHistory, Sysvar,
},
};
Expand Down Expand Up @@ -45,6 +45,7 @@ pub fn process_instruction(
}

// Fees
#[allow(deprecated)]
{
msg!("Fees identifier:");
sysvar::fees::id().log();
Expand Down
8 changes: 4 additions & 4 deletions programs/bpf/rust/sysvar/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use solana_bpf_rust_sysvar::process_instruction;
use solana_program_test::*;
use solana_sdk::sysvar::{fees, recent_blockhashes};
use solana_sdk::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
signature::Signer,
sysvar::{
clock, epoch_schedule, fees, instructions, recent_blockhashes, rent, slot_hashes,
slot_history, stake_history,
},
sysvar::{clock, epoch_schedule, instructions, rent, slot_hashes, slot_history, stake_history},
transaction::Transaction,
};

Expand All @@ -30,8 +28,10 @@ async fn test_sysvars() {
AccountMeta::new(Pubkey::new_unique(), false),
AccountMeta::new_readonly(clock::id(), false),
AccountMeta::new_readonly(epoch_schedule::id(), false),
#[allow(deprecated)]
AccountMeta::new_readonly(fees::id(), false),
AccountMeta::new_readonly(instructions::id(), false),
#[allow(deprecated)]
AccountMeta::new_readonly(recent_blockhashes::id(), false),
AccountMeta::new_readonly(rent::id(), false),
AccountMeta::new_readonly(slot_hashes::id(), false),
Expand Down
11 changes: 3 additions & 8 deletions programs/bpf/rust/upgradeable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

extern crate solana_program;
use solana_program::{
account_info::AccountInfo,
entrypoint,
entrypoint::ProgramResult,
msg,
pubkey::Pubkey,
sysvar::{clock, fees},
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, msg, pubkey::Pubkey,
sysvar::clock,
};

entrypoint!(process_instruction);
Expand All @@ -17,9 +13,8 @@ fn process_instruction(
_instruction_data: &[u8],
) -> ProgramResult {
msg!("Upgradeable program");
assert_eq!(accounts.len(), 3);
assert_eq!(accounts.len(), 2);
assert_eq!(accounts[0].key, program_id);
assert_eq!(*accounts[1].key, clock::id());
assert_eq!(*accounts[2].key, fees::id());
Err(42.into())
}
11 changes: 3 additions & 8 deletions programs/bpf/rust/upgraded/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

extern crate solana_program;
use solana_program::{
account_info::AccountInfo,
entrypoint,
entrypoint::ProgramResult,
msg,
pubkey::Pubkey,
sysvar::{clock, fees},
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, msg, pubkey::Pubkey,
sysvar::clock,
};

entrypoint!(process_instruction);
Expand All @@ -17,9 +13,8 @@ fn process_instruction(
_instruction_data: &[u8],
) -> ProgramResult {
msg!("Upgraded program");
assert_eq!(accounts.len(), 3);
assert_eq!(accounts.len(), 2);
assert_eq!(accounts[0].key, program_id);
assert_eq!(*accounts[1].key, clock::id());
assert_eq!(*accounts[2].key, fees::id());
Err(43.into())
}
14 changes: 3 additions & 11 deletions programs/bpf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use solana_sdk::{
pubkey::Pubkey,
signature::{keypair_from_seed, Keypair, Signer},
system_instruction,
sysvar::{clock, fees, rent},
sysvar::{clock, rent},
transaction::{Transaction, TransactionError},
};
use solana_transaction_status::{
Expand Down Expand Up @@ -1258,11 +1258,8 @@ fn test_program_bpf_call_depth() {
let result = bank_client.send_and_confirm_instruction(&mint_keypair, instruction);
assert!(result.is_ok());

let instruction = Instruction::new_with_bincode(
program_id,
&ComputeBudget::default().max_call_depth,
vec![],
);
let instruction =
Instruction::new_with_bincode(program_id, &ComputeBudget::default().max_call_depth, vec![]);
let result = bank_client.send_and_confirm_instruction(&mint_keypair, instruction);
assert!(result.is_err());
}
Expand Down Expand Up @@ -1701,7 +1698,6 @@ fn test_program_bpf_upgrade() {
vec![
AccountMeta::new(program_id.clone(), false),
AccountMeta::new(clock::id(), false),
AccountMeta::new(fees::id(), false),
],
);

Expand Down Expand Up @@ -1797,7 +1793,6 @@ fn test_program_bpf_upgrade_and_invoke_in_same_tx() {
vec![
AccountMeta::new(program_id.clone(), false),
AccountMeta::new(clock::id(), false),
AccountMeta::new(fees::id(), false),
],
);

Expand Down Expand Up @@ -1886,7 +1881,6 @@ fn test_program_bpf_invoke_upgradeable_via_cpi() {
AccountMeta::new(program_id, false),
AccountMeta::new(program_id, false),
AccountMeta::new(clock::id(), false),
AccountMeta::new(fees::id(), false),
],
);

Expand Down Expand Up @@ -2077,7 +2071,6 @@ fn test_program_bpf_upgrade_via_cpi() {
AccountMeta::new(program_id, false),
AccountMeta::new(program_id, false),
AccountMeta::new(clock::id(), false),
AccountMeta::new(fees::id(), false),
],
);

Expand Down Expand Up @@ -2182,7 +2175,6 @@ fn test_program_bpf_upgrade_self_via_cpi() {
AccountMeta::new(noop_program_id, false),
AccountMeta::new(noop_program_id, false),
AccountMeta::new(clock::id(), false),
AccountMeta::new(fees::id(), false),
],
);

Expand Down
6 changes: 5 additions & 1 deletion programs/bpf_loader/src/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use solana_rbpf::{
vm::{EbpfVm, SyscallObject, SyscallRegistry},
};
use solana_runtime::message_processor::MessageProcessor;
#[allow(deprecated)]
use solana_sdk::sysvar::fees::Fees;
use solana_sdk::{
account::{Account, AccountSharedData, ReadableAccount},
account_info::AccountInfo,
Expand All @@ -35,7 +37,7 @@ use solana_sdk::{
secp256k1_recover::{
Secp256k1RecoverError, SECP256K1_PUBLIC_KEY_LENGTH, SECP256K1_SIGNATURE_LENGTH,
},
sysvar::{self, fees::Fees, Sysvar, SysvarId},
sysvar::{self, Sysvar, SysvarId},
};
use std::{
alloc::Layout,
Expand Down Expand Up @@ -1114,6 +1116,7 @@ struct SyscallGetFeesSysvar<'a> {
invoke_context: Rc<RefCell<&'a mut dyn InvokeContext>>,
loader_id: &'a Pubkey,
}
#[allow(deprecated)]
impl<'a> SyscallObject<BpfError> for SyscallGetFeesSysvar<'a> {
fn call(
&mut self,
Expand Down Expand Up @@ -3365,6 +3368,7 @@ mod tests {
}

// Test fees sysvar
#[allow(deprecated)]
{
let got_fees = Fees::default();
let got_fees_va = 2048;
Expand Down
Loading