Skip to content

Commit

Permalink
Demote write locks on transaction program ids (#19593)
Browse files Browse the repository at this point in the history
* Add feature

* Demote write lock on program ids

* Fixup bpf tests

* Update MappedMessage::is_writable

* Comma nit

* Review comments

(cherry picked from commit decec3c)

# Conflicts:
#	core/src/banking_stage.rs
#	core/src/cost_model.rs
#	core/src/cost_tracker.rs
#	ledger-tool/src/main.rs
#	program-runtime/src/instruction_processor.rs
#	programs/bpf/tests/programs.rs
#	programs/bpf_loader/src/syscalls.rs
#	rpc/src/transaction_status_service.rs
#	runtime/src/accounts.rs
#	runtime/src/bank.rs
#	runtime/src/message_processor.rs
#	sdk/benches/serialize_instructions.rs
#	sdk/program/src/message/mapped.rs
#	sdk/program/src/message/sanitized.rs
#	sdk/src/transaction/sanitized.rs
  • Loading branch information
CriesofCarrots authored and mergify-bot committed Sep 4, 2021
1 parent c180f4c commit d40bb38
Show file tree
Hide file tree
Showing 20 changed files with 3,736 additions and 31 deletions.
2 changes: 1 addition & 1 deletion cli-output/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn format_account_mode(message: &Message, index: usize) -> String {
} else {
"-"
},
if message.is_writable(index) {
if message.is_writable(index, /*demote_program_write_locks=*/ true) {
"w" // comment for consistent rust fmt (no joking; lol)
} else {
"-"
Expand Down
91 changes: 91 additions & 0 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,19 @@ impl BankingStage {
msgs: &Packets,
transaction_indexes: &[usize],
libsecp256k1_0_5_upgrade_enabled: bool,
<<<<<<< HEAD
) -> (Vec<HashedTransaction<'static>>, Vec<usize>) {
transaction_indexes
=======
libsecp256k1_fail_on_bad_count: bool,
cost_tracker: &Arc<RwLock<CostTracker>>,
banking_stage_stats: &BankingStageStats,
demote_program_write_locks: bool,
) -> (Vec<SanitizedTransaction>, Vec<usize>, Vec<usize>) {
let mut retryable_transaction_packet_indexes: Vec<usize> = vec![];

let verified_transactions_with_packet_indexes: Vec<_> = transaction_indexes
>>>>>>> decec3cd8 (Demote write locks on transaction program ids (#19593))
.iter()
.filter_map(|tx_index| {
let p = &msgs.packets[*tx_index];
Expand All @@ -980,7 +991,44 @@ impl BankingStage {
tx_index,
))
})
<<<<<<< HEAD
.unzip()
=======
.collect();
banking_stage_stats.cost_tracker_check_count.fetch_add(
verified_transactions_with_packet_indexes.len(),
Ordering::Relaxed,
);

let mut cost_tracker_check_time = Measure::start("cost_tracker_check_time");
let (filtered_transactions, filter_transaction_packet_indexes) = {
let cost_tracker_readonly = cost_tracker.read().unwrap();
verified_transactions_with_packet_indexes
.into_iter()
.filter_map(|(tx, tx_index)| {
let result = cost_tracker_readonly
.would_transaction_fit(&tx, demote_program_write_locks);
if result.is_err() {
debug!("transaction {:?} would exceed limit: {:?}", tx, result);
retryable_transaction_packet_indexes.push(tx_index);
return None;
}
Some((tx, tx_index))
})
.unzip()
};
cost_tracker_check_time.stop();

banking_stage_stats
.cost_tracker_check_elapsed
.fetch_add(cost_tracker_check_time.as_us(), Ordering::Relaxed);

(
filtered_transactions,
filter_transaction_packet_indexes,
retryable_transaction_packet_indexes,
)
>>>>>>> decec3cd8 (Demote write locks on transaction program ids (#19593))
}

/// This function filters pending packets that are still valid
Expand Down Expand Up @@ -1033,11 +1081,24 @@ impl BankingStage {
banking_stage_stats: &BankingStageStats,
) -> (usize, usize, Vec<usize>) {
let mut packet_conversion_time = Measure::start("packet_conversion");
<<<<<<< HEAD
let (transactions, transaction_to_packet_indexes) = Self::transactions_from_packets(
msgs,
&packet_indexes,
bank.libsecp256k1_0_5_upgrade_enabled(),
);
=======
let (transactions, transaction_to_packet_indexes, retryable_packet_indexes) =
Self::transactions_from_packets(
msgs,
&packet_indexes,
bank.libsecp256k1_0_5_upgrade_enabled(),
bank.libsecp256k1_fail_on_bad_count(),
cost_tracker,
banking_stage_stats,
bank.demote_program_write_locks(),
);
>>>>>>> decec3cd8 (Demote write locks on transaction program ids (#19593))
packet_conversion_time.stop();

debug!(
Expand All @@ -1059,7 +1120,21 @@ impl BankingStage {
);
process_tx_time.stop();

<<<<<<< HEAD
let unprocessed_tx_count = unprocessed_tx_indexes.len();
=======
// applying cost of processed transactions to shared cost_tracker
let mut cost_tracking_time = Measure::start("cost_tracking_time");
transactions.iter().enumerate().for_each(|(index, tx)| {
if unprocessed_tx_indexes.iter().all(|&i| i != index) {
cost_tracker
.write()
.unwrap()
.add_transaction_cost(tx, bank.demote_program_write_locks());
}
});
cost_tracking_time.stop();
>>>>>>> decec3cd8 (Demote write locks on transaction program ids (#19593))

let mut filter_pending_packets_time = Measure::start("filter_pending_packets_time");
let filtered_unprocessed_packet_indexes = Self::filter_pending_packets_from_pending_txs(
Expand Down Expand Up @@ -1104,11 +1179,27 @@ impl BankingStage {
}
}

<<<<<<< HEAD
let (transactions, transaction_to_packet_indexes) = Self::transactions_from_packets(
msgs,
&transaction_indexes,
bank.libsecp256k1_0_5_upgrade_enabled(),
);
=======
let mut unprocessed_packet_conversion_time =
Measure::start("unprocessed_packet_conversion");
let (transactions, transaction_to_packet_indexes, retry_packet_indexes) =
Self::transactions_from_packets(
msgs,
transaction_indexes,
bank.libsecp256k1_0_5_upgrade_enabled(),
bank.libsecp256k1_fail_on_bad_count(),
cost_tracker,
banking_stage_stats,
bank.demote_program_write_locks(),
);
unprocessed_packet_conversion_time.stop();
>>>>>>> decec3cd8 (Demote write locks on transaction program ids (#19593))

let tx_count = transaction_to_packet_indexes.len();

Expand Down
Loading

0 comments on commit d40bb38

Please sign in to comment.