-
Notifications
You must be signed in to change notification settings - Fork 378
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
Conversation
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>( |
There was a problem hiding this comment.
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.
Separating this out and making fields non-pub makes a follow-up change to use a single map simpler. |
} | ||
|
||
fn lock_readonly(&mut self, key: &Pubkey) { | ||
*self.readonly_locks.entry(*key).or_default() += 1; |
There was a problem hiding this comment.
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()
🎉
accounts-db/src/account_locks.rs
Outdated
for (key, writable) in keys.clone() { | ||
if writable { | ||
if !self.can_write_lock(key) { | ||
debug!("Writable account in use: {:?}", key); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accounts-db/src/account_locks.rs
Outdated
/// 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>( |
There was a problem hiding this comment.
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()"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Problem
AccountLocks
structure and functionalitySummary of Changes
AccountLocks
to its' own moduleFixes #