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_pubkey::Pubkey,
16 solana_signer::Signer,
17};
18
19#[cfg(feature = "dev-context-only-utils")]
20pub fn setup_bank_and_vote_pubkeys_for_tests(
21 num_vote_accounts: usize,
22 stake: u64,
23) -> (Bank, Vec<Pubkey>) {
24 let validator_voting_keypairs: Vec<_> = (0..num_vote_accounts)
26 .map(|_| ValidatorVoteKeypairs::new_rand())
27 .collect();
28
29 let vote_pubkeys: Vec<_> = validator_voting_keypairs
30 .iter()
31 .map(|k| k.vote_keypair.pubkey())
32 .collect();
33 let GenesisConfigInfo { genesis_config, .. } =
34 genesis_utils::create_genesis_config_with_vote_accounts(
35 10_000,
36 &validator_voting_keypairs,
37 vec![stake; validator_voting_keypairs.len()],
38 );
39 let bank = Bank::new_for_tests(&genesis_config);
40 (bank, vote_pubkeys)
41}
42
43pub fn find_and_send_votes(
44 sanitized_txs: &[impl TransactionWithMeta],
45 commit_results: &[TransactionCommitResult],
46 vote_sender: Option<&ReplayVoteSender>,
47) {
48 if let Some(vote_sender) = vote_sender {
49 sanitized_txs
50 .iter()
51 .zip(commit_results.iter())
52 .for_each(|(tx, commit_result)| {
53 if tx.is_simple_vote_transaction() && commit_result.was_executed_successfully() {
54 if let Some(parsed_vote) = vote_parser::parse_sanitized_vote_transaction(tx) {
55 if parsed_vote.1.last_voted_slot().is_some() {
56 let _ = vote_sender.send(parsed_vote);
57 }
58 }
59 }
60 });
61 }
62}