Skip to content

Commit

Permalink
Code cleanup: In vote and stake processor (#23353)
Browse files Browse the repository at this point in the history
* Enable benchmarks of vote processor.

* Inlines from_keyed_account() in stake instruction.
  • Loading branch information
Lichtso authored Feb 25, 2022
1 parent 0ad4757 commit 569d531
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
15 changes: 1 addition & 14 deletions programs/stake/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use {
solana_sdk::{
account::{AccountSharedData, ReadableAccount, WritableAccount},
genesis_config::GenesisConfig,
instruction::InstructionError,
keyed_account::KeyedAccount,
stake::config::{self, Config},
},
};
Expand All @@ -23,13 +21,6 @@ pub fn from<T: ReadableAccount>(account: &T) -> Option<Config> {
.and_then(|data| deserialize(data).ok())
}

pub fn from_keyed_account(account: &KeyedAccount) -> Result<Config, InstructionError> {
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)
}
Expand All @@ -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)
);
}
}
18 changes: 8 additions & 10 deletions programs/stake/src/stake_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 0 additions & 2 deletions programs/vote/benches/process_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 569d531

Please sign in to comment.