Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit d3db821

Browse files
committed
Add tests
1 parent e6edb7c commit d3db821

File tree

3 files changed

+478
-12
lines changed

3 files changed

+478
-12
lines changed

core/src/banking_stage.rs

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use {
66
crate::{
77
forward_packet_batches_by_accounts::ForwardPacketBatchesByAccounts,
88
immutable_deserialized_packet::ImmutableDeserializedPacket,
9-
latest_unprocessed_votes::{self, DeserializedVotePacket, LatestUnprocessedVotes, VoteSource},
9+
latest_unprocessed_votes::{
10+
self, DeserializedVotePacket, LatestUnprocessedVotes, VoteSource,
11+
},
1012
leader_slot_banking_stage_metrics::{LeaderSlotMetricsTracker, ProcessTransactionsSummary},
1113
leader_slot_banking_stage_timing_metrics::{
1214
LeaderExecuteAndCommitTimings, RecordTransactionsTimings,
@@ -1234,14 +1236,12 @@ impl BankingStage {
12341236
bank_forks: &Arc<RwLock<BankForks>>,
12351237
) {
12361238
let forward_option = unprocessed_transaction_storage.forward_option();
1237-
// The gossip thread should not even reach this point
1238-
assert!(!matches!(forward_option, ForwardOption::NotForward));
12391239

12401240
// get current root bank from bank_forks, use it to sanitize transaction and
12411241
// load all accounts from address loader;
12421242
let current_bank = bank_forks.read().unwrap().root_bank();
12431243
let mut forward_packet_batches_by_accounts =
1244-
ForwardPacketBatchesByAccounts::new_with_default_batch_limits(current_bank.clone());
1244+
ForwardPacketBatchesByAccounts::new_with_default_batch_limits(current_bank);
12451245
let filter_forwarding_result = unprocessed_transaction_storage
12461246
.filter_forwardable_packets_and_add_batches(&mut forward_packet_batches_by_accounts);
12471247

@@ -2494,6 +2494,9 @@ mod tests {
24942494
},
24952495
solana_streamer::{recvmmsg::recv_mmsg, socket::SocketAddrSpace},
24962496
solana_transaction_status::{TransactionStatusMeta, VersionedTransactionWithStatusMeta},
2497+
solana_vote_program::{
2498+
vote_state::VoteStateUpdate, vote_transaction::new_vote_state_update_transaction,
2499+
},
24972500
std::{
24982501
borrow::Cow,
24992502
collections::HashSet,
@@ -4730,4 +4733,71 @@ mod tests {
47304733
BankingStage::filter_processed_packets(retryable_indexes.iter(), f);
47314734
assert_eq!(non_retryable_indexes, vec![(0, 1), (4, 5), (6, 8)]);
47324735
}
4736+
4737+
#[test]
4738+
fn test_unprocessed_transaction_storage_deserialize_and_insert() {
4739+
let keypair = Keypair::new();
4740+
let vote_keypair = Keypair::new();
4741+
let pubkey = solana_sdk::pubkey::new_rand();
4742+
4743+
let small_transfer = Packet::from_data(
4744+
None,
4745+
system_transaction::transfer(&keypair, &pubkey, 1, Hash::new_unique()),
4746+
)
4747+
.unwrap();
4748+
let mut vote = Packet::from_data(
4749+
None,
4750+
new_vote_state_update_transaction(
4751+
VoteStateUpdate::default(),
4752+
Hash::new_unique(),
4753+
&keypair,
4754+
&vote_keypair,
4755+
&vote_keypair,
4756+
None,
4757+
),
4758+
)
4759+
.unwrap();
4760+
vote.meta.flags.set(PacketFlags::SIMPLE_VOTE_TX, true);
4761+
let big_transfer = Packet::from_data(
4762+
None,
4763+
system_transaction::transfer(&keypair, &pubkey, 1000000, Hash::new_unique()),
4764+
)
4765+
.unwrap();
4766+
4767+
let packet_batch = PacketBatch::new(vec![
4768+
small_transfer.clone(),
4769+
vote.clone(),
4770+
big_transfer.clone(),
4771+
]);
4772+
4773+
for thread_type in [
4774+
ThreadType::Transactions,
4775+
ThreadType::Voting(VoteSource::Gossip),
4776+
ThreadType::Voting(VoteSource::Tpu),
4777+
] {
4778+
let mut transaction_storage = UnprocessedTransactionStorage::TransactionStorage(
4779+
UnprocessedPacketBatches::with_capacity(100),
4780+
thread_type,
4781+
);
4782+
transaction_storage
4783+
.deserialize_and_insert_batch(&packet_batch, &(0..3 as usize).collect_vec());
4784+
let deserialized_packets = transaction_storage
4785+
.iter()
4786+
.map(|packet| packet.immutable_section().original_packet().clone())
4787+
.collect_vec();
4788+
assert_eq!(3, deserialized_packets.len());
4789+
assert!(deserialized_packets.contains(&small_transfer));
4790+
assert!(deserialized_packets.contains(&vote));
4791+
assert!(deserialized_packets.contains(&big_transfer));
4792+
}
4793+
4794+
for vote_source in [VoteSource::Gossip, VoteSource::Tpu] {
4795+
let mut transaction_storage = UnprocessedTransactionStorage::VoteStorage(
4796+
Arc::new(LatestUnprocessedVotes::new()),
4797+
vote_source,
4798+
);
4799+
transaction_storage.deserialize_and_insert_batch(&packet_batch, &(0..3 as usize).collect_vec());
4800+
assert_eq!(1, transaction_storage.len());
4801+
}
4802+
}
47334803
}

0 commit comments

Comments
 (0)