Readonlyaccounts (#16743)

* lamports -> lamports()

* format
This commit is contained in:
Jeff Washington (jwash)
2021-04-22 15:04:55 -05:00
committed by GitHub
parent 636b5987af
commit fc12841d95
9 changed files with 20 additions and 16 deletions

View File

@ -2495,8 +2495,8 @@ fn main() {
Sol(base_account.lamports), Sol(base_account.lamports),
Sol(warped_account.lamports), Sol(warped_account.lamports),
Sol(delta), Sol(delta),
((warped_account.lamports as f64) ((warped_account.lamports() as f64)
/ (base_account.lamports as f64) / (base_account.lamports() as f64)
* 100_f64) * 100_f64)
- 100_f64, - 100_f64,
detail, detail,

View File

@ -17,7 +17,7 @@ use dashmap::{
use log::*; use log::*;
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
use solana_sdk::{ use solana_sdk::{
account::{Account, AccountSharedData}, account::{Account, AccountSharedData, ReadableAccount},
account_utils::StateMut, account_utils::StateMut,
bpf_loader_upgradeable::{self, UpgradeableLoaderState}, bpf_loader_upgradeable::{self, UpgradeableLoaderState},
clock::{Slot, INITIAL_RENT_EPOCH}, clock::{Slot, INITIAL_RENT_EPOCH},
@ -456,7 +456,7 @@ impl Accounts {
account: AccountSharedData, account: AccountSharedData,
slot: Slot, slot: Slot,
) -> Option<(AccountSharedData, Slot)> { ) -> Option<(AccountSharedData, Slot)> {
if account.lamports > 0 { if account.lamports() > 0 {
Some((account, slot)) Some((account, slot))
} else { } else {
None None

View File

@ -4029,7 +4029,7 @@ impl Bank {
.minimum_balance(nonce::State::size()), .minimum_balance(nonce::State::size()),
_ => 0, _ => 0,
}; };
if lamports + min_balance > account.lamports { if lamports + min_balance > account.lamports() {
return Err(TransactionError::InsufficientFundsForFee); return Err(TransactionError::InsufficientFundsForFee);
} }

View File

@ -125,13 +125,13 @@ impl PreAccount {
// An account not assigned to the program cannot have its balance decrease. // An account not assigned to the program cannot have its balance decrease.
if *program_id != pre.owner // line coverage used to get branch coverage if *program_id != pre.owner // line coverage used to get branch coverage
&& pre.lamports > post.lamports && pre.lamports() > post.lamports
{ {
return Err(InstructionError::ExternalAccountLamportSpend); return Err(InstructionError::ExternalAccountLamportSpend);
} }
// The balance of read-only and executable accounts may not change // 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 lamports_changed {
if !is_writable { if !is_writable {
return Err(InstructionError::ReadonlyLamportChange); return Err(InstructionError::ReadonlyLamportChange);
@ -1979,7 +1979,7 @@ mod tests {
MockSystemInstruction::BorrowFail => { MockSystemInstruction::BorrowFail => {
let from_account = keyed_accounts[0].try_account_ref_mut()?; let from_account = keyed_accounts[0].try_account_ref_mut()?;
let dup_account = keyed_accounts[2].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); return Err(InstructionError::InvalidArgument);
} }
Ok(()) Ok(())

View File

@ -84,7 +84,7 @@ impl RentCollector {
.due(account.lamports, account.data().len(), years_elapsed); .due(account.lamports, account.data().len(), years_elapsed);
if exempt || rent_due != 0 { if exempt || rent_due != 0 {
if account.lamports > rent_due { if account.lamports() > rent_due {
account.rent_epoch = self.epoch account.rent_epoch = self.epoch
+ if exempt { + if exempt {
// Rent isn't collected for the next epoch // Rent isn't collected for the next epoch
@ -158,7 +158,7 @@ mod tests {
assert_ne!(existing_account.rent_epoch, old_epoch); assert_ne!(existing_account.rent_epoch, old_epoch);
// newly created account should be collected for less rent; thus more remaining balance // 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); assert_eq!(created_account.rent_epoch, existing_account.rent_epoch);
} }

View File

@ -129,7 +129,7 @@ impl Stakes {
let old = self.vote_accounts.remove(pubkey); let old = self.vote_accounts.remove(pubkey);
// when account is removed (lamports == 0 or data uninitialized), don't read so that // 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. // 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())) && !(check_vote_init && VoteState::is_uninitialized_no_deser(&account.data()))
{ {
let stake = old.as_ref().map_or_else( let stake = old.as_ref().map_or_else(
@ -162,7 +162,7 @@ impl Stakes {
let stake = delegation.map(|delegation| { let stake = delegation.map(|delegation| {
( (
delegation.voter_pubkey, delegation.voter_pubkey,
if account.lamports != 0 { if account.lamports() != 0 {
delegation.stake( delegation.stake(
self.epoch, self.epoch,
Some(&self.stake_history), Some(&self.stake_history),

View File

@ -155,7 +155,7 @@ fn create_account(
// if it looks like the `to` account is already in use, bail // if it looks like the `to` account is already in use, bail
{ {
let to = &mut to.try_account_ref_mut()?; let to = &mut to.try_account_ref_mut()?;
if to.lamports > 0 { if to.lamports() > 0 {
ic_msg!( ic_msg!(
invoke_context, invoke_context,
"Create Account: account {:?} already in use", "Create Account: account {:?} already in use",

View File

@ -36,7 +36,7 @@ impl<'a> KeyedAccount<'a> {
} }
pub fn lamports(&self) -> Result<u64, InstructionError> { pub fn lamports(&self) -> Result<u64, InstructionError> {
Ok(self.try_borrow()?.lamports) Ok(self.try_borrow()?.lamports())
} }
pub fn data_len(&self) -> Result<usize, InstructionError> { pub fn data_len(&self) -> Result<usize, InstructionError> {

View File

@ -267,6 +267,7 @@ where
mod test { mod test {
use super::*; use super::*;
use crate::{ use crate::{
account::ReadableAccount,
account_utils::State as AccountUtilsState, account_utils::State as AccountUtilsState,
keyed_account::KeyedAccount, keyed_account::KeyedAccount,
nonce::{self, State}, nonce::{self, State},
@ -610,9 +611,12 @@ mod test {
// Deinitializes Account state // Deinitializes Account state
assert_eq!(state, State::Uninitialized); assert_eq!(state, State::Uninitialized);
// Empties Account balance // 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` // 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);
}) })
}) })
} }