diff --git a/cli/src/wallet.rs b/cli/src/wallet.rs index c2347f4bd..6a8e47fb3 100644 --- a/cli/src/wallet.rs +++ b/cli/src/wallet.rs @@ -871,7 +871,7 @@ fn process_deploy( // Build transactions to calculate fees let mut messages: Vec<&Message> = Vec::new(); let (blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?; - let mut create_account_tx = system_transaction::create_rent_exempted_account( + let mut create_account_tx = system_transaction::create_account( &config.keypair, &program_id.pubkey(), blockhash, diff --git a/core/src/chacha.rs b/core/src/chacha.rs index 833f6cdd4..c668d6410 100644 --- a/core/src/chacha.rs +++ b/core/src/chacha.rs @@ -153,7 +153,7 @@ mod tests { hasher.hash(&buf[..size]); // golden needs to be updated if blob stuff changes.... - let golden: Hash = "7P2RmguCZaaBDzjvAej6RnqiA3v82s3PyaCX3uNzsjfc" + let golden: Hash = "CLGvEayebjdgnLdttFAweZE9rqVkehXqEStUifG9kiU9" .parse() .unwrap(); diff --git a/drone/src/drone.rs b/drone/src/drone.rs index 9f03e4258..8fa863ed7 100644 --- a/drone/src/drone.rs +++ b/drone/src/drone.rs @@ -396,8 +396,7 @@ mod tests { SystemInstruction::CreateAccount { lamports: 2, space: 0, - program_id: Pubkey::default(), - require_rent_exemption: false + program_id: Pubkey::default() } ); diff --git a/programs/stake_api/src/stake_instruction.rs b/programs/stake_api/src/stake_instruction.rs index 9c7853bce..12985076f 100644 --- a/programs/stake_api/src/stake_instruction.rs +++ b/programs/stake_api/src/stake_instruction.rs @@ -110,7 +110,7 @@ pub fn create_stake_account_with_lockup( custodian: &Pubkey, ) -> Vec { vec![ - system_instruction::create_rent_exempted_account( + system_instruction::create_account( from_pubkey, stake_pubkey, lamports, diff --git a/programs/vote_api/src/vote_instruction.rs b/programs/vote_api/src/vote_instruction.rs index 05241efc1..dccd433a8 100644 --- a/programs/vote_api/src/vote_instruction.rs +++ b/programs/vote_api/src/vote_instruction.rs @@ -87,13 +87,8 @@ pub fn create_account( lamports: u64, ) -> Vec { let space = VoteState::size_of() as u64; - let create_ix = system_instruction::create_rent_exempted_account( - from_pubkey, - vote_pubkey, - lamports, - space, - &id(), - ); + let create_ix = + system_instruction::create_account(from_pubkey, vote_pubkey, lamports, space, &id()); let init_ix = initialize_account(vote_pubkey, node_pubkey, commission); vec![create_ix, init_ix] } diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 74e7235f7..88ca5d605 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -275,7 +275,6 @@ impl Bank { bank.update_stake_history(None); } bank.update_clock(); - bank.update_rent(); bank } diff --git a/runtime/src/loader_utils.rs b/runtime/src/loader_utils.rs index 85f525adc..3e4065867 100644 --- a/runtime/src/loader_utils.rs +++ b/runtime/src/loader_utils.rs @@ -16,7 +16,7 @@ pub fn load_program( let program_keypair = Keypair::new(); let program_pubkey = program_keypair.pubkey(); - let instruction = system_instruction::create_rent_exempted_account( + let instruction = system_instruction::create_account( &from_keypair.pubkey(), &program_pubkey, 1, diff --git a/runtime/src/system_instruction_processor.rs b/runtime/src/system_instruction_processor.rs index 5d072c5dd..7c5bd64aa 100644 --- a/runtime/src/system_instruction_processor.rs +++ b/runtime/src/system_instruction_processor.rs @@ -2,22 +2,18 @@ use log::*; use solana_sdk::account::KeyedAccount; use solana_sdk::instruction::InstructionError; use solana_sdk::pubkey::Pubkey; -use solana_sdk::rent_calculator::RentCalculator; use solana_sdk::system_instruction::{SystemError, SystemInstruction}; use solana_sdk::system_program; use solana_sdk::sysvar; -use solana_sdk::sysvar::rent; const FROM_ACCOUNT_INDEX: usize = 0; const TO_ACCOUNT_INDEX: usize = 1; -const RENT_SYSVAR_ACCOUNT_INDEX: usize = 2; fn create_system_account( keyed_accounts: &mut [KeyedAccount], lamports: u64, space: u64, program_id: &Pubkey, - rent_exemption_calculator: Option, ) -> Result<(), SystemError> { if !system_program::check_id(&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner) { debug!( @@ -60,13 +56,6 @@ fn create_system_account( ); Err(SystemError::ResultWithNegativeLamports)?; } - - if let Some(calculator) = rent_exemption_calculator { - if !calculator.is_exempt(lamports, space as usize) { - Err(SystemError::InsufficientFunds)?; - } - } - keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports -= lamports; keyed_accounts[TO_ACCOUNT_INDEX].account.lamports += lamports; keyed_accounts[TO_ACCOUNT_INDEX].account.owner = *program_id; @@ -118,28 +107,7 @@ pub fn process_instruction( lamports, space, program_id, - require_rent_exemption, - } => { - let rent_exemption_calculator: Option = if require_rent_exemption { - if keyed_accounts.len() < (RENT_SYSVAR_ACCOUNT_INDEX + 1) { - Err(InstructionError::InvalidInstructionData)?; - } - Some( - rent::from_keyed_account(&keyed_accounts[RENT_SYSVAR_ACCOUNT_INDEX])? - .rent_calculator, - ) - } else { - None - }; - - create_system_account( - keyed_accounts, - lamports, - space, - &program_id, - rent_exemption_calculator, - ) - } + } => create_system_account(keyed_accounts, lamports, space, &program_id), SystemInstruction::Assign { program_id } => { if !system_program::check_id(&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner) { Err(InstructionError::IncorrectProgramId)?; @@ -165,7 +133,6 @@ mod tests { use solana_sdk::client::SyncClient; use solana_sdk::genesis_block::create_genesis_block; use solana_sdk::instruction::{AccountMeta, Instruction, InstructionError}; - use solana_sdk::rent_calculator::RentCalculator; use solana_sdk::signature::{Keypair, KeypairUtil}; use solana_sdk::system_program; use solana_sdk::transaction::TransactionError; @@ -183,7 +150,7 @@ mod tests { KeyedAccount::new(&from, true, &mut from_account), KeyedAccount::new(&to, false, &mut to_account), ]; - create_system_account(&mut keyed_accounts, 50, 2, &new_program_owner, None).unwrap(); + create_system_account(&mut keyed_accounts, 50, 2, &new_program_owner).unwrap(); let from_lamports = from_account.lamports; let to_lamports = to_account.lamports; let to_owner = to_account.owner; @@ -209,7 +176,7 @@ mod tests { KeyedAccount::new(&from, true, &mut from_account), KeyedAccount::new(&to, false, &mut to_account), ]; - let result = create_system_account(&mut keyed_accounts, 150, 2, &new_program_owner, None); + let result = create_system_account(&mut keyed_accounts, 150, 2, &new_program_owner); assert_eq!(result, Err(SystemError::ResultWithNegativeLamports)); let from_lamports = from_account.lamports; assert_eq!(from_lamports, 100); @@ -232,7 +199,7 @@ mod tests { KeyedAccount::new(&from, true, &mut from_account), KeyedAccount::new(&owned_key, false, &mut owned_account), ]; - let result = create_system_account(&mut keyed_accounts, 50, 2, &new_program_owner, None); + let result = create_system_account(&mut keyed_accounts, 50, 2, &new_program_owner); assert_eq!(result, Err(SystemError::AccountAlreadyInUse)); let from_lamports = from_account.lamports; assert_eq!(from_lamports, 100); @@ -253,7 +220,7 @@ mod tests { KeyedAccount::new(&to, false, &mut to_account), ]; // fail to create a sysvar::id() owned account - let result = create_system_account(&mut keyed_accounts, 50, 2, &sysvar::id(), None); + let result = create_system_account(&mut keyed_accounts, 50, 2, &sysvar::id()); assert_eq!(result, Err(SystemError::InvalidProgramId)); let to = sysvar::fees::id(); @@ -264,7 +231,7 @@ mod tests { KeyedAccount::new(&to, false, &mut to_account), ]; // fail to create an account with a sysvar id - let result = create_system_account(&mut keyed_accounts, 50, 2, &system_program::id(), None); + let result = create_system_account(&mut keyed_accounts, 50, 2, &system_program::id()); assert_eq!(result, Err(SystemError::InvalidAccountId)); let from_lamports = from_account.lamports; @@ -289,66 +256,12 @@ mod tests { KeyedAccount::new(&from, true, &mut from_account), KeyedAccount::new(&populated_key, false, &mut populated_account), ]; - let result = create_system_account(&mut keyed_accounts, 50, 2, &new_program_owner, None); + let result = create_system_account(&mut keyed_accounts, 50, 2, &new_program_owner); assert_eq!(result, Err(SystemError::AccountAlreadyInUse)); assert_eq!(from_account.lamports, 100); assert_eq!(populated_account, unchanged_account); } - #[test] - fn test_create_rent_exempt() { - let other_program = Pubkey::new(&[9; 32]); - - let from = Pubkey::new_rand(); - let mut from_account = Account::new(1000, 0, &system_program::id()); - let to = Pubkey::new_rand(); - let mut to_account = Account::new(0, 0, &Pubkey::default()); - let rent_id = rent::id(); - let rent_calculator = RentCalculator { - lamports_per_byte_year: 50, - exemption_threshold: 2.0, - burn_percent: 0, - }; - let mut rent_sysvar_account = rent::create_account(50, &rent_calculator); - let mut keyed_accounts = vec![ - KeyedAccount::new(&from, true, &mut from_account), - KeyedAccount::new(&to, false, &mut to_account), - KeyedAccount::new(&rent_id, false, &mut rent_sysvar_account), - ]; - - // if rent exemption flag is false, then account will be created successfully. - let result = create_system_account(&mut keyed_accounts, 0, 2, &other_program, None); - assert_eq!(result, Ok(())); - - let to = Pubkey::new_rand(); - let mut to_account = Account::new(0, 0, &Pubkey::default()); - keyed_accounts[1] = KeyedAccount::new(&to, false, &mut to_account); - - // there must be sufficient amount of lamport in account to be created as rent exempted - let result = create_system_account( - &mut keyed_accounts, - 0, - 2, - &other_program, - Some(rent_calculator), - ); - assert_eq!(result, Err(SystemError::InsufficientFunds)); - - let to = Pubkey::new_rand(); - let mut to_account = Account::new(0, 0, &Pubkey::default()); - keyed_accounts[1] = KeyedAccount::new(&to, false, &mut to_account); - - // amount of lamports must be sufficient for account to be rent exempt - let result = create_system_account( - &mut keyed_accounts, - 500, - 2, - &other_program, - Some(rent_calculator), - ); - assert_eq!(result, Ok(())); - } - #[test] fn test_create_not_system_account() { let other_program = Pubkey::new(&[9; 32]); @@ -361,7 +274,7 @@ mod tests { KeyedAccount::new(&from, true, &mut from_account), KeyedAccount::new(&to, false, &mut to_account), ]; - let result = create_system_account(&mut keyed_accounts, 50, 2, &other_program, None); + let result = create_system_account(&mut keyed_accounts, 50, 2, &other_program); assert_eq!(result, Err(SystemError::SourceNotSystemAccount)); } diff --git a/sdk/src/system_instruction.rs b/sdk/src/system_instruction.rs index 0d31e3010..0a5151d1f 100644 --- a/sdk/src/system_instruction.rs +++ b/sdk/src/system_instruction.rs @@ -2,7 +2,6 @@ use crate::instruction::{AccountMeta, Instruction}; use crate::instruction_processor_utils::DecodeError; use crate::pubkey::Pubkey; use crate::system_program; -use crate::sysvar::rent; use num_derive::FromPrimitive; #[derive(Serialize, Debug, Clone, PartialEq, FromPrimitive)] @@ -12,7 +11,6 @@ pub enum SystemError { SourceNotSystemAccount, InvalidProgramId, InvalidAccountId, - InsufficientFunds, } impl DecodeError for SystemError { @@ -33,16 +31,13 @@ pub enum SystemInstruction { /// Create a new account /// * Transaction::keys[0] - source /// * Transaction::keys[1] - new account key - /// * Transaction::keys[2] - rent sysvar account key (Only required if require_rent_exemption is true) /// * lamports - number of lamports to transfer to the new account /// * space - memory to allocate if greater then zero /// * program_id - the program id of the new account - /// * require_rent_exemption - if set to true, only allow account creation if it's rent exempt CreateAccount { lamports: u64, space: u64, program_id: Pubkey, - require_rent_exemption: bool, }, /// Assign account to a program /// * Transaction::keys[0] - account to assign @@ -60,43 +55,16 @@ pub fn create_account( space: u64, program_id: &Pubkey, ) -> Instruction { - generate_create_account_instruction(from_pubkey, to_pubkey, lamports, space, program_id, false) -} - -pub fn create_rent_exempted_account( - from_pubkey: &Pubkey, - to_pubkey: &Pubkey, - lamports: u64, - space: u64, - program_id: &Pubkey, -) -> Instruction { - generate_create_account_instruction(from_pubkey, to_pubkey, lamports, space, program_id, true) -} - -pub(crate) fn generate_create_account_instruction( - from_pubkey: &Pubkey, - to_pubkey: &Pubkey, - lamports: u64, - space: u64, - program_id: &Pubkey, - require_rent_exemption: bool, -) -> Instruction { - let mut account_metas = vec![ + let account_metas = vec![ AccountMeta::new(*from_pubkey, true), AccountMeta::new(*to_pubkey, false), ]; - - if require_rent_exemption { - account_metas.push(AccountMeta::new(rent::id(), false)); - } - Instruction::new( system_program::id(), &SystemInstruction::CreateAccount { lamports, space, program_id: *program_id, - require_rent_exemption, }, account_metas, ) diff --git a/sdk/src/system_transaction.rs b/sdk/src/system_transaction.rs index 69bba15fb..cc891bfde 100644 --- a/sdk/src/system_transaction.rs +++ b/sdk/src/system_transaction.rs @@ -15,55 +15,10 @@ pub fn create_account( lamports: u64, space: u64, program_id: &Pubkey, -) -> Transaction { - generate_create_account_tx( - from_keypair, - to, - recent_blockhash, - lamports, - space, - program_id, - false, - ) -} - -pub fn create_rent_exempted_account( - from_keypair: &Keypair, - to: &Pubkey, - recent_blockhash: Hash, - lamports: u64, - space: u64, - program_id: &Pubkey, -) -> Transaction { - generate_create_account_tx( - from_keypair, - to, - recent_blockhash, - lamports, - space, - program_id, - true, - ) -} - -fn generate_create_account_tx( - from_keypair: &Keypair, - to: &Pubkey, - recent_blockhash: Hash, - lamports: u64, - space: u64, - program_id: &Pubkey, - require_rent_exemption: bool, ) -> Transaction { let from_pubkey = from_keypair.pubkey(); - let create_instruction = system_instruction::generate_create_account_instruction( - &from_pubkey, - to, - lamports, - space, - program_id, - require_rent_exemption, - ); + let create_instruction = + system_instruction::create_account(&from_pubkey, to, lamports, space, program_id); let instructions = vec![create_instruction]; Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash) } diff --git a/sdk/src/sysvar/rent.rs b/sdk/src/sysvar/rent.rs index e8ecbda95..10e3d7a71 100644 --- a/sdk/src/sysvar/rent.rs +++ b/sdk/src/sysvar/rent.rs @@ -49,16 +49,6 @@ pub fn create_account(lamports: u64, rent_calculator: &RentCalculator) -> Accoun .unwrap() } -use crate::account::KeyedAccount; -use crate::instruction::InstructionError; - -pub fn from_keyed_account(account: &KeyedAccount) -> Result { - if !check_id(account.unsigned_key()) { - return Err(InstructionError::InvalidArgument); - } - Rent::from_account(account.account).ok_or(InstructionError::InvalidArgument) -} - #[cfg(test)] mod tests { use super::*;