make executable, vote and stake account rent exempt (#6017)

* add missing convenience method

* require vote account to be exempt

* make stake account rent exempt

* making executable rent exempt

* rent will be initialized in genesis

* add test for update_rent
This commit is contained in:
Parth
2019-10-04 02:52:48 +05:30
committed by GitHub
parent cf2bcee607
commit 92ea11fca1
7 changed files with 168 additions and 16 deletions

View File

@ -1,5 +1,6 @@
use crate::instruction::{AccountMeta, Instruction};
use crate::pubkey::Pubkey;
use crate::sysvar::rent;
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub enum LoaderInstruction {
@ -15,6 +16,7 @@ pub enum LoaderInstruction {
/// bit of the Account
///
/// * key[0] - the account to prepare for execution
/// * key[1] - rent sysvar account
///
/// The transaction must be signed by key[0]
Finalize,
@ -40,6 +42,9 @@ pub fn write(
}
pub fn finalize(account_pubkey: &Pubkey, program_id: &Pubkey) -> Instruction {
let account_metas = vec![AccountMeta::new(*account_pubkey, true)];
let account_metas = vec![
AccountMeta::new(*account_pubkey, true),
AccountMeta::new(rent::id(), false),
];
Instruction::new(*program_id, &LoaderInstruction::Finalize, account_metas)
}

View File

@ -49,6 +49,30 @@ 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<Rent, InstructionError> {
if !check_id(account.unsigned_key()) {
return Err(InstructionError::InvalidArgument);
}
Rent::from_account(account.account).ok_or(InstructionError::InvalidArgument)
}
pub fn verify_rent_exemption(
account: &KeyedAccount,
rent_sysvar_account: &KeyedAccount,
) -> Result<(), InstructionError> {
if !from_keyed_account(rent_sysvar_account)?
.rent_calculator
.is_exempt(account.account.lamports, account.account.data.len())
{
Err(InstructionError::InsufficientFunds)
} else {
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;