Feature disable fees sysvar (#18981)

* Feature disable fees sysvar

* nudge
This commit is contained in:
Jack May
2021-08-01 17:31:11 -07:00
committed by GitHub
parent 9d2f0e237b
commit 77861e2d40
7 changed files with 42 additions and 55 deletions

View File

@ -2,12 +2,11 @@
extern crate solana_program;
#[allow(deprecated)]
use solana_program::sysvar::{fees::Fees, recent_blockhashes::RecentBlockhashes};
use solana_program::sysvar::recent_blockhashes::RecentBlockhashes;
use solana_program::{
account_info::AccountInfo,
entrypoint,
entrypoint::ProgramResult,
fee_calculator::FeeCalculator,
msg,
program_error::ProgramError,
pubkey::Pubkey,
@ -44,22 +43,10 @@ pub fn process_instruction(
assert_eq!(epoch_schedule, got_epoch_schedule);
}
// Fees
#[allow(deprecated)]
{
msg!("Fees identifier:");
sysvar::fees::id().log();
let fees = Fees::from_account_info(&accounts[4]).unwrap();
let fee_calculator = fees.fee_calculator.clone();
assert_ne!(fee_calculator, FeeCalculator::default());
let got_fees = Fees::get()?;
assert_eq!(fees, got_fees);
}
// Instructions
msg!("Instructions identifier:");
sysvar::instructions::id().log();
let index = instructions::load_current_index(&accounts[5].try_borrow_data()?);
let index = instructions::load_current_index(&accounts[4].try_borrow_data()?);
assert_eq!(0, index);
// Recent Blockhashes
@ -67,7 +54,7 @@ pub fn process_instruction(
{
msg!("RecentBlockhashes identifier:");
sysvar::recent_blockhashes::id().log();
let recent_blockhashes = RecentBlockhashes::from_account_info(&accounts[6]).unwrap();
let recent_blockhashes = RecentBlockhashes::from_account_info(&accounts[5]).unwrap();
assert_ne!(recent_blockhashes, RecentBlockhashes::default());
}
@ -75,7 +62,7 @@ pub fn process_instruction(
{
msg!("Rent identifier:");
sysvar::rent::id().log();
let rent = Rent::from_account_info(&accounts[7]).unwrap();
let rent = Rent::from_account_info(&accounts[6]).unwrap();
assert_eq!(rent, Rent::default());
let got_rent = Rent::get()?;
assert_eq!(rent, got_rent);
@ -86,7 +73,7 @@ pub fn process_instruction(
sysvar::slot_hashes::id().log();
assert_eq!(
Err(ProgramError::UnsupportedSysvar),
SlotHashes::from_account_info(&accounts[8])
SlotHashes::from_account_info(&accounts[7])
);
// Slot History
@ -94,13 +81,13 @@ pub fn process_instruction(
sysvar::slot_history::id().log();
assert_eq!(
Err(ProgramError::UnsupportedSysvar),
SlotHistory::from_account_info(&accounts[9])
SlotHistory::from_account_info(&accounts[8])
);
// Stake History
msg!("StakeHistory identifier:");
sysvar::stake_history::id().log();
let _ = StakeHistory::from_account_info(&accounts[10]).unwrap();
let _ = StakeHistory::from_account_info(&accounts[9]).unwrap();
Ok(())
}

View File

@ -28,8 +28,6 @@ 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),

View File

@ -21,8 +21,8 @@ use solana_sdk::{
entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS},
epoch_schedule::EpochSchedule,
feature_set::{
blake3_syscall_enabled, enforce_aligned_host_addrs, libsecp256k1_0_5_upgrade_enabled,
memory_ops_syscalls, secp256k1_recover_syscall_enabled,
blake3_syscall_enabled, disable_fees_sysvar, enforce_aligned_host_addrs,
libsecp256k1_0_5_upgrade_enabled, memory_ops_syscalls, secp256k1_recover_syscall_enabled,
},
hash::{Hasher, HASH_BYTES},
ic_msg,
@ -150,8 +150,10 @@ pub fn register_syscalls(
b"sol_get_epoch_schedule_sysvar",
SyscallGetEpochScheduleSysvar::call,
)?;
syscall_registry
.register_syscall_by_name(b"sol_get_fees_sysvar", SyscallGetFeesSysvar::call)?;
if invoke_context.is_feature_active(&disable_fees_sysvar::id()) {
syscall_registry
.register_syscall_by_name(b"sol_get_fees_sysvar", SyscallGetFeesSysvar::call)?;
}
syscall_registry
.register_syscall_by_name(b"sol_get_rent_sysvar", SyscallGetRentSysvar::call)?;
@ -346,6 +348,9 @@ pub fn bind_syscall_context_objects<'a>(
}),
);
let is_fee_sysvar_via_syscall_active =
!invoke_context.is_feature_active(&disable_fees_sysvar::id());
let invoke_context = Rc::new(RefCell::new(invoke_context));
vm.bind_syscall_context_object(
@ -362,13 +367,14 @@ pub fn bind_syscall_context_objects<'a>(
}),
None,
)?;
vm.bind_syscall_context_object(
bind_feature_gated_syscall_context_object!(
vm,
is_fee_sysvar_via_syscall_active,
Box::new(SyscallGetFeesSysvar {
invoke_context: invoke_context.clone(),
loader_id,
}),
None,
)?;
);
vm.bind_syscall_context_object(
Box::new(SyscallGetRentSysvar {
invoke_context: invoke_context.clone(),