Credit-Only Accounts: Cache account balance for thread-safe load/store (#4691)
* Implement CreditOnlyLocks * Update credit-only atomic on account load * Update credit-only atomic after bank.freeze_lock; store credits if all credit-only lock references are dropped * Commit credit-only credits on bank freeze * Update core to CreditAccountLocks * Impl credit-only in System Transfer * Rework CreditAccountLocks, test, and fix bugs * Review comments: Pass CreditAccountLocks by reference; Tighten up insert block * Only store credits on completed slot * Check balance in bench_exchange funding to ensure commit_credits has completed * Add is_debitable info to KeyedAccount meta to pass into programs * Reinstate CreditOnlyLocks check on lock_account * Rework CreditAccountLocks to remove strong_count usage * Add multi-threaded credit-only locks test * Improve RwLocks usage * Review comments: panic if bad things happen; tighter code * Assert lock_accounts race does not happen * Revert panic if bad things happen; not a bad thing
This commit is contained in:
@ -311,7 +311,7 @@ mod tests {
|
||||
let mut to_account = Account::new(1, 0, &Pubkey::new(&[3; 32])); // account owner should not matter
|
||||
let mut keyed_accounts = [
|
||||
KeyedAccount::new(&from, true, &mut from_account),
|
||||
KeyedAccount::new(&to, false, &mut to_account),
|
||||
KeyedAccount::new_credit_only(&to, false, &mut to_account),
|
||||
];
|
||||
transfer_lamports(&mut keyed_accounts, 50).unwrap();
|
||||
let from_lamports = from_account.lamports;
|
||||
@ -322,7 +322,7 @@ mod tests {
|
||||
// Attempt to move more lamports than remaining in from_account
|
||||
keyed_accounts = [
|
||||
KeyedAccount::new(&from, true, &mut from_account),
|
||||
KeyedAccount::new(&to, false, &mut to_account),
|
||||
KeyedAccount::new_credit_only(&to, false, &mut to_account),
|
||||
];
|
||||
let result = transfer_lamports(&mut keyed_accounts, 100);
|
||||
assert_eq!(result, Err(SystemError::ResultWithNegativeLamports));
|
||||
|
Reference in New Issue
Block a user