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:
parent
0ad4757159
commit
569d531573
|
@ -11,8 +11,6 @@ use {
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::{AccountSharedData, ReadableAccount, WritableAccount},
|
account::{AccountSharedData, ReadableAccount, WritableAccount},
|
||||||
genesis_config::GenesisConfig,
|
genesis_config::GenesisConfig,
|
||||||
instruction::InstructionError,
|
|
||||||
keyed_account::KeyedAccount,
|
|
||||||
stake::config::{self, Config},
|
stake::config::{self, Config},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -23,13 +21,6 @@ pub fn from<T: ReadableAccount>(account: &T) -> Option<Config> {
|
||||||
.and_then(|data| deserialize(data).ok())
|
.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 {
|
pub fn create_account(lamports: u64, config: &Config) -> AccountSharedData {
|
||||||
create_config_account(vec![], config, lamports)
|
create_config_account(vec![], config, lamports)
|
||||||
}
|
}
|
||||||
|
@ -47,15 +38,11 @@ pub fn add_genesis_account(genesis_config: &mut GenesisConfig) -> u64 {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use {super::*, solana_sdk::pubkey::Pubkey, std::cell::RefCell};
|
use {super::*, std::cell::RefCell};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test() {
|
fn test() {
|
||||||
let account = RefCell::new(create_account(0, &Config::default()));
|
let account = RefCell::new(create_account(0, &Config::default()));
|
||||||
assert_eq!(from(&account.borrow()), Some(Config::default()));
|
assert_eq!(from(&account.borrow()), Some(Config::default()));
|
||||||
assert_eq!(
|
|
||||||
from_keyed_account(&KeyedAccount::new(&Pubkey::default(), false, &account)),
|
|
||||||
Err(InstructionError::InvalidArgument)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,16 +133,14 @@ pub fn process_instruction(
|
||||||
keyed_account_at_index(keyed_accounts, first_instruction_account + 3)?,
|
keyed_account_at_index(keyed_accounts, first_instruction_account + 3)?,
|
||||||
invoke_context,
|
invoke_context,
|
||||||
)?;
|
)?;
|
||||||
me.delegate(
|
let config_account =
|
||||||
vote,
|
keyed_account_at_index(keyed_accounts, first_instruction_account + 4)?;
|
||||||
&clock,
|
if !config::check_id(config_account.unsigned_key()) {
|
||||||
&stake_history,
|
return Err(InstructionError::InvalidArgument);
|
||||||
&config::from_keyed_account(keyed_account_at_index(
|
}
|
||||||
keyed_accounts,
|
let config = config::from(&*config_account.try_account_ref()?)
|
||||||
first_instruction_account + 4,
|
.ok_or(InstructionError::InvalidArgument)?;
|
||||||
)?)?,
|
me.delegate(vote, &clock, &stake_history, &config, &signers)
|
||||||
&signers,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
StakeInstruction::Split(lamports) => {
|
StakeInstruction::Split(lamports) => {
|
||||||
let split_stake =
|
let split_stake =
|
||||||
|
|
|
@ -122,7 +122,6 @@ fn bench_process_vote_instruction(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
#[ignore]
|
|
||||||
fn bench_process_vote(bencher: &mut Bencher) {
|
fn bench_process_vote(bencher: &mut Bencher) {
|
||||||
let (num_initial_votes, slot_hashes, transaction_accounts, instruction_accounts) =
|
let (num_initial_votes, slot_hashes, transaction_accounts, instruction_accounts) =
|
||||||
create_accounts();
|
create_accounts();
|
||||||
|
@ -151,7 +150,6 @@ fn bench_process_vote(bencher: &mut Bencher) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
#[ignore]
|
|
||||||
fn bench_process_vote_state_update(bencher: &mut Bencher) {
|
fn bench_process_vote_state_update(bencher: &mut Bencher) {
|
||||||
let (num_initial_votes, slot_hashes, transaction_accounts, instruction_accounts) =
|
let (num_initial_votes, slot_hashes, transaction_accounts, instruction_accounts) =
|
||||||
create_accounts();
|
create_accounts();
|
||||||
|
|
Loading…
Reference in New Issue