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

Separate AccountLocks + Refactor #2390

Merged
merged 8 commits into from
Aug 5, 2024

Conversation

apfitzge
Copy link

@apfitzge apfitzge commented Aug 1, 2024

Problem

  • Have been doing incremental improvements to AccountLocks structure and functionality

Summary of Changes

  • Move AccountLocks to its' own module
  • Refactor/rename top-level functions
  • Add testing of only account locks structure

Fixes #

Comment on lines -564 to -592
fn lock_account<'a>(
&self,
account_locks: &mut AccountLocks,
keys: impl Iterator<Item = (&'a Pubkey, bool)> + Clone,
) -> Result<()> {
for (k, writable) in keys.clone() {
if writable {
if account_locks.is_locked_write(k) || account_locks.is_locked_readonly(k) {
debug!("Writable account in use: {:?}", k);
return Err(TransactionError::AccountInUse);
}
} else if account_locks.is_locked_write(k) {
debug!("Read-only account in use: {:?}", k);
return Err(TransactionError::AccountInUse);
}
}

for (k, writable) in keys {
if writable {
account_locks.write_locks.insert(*k);
} else if !account_locks.lock_readonly(k) {
account_locks.insert_new_readonly(k);
}
}

Ok(())
}

fn unlock_account<'a>(
Copy link
Author

Choose a reason for hiding this comment

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

these functions used to be on Accounts but don't even use self.
They are no on the AccountLocks struct directly.

@apfitzge
Copy link
Author

apfitzge commented Aug 1, 2024

Separating this out and making fields non-pub makes a follow-up change to use a single map simpler.
That change will reduce the number of pubkey hashes we need to do.

@apfitzge apfitzge changed the title Move AccountLocks to separate module Separate AccountLocks + Refactor Aug 1, 2024
@apfitzge apfitzge self-assigned this Aug 1, 2024
@apfitzge apfitzge marked this pull request as ready for review August 1, 2024 18:12
}

fn lock_readonly(&mut self, key: &Pubkey) {
*self.readonly_locks.entry(*key).or_default() += 1;

Choose a reason for hiding this comment

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

this is much better than if !lock_readonly() then insert_new_readonly() 🎉

for (key, writable) in keys.clone() {
if writable {
if !self.can_write_lock(key) {
debug!("Writable account in use: {:?}", key);

Choose a reason for hiding this comment

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

nit: maybe remove this debug line, doubt it is monitored at all.

Copy link
Author

Choose a reason for hiding this comment

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

/// The bool in the tuple indicates if the account is writable.
/// Returns an error if any of the accounts are already locked in a way
/// that conflicts with the requested lock.
pub fn try_lock_accounts_for_transaction<'a>(

Choose a reason for hiding this comment

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

nitpick on naming: the function say do something "_for_transaction", but there is no transaction in parameter list, only account keys. So maybe just "try_lock_accounts()"?

Copy link
Author

Choose a reason for hiding this comment

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

@apfitzge apfitzge requested a review from tao-stones August 2, 2024 20:24
Copy link

@tao-stones tao-stones left a comment

Choose a reason for hiding this comment

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

lgtm

@apfitzge apfitzge merged commit d0027dd into anza-xyz:master Aug 5, 2024
42 checks passed
@apfitzge apfitzge deleted the separate_account_locks branch August 5, 2024 15:15
ray-kast pushed a commit to abklabs/agave that referenced this pull request Nov 27, 2024
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