Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unified_scheduler_logic: replace get_account_locks_unchecked #2554

Conversation

apfitzge
Copy link

Problem

  • validate_account_locks function got pulled into account_locks from sdk
  • following that change, get_account_locks and get_account_locks_unchecked will be deprecated
  • unified-scheduler-logic crate uses get_account_locks_unchecked

Summary of Changes

  • Replace use of get_account_locks_unchecked with more direct access

Fixes #

// 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();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get rid of 2 allocations here

.map(|(index, address)| {
LockContext::new(
usage_queue_loader(*address),
if message.is_writable(index) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iteration + call to is_writable is what get_account_locks_unchecked was doing anyway.
So would expect performance to be slightly better since we are removing allocation and an iteration without adding additional work.

@apfitzge apfitzge requested a review from ryoqun August 12, 2024 14:47
@apfitzge apfitzge marked this pull request as ready for review August 12, 2024 14:47
@apfitzge apfitzge self-assigned this Aug 12, 2024
Comment on lines 777 to 778
let message = transaction.message();
let lock_contexts = message
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: method chain can be extended further:

let lock_contexts = transaction
    .message()
    .account_keys()
    ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 775 to 776
// Locks are validated later in the pipeline. Here we create a task
// without checking that locks are valid.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact, checking locks must be done prior to enqueuing tasks. that's because SchedulingStateMachine will cause dead locks on the existence of non-unique UsageQeueues inside a given Task.

So, the original comment was wrong and misleading... Nevertheless, this comment has been serving as a reminder for me. how about retaining it while being updated like this?:

// It's crucial for tasks to be validated with
// `SanitizedTransaction::validate_account_locks()` prior to the creation.
// That's because it's part of protocol consensus regarding the rejection of
// blocks containing malformed transactions (`AccountLoadedTwice` and
// `TooManyAccountLocks`). Even more,`SchedulingStateMachine` can't properly
// handle transactions with duplicate addresses (those falling under
// `AccountLoadedTwice`).
//
// However, it's okay for now not to call `::validate_account_locks()` here. 
//
// Currently the replaying stage is always calling `get_account_locks()`
// regardless unified scheduler is enabled or not at the blockstore 
// (`Bank::prepare_sanitized_batch()` is called in `process_entries()`).
// This verification will be hoisted for optimization
// when removing `--block-verificatio-method=blockstore-processor`.
//
// As for banking stage with unified scheduler, it will need to run
// `.validate_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, to simplify the two code paths regarding the essential
// `validate_account_locks` validation.
//
// Lastly, `validate_account_locks()` is currently called in
// `DefaultTransactionHandler::handle()` via
// `Bank::prepare_unlocked_batch_from_single_tx()` as well.
// This redundancy is known. It was just left as-is out of abundance of caution.

(please reword and/or reformat as needed...)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@ryoqun ryoqun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. thanks for updating the comment.

(ci is failing partly due to test_scheduler_drop_short_circuiting.... sorry about that. I'll work on it soon.)

@apfitzge apfitzge merged commit fc208a0 into anza-xyz:master Aug 13, 2024
41 checks passed
@apfitzge apfitzge deleted the unified_scheduler_get_account_locks_unchecked branch August 13, 2024 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants