solana_runtime/
bank_utils.rs1use {
2 crate::vote_sender_types::ReplayVoteSender,
3 solana_runtime_transaction::transaction_with_meta::TransactionWithMeta,
4 solana_svm::transaction_commit_result::{
5 TransactionCommitResult, TransactionCommitResultExtensions,
6 },
7 solana_vote::vote_parser,
8};
9#[cfg(feature = "dev-context-only-utils")]
10use {
11 crate::{
12 bank::Bank,
13 genesis_utils::{self, GenesisConfigInfo, ValidatorVoteKeypairs},
14 },
15 solana_sdk::{pubkey::Pubkey, signature::Signer},
16};
17
18#[cfg(feature = "dev-context-only-utils")]
19pub fn setup_bank_and_vote_pubkeys_for_tests(
20 num_vote_accounts: usize,
21 stake: u64,
22) -> (Bank, Vec<Pubkey>) {
23 let validator_voting_keypairs: Vec<_> = (0..num_vote_accounts)
25 .map(|_| ValidatorVoteKeypairs::new_rand())
26 .collect();
27
28 let vote_pubkeys: Vec<_> = validator_voting_keypairs
29 .iter()
30 .map(|k| k.vote_keypair.pubkey())
31 .collect();
32 let GenesisConfigInfo { genesis_config, .. } =
33 genesis_utils::create_genesis_config_with_vote_accounts(
34 10_000,
35 &validator_voting_keypairs,
36 vec![stake; validator_voting_keypairs.len()],
37 );
38 let bank = Bank::new_for_tests(&genesis_config);
39 (bank, vote_pubkeys)
40}
41
42pub fn find_and_send_votes(
43 sanitized_txs: &[impl TransactionWithMeta],
44 commit_results: &[TransactionCommitResult],
45 vote_sender: Option<&ReplayVoteSender>,
46) {
47 if let Some(vote_sender) = vote_sender {
48 sanitized_txs
49 .iter()
50 .zip(commit_results.iter())
51 .for_each(|(tx, commit_result)| {
52 if tx.is_simple_vote_transaction() && commit_result.was_executed_successfully() {
53 if let Some(parsed_vote) = vote_parser::parse_sanitized_vote_transaction(tx) {
54 if parsed_vote.1.last_voted_slot().is_some() {
55 let _ = vote_sender.send(parsed_vote);
56 }
57 }
58 }
59 });
60 }
61}