Skip to content

Commit

Permalink
Use ReadWriteAccountSet
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Nov 17, 2022
1 parent e7814e8 commit ea7ed8b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 42 deletions.
2 changes: 1 addition & 1 deletion core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ impl BankingStage {

// Clear payload for next iteration
payload.sanitized_transactions.clear();
payload.write_accounts.clear();
payload.account_locks.clear();

let ProcessTransactionsSummary {
reached_max_poh_height,
Expand Down
52 changes: 11 additions & 41 deletions core/src/unprocessed_transaction_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use {
},
leader_slot_banking_stage_metrics::LeaderSlotMetricsTracker,
multi_iterator_scanner::{MultiIteratorScanner, ProcessingDecision},
read_write_account_set::ReadWriteAccountSet,
unprocessed_packet_batches::{
DeserializedPacket, PacketBatchInsertionMetrics, UnprocessedPacketBatches,
},
Expand All @@ -18,13 +19,10 @@ use {
solana_measure::measure,
solana_runtime::bank::Bank,
solana_sdk::{
clock::FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET, pubkey::Pubkey,
saturating_add_assign, transaction::SanitizedTransaction,
},
std::{
collections::HashSet,
sync::{atomic::Ordering, Arc},
clock::FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET, saturating_add_assign,
transaction::SanitizedTransaction,
},
std::sync::{atomic::Ordering, Arc},
};

// Step-size set to be 64, equal to the maximum batch/entry size. With the
Expand Down Expand Up @@ -131,7 +129,7 @@ fn filter_processed_packets<'a, F>(
/// multi-iterator checking function.
pub struct ConsumeScannerPayload<'a> {
pub reached_end_of_slot: bool,
pub write_accounts: HashSet<Pubkey>,
pub account_locks: ReadWriteAccountSet,
pub sanitized_transactions: Vec<SanitizedTransaction>,
pub slot_metrics_tracker: &'a mut LeaderSlotMetricsTracker,
}
Expand All @@ -149,17 +147,8 @@ fn consume_scan_should_process_packet(

// Before sanitization, let's quickly check the static keys (performance optimization)
let message = &packet.transaction().get_message().message;
let static_keys = message.static_account_keys();
for key in static_keys.iter().enumerate().filter_map(|(idx, key)| {
if message.is_maybe_writable(idx) {
Some(key)
} else {
None
}
}) {
if payload.write_accounts.contains(key) {
return ProcessingDecision::Later;
}
if !payload.account_locks.check_static_account_locks(message) {
return ProcessingDecision::Later;
}

// Try to deserialize the packet
Expand All @@ -177,30 +166,11 @@ fn consume_scan_should_process_packet(

if let Some(sanitized_transaction) = maybe_sanitized_transaction {
let message = sanitized_transaction.message();

let conflicts_with_batch = message.account_keys().iter().enumerate().any(|(idx, key)| {
if message.is_writable(idx) {
payload.write_accounts.contains(key)
} else {
false
}
});

if conflicts_with_batch {
ProcessingDecision::Later
} else {
message
.account_keys()
.iter()
.enumerate()
.for_each(|(idx, key)| {
if message.is_writable(idx) {
payload.write_accounts.insert(*key);
}
});

if payload.account_locks.try_locking(message) {
payload.sanitized_transactions.push(sanitized_transaction);
ProcessingDecision::Now
} else {
ProcessingDecision::Later
}
} else {
ProcessingDecision::Never
Expand All @@ -221,7 +191,7 @@ where
{
let payload = ConsumeScannerPayload {
reached_end_of_slot: false,
write_accounts: HashSet::new(),
account_locks: ReadWriteAccountSet::default(),
sanitized_transactions: Vec::with_capacity(UNPROCESSED_BUFFER_STEP_SIZE),
slot_metrics_tracker,
};
Expand Down

0 comments on commit ea7ed8b

Please sign in to comment.