separate account locks validation from creating the locks (#28292)

This commit is contained in:
apfitzge 2022-10-07 12:23:18 -05:00 committed by GitHub
parent 50985f79a1
commit 3781c0668f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 7 deletions

View File

@ -199,13 +199,8 @@ impl SanitizedTransaction {
&self,
tx_account_lock_limit: usize,
) -> Result<TransactionAccountLocks> {
if self.message.has_duplicates() {
Err(TransactionError::AccountLoadedTwice)
} else if self.message.account_keys().len() > tx_account_lock_limit {
Err(TransactionError::TooManyAccountLocks)
} else {
Ok(self.get_account_locks_unchecked())
}
Self::validate_account_locks(self.message(), tx_account_lock_limit)?;
Ok(self.get_account_locks_unchecked())
}
/// Return the list of accounts that must be locked during processing this transaction.
@ -281,4 +276,18 @@ impl SanitizedTransaction {
}
Ok(())
}
/// Validate a transaction message against locked accounts
fn validate_account_locks(
message: &SanitizedMessage,
tx_account_lock_limit: usize,
) -> Result<()> {
if message.has_duplicates() {
Err(TransactionError::AccountLoadedTwice)
} else if message.account_keys().len() > tx_account_lock_limit {
Err(TransactionError::TooManyAccountLocks)
} else {
Ok(())
}
}
}