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

Commit 073d0bc

Browse files
committed
Add safety comment for get_account_locks_unchecked
1 parent 8eb98b2 commit 073d0bc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

runtime/src/bank.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4235,6 +4235,9 @@ impl Bank {
42354235
transaction: &'a SanitizedTransaction,
42364236
) -> TransactionBatch<'_, '_> {
42374237
let tx_account_lock_limit = self.get_transaction_account_lock_limit();
4238+
// Note that switching this to .get_account_locks_unchecked() is unacceptable currently.
4239+
// The unified scheduler relies on the checks enforced here.
4240+
// See a comment in SchedulingStateMachine::create_task().
42384241
let lock_result = transaction
42394242
.get_account_locks(tx_account_lock_limit)
42404243
.map(|_| ());

unified-scheduler-logic/src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,20 @@ impl SchedulingStateMachine {
657657
index: usize,
658658
page_loader: &mut impl FnMut(Pubkey) -> Page,
659659
) -> Task {
660-
// this is safe bla bla
660+
// Calling the _unchecked() version here is safe for faster operation, because
661+
// `get_account_locks()` (the safe variant) is ensured to be called in
662+
// DefaultTransactionHandler::handle() via Bank::prepare_unlocked_batch_from_single_tx().
663+
//
664+
// The safe variant has additional account-locking related verifications, which is crutial.
665+
//
666+
// Currently the replaying stage is redundantly calling `get_accont_locks()` when unified
667+
// scheduler is enabled on the given transaction at the blockstore. This will be relaxed
668+
// for optimization in the future. As for banking stage with unified scheduler, it will
669+
// need to run .get_account_locks() at least once somewhere in the code path. In the
670+
// distant future, this function `create_task()` should be adjusted so that both stages do
671+
// the checks before calling this (say, with some ad-hoc type like
672+
// `SanitizedTransactionWithCheckedAccountLocks`) or do the chccks here, resulting in
673+
// eliminating the redudant one in the replaying stage and in the handler.
661674
let locks = transaction.get_account_locks_unchecked();
662675

663676
let writable_locks = locks

0 commit comments

Comments
 (0)