From 569d531573b64cef0abff888b40a9b7f8d1095f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Fri, 25 Feb 2022 21:05:05 +0100 Subject: [PATCH] Code cleanup: In vote and stake processor (#23353) * Enable benchmarks of vote processor. * Inlines from_keyed_account() in stake instruction. --- programs/stake/src/config.rs | 15 +-------------- programs/stake/src/stake_instruction.rs | 18 ++++++++---------- programs/vote/benches/process_vote.rs | 2 -- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/programs/stake/src/config.rs b/programs/stake/src/config.rs index d5e48893d36320..a51e22fe4688f9 100644 --- a/programs/stake/src/config.rs +++ b/programs/stake/src/config.rs @@ -11,8 +11,6 @@ use { solana_sdk::{ account::{AccountSharedData, ReadableAccount, WritableAccount}, genesis_config::GenesisConfig, - instruction::InstructionError, - keyed_account::KeyedAccount, stake::config::{self, Config}, }, }; @@ -23,13 +21,6 @@ pub fn from(account: &T) -> Option { .and_then(|data| deserialize(data).ok()) } -pub fn from_keyed_account(account: &KeyedAccount) -> Result { - if !config::check_id(account.unsigned_key()) { - return Err(InstructionError::InvalidArgument); - } - from(&*account.try_account_ref()?).ok_or(InstructionError::InvalidArgument) -} - pub fn create_account(lamports: u64, config: &Config) -> AccountSharedData { create_config_account(vec![], config, lamports) } @@ -47,15 +38,11 @@ pub fn add_genesis_account(genesis_config: &mut GenesisConfig) -> u64 { #[cfg(test)] mod tests { - use {super::*, solana_sdk::pubkey::Pubkey, std::cell::RefCell}; + use {super::*, std::cell::RefCell}; #[test] fn test() { let account = RefCell::new(create_account(0, &Config::default())); assert_eq!(from(&account.borrow()), Some(Config::default())); - assert_eq!( - from_keyed_account(&KeyedAccount::new(&Pubkey::default(), false, &account)), - Err(InstructionError::InvalidArgument) - ); } } diff --git a/programs/stake/src/stake_instruction.rs b/programs/stake/src/stake_instruction.rs index b7c9ca34e6649e..315c3c5a792e31 100644 --- a/programs/stake/src/stake_instruction.rs +++ b/programs/stake/src/stake_instruction.rs @@ -133,16 +133,14 @@ pub fn process_instruction( keyed_account_at_index(keyed_accounts, first_instruction_account + 3)?, invoke_context, )?; - me.delegate( - vote, - &clock, - &stake_history, - &config::from_keyed_account(keyed_account_at_index( - keyed_accounts, - first_instruction_account + 4, - )?)?, - &signers, - ) + let config_account = + keyed_account_at_index(keyed_accounts, first_instruction_account + 4)?; + if !config::check_id(config_account.unsigned_key()) { + return Err(InstructionError::InvalidArgument); + } + let config = config::from(&*config_account.try_account_ref()?) + .ok_or(InstructionError::InvalidArgument)?; + me.delegate(vote, &clock, &stake_history, &config, &signers) } StakeInstruction::Split(lamports) => { let split_stake = diff --git a/programs/vote/benches/process_vote.rs b/programs/vote/benches/process_vote.rs index 61e6f759d90968..55e7f1166fde2e 100644 --- a/programs/vote/benches/process_vote.rs +++ b/programs/vote/benches/process_vote.rs @@ -122,7 +122,6 @@ fn bench_process_vote_instruction( } #[bench] -#[ignore] fn bench_process_vote(bencher: &mut Bencher) { let (num_initial_votes, slot_hashes, transaction_accounts, instruction_accounts) = create_accounts(); @@ -151,7 +150,6 @@ fn bench_process_vote(bencher: &mut Bencher) { } #[bench] -#[ignore] fn bench_process_vote_state_update(bencher: &mut Bencher) { let (num_initial_votes, slot_hashes, transaction_accounts, instruction_accounts) = create_accounts();