diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 0b5d5a11a8..cae2f06c74 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -2495,8 +2495,8 @@ fn main() { Sol(base_account.lamports), Sol(warped_account.lamports), Sol(delta), - ((warped_account.lamports as f64) - / (base_account.lamports as f64) + ((warped_account.lamports() as f64) + / (base_account.lamports() as f64) * 100_f64) - 100_f64, detail, diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index d18d0c6f03..23eebac58b 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -17,7 +17,7 @@ use dashmap::{ use log::*; use rand::{thread_rng, Rng}; use solana_sdk::{ - account::{Account, AccountSharedData}, + account::{Account, AccountSharedData, ReadableAccount}, account_utils::StateMut, bpf_loader_upgradeable::{self, UpgradeableLoaderState}, clock::{Slot, INITIAL_RENT_EPOCH}, @@ -456,7 +456,7 @@ impl Accounts { account: AccountSharedData, slot: Slot, ) -> Option<(AccountSharedData, Slot)> { - if account.lamports > 0 { + if account.lamports() > 0 { Some((account, slot)) } else { None diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index cabbb6934a..37ed3b8513 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -4029,7 +4029,7 @@ impl Bank { .minimum_balance(nonce::State::size()), _ => 0, }; - if lamports + min_balance > account.lamports { + if lamports + min_balance > account.lamports() { return Err(TransactionError::InsufficientFundsForFee); } diff --git a/runtime/src/message_processor.rs b/runtime/src/message_processor.rs index e0c8990dcd..63bf43ec81 100644 --- a/runtime/src/message_processor.rs +++ b/runtime/src/message_processor.rs @@ -125,13 +125,13 @@ impl PreAccount { // An account not assigned to the program cannot have its balance decrease. if *program_id != pre.owner // line coverage used to get branch coverage - && pre.lamports > post.lamports + && pre.lamports() > post.lamports { return Err(InstructionError::ExternalAccountLamportSpend); } // The balance of read-only and executable accounts may not change - let lamports_changed = pre.lamports != post.lamports; + let lamports_changed = pre.lamports() != post.lamports; if lamports_changed { if !is_writable { return Err(InstructionError::ReadonlyLamportChange); @@ -1979,7 +1979,7 @@ mod tests { MockSystemInstruction::BorrowFail => { let from_account = keyed_accounts[0].try_account_ref_mut()?; let dup_account = keyed_accounts[2].try_account_ref_mut()?; - if from_account.lamports != dup_account.lamports { + if from_account.lamports() != dup_account.lamports() { return Err(InstructionError::InvalidArgument); } Ok(()) diff --git a/runtime/src/rent_collector.rs b/runtime/src/rent_collector.rs index 5434659c26..0a47502b6a 100644 --- a/runtime/src/rent_collector.rs +++ b/runtime/src/rent_collector.rs @@ -84,7 +84,7 @@ impl RentCollector { .due(account.lamports, account.data().len(), years_elapsed); if exempt || rent_due != 0 { - if account.lamports > rent_due { + if account.lamports() > rent_due { account.rent_epoch = self.epoch + if exempt { // Rent isn't collected for the next epoch @@ -158,7 +158,7 @@ mod tests { assert_ne!(existing_account.rent_epoch, old_epoch); // newly created account should be collected for less rent; thus more remaining balance - assert!(created_account.lamports > existing_account.lamports); + assert!(created_account.lamports() > existing_account.lamports); assert_eq!(created_account.rent_epoch, existing_account.rent_epoch); } diff --git a/runtime/src/stakes.rs b/runtime/src/stakes.rs index f43844abd5..532b521e7f 100644 --- a/runtime/src/stakes.rs +++ b/runtime/src/stakes.rs @@ -129,7 +129,7 @@ impl Stakes { let old = self.vote_accounts.remove(pubkey); // when account is removed (lamports == 0 or data uninitialized), don't read so that // given `pubkey` can be used for any owner in the future, while not affecting Stakes. - if account.lamports != 0 + if account.lamports() != 0 && !(check_vote_init && VoteState::is_uninitialized_no_deser(&account.data())) { let stake = old.as_ref().map_or_else( @@ -162,7 +162,7 @@ impl Stakes { let stake = delegation.map(|delegation| { ( delegation.voter_pubkey, - if account.lamports != 0 { + if account.lamports() != 0 { delegation.stake( self.epoch, Some(&self.stake_history), diff --git a/runtime/src/system_instruction_processor.rs b/runtime/src/system_instruction_processor.rs index 1a91b2837b..b38eb04b45 100644 --- a/runtime/src/system_instruction_processor.rs +++ b/runtime/src/system_instruction_processor.rs @@ -155,7 +155,7 @@ fn create_account( // if it looks like the `to` account is already in use, bail { let to = &mut to.try_account_ref_mut()?; - if to.lamports > 0 { + if to.lamports() > 0 { ic_msg!( invoke_context, "Create Account: account {:?} already in use", diff --git a/sdk/src/keyed_account.rs b/sdk/src/keyed_account.rs index 30e9eeb3ec..6e5c1e6dcf 100644 --- a/sdk/src/keyed_account.rs +++ b/sdk/src/keyed_account.rs @@ -36,7 +36,7 @@ impl<'a> KeyedAccount<'a> { } pub fn lamports(&self) -> Result { - Ok(self.try_borrow()?.lamports) + Ok(self.try_borrow()?.lamports()) } pub fn data_len(&self) -> Result { diff --git a/sdk/src/nonce_keyed_account.rs b/sdk/src/nonce_keyed_account.rs index b9725bd996..731b4c0d2a 100644 --- a/sdk/src/nonce_keyed_account.rs +++ b/sdk/src/nonce_keyed_account.rs @@ -267,6 +267,7 @@ where mod test { use super::*; use crate::{ + account::ReadableAccount, account_utils::State as AccountUtilsState, keyed_account::KeyedAccount, nonce::{self, State}, @@ -610,9 +611,12 @@ mod test { // Deinitializes Account state assert_eq!(state, State::Uninitialized); // Empties Account balance - assert_eq!(nonce_keyed.account.borrow().lamports, expect_nonce_lamports); + assert_eq!( + nonce_keyed.account.borrow().lamports(), + expect_nonce_lamports + ); // Account balance goes to `to` - assert_eq!(to_keyed.account.borrow().lamports, expect_to_lamports); + assert_eq!(to_keyed.account.borrow().lamports(), expect_to_lamports); }) }) }