Skip to content

Commit

Permalink
unified_scheduler_logic: replace get_account_locks_unchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Aug 12, 2024
1 parent 2f19326 commit bb4a4a2
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions unified-scheduler-logic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,35 +772,22 @@ impl SchedulingStateMachine {
index: usize,
usage_queue_loader: &mut impl FnMut(Pubkey) -> UsageQueue,
) -> Task {
// Calling the _unchecked() version here is safe for faster operation, because
// `get_account_locks()` (the safe variant) is ensured to be called in
// DefaultTransactionHandler::handle() via Bank::prepare_unlocked_batch_from_single_tx().
//
// The safe variant has additional account-locking related verifications, which is crucial.
//
// Currently the replaying stage is redundantly calling `get_account_locks()` when unified
// scheduler is enabled on the given transaction at the blockstore. This will be relaxed
// for optimization in the future. As for banking stage with unified scheduler, it will
// need to run .get_account_locks() at least once somewhere in the code path. In the
// distant future, this function `create_task()` should be adjusted so that both stages do
// the checks before calling this (say, with some ad-hoc type like
// `SanitizedTransactionWithCheckedAccountLocks`) or do the checks here, resulting in
// eliminating the redundant one in the replaying stage and in the handler.
let locks = transaction.get_account_locks_unchecked();

let writable_locks = locks
.writable
// Locks are validated later in the pipeline. Here we create a task
// without checking that locks are valid.
let message = transaction.message();
let lock_contexts = message
.account_keys()
.iter()
.map(|address| (address, RequestedUsage::Writable));
let readonly_locks = locks
.readonly
.iter()
.map(|address| (address, RequestedUsage::Readonly));

let lock_contexts = writable_locks
.chain(readonly_locks)
.map(|(address, requested_usage)| {
LockContext::new(usage_queue_loader(**address), requested_usage)
.enumerate()
.map(|(index, address)| {
LockContext::new(
usage_queue_loader(*address),
if message.is_writable(index) {
RequestedUsage::Writable
} else {
RequestedUsage::Readonly
},
)
})
.collect();

Expand Down

0 comments on commit bb4a4a2

Please sign in to comment.