Code cleanup: In vote and stake processor (#23353)

* Enable benchmarks of vote processor.

* Inlines from_keyed_account() in stake instruction.
This commit is contained in:
Alexander Meißner 2022-02-25 21:05:05 +01:00 committed by GitHub
parent 0ad4757159
commit 569d531573
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 26 deletions

View File

@ -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<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)
}
@ -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)
);
}
}

View File

@ -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 =

View File

@ -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();