Inlines verify_rent_exemption() in vote processor. (#24146)

This commit is contained in:
Alexander Meißner 2022-04-06 22:13:06 +02:00 committed by GitHub
parent 2d1f27ed8e
commit 25304ce485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 17 deletions

View File

@ -8,11 +8,8 @@ use {
invoke_context::InvokeContext, sysvar_cache::get_sysvar_with_account_check, invoke_context::InvokeContext, sysvar_cache::get_sysvar_with_account_check,
}, },
solana_sdk::{ solana_sdk::{
feature_set, feature_set, instruction::InstructionError, keyed_account::keyed_account_at_index,
instruction::InstructionError,
keyed_account::{keyed_account_at_index, KeyedAccount},
program_utils::limited_deserialize, program_utils::limited_deserialize,
sysvar::rent::Rent,
}, },
}; };
@ -37,7 +34,9 @@ pub fn process_instruction(
match limited_deserialize(data)? { match limited_deserialize(data)? {
VoteInstruction::InitializeAccount(vote_init) => { VoteInstruction::InitializeAccount(vote_init) => {
let rent = get_sysvar_with_account_check::rent(invoke_context, instruction_context, 1)?; let rent = get_sysvar_with_account_check::rent(invoke_context, instruction_context, 1)?;
verify_rent_exemption(me, &rent)?; if !rent.is_exempt(me.lamports()?, me.data_len()?) {
return Err(InstructionError::InsufficientFunds);
}
let clock = let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?; get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?;
vote_state::initialize_account(me, &vote_init, &signers, &clock) vote_state::initialize_account(me, &vote_init, &signers, &clock)
@ -159,17 +158,6 @@ pub fn process_instruction(
} }
} }
fn verify_rent_exemption(
keyed_account: &KeyedAccount,
rent: &Rent,
) -> Result<(), InstructionError> {
if !rent.is_exempt(keyed_account.lamports()?, keyed_account.data_len()?) {
Err(InstructionError::InsufficientFunds)
} else {
Ok(())
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use { use {
@ -195,7 +183,7 @@ mod tests {
hash::Hash, hash::Hash,
instruction::{AccountMeta, Instruction}, instruction::{AccountMeta, Instruction},
pubkey::Pubkey, pubkey::Pubkey,
sysvar::{self, clock::Clock, slot_hashes::SlotHashes}, sysvar::{self, clock::Clock, rent::Rent, slot_hashes::SlotHashes},
}, },
std::{collections::HashSet, str::FromStr}, std::{collections::HashSet, str::FromStr},
}; };