solana_runtime/
bank_utils.rs

1use {
2    crate::{
3        bank::{Bank, TransactionResults},
4        genesis_utils::{self, GenesisConfigInfo, ValidatorVoteKeypairs},
5        vote_parser,
6        vote_sender_types::ReplayVoteSender,
7    },
8    solana_sdk::{pubkey::Pubkey, signature::Signer, transaction::SanitizedTransaction},
9};
10
11pub fn setup_bank_and_vote_pubkeys_for_tests(
12    num_vote_accounts: usize,
13    stake: u64,
14) -> (Bank, Vec<Pubkey>) {
15    // Create some voters at genesis
16    let validator_voting_keypairs: Vec<_> = (0..num_vote_accounts)
17        .map(|_| ValidatorVoteKeypairs::new_rand())
18        .collect();
19
20    let vote_pubkeys: Vec<_> = validator_voting_keypairs
21        .iter()
22        .map(|k| k.vote_keypair.pubkey())
23        .collect();
24    let GenesisConfigInfo { genesis_config, .. } =
25        genesis_utils::create_genesis_config_with_vote_accounts(
26            10_000,
27            &validator_voting_keypairs,
28            vec![stake; validator_voting_keypairs.len()],
29        );
30    let bank = Bank::new_for_tests(&genesis_config);
31    (bank, vote_pubkeys)
32}
33
34pub fn find_and_send_votes(
35    sanitized_txs: &[SanitizedTransaction],
36    tx_results: &TransactionResults,
37    vote_sender: Option<&ReplayVoteSender>,
38) {
39    let TransactionResults {
40        execution_results, ..
41    } = tx_results;
42    if let Some(vote_sender) = vote_sender {
43        sanitized_txs
44            .iter()
45            .zip(execution_results.iter())
46            .for_each(|(tx, result)| {
47                if tx.is_simple_vote_transaction() && result.was_executed_successfully() {
48                    if let Some(parsed_vote) = vote_parser::parse_sanitized_vote_transaction(tx) {
49                        if parsed_vote.1.last_voted_slot().is_some() {
50                            let _ = vote_sender.send(parsed_vote);
51                        }
52                    }
53                }
54            });
55    }
56}