Feature disable fees sysvar (#18981)
* Feature disable fees sysvar * nudge
This commit is contained in:
@ -1,12 +1,9 @@
|
|||||||
#[allow(deprecated)]
|
|
||||||
use solana_sdk::sysvar::fees::Fees;
|
|
||||||
use {
|
use {
|
||||||
solana_program_test::{processor, ProgramTest},
|
solana_program_test::{processor, ProgramTest},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account_info::AccountInfo, clock::Clock, entrypoint::ProgramResult,
|
account_info::AccountInfo, clock::Clock, entrypoint::ProgramResult,
|
||||||
epoch_schedule::EpochSchedule, fee_calculator::FeeCalculator, instruction::Instruction,
|
epoch_schedule::EpochSchedule, instruction::Instruction, msg, pubkey::Pubkey, rent::Rent,
|
||||||
msg, pubkey::Pubkey, rent::Rent, signature::Signer, sysvar::Sysvar,
|
signature::Signer, sysvar::Sysvar, transaction::Transaction,
|
||||||
transaction::Transaction,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -24,17 +21,6 @@ fn sysvar_getter_process_instruction(
|
|||||||
let epoch_schedule = EpochSchedule::get()?;
|
let epoch_schedule = EpochSchedule::get()?;
|
||||||
assert_eq!(epoch_schedule, EpochSchedule::default());
|
assert_eq!(epoch_schedule, EpochSchedule::default());
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
{
|
|
||||||
let fees = Fees::get()?;
|
|
||||||
assert_eq!(
|
|
||||||
fees.fee_calculator,
|
|
||||||
FeeCalculator {
|
|
||||||
lamports_per_signature: 5000
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let rent = Rent::get()?;
|
let rent = Rent::get()?;
|
||||||
assert_eq!(rent, Rent::default());
|
assert_eq!(rent, Rent::default());
|
||||||
|
|
||||||
|
@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
extern crate solana_program;
|
extern crate solana_program;
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
use solana_program::sysvar::{fees::Fees, recent_blockhashes::RecentBlockhashes};
|
use solana_program::sysvar::recent_blockhashes::RecentBlockhashes;
|
||||||
use solana_program::{
|
use solana_program::{
|
||||||
account_info::AccountInfo,
|
account_info::AccountInfo,
|
||||||
entrypoint,
|
entrypoint,
|
||||||
entrypoint::ProgramResult,
|
entrypoint::ProgramResult,
|
||||||
fee_calculator::FeeCalculator,
|
|
||||||
msg,
|
msg,
|
||||||
program_error::ProgramError,
|
program_error::ProgramError,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
@ -44,22 +43,10 @@ pub fn process_instruction(
|
|||||||
assert_eq!(epoch_schedule, got_epoch_schedule);
|
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
|
// Instructions
|
||||||
msg!("Instructions identifier:");
|
msg!("Instructions identifier:");
|
||||||
sysvar::instructions::id().log();
|
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);
|
assert_eq!(0, index);
|
||||||
|
|
||||||
// Recent Blockhashes
|
// Recent Blockhashes
|
||||||
@ -67,7 +54,7 @@ pub fn process_instruction(
|
|||||||
{
|
{
|
||||||
msg!("RecentBlockhashes identifier:");
|
msg!("RecentBlockhashes identifier:");
|
||||||
sysvar::recent_blockhashes::id().log();
|
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());
|
assert_ne!(recent_blockhashes, RecentBlockhashes::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +62,7 @@ pub fn process_instruction(
|
|||||||
{
|
{
|
||||||
msg!("Rent identifier:");
|
msg!("Rent identifier:");
|
||||||
sysvar::rent::id().log();
|
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());
|
assert_eq!(rent, Rent::default());
|
||||||
let got_rent = Rent::get()?;
|
let got_rent = Rent::get()?;
|
||||||
assert_eq!(rent, got_rent);
|
assert_eq!(rent, got_rent);
|
||||||
@ -86,7 +73,7 @@ pub fn process_instruction(
|
|||||||
sysvar::slot_hashes::id().log();
|
sysvar::slot_hashes::id().log();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Err(ProgramError::UnsupportedSysvar),
|
Err(ProgramError::UnsupportedSysvar),
|
||||||
SlotHashes::from_account_info(&accounts[8])
|
SlotHashes::from_account_info(&accounts[7])
|
||||||
);
|
);
|
||||||
|
|
||||||
// Slot History
|
// Slot History
|
||||||
@ -94,13 +81,13 @@ pub fn process_instruction(
|
|||||||
sysvar::slot_history::id().log();
|
sysvar::slot_history::id().log();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Err(ProgramError::UnsupportedSysvar),
|
Err(ProgramError::UnsupportedSysvar),
|
||||||
SlotHistory::from_account_info(&accounts[9])
|
SlotHistory::from_account_info(&accounts[8])
|
||||||
);
|
);
|
||||||
|
|
||||||
// Stake History
|
// Stake History
|
||||||
msg!("StakeHistory identifier:");
|
msg!("StakeHistory identifier:");
|
||||||
sysvar::stake_history::id().log();
|
sysvar::stake_history::id().log();
|
||||||
let _ = StakeHistory::from_account_info(&accounts[10]).unwrap();
|
let _ = StakeHistory::from_account_info(&accounts[9]).unwrap();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,6 @@ async fn test_sysvars() {
|
|||||||
AccountMeta::new(Pubkey::new_unique(), false),
|
AccountMeta::new(Pubkey::new_unique(), false),
|
||||||
AccountMeta::new_readonly(clock::id(), false),
|
AccountMeta::new_readonly(clock::id(), false),
|
||||||
AccountMeta::new_readonly(epoch_schedule::id(), false),
|
AccountMeta::new_readonly(epoch_schedule::id(), false),
|
||||||
#[allow(deprecated)]
|
|
||||||
AccountMeta::new_readonly(fees::id(), false),
|
|
||||||
AccountMeta::new_readonly(instructions::id(), false),
|
AccountMeta::new_readonly(instructions::id(), false),
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
AccountMeta::new_readonly(recent_blockhashes::id(), false),
|
AccountMeta::new_readonly(recent_blockhashes::id(), false),
|
||||||
|
@ -21,8 +21,8 @@ use solana_sdk::{
|
|||||||
entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS},
|
entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS},
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
feature_set::{
|
feature_set::{
|
||||||
blake3_syscall_enabled, enforce_aligned_host_addrs, libsecp256k1_0_5_upgrade_enabled,
|
blake3_syscall_enabled, disable_fees_sysvar, enforce_aligned_host_addrs,
|
||||||
memory_ops_syscalls, secp256k1_recover_syscall_enabled,
|
libsecp256k1_0_5_upgrade_enabled, memory_ops_syscalls, secp256k1_recover_syscall_enabled,
|
||||||
},
|
},
|
||||||
hash::{Hasher, HASH_BYTES},
|
hash::{Hasher, HASH_BYTES},
|
||||||
ic_msg,
|
ic_msg,
|
||||||
@ -150,8 +150,10 @@ pub fn register_syscalls(
|
|||||||
b"sol_get_epoch_schedule_sysvar",
|
b"sol_get_epoch_schedule_sysvar",
|
||||||
SyscallGetEpochScheduleSysvar::call,
|
SyscallGetEpochScheduleSysvar::call,
|
||||||
)?;
|
)?;
|
||||||
syscall_registry
|
if invoke_context.is_feature_active(&disable_fees_sysvar::id()) {
|
||||||
.register_syscall_by_name(b"sol_get_fees_sysvar", SyscallGetFeesSysvar::call)?;
|
syscall_registry
|
||||||
|
.register_syscall_by_name(b"sol_get_fees_sysvar", SyscallGetFeesSysvar::call)?;
|
||||||
|
}
|
||||||
syscall_registry
|
syscall_registry
|
||||||
.register_syscall_by_name(b"sol_get_rent_sysvar", SyscallGetRentSysvar::call)?;
|
.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));
|
let invoke_context = Rc::new(RefCell::new(invoke_context));
|
||||||
|
|
||||||
vm.bind_syscall_context_object(
|
vm.bind_syscall_context_object(
|
||||||
@ -362,13 +367,14 @@ pub fn bind_syscall_context_objects<'a>(
|
|||||||
}),
|
}),
|
||||||
None,
|
None,
|
||||||
)?;
|
)?;
|
||||||
vm.bind_syscall_context_object(
|
bind_feature_gated_syscall_context_object!(
|
||||||
|
vm,
|
||||||
|
is_fee_sysvar_via_syscall_active,
|
||||||
Box::new(SyscallGetFeesSysvar {
|
Box::new(SyscallGetFeesSysvar {
|
||||||
invoke_context: invoke_context.clone(),
|
invoke_context: invoke_context.clone(),
|
||||||
loader_id,
|
loader_id,
|
||||||
}),
|
}),
|
||||||
None,
|
);
|
||||||
)?;
|
|
||||||
vm.bind_syscall_context_object(
|
vm.bind_syscall_context_object(
|
||||||
Box::new(SyscallGetRentSysvar {
|
Box::new(SyscallGetRentSysvar {
|
||||||
invoke_context: invoke_context.clone(),
|
invoke_context: invoke_context.clone(),
|
||||||
|
@ -1754,12 +1754,17 @@ impl Bank {
|
|||||||
|
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
fn update_fees(&self) {
|
fn update_fees(&self) {
|
||||||
self.update_sysvar_account(&sysvar::fees::id(), |account| {
|
if !self
|
||||||
create_account(
|
.feature_set
|
||||||
&sysvar::fees::Fees::new(&self.fee_calculator),
|
.is_active(&feature_set::disable_fees_sysvar::id())
|
||||||
self.inherit_specially_retained_account_fields(account),
|
{
|
||||||
)
|
self.update_sysvar_account(&sysvar::fees::id(), |account| {
|
||||||
});
|
create_account(
|
||||||
|
&sysvar::fees::Fees::new(&self.fee_calculator),
|
||||||
|
self.inherit_specially_retained_account_fields(account),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_rent(&self) {
|
fn update_rent(&self) {
|
||||||
@ -7410,8 +7415,8 @@ pub(crate) mod tests {
|
|||||||
|
|
||||||
bank.collect_rent_in_partition((0, 0, 1)); // all range
|
bank.collect_rent_in_partition((0, 0, 1)); // all range
|
||||||
|
|
||||||
// unrelated 1-lamport account exists
|
// unrelated 1-lamport accounts exists
|
||||||
assert_eq!(bank.collected_rent.load(Relaxed), rent_collected + 1);
|
assert_eq!(bank.collected_rent.load(Relaxed), rent_collected + 2);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.get_account(&rent_due_pubkey).unwrap().lamports(),
|
bank.get_account(&rent_due_pubkey).unwrap().lamports(),
|
||||||
little_lamports - rent_collected
|
little_lamports - rent_collected
|
||||||
|
@ -122,8 +122,8 @@ pub(crate) fn sol_get_epoch_schedule_sysvar(var_addr: *mut u8) -> u64 {
|
|||||||
.sol_get_epoch_schedule_sysvar(var_addr)
|
.sol_get_epoch_schedule_sysvar(var_addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn sol_get_fees_sysvar(var_addr: *mut u8) -> u64 {
|
pub(crate) fn sol_get_fees_sysvar(_var_addr: *mut u8) -> u64 {
|
||||||
SYSCALL_STUBS.read().unwrap().sol_get_fees_sysvar(var_addr)
|
UNSUPPORTED_SYSVAR
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn sol_get_rent_sysvar(var_addr: *mut u8) -> u64 {
|
pub(crate) fn sol_get_rent_sysvar(var_addr: *mut u8) -> u64 {
|
||||||
|
@ -179,6 +179,10 @@ pub mod merge_nonce_error_into_system_error {
|
|||||||
solana_sdk::declare_id!("21AWDosvp3pBamFW91KB35pNoaoZVTM7ess8nr2nt53B");
|
solana_sdk::declare_id!("21AWDosvp3pBamFW91KB35pNoaoZVTM7ess8nr2nt53B");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod disable_fees_sysvar {
|
||||||
|
solana_sdk::declare_id!("JAN1trEUEtZjgXYzNBYHU9DYd7GnThhXfFP7SzPXkPsG");
|
||||||
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
/// Map of feature identifiers to user-visible description
|
/// Map of feature identifiers to user-visible description
|
||||||
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
|
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
|
||||||
@ -218,6 +222,7 @@ lazy_static! {
|
|||||||
(tx_wide_compute_cap::id(), "Transaction wide compute cap"),
|
(tx_wide_compute_cap::id(), "Transaction wide compute cap"),
|
||||||
(spl_token_v2_set_authority_fix::id(), "spl-token set_authority fix"),
|
(spl_token_v2_set_authority_fix::id(), "spl-token set_authority fix"),
|
||||||
(merge_nonce_error_into_system_error::id(), "merge NonceError into SystemError"),
|
(merge_nonce_error_into_system_error::id(), "merge NonceError into SystemError"),
|
||||||
|
(disable_fees_sysvar::id(), "disable fees sysvar"),
|
||||||
/*************** ADD NEW FEATURES HERE ***************/
|
/*************** ADD NEW FEATURES HERE ***************/
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
|
Reference in New Issue
Block a user