diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 9982dfb322..f0c07d2b60 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -9957,7 +9957,7 @@ pub mod tests { // Store an account let lamports = 42; let mut account = AccountSharedData::new(1, 0, &AccountSharedData::default().owner); - account.lamports = lamports; + account.set_lamports(lamports); db.store_uncached(slot, &[(&pubkey, &account)]); // Set the slot as a root so account loads will see the contents of this slot @@ -10032,7 +10032,7 @@ pub mod tests { // Store an account let lamports = 42; let mut account = AccountSharedData::new(1, 0, &AccountSharedData::default().owner); - account.lamports = lamports; + account.set_lamports(lamports); db.store_uncached(slot, &[(&pubkey, &account)]); let t_purge_slot = { diff --git a/runtime/src/message_processor.rs b/runtime/src/message_processor.rs index 9c747f642b..e0c8990dcd 100644 --- a/runtime/src/message_processor.rs +++ b/runtime/src/message_processor.rs @@ -1458,8 +1458,8 @@ mod tests { self } pub fn lamports(mut self, pre: u64, post: u64) -> Self { - self.pre.account.borrow_mut().lamports = pre; - self.post.lamports = post; + self.pre.account.borrow_mut().set_lamports(pre); + self.post.set_lamports(post); self } pub fn owner(mut self, post: &Pubkey) -> Self { diff --git a/sdk/src/nonce_keyed_account.rs b/sdk/src/nonce_keyed_account.rs index 30d14d2a1d..b9725bd996 100644 --- a/sdk/src/nonce_keyed_account.rs +++ b/sdk/src/nonce_keyed_account.rs @@ -1,6 +1,10 @@ use crate::{ - account_utils::State as AccountUtilsState, ic_msg, keyed_account::KeyedAccount, - nonce_account::create_account, process_instruction::InvokeContext, + account::{ReadableAccount, WritableAccount}, + account_utils::State as AccountUtilsState, + ic_msg, + keyed_account::KeyedAccount, + nonce_account::create_account, + process_instruction::InvokeContext, }; use solana_program::{ instruction::{checked_add, InstructionError}, @@ -153,14 +157,18 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> { return Err(InstructionError::MissingRequiredSignature); } - let nonce_balance = self.try_account_ref_mut()?.lamports; - self.try_account_ref_mut()?.lamports = nonce_balance - .checked_sub(lamports) - .ok_or(InstructionError::ArithmeticOverflow)?; - let to_balance = to.try_account_ref_mut()?.lamports; - to.try_account_ref_mut()?.lamports = to_balance - .checked_add(lamports) - .ok_or(InstructionError::ArithmeticOverflow)?; + let nonce_balance = self.try_account_ref_mut()?.lamports(); + self.try_account_ref_mut()?.set_lamports( + nonce_balance + .checked_sub(lamports) + .ok_or(InstructionError::ArithmeticOverflow)?, + ); + let to_balance = to.try_account_ref_mut()?.lamports(); + to.try_account_ref_mut()?.set_lamports( + to_balance + .checked_add(lamports) + .ok_or(InstructionError::ArithmeticOverflow)?, + ); Ok(()) }