Account->AccountSharedData (#15691)
This commit is contained in:
committed by
GitHub
parent
61c7ce857e
commit
8a3135d17b
@ -11,7 +11,7 @@ use solana_runtime::{
|
||||
bank::*,
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account::AccountSharedData,
|
||||
genesis_config::{create_genesis_config, ClusterType},
|
||||
hash::Hash,
|
||||
pubkey::Pubkey,
|
||||
@ -27,7 +27,8 @@ use test::Bencher;
|
||||
fn deposit_many(bank: &Bank, pubkeys: &mut Vec<Pubkey>, num: usize) {
|
||||
for t in 0..num {
|
||||
let pubkey = solana_sdk::pubkey::new_rand();
|
||||
let account = Account::new((t + 1) as u64, 0, &Account::default().owner);
|
||||
let account =
|
||||
AccountSharedData::new((t + 1) as u64, 0, &AccountSharedData::default().owner);
|
||||
pubkeys.push(pubkey);
|
||||
assert!(bank.get_account(&pubkey).is_none());
|
||||
bank.deposit(&pubkey, (t + 1) as u64);
|
||||
@ -157,10 +158,11 @@ fn bench_delete_dependencies(bencher: &mut Bencher) {
|
||||
false,
|
||||
);
|
||||
let mut old_pubkey = Pubkey::default();
|
||||
let zero_account = Account::new(0, 0, &Account::default().owner);
|
||||
let zero_account = AccountSharedData::new(0, 0, &AccountSharedData::default().owner);
|
||||
for i in 0..1000 {
|
||||
let pubkey = solana_sdk::pubkey::new_rand();
|
||||
let account = Account::new((i + 1) as u64, 0, &Account::default().owner);
|
||||
let account =
|
||||
AccountSharedData::new((i + 1) as u64, 0, &AccountSharedData::default().owner);
|
||||
accounts.store_slow_uncached(i, &pubkey, &account);
|
||||
accounts.store_slow_uncached(i, &old_pubkey, &zero_account);
|
||||
old_pubkey = pubkey;
|
||||
@ -195,7 +197,7 @@ fn store_accounts_with_possible_contention<F: 'static>(
|
||||
(0..num_keys)
|
||||
.map(|_| {
|
||||
let pubkey = solana_sdk::pubkey::new_rand();
|
||||
let account = Account::new(1, 0, &Account::default().owner);
|
||||
let account = AccountSharedData::new(1, 0, &AccountSharedData::default().owner);
|
||||
accounts.store_slow_uncached(slot, &pubkey, &account);
|
||||
pubkey
|
||||
})
|
||||
@ -215,7 +217,7 @@ fn store_accounts_with_possible_contention<F: 'static>(
|
||||
|
||||
let num_new_keys = 1000;
|
||||
let new_accounts: Vec<_> = (0..num_new_keys)
|
||||
.map(|_| Account::new(1, 0, &Account::default().owner))
|
||||
.map(|_| AccountSharedData::new(1, 0, &AccountSharedData::default().owner))
|
||||
.collect();
|
||||
bencher.iter(|| {
|
||||
for account in &new_accounts {
|
||||
@ -247,7 +249,9 @@ fn bench_concurrent_read_write(bencher: &mut Bencher) {
|
||||
#[ignore]
|
||||
fn bench_concurrent_scan_write(bencher: &mut Bencher) {
|
||||
store_accounts_with_possible_contention("concurrent_scan_write", bencher, |accounts, _| loop {
|
||||
test::black_box(accounts.load_by_program(&HashMap::new(), &Account::default().owner));
|
||||
test::black_box(
|
||||
accounts.load_by_program(&HashMap::new(), &AccountSharedData::default().owner),
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
@ -301,7 +305,7 @@ fn bench_rwlock_hashmap_single_reader_with_n_writers(bencher: &mut Bencher) {
|
||||
})
|
||||
}
|
||||
|
||||
fn setup_bench_dashmap_iter() -> (Arc<Accounts>, DashMap<Pubkey, (Account, Hash)>) {
|
||||
fn setup_bench_dashmap_iter() -> (Arc<Accounts>, DashMap<Pubkey, (AccountSharedData, Hash)>) {
|
||||
let accounts = Arc::new(Accounts::new_with_config(
|
||||
vec![
|
||||
PathBuf::from(std::env::var("FARF_DIR").unwrap_or_else(|_| "farf".to_string()))
|
||||
@ -320,7 +324,7 @@ fn setup_bench_dashmap_iter() -> (Arc<Accounts>, DashMap<Pubkey, (Account, Hash)
|
||||
dashmap.insert(
|
||||
Pubkey::new_unique(),
|
||||
(
|
||||
Account::new(1, 0, &Account::default().owner),
|
||||
AccountSharedData::new(1, 0, &AccountSharedData::default().owner),
|
||||
Hash::new_unique(),
|
||||
),
|
||||
);
|
||||
|
@ -4,7 +4,7 @@ extern crate test;
|
||||
|
||||
use log::*;
|
||||
use solana_runtime::message_processor::{ExecuteDetailsTimings, PreAccount};
|
||||
use solana_sdk::{account::Account, pubkey, rent::Rent};
|
||||
use solana_sdk::{account::AccountSharedData, pubkey, rent::Rent};
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
@ -15,10 +15,10 @@ fn bench_verify_account_changes_data(bencher: &mut Bencher) {
|
||||
let non_owner = pubkey::new_rand();
|
||||
let pre = PreAccount::new(
|
||||
&pubkey::new_rand(),
|
||||
&Account::new(0, BUFSIZE, &owner),
|
||||
&AccountSharedData::new(0, BUFSIZE, &owner),
|
||||
false,
|
||||
);
|
||||
let post = Account::new(0, BUFSIZE, &owner);
|
||||
let post = AccountSharedData::new(0, BUFSIZE, &owner);
|
||||
assert_eq!(
|
||||
pre.verify(
|
||||
&owner,
|
||||
@ -52,7 +52,7 @@ fn bench_verify_account_changes_data(bencher: &mut Bencher) {
|
||||
|
||||
let pre = PreAccount::new(
|
||||
&pubkey::new_rand(),
|
||||
&Account::new(0, BUFSIZE, &owner),
|
||||
&AccountSharedData::new(0, BUFSIZE, &owner),
|
||||
false,
|
||||
);
|
||||
bencher.iter(|| {
|
||||
|
@ -16,7 +16,7 @@ use dashmap::{
|
||||
use log::*;
|
||||
use rand::{thread_rng, Rng};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account::AccountSharedData,
|
||||
account_utils::StateMut,
|
||||
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
||||
clock::Slot,
|
||||
@ -92,10 +92,10 @@ pub struct Accounts {
|
||||
}
|
||||
|
||||
// for the load instructions
|
||||
pub type TransactionAccounts = Vec<Account>;
|
||||
pub type TransactionAccountDeps = Vec<(Pubkey, Account)>;
|
||||
pub type TransactionAccounts = Vec<AccountSharedData>;
|
||||
pub type TransactionAccountDeps = Vec<(Pubkey, AccountSharedData)>;
|
||||
pub type TransactionRent = u64;
|
||||
pub type TransactionLoaders = Vec<Vec<(Pubkey, Account)>>;
|
||||
pub type TransactionLoaders = Vec<Vec<(Pubkey, AccountSharedData)>>;
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
pub struct LoadedTransaction {
|
||||
pub accounts: TransactionAccounts,
|
||||
@ -162,13 +162,13 @@ impl Accounts {
|
||||
false
|
||||
}
|
||||
|
||||
fn construct_instructions_account(message: &Message) -> Account {
|
||||
fn construct_instructions_account(message: &Message) -> AccountSharedData {
|
||||
let mut data = message.serialize_instructions();
|
||||
// add room for current instruction index.
|
||||
data.resize(data.len() + 2, 0);
|
||||
Account {
|
||||
AccountSharedData {
|
||||
data,
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
}
|
||||
}
|
||||
|
||||
@ -248,7 +248,7 @@ impl Accounts {
|
||||
}
|
||||
} else {
|
||||
// Fill in an empty account for the program slots.
|
||||
Account::default()
|
||||
AccountSharedData::default()
|
||||
};
|
||||
accounts.push(account);
|
||||
}
|
||||
@ -318,7 +318,7 @@ impl Accounts {
|
||||
ancestors: &Ancestors,
|
||||
program_id: &Pubkey,
|
||||
error_counters: &mut ErrorCounters,
|
||||
) -> Result<Vec<(Pubkey, Account)>> {
|
||||
) -> Result<Vec<(Pubkey, AccountSharedData)>> {
|
||||
let mut accounts = Vec::new();
|
||||
let mut depth = 0;
|
||||
let mut program_id = *program_id;
|
||||
@ -448,7 +448,11 @@ impl Accounts {
|
||||
}
|
||||
|
||||
/// Slow because lock is held for 1 operation instead of many
|
||||
pub fn load_slow(&self, ancestors: &Ancestors, pubkey: &Pubkey) -> Option<(Account, Slot)> {
|
||||
pub fn load_slow(
|
||||
&self,
|
||||
ancestors: &Ancestors,
|
||||
pubkey: &Pubkey,
|
||||
) -> Option<(AccountSharedData, Slot)> {
|
||||
let (account, slot) = self.accounts_db.load_slow(ancestors, pubkey)?;
|
||||
|
||||
if account.lamports > 0 {
|
||||
@ -512,7 +516,7 @@ impl Accounts {
|
||||
&self,
|
||||
slot: Slot,
|
||||
program_id: Option<&Pubkey>,
|
||||
) -> Vec<(Pubkey, Account)> {
|
||||
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||
self.scan_slot(slot, |stored_account| {
|
||||
let hit = match program_id {
|
||||
None => true,
|
||||
@ -611,9 +615,9 @@ impl Accounts {
|
||||
lamports > 0
|
||||
}
|
||||
|
||||
fn load_while_filtering<F: Fn(&Account) -> bool>(
|
||||
collector: &mut Vec<(Pubkey, Account)>,
|
||||
some_account_tuple: Option<(&Pubkey, Account, Slot)>,
|
||||
fn load_while_filtering<F: Fn(&AccountSharedData) -> bool>(
|
||||
collector: &mut Vec<(Pubkey, AccountSharedData)>,
|
||||
some_account_tuple: Option<(&Pubkey, AccountSharedData, Slot)>,
|
||||
filter: F,
|
||||
) {
|
||||
if let Some(mapped_account_tuple) = some_account_tuple
|
||||
@ -628,10 +632,10 @@ impl Accounts {
|
||||
&self,
|
||||
ancestors: &Ancestors,
|
||||
program_id: &Pubkey,
|
||||
) -> Vec<(Pubkey, Account)> {
|
||||
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||
self.accounts_db.scan_accounts(
|
||||
ancestors,
|
||||
|collector: &mut Vec<(Pubkey, Account)>, some_account_tuple| {
|
||||
|collector: &mut Vec<(Pubkey, AccountSharedData)>, some_account_tuple| {
|
||||
Self::load_while_filtering(collector, some_account_tuple, |account| {
|
||||
account.owner == *program_id
|
||||
})
|
||||
@ -639,15 +643,15 @@ impl Accounts {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn load_by_program_with_filter<F: Fn(&Account) -> bool>(
|
||||
pub fn load_by_program_with_filter<F: Fn(&AccountSharedData) -> bool>(
|
||||
&self,
|
||||
ancestors: &Ancestors,
|
||||
program_id: &Pubkey,
|
||||
filter: F,
|
||||
) -> Vec<(Pubkey, Account)> {
|
||||
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||
self.accounts_db.scan_accounts(
|
||||
ancestors,
|
||||
|collector: &mut Vec<(Pubkey, Account)>, some_account_tuple| {
|
||||
|collector: &mut Vec<(Pubkey, AccountSharedData)>, some_account_tuple| {
|
||||
Self::load_while_filtering(collector, some_account_tuple, |account| {
|
||||
account.owner == *program_id && filter(account)
|
||||
})
|
||||
@ -655,25 +659,25 @@ impl Accounts {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn load_by_index_key_with_filter<F: Fn(&Account) -> bool>(
|
||||
pub fn load_by_index_key_with_filter<F: Fn(&AccountSharedData) -> bool>(
|
||||
&self,
|
||||
ancestors: &Ancestors,
|
||||
index_key: &IndexKey,
|
||||
filter: F,
|
||||
) -> Vec<(Pubkey, Account)> {
|
||||
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||
self.accounts_db.index_scan_accounts(
|
||||
ancestors,
|
||||
*index_key,
|
||||
|collector: &mut Vec<(Pubkey, Account)>, some_account_tuple| {
|
||||
|collector: &mut Vec<(Pubkey, AccountSharedData)>, some_account_tuple| {
|
||||
Self::load_while_filtering(collector, some_account_tuple, |account| filter(account))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn load_all(&self, ancestors: &Ancestors) -> Vec<(Pubkey, Account, Slot)> {
|
||||
pub fn load_all(&self, ancestors: &Ancestors) -> Vec<(Pubkey, AccountSharedData, Slot)> {
|
||||
self.accounts_db.scan_accounts(
|
||||
ancestors,
|
||||
|collector: &mut Vec<(Pubkey, Account, Slot)>, some_account_tuple| {
|
||||
|collector: &mut Vec<(Pubkey, AccountSharedData, Slot)>, some_account_tuple| {
|
||||
if let Some((pubkey, account, slot)) =
|
||||
some_account_tuple.filter(|(_, account, _)| Self::is_loadable(account.lamports))
|
||||
{
|
||||
@ -687,12 +691,12 @@ impl Accounts {
|
||||
&self,
|
||||
ancestors: &Ancestors,
|
||||
range: R,
|
||||
) -> Vec<(Pubkey, Account)> {
|
||||
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||
self.accounts_db.range_scan_accounts(
|
||||
"load_to_collect_rent_eagerly_scan_elapsed",
|
||||
ancestors,
|
||||
range,
|
||||
|collector: &mut Vec<(Pubkey, Account)>, option| {
|
||||
|collector: &mut Vec<(Pubkey, AccountSharedData)>, option| {
|
||||
Self::load_while_filtering(collector, option, |_| true)
|
||||
},
|
||||
)
|
||||
@ -701,11 +705,11 @@ impl Accounts {
|
||||
/// Slow because lock is held for 1 operation instead of many.
|
||||
/// WARNING: This noncached version is only to be used for tests/benchmarking
|
||||
/// as bypassing the cache in general is not supported
|
||||
pub fn store_slow_uncached(&self, slot: Slot, pubkey: &Pubkey, account: &Account) {
|
||||
pub fn store_slow_uncached(&self, slot: Slot, pubkey: &Pubkey, account: &AccountSharedData) {
|
||||
self.accounts_db.store_uncached(slot, &[(pubkey, account)]);
|
||||
}
|
||||
|
||||
pub fn store_slow_cached(&self, slot: Slot, pubkey: &Pubkey, account: &Account) {
|
||||
pub fn store_slow_cached(&self, slot: Slot, pubkey: &Pubkey, account: &AccountSharedData) {
|
||||
self.accounts_db.store_cached(slot, &[(pubkey, account)]);
|
||||
}
|
||||
|
||||
@ -865,7 +869,7 @@ impl Accounts {
|
||||
rent_collector: &RentCollector,
|
||||
last_blockhash_with_fee_calculator: &(Hash, FeeCalculator),
|
||||
fix_recent_blockhashes_sysvar_delay: bool,
|
||||
) -> Vec<(&'a Pubkey, &'a Account)> {
|
||||
) -> Vec<(&'a Pubkey, &'a AccountSharedData)> {
|
||||
let mut accounts = Vec::with_capacity(loaded.len());
|
||||
for (i, ((raccs, _nonce_rollback), (_, tx))) in loaded
|
||||
.iter_mut()
|
||||
@ -945,10 +949,10 @@ impl Accounts {
|
||||
}
|
||||
|
||||
pub fn prepare_if_nonce_account(
|
||||
account: &mut Account,
|
||||
account: &mut AccountSharedData,
|
||||
account_pubkey: &Pubkey,
|
||||
tx_result: &Result<()>,
|
||||
maybe_nonce_rollback: Option<(&Pubkey, &Account, Option<&Account>)>,
|
||||
maybe_nonce_rollback: Option<(&Pubkey, &AccountSharedData, Option<&AccountSharedData>)>,
|
||||
last_blockhash_with_fee_calculator: &(Hash, FeeCalculator),
|
||||
fix_recent_blockhashes_sysvar_delay: bool,
|
||||
) -> bool {
|
||||
@ -994,7 +998,8 @@ pub fn create_test_accounts(
|
||||
) {
|
||||
for t in 0..num {
|
||||
let pubkey = solana_sdk::pubkey::new_rand();
|
||||
let account = Account::new((t + 1) as u64, 0, &Account::default().owner);
|
||||
let account =
|
||||
AccountSharedData::new((t + 1) as u64, 0, &AccountSharedData::default().owner);
|
||||
accounts.store_slow_uncached(slot, &pubkey, &account);
|
||||
pubkeys.push(pubkey);
|
||||
}
|
||||
@ -1005,7 +1010,7 @@ pub fn create_test_accounts(
|
||||
pub fn update_accounts_bench(accounts: &Accounts, pubkeys: &[Pubkey], slot: u64) {
|
||||
for pubkey in pubkeys {
|
||||
let amount = thread_rng().gen_range(0, 10);
|
||||
let account = Account::new(amount, 0, &Account::default().owner);
|
||||
let account = AccountSharedData::new(amount, 0, &AccountSharedData::default().owner);
|
||||
accounts.store_slow_uncached(slot, &pubkey, &account);
|
||||
}
|
||||
}
|
||||
@ -1015,7 +1020,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::rent_collector::RentCollector;
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account::AccountSharedData,
|
||||
epoch_schedule::EpochSchedule,
|
||||
fee_calculator::FeeCalculator,
|
||||
genesis_config::ClusterType,
|
||||
@ -1034,7 +1039,7 @@ mod tests {
|
||||
|
||||
fn load_accounts_with_fee_and_rent(
|
||||
tx: Transaction,
|
||||
ka: &[(Pubkey, Account)],
|
||||
ka: &[(Pubkey, AccountSharedData)],
|
||||
fee_calculator: &FeeCalculator,
|
||||
rent_collector: &RentCollector,
|
||||
error_counters: &mut ErrorCounters,
|
||||
@ -1062,7 +1067,7 @@ mod tests {
|
||||
|
||||
fn load_accounts_with_fee(
|
||||
tx: Transaction,
|
||||
ka: &[(Pubkey, Account)],
|
||||
ka: &[(Pubkey, AccountSharedData)],
|
||||
fee_calculator: &FeeCalculator,
|
||||
error_counters: &mut ErrorCounters,
|
||||
) -> Vec<TransactionLoadResult> {
|
||||
@ -1072,7 +1077,7 @@ mod tests {
|
||||
|
||||
fn load_accounts(
|
||||
tx: Transaction,
|
||||
ka: &[(Pubkey, Account)],
|
||||
ka: &[(Pubkey, AccountSharedData)],
|
||||
error_counters: &mut ErrorCounters,
|
||||
) -> Vec<TransactionLoadResult> {
|
||||
let fee_calculator = FeeCalculator::default();
|
||||
@ -1081,7 +1086,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_no_key() {
|
||||
let accounts: Vec<(Pubkey, Account)> = Vec::new();
|
||||
let accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let instructions = vec![CompiledInstruction::new(0, &(), vec![0])];
|
||||
@ -1105,7 +1110,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_no_account_0_exists() {
|
||||
let accounts: Vec<(Pubkey, Account)> = Vec::new();
|
||||
let accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
@ -1131,17 +1136,17 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_unknown_program_id() {
|
||||
let mut accounts: Vec<(Pubkey, Account)> = Vec::new();
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
let key0 = keypair.pubkey();
|
||||
let key1 = Pubkey::new(&[5u8; 32]);
|
||||
|
||||
let account = Account::new(1, 0, &Pubkey::default());
|
||||
let account = AccountSharedData::new(1, 0, &Pubkey::default());
|
||||
accounts.push((key0, account));
|
||||
|
||||
let account = Account::new(2, 1, &Pubkey::default());
|
||||
let account = AccountSharedData::new(2, 1, &Pubkey::default());
|
||||
accounts.push((key1, account));
|
||||
|
||||
let instructions = vec![CompiledInstruction::new(1, &(), vec![0])];
|
||||
@ -1165,13 +1170,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_insufficient_funds() {
|
||||
let mut accounts: Vec<(Pubkey, Account)> = Vec::new();
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
let key0 = keypair.pubkey();
|
||||
|
||||
let account = Account::new(1, 0, &Pubkey::default());
|
||||
let account = AccountSharedData::new(1, 0, &Pubkey::default());
|
||||
accounts.push((key0, account));
|
||||
|
||||
let instructions = vec![CompiledInstruction::new(1, &(), vec![0])];
|
||||
@ -1199,13 +1204,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_invalid_account_for_fee() {
|
||||
let mut accounts: Vec<(Pubkey, Account)> = Vec::new();
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
let key0 = keypair.pubkey();
|
||||
|
||||
let account = Account::new(1, 1, &solana_sdk::pubkey::new_rand()); // <-- owner is not the system program
|
||||
let account = AccountSharedData::new(1, 1, &solana_sdk::pubkey::new_rand()); // <-- owner is not the system program
|
||||
accounts.push((key0, account));
|
||||
|
||||
let instructions = vec![CompiledInstruction::new(1, &(), vec![0])];
|
||||
@ -1244,7 +1249,7 @@ mod tests {
|
||||
let nonce = Keypair::new();
|
||||
let mut accounts = vec![(
|
||||
nonce.pubkey(),
|
||||
Account::new_data(
|
||||
AccountSharedData::new_data(
|
||||
min_balance * 2,
|
||||
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
||||
nonce::state::Data::default(),
|
||||
@ -1304,18 +1309,18 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_no_loaders() {
|
||||
let mut accounts: Vec<(Pubkey, Account)> = Vec::new();
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
let key0 = keypair.pubkey();
|
||||
let key1 = Pubkey::new(&[5u8; 32]);
|
||||
|
||||
let mut account = Account::new(1, 0, &Pubkey::default());
|
||||
let mut account = AccountSharedData::new(1, 0, &Pubkey::default());
|
||||
account.rent_epoch = 1;
|
||||
accounts.push((key0, account));
|
||||
|
||||
let mut account = Account::new(2, 1, &Pubkey::default());
|
||||
let mut account = AccountSharedData::new(2, 1, &Pubkey::default());
|
||||
account.rent_epoch = 1;
|
||||
accounts.push((key1, account));
|
||||
|
||||
@ -1345,7 +1350,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_max_call_depth() {
|
||||
let mut accounts: Vec<(Pubkey, Account)> = Vec::new();
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
@ -1357,35 +1362,35 @@ mod tests {
|
||||
let key5 = Pubkey::new(&[9u8; 32]);
|
||||
let key6 = Pubkey::new(&[10u8; 32]);
|
||||
|
||||
let account = Account::new(1, 0, &Pubkey::default());
|
||||
let account = AccountSharedData::new(1, 0, &Pubkey::default());
|
||||
accounts.push((key0, account));
|
||||
|
||||
let mut account = Account::new(40, 1, &Pubkey::default());
|
||||
let mut account = AccountSharedData::new(40, 1, &Pubkey::default());
|
||||
account.executable = true;
|
||||
account.owner = native_loader::id();
|
||||
accounts.push((key1, account));
|
||||
|
||||
let mut account = Account::new(41, 1, &Pubkey::default());
|
||||
let mut account = AccountSharedData::new(41, 1, &Pubkey::default());
|
||||
account.executable = true;
|
||||
account.owner = key1;
|
||||
accounts.push((key2, account));
|
||||
|
||||
let mut account = Account::new(42, 1, &Pubkey::default());
|
||||
let mut account = AccountSharedData::new(42, 1, &Pubkey::default());
|
||||
account.executable = true;
|
||||
account.owner = key2;
|
||||
accounts.push((key3, account));
|
||||
|
||||
let mut account = Account::new(43, 1, &Pubkey::default());
|
||||
let mut account = AccountSharedData::new(43, 1, &Pubkey::default());
|
||||
account.executable = true;
|
||||
account.owner = key3;
|
||||
accounts.push((key4, account));
|
||||
|
||||
let mut account = Account::new(44, 1, &Pubkey::default());
|
||||
let mut account = AccountSharedData::new(44, 1, &Pubkey::default());
|
||||
account.executable = true;
|
||||
account.owner = key4;
|
||||
accounts.push((key5, account));
|
||||
|
||||
let mut account = Account::new(45, 1, &Pubkey::default());
|
||||
let mut account = AccountSharedData::new(45, 1, &Pubkey::default());
|
||||
account.executable = true;
|
||||
account.owner = key5;
|
||||
accounts.push((key6, account));
|
||||
@ -1411,17 +1416,17 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_bad_program_id() {
|
||||
let mut accounts: Vec<(Pubkey, Account)> = Vec::new();
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
let key0 = keypair.pubkey();
|
||||
let key1 = Pubkey::new(&[5u8; 32]);
|
||||
|
||||
let account = Account::new(1, 0, &Pubkey::default());
|
||||
let account = AccountSharedData::new(1, 0, &Pubkey::default());
|
||||
accounts.push((key0, account));
|
||||
|
||||
let mut account = Account::new(40, 1, &native_loader::id());
|
||||
let mut account = AccountSharedData::new(40, 1, &native_loader::id());
|
||||
account.executable = true;
|
||||
accounts.push((key1, account));
|
||||
|
||||
@ -1446,17 +1451,17 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_bad_owner() {
|
||||
let mut accounts: Vec<(Pubkey, Account)> = Vec::new();
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
let key0 = keypair.pubkey();
|
||||
let key1 = Pubkey::new(&[5u8; 32]);
|
||||
|
||||
let account = Account::new(1, 0, &Pubkey::default());
|
||||
let account = AccountSharedData::new(1, 0, &Pubkey::default());
|
||||
accounts.push((key0, account));
|
||||
|
||||
let mut account = Account::new(40, 1, &Pubkey::default());
|
||||
let mut account = AccountSharedData::new(40, 1, &Pubkey::default());
|
||||
account.executable = true;
|
||||
accounts.push((key1, account));
|
||||
|
||||
@ -1481,17 +1486,17 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_not_executable() {
|
||||
let mut accounts: Vec<(Pubkey, Account)> = Vec::new();
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
let key0 = keypair.pubkey();
|
||||
let key1 = Pubkey::new(&[5u8; 32]);
|
||||
|
||||
let account = Account::new(1, 0, &Pubkey::default());
|
||||
let account = AccountSharedData::new(1, 0, &Pubkey::default());
|
||||
accounts.push((key0, account));
|
||||
|
||||
let account = Account::new(40, 1, &native_loader::id());
|
||||
let account = AccountSharedData::new(40, 1, &native_loader::id());
|
||||
accounts.push((key1, account));
|
||||
|
||||
let instructions = vec![CompiledInstruction::new(1, &(), vec![0])];
|
||||
@ -1515,7 +1520,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_multiple_loaders() {
|
||||
let mut accounts: Vec<(Pubkey, Account)> = Vec::new();
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
@ -1523,17 +1528,17 @@ mod tests {
|
||||
let key1 = Pubkey::new(&[5u8; 32]);
|
||||
let key2 = Pubkey::new(&[6u8; 32]);
|
||||
|
||||
let mut account = Account::new(1, 0, &Pubkey::default());
|
||||
let mut account = AccountSharedData::new(1, 0, &Pubkey::default());
|
||||
account.rent_epoch = 1;
|
||||
accounts.push((key0, account));
|
||||
|
||||
let mut account = Account::new(40, 1, &Pubkey::default());
|
||||
let mut account = AccountSharedData::new(40, 1, &Pubkey::default());
|
||||
account.executable = true;
|
||||
account.rent_epoch = 1;
|
||||
account.owner = native_loader::id();
|
||||
accounts.push((key1, account));
|
||||
|
||||
let mut account = Account::new(41, 1, &Pubkey::default());
|
||||
let mut account = AccountSharedData::new(41, 1, &Pubkey::default());
|
||||
account.executable = true;
|
||||
account.rent_epoch = 1;
|
||||
account.owner = key1;
|
||||
@ -1580,13 +1585,13 @@ mod tests {
|
||||
|
||||
// Load accounts owned by various programs into AccountsDb
|
||||
let pubkey0 = solana_sdk::pubkey::new_rand();
|
||||
let account0 = Account::new(1, 0, &Pubkey::new(&[2; 32]));
|
||||
let account0 = AccountSharedData::new(1, 0, &Pubkey::new(&[2; 32]));
|
||||
accounts.store_slow_uncached(0, &pubkey0, &account0);
|
||||
let pubkey1 = solana_sdk::pubkey::new_rand();
|
||||
let account1 = Account::new(1, 0, &Pubkey::new(&[2; 32]));
|
||||
let account1 = AccountSharedData::new(1, 0, &Pubkey::new(&[2; 32]));
|
||||
accounts.store_slow_uncached(0, &pubkey1, &account1);
|
||||
let pubkey2 = solana_sdk::pubkey::new_rand();
|
||||
let account2 = Account::new(1, 0, &Pubkey::new(&[3; 32]));
|
||||
let account2 = AccountSharedData::new(1, 0, &Pubkey::new(&[3; 32]));
|
||||
accounts.store_slow_uncached(0, &pubkey2, &account2);
|
||||
|
||||
let loaded = accounts.load_by_program_slot(0, Some(&Pubkey::new(&[2; 32])));
|
||||
@ -1630,10 +1635,10 @@ mod tests {
|
||||
let keypair2 = Keypair::new();
|
||||
let keypair3 = Keypair::new();
|
||||
|
||||
let account0 = Account::new(1, 0, &Pubkey::default());
|
||||
let account1 = Account::new(2, 0, &Pubkey::default());
|
||||
let account2 = Account::new(3, 0, &Pubkey::default());
|
||||
let account3 = Account::new(4, 0, &Pubkey::default());
|
||||
let account0 = AccountSharedData::new(1, 0, &Pubkey::default());
|
||||
let account1 = AccountSharedData::new(2, 0, &Pubkey::default());
|
||||
let account2 = AccountSharedData::new(3, 0, &Pubkey::default());
|
||||
let account3 = AccountSharedData::new(4, 0, &Pubkey::default());
|
||||
|
||||
let accounts =
|
||||
Accounts::new_with_config(Vec::new(), &ClusterType::Development, HashSet::new(), false);
|
||||
@ -1738,9 +1743,9 @@ mod tests {
|
||||
let keypair1 = Keypair::new();
|
||||
let keypair2 = Keypair::new();
|
||||
|
||||
let account0 = Account::new(1, 0, &Pubkey::default());
|
||||
let account1 = Account::new(2, 0, &Pubkey::default());
|
||||
let account2 = Account::new(3, 0, &Pubkey::default());
|
||||
let account0 = AccountSharedData::new(1, 0, &Pubkey::default());
|
||||
let account1 = AccountSharedData::new(2, 0, &Pubkey::default());
|
||||
let account2 = AccountSharedData::new(3, 0, &Pubkey::default());
|
||||
|
||||
let accounts =
|
||||
Accounts::new_with_config(Vec::new(), &ClusterType::Development, HashSet::new(), false);
|
||||
@ -1840,9 +1845,9 @@ mod tests {
|
||||
|
||||
let loaders = vec![(Ok(()), None), (Ok(()), None)];
|
||||
|
||||
let account0 = Account::new(1, 0, &Pubkey::default());
|
||||
let account1 = Account::new(2, 0, &Pubkey::default());
|
||||
let account2 = Account::new(3, 0, &Pubkey::default());
|
||||
let account0 = AccountSharedData::new(1, 0, &Pubkey::default());
|
||||
let account1 = AccountSharedData::new(2, 0, &Pubkey::default());
|
||||
let account2 = AccountSharedData::new(3, 0, &Pubkey::default());
|
||||
|
||||
let transaction_accounts0 = vec![account0, account2.clone()];
|
||||
let transaction_loaders0 = vec![];
|
||||
@ -1923,11 +1928,12 @@ mod tests {
|
||||
let accounts =
|
||||
Accounts::new_with_config(Vec::new(), &ClusterType::Development, HashSet::new(), false);
|
||||
let mut old_pubkey = Pubkey::default();
|
||||
let zero_account = Account::new(0, 0, &Account::default().owner);
|
||||
let zero_account = AccountSharedData::new(0, 0, &AccountSharedData::default().owner);
|
||||
info!("storing..");
|
||||
for i in 0..2_000 {
|
||||
let pubkey = solana_sdk::pubkey::new_rand();
|
||||
let account = Account::new((i + 1) as u64, 0, &Account::default().owner);
|
||||
let account =
|
||||
AccountSharedData::new((i + 1) as u64, 0, &AccountSharedData::default().owner);
|
||||
accounts.store_slow_uncached(i, &pubkey, &account);
|
||||
accounts.store_slow_uncached(i, &old_pubkey, &zero_account);
|
||||
old_pubkey = pubkey;
|
||||
@ -1984,17 +1990,17 @@ mod tests {
|
||||
|
||||
fn create_accounts_prepare_if_nonce_account() -> (
|
||||
Pubkey,
|
||||
Account,
|
||||
Account,
|
||||
AccountSharedData,
|
||||
AccountSharedData,
|
||||
Hash,
|
||||
FeeCalculator,
|
||||
Option<Account>,
|
||||
Option<AccountSharedData>,
|
||||
) {
|
||||
let data = nonce::state::Versions::new_current(nonce::State::Initialized(
|
||||
nonce::state::Data::default(),
|
||||
));
|
||||
let account = Account::new_data(42, &data, &system_program::id()).unwrap();
|
||||
let pre_account = Account {
|
||||
let account = AccountSharedData::new_data(42, &data, &system_program::id()).unwrap();
|
||||
let pre_account = AccountSharedData {
|
||||
lamports: 43,
|
||||
..account.clone()
|
||||
};
|
||||
@ -2011,12 +2017,12 @@ mod tests {
|
||||
}
|
||||
|
||||
fn run_prepare_if_nonce_account_test(
|
||||
account: &mut Account,
|
||||
account: &mut AccountSharedData,
|
||||
account_pubkey: &Pubkey,
|
||||
tx_result: &Result<()>,
|
||||
maybe_nonce_rollback: Option<(&Pubkey, &Account, Option<&Account>)>,
|
||||
maybe_nonce_rollback: Option<(&Pubkey, &AccountSharedData, Option<&AccountSharedData>)>,
|
||||
last_blockhash_with_fee_calculator: &(Hash, FeeCalculator),
|
||||
expect_account: &Account,
|
||||
expect_account: &AccountSharedData,
|
||||
) -> bool {
|
||||
// Verify expect_account's relationship
|
||||
match maybe_nonce_rollback {
|
||||
@ -2088,7 +2094,7 @@ mod tests {
|
||||
) = create_accounts_prepare_if_nonce_account();
|
||||
let post_account_pubkey = pre_account_pubkey;
|
||||
|
||||
let mut post_account = Account::default();
|
||||
let mut post_account = AccountSharedData::default();
|
||||
let expect_account = post_account.clone();
|
||||
assert!(run_prepare_if_nonce_account_test(
|
||||
&mut post_account,
|
||||
@ -2192,8 +2198,9 @@ mod tests {
|
||||
blockhash,
|
||||
fee_calculator: FeeCalculator::default(),
|
||||
}));
|
||||
let nonce_account_pre = Account::new_data(42, &nonce_state, &system_program::id()).unwrap();
|
||||
let from_account_pre = Account::new(4242, 0, &Pubkey::default());
|
||||
let nonce_account_pre =
|
||||
AccountSharedData::new_data(42, &nonce_state, &system_program::id()).unwrap();
|
||||
let from_account_pre = AccountSharedData::new(4242, 0, &Pubkey::default());
|
||||
|
||||
let nonce_rollback = Some(NonceRollbackFull::new(
|
||||
nonce_address,
|
||||
@ -2215,12 +2222,12 @@ mod tests {
|
||||
fee_calculator: FeeCalculator::default(),
|
||||
}));
|
||||
let nonce_account_post =
|
||||
Account::new_data(43, &nonce_state, &system_program::id()).unwrap();
|
||||
AccountSharedData::new_data(43, &nonce_state, &system_program::id()).unwrap();
|
||||
|
||||
let from_account_post = Account::new(4199, 0, &Pubkey::default());
|
||||
let to_account = Account::new(2, 0, &Pubkey::default());
|
||||
let nonce_authority_account = Account::new(3, 0, &Pubkey::default());
|
||||
let recent_blockhashes_sysvar_account = Account::new(4, 0, &Pubkey::default());
|
||||
let from_account_post = AccountSharedData::new(4199, 0, &Pubkey::default());
|
||||
let to_account = AccountSharedData::new(2, 0, &Pubkey::default());
|
||||
let nonce_authority_account = AccountSharedData::new(3, 0, &Pubkey::default());
|
||||
let recent_blockhashes_sysvar_account = AccountSharedData::new(4, 0, &Pubkey::default());
|
||||
|
||||
let transaction_accounts = vec![
|
||||
from_account_post,
|
||||
@ -2303,7 +2310,8 @@ mod tests {
|
||||
blockhash,
|
||||
fee_calculator: FeeCalculator::default(),
|
||||
}));
|
||||
let nonce_account_pre = Account::new_data(42, &nonce_state, &system_program::id()).unwrap();
|
||||
let nonce_account_pre =
|
||||
AccountSharedData::new_data(42, &nonce_state, &system_program::id()).unwrap();
|
||||
|
||||
let nonce_rollback = Some(NonceRollbackFull::new(
|
||||
nonce_address,
|
||||
@ -2325,12 +2333,12 @@ mod tests {
|
||||
fee_calculator: FeeCalculator::default(),
|
||||
}));
|
||||
let nonce_account_post =
|
||||
Account::new_data(43, &nonce_state, &system_program::id()).unwrap();
|
||||
AccountSharedData::new_data(43, &nonce_state, &system_program::id()).unwrap();
|
||||
|
||||
let from_account_post = Account::new(4200, 0, &Pubkey::default());
|
||||
let to_account = Account::new(2, 0, &Pubkey::default());
|
||||
let nonce_authority_account = Account::new(3, 0, &Pubkey::default());
|
||||
let recent_blockhashes_sysvar_account = Account::new(4, 0, &Pubkey::default());
|
||||
let from_account_post = AccountSharedData::new(4200, 0, &Pubkey::default());
|
||||
let to_account = AccountSharedData::new(2, 0, &Pubkey::default());
|
||||
let nonce_authority_account = AccountSharedData::new(3, 0, &Pubkey::default());
|
||||
let recent_blockhashes_sysvar_account = AccountSharedData::new(4, 0, &Pubkey::default());
|
||||
|
||||
let transaction_accounts = vec![
|
||||
from_account_post,
|
||||
|
@ -424,7 +424,7 @@ mod test {
|
||||
use super::*;
|
||||
use crate::genesis_utils::create_genesis_config;
|
||||
use crossbeam_channel::unbounded;
|
||||
use solana_sdk::{account::Account, pubkey::Pubkey};
|
||||
use solana_sdk::{account::AccountSharedData, pubkey::Pubkey};
|
||||
|
||||
#[test]
|
||||
fn test_accounts_background_service_remove_dead_slots() {
|
||||
@ -438,7 +438,10 @@ mod test {
|
||||
|
||||
// Store an account in slot 0
|
||||
let account_key = Pubkey::new_unique();
|
||||
bank0.store_account(&account_key, &Account::new(264, 0, &Pubkey::default()));
|
||||
bank0.store_account(
|
||||
&account_key,
|
||||
&AccountSharedData::new(264, 0, &Pubkey::default()),
|
||||
);
|
||||
assert!(bank0.get_account(&account_key).is_some());
|
||||
pruned_banks_sender.send(0).unwrap();
|
||||
AccountsBackgroundService::remove_dead_slots(&bank0, &request_handler, &mut 0, &mut 0);
|
||||
|
@ -1,5 +1,5 @@
|
||||
use dashmap::DashMap;
|
||||
use solana_sdk::{account::Account, clock::Slot, hash::Hash, pubkey::Pubkey};
|
||||
use solana_sdk::{account::AccountSharedData, clock::Slot, hash::Hash, pubkey::Pubkey};
|
||||
use std::{
|
||||
collections::BTreeSet,
|
||||
ops::Deref,
|
||||
@ -42,7 +42,7 @@ impl SlotCacheInner {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn insert(&self, pubkey: &Pubkey, account: Account, hash: Hash) {
|
||||
pub fn insert(&self, pubkey: &Pubkey, account: AccountSharedData, hash: Hash) {
|
||||
if self.cache.contains_key(pubkey) {
|
||||
self.same_account_writes.fetch_add(1, Ordering::Relaxed);
|
||||
self.same_account_writes_size
|
||||
@ -86,7 +86,7 @@ impl Deref for SlotCacheInner {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CachedAccount {
|
||||
pub account: Account,
|
||||
pub account: AccountSharedData,
|
||||
pub hash: Hash,
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ impl AccountsCache {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn store(&self, slot: Slot, pubkey: &Pubkey, account: Account, hash: Hash) {
|
||||
pub fn store(&self, slot: Slot, pubkey: &Pubkey, account: AccountSharedData, hash: Hash) {
|
||||
let slot_cache = self.slot_cache(slot).unwrap_or_else(||
|
||||
// DashMap entry.or_insert() returns a RefMut, essentially a write lock,
|
||||
// which is dropped after this block ends, minimizing time held by the lock.
|
||||
@ -235,7 +235,7 @@ pub mod tests {
|
||||
cache.store(
|
||||
inserted_slot,
|
||||
&Pubkey::new_unique(),
|
||||
Account::new(1, 0, &Pubkey::default()),
|
||||
AccountSharedData::new(1, 0, &Pubkey::default()),
|
||||
Hash::default(),
|
||||
);
|
||||
// If the cache is told the size limit is 0, it should return the one slot
|
||||
@ -253,7 +253,7 @@ pub mod tests {
|
||||
cache.store(
|
||||
inserted_slot,
|
||||
&Pubkey::new_unique(),
|
||||
Account::new(1, 0, &Pubkey::default()),
|
||||
AccountSharedData::new(1, 0, &Pubkey::default()),
|
||||
Hash::default(),
|
||||
);
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -828,7 +828,7 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
|
||||
self.program_id_index.insert(account_owner, pubkey, slot);
|
||||
}
|
||||
// Note because of the below check below on the account data length, when an
|
||||
// account hits zero lamports and is reset to Account::Default, then we skip
|
||||
// account hits zero lamports and is reset to AccountSharedData::Default, then we skip
|
||||
// the below updates to the secondary indexes.
|
||||
//
|
||||
// Skipping means not updating secondary index to mark the account as missing.
|
||||
@ -837,7 +837,7 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
|
||||
// removed from the secondary index, the scan function will:
|
||||
// 1) consult the primary index via `get(&pubkey, Some(ancestors), max_root)`
|
||||
// and find the zero-lamport version
|
||||
// 2) When the fetch from storage occurs, it will return Account::Default
|
||||
// 2) When the fetch from storage occurs, it will return AccountSharedData::Default
|
||||
// (as persisted tombstone for snapshots). This will then ultimately be
|
||||
// filtered out by post-scan filters, like in `get_filtered_spl_token_accounts_by_owner()`.
|
||||
if *account_owner == inline_spl_token_v2_0::id()
|
||||
|
@ -5,7 +5,7 @@ use log::*;
|
||||
use memmap2::MmapMut;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account::AccountSharedData,
|
||||
clock::{Epoch, Slot},
|
||||
hash::Hash,
|
||||
pubkey::Pubkey,
|
||||
@ -57,8 +57,8 @@ pub struct AccountMeta {
|
||||
pub rent_epoch: Epoch,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Account> for AccountMeta {
|
||||
fn from(account: &'a Account) -> Self {
|
||||
impl<'a> From<&'a AccountSharedData> for AccountMeta {
|
||||
fn from(account: &'a AccountSharedData) -> Self {
|
||||
Self {
|
||||
lamports: account.lamports,
|
||||
owner: account.owner,
|
||||
@ -83,8 +83,8 @@ pub struct StoredAccountMeta<'a> {
|
||||
|
||||
impl<'a> StoredAccountMeta<'a> {
|
||||
/// Return a new Account by copying all the data referenced by the `StoredAccountMeta`.
|
||||
pub fn clone_account(&self) -> Account {
|
||||
Account {
|
||||
pub fn clone_account(&self) -> AccountSharedData {
|
||||
AccountSharedData {
|
||||
lamports: self.account_meta.lamports,
|
||||
owner: self.account_meta.owner,
|
||||
executable: self.account_meta.executable,
|
||||
@ -103,8 +103,8 @@ impl<'a> StoredAccountMeta<'a> {
|
||||
}
|
||||
|
||||
fn sanitize_lamports(&self) -> bool {
|
||||
// Sanitize 0 lamports to ensure to be same as Account::default()
|
||||
self.account_meta.lamports != 0 || self.clone_account() == Account::default()
|
||||
// Sanitize 0 lamports to ensure to be same as AccountSharedData::default()
|
||||
self.account_meta.lamports != 0 || self.clone_account() == AccountSharedData::default()
|
||||
}
|
||||
|
||||
fn ref_executable_byte(&self) -> &u8 {
|
||||
@ -431,7 +431,7 @@ impl AppendVec {
|
||||
next,
|
||||
))
|
||||
}
|
||||
pub fn get_account_test(&self, offset: usize) -> Option<(StoredMeta, Account)> {
|
||||
pub fn get_account_test(&self, offset: usize) -> Option<(StoredMeta, AccountSharedData)> {
|
||||
let (stored_account, _) = self.get_account(offset)?;
|
||||
let meta = stored_account.meta.clone();
|
||||
Some((meta, stored_account.clone_account()))
|
||||
@ -457,7 +457,7 @@ impl AppendVec {
|
||||
/// and will be available to other threads.
|
||||
pub fn append_accounts(
|
||||
&self,
|
||||
accounts: &[(StoredMeta, &Account)],
|
||||
accounts: &[(StoredMeta, &AccountSharedData)],
|
||||
hashes: &[Hash],
|
||||
) -> Vec<usize> {
|
||||
let _lock = self.append_lock.lock().unwrap();
|
||||
@ -496,7 +496,7 @@ impl AppendVec {
|
||||
pub fn append_account(
|
||||
&self,
|
||||
storage_meta: StoredMeta,
|
||||
account: &Account,
|
||||
account: &AccountSharedData,
|
||||
hash: Hash,
|
||||
) -> Option<usize> {
|
||||
let res = self.append_accounts(&[(storage_meta, account)], &[hash]);
|
||||
@ -512,7 +512,7 @@ pub mod test_utils {
|
||||
use super::StoredMeta;
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::{thread_rng, Rng};
|
||||
use solana_sdk::account::Account;
|
||||
use solana_sdk::account::AccountSharedData;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use std::fs::create_dir_all;
|
||||
use std::path::PathBuf;
|
||||
@ -543,9 +543,9 @@ pub mod test_utils {
|
||||
TempFile { path: buf }
|
||||
}
|
||||
|
||||
pub fn create_test_account(sample: usize) -> (StoredMeta, Account) {
|
||||
pub fn create_test_account(sample: usize) -> (StoredMeta, AccountSharedData) {
|
||||
let data_len = sample % 256;
|
||||
let mut account = Account::new(sample as u64, 0, &Pubkey::default());
|
||||
let mut account = AccountSharedData::new(sample as u64, 0, &Pubkey::default());
|
||||
account.data = (0..data_len).map(|_| data_len as u8).collect();
|
||||
let stored_meta = StoredMeta {
|
||||
write_version: 0,
|
||||
@ -566,7 +566,7 @@ pub mod tests {
|
||||
use std::time::Instant;
|
||||
|
||||
impl AppendVec {
|
||||
fn append_account_test(&self, data: &(StoredMeta, Account)) -> Option<usize> {
|
||||
fn append_account_test(&self, data: &(StoredMeta, AccountSharedData)) -> Option<usize> {
|
||||
self.append_account(data.0.clone(), &data.1, Hash::default())
|
||||
}
|
||||
}
|
||||
@ -740,7 +740,7 @@ pub mod tests {
|
||||
let pubkey = solana_sdk::pubkey::new_rand();
|
||||
let owner = Pubkey::default();
|
||||
let data_len = 3_u64;
|
||||
let mut account = Account::new(0, data_len as usize, &owner);
|
||||
let mut account = AccountSharedData::new(0, data_len as usize, &owner);
|
||||
account.data = b"abc".to_vec();
|
||||
let stored_meta = StoredMeta {
|
||||
write_version: 0,
|
||||
|
@ -31,7 +31,7 @@ use rayon::ThreadPool;
|
||||
use solana_measure::measure::Measure;
|
||||
use solana_metrics::{datapoint_debug, inc_new_counter_debug, inc_new_counter_info};
|
||||
use solana_sdk::{
|
||||
account::{create_account, from_account, Account},
|
||||
account::{create_account_shared_data as create_account, from_account, AccountSharedData},
|
||||
clock::{
|
||||
Epoch, Slot, SlotCount, SlotIndex, UnixTimestamp, DEFAULT_TICKS_PER_SECOND,
|
||||
MAX_PROCESSING_AGE, MAX_RECENT_BLOCKHASHES, MAX_TRANSACTION_FORWARDING_DELAY,
|
||||
@ -113,9 +113,9 @@ impl ExecuteTimings {
|
||||
type BankStatusCache = StatusCache<Result<()>>;
|
||||
#[frozen_abi(digest = "EcB9J7sm37t1R47vLcvGuNeiRciB4Efq1EDWDWL6Bp5h")]
|
||||
pub type BankSlotDelta = SlotDelta<Result<()>>;
|
||||
type TransactionAccountRefCells = Vec<Rc<RefCell<Account>>>;
|
||||
type TransactionAccountDepRefCells = Vec<(Pubkey, RefCell<Account>)>;
|
||||
type TransactionLoaderRefCells = Vec<Vec<(Pubkey, RefCell<Account>)>>;
|
||||
type TransactionAccountRefCells = Vec<Rc<RefCell<AccountSharedData>>>;
|
||||
type TransactionAccountDepRefCells = Vec<(Pubkey, RefCell<AccountSharedData>)>;
|
||||
type TransactionLoaderRefCells = Vec<Vec<(Pubkey, RefCell<AccountSharedData>)>>;
|
||||
|
||||
// Eager rent collection repeats in cyclic manner.
|
||||
// Each cycle is composed of <partition_count> number of tiny pubkey subranges
|
||||
@ -444,19 +444,19 @@ pub struct TransactionLogCollector {
|
||||
|
||||
pub trait NonceRollbackInfo {
|
||||
fn nonce_address(&self) -> &Pubkey;
|
||||
fn nonce_account(&self) -> &Account;
|
||||
fn nonce_account(&self) -> &AccountSharedData;
|
||||
fn fee_calculator(&self) -> Option<FeeCalculator>;
|
||||
fn fee_account(&self) -> Option<&Account>;
|
||||
fn fee_account(&self) -> Option<&AccountSharedData>;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct NonceRollbackPartial {
|
||||
nonce_address: Pubkey,
|
||||
nonce_account: Account,
|
||||
nonce_account: AccountSharedData,
|
||||
}
|
||||
|
||||
impl NonceRollbackPartial {
|
||||
pub fn new(nonce_address: Pubkey, nonce_account: Account) -> Self {
|
||||
pub fn new(nonce_address: Pubkey, nonce_account: AccountSharedData) -> Self {
|
||||
Self {
|
||||
nonce_address,
|
||||
nonce_account,
|
||||
@ -468,13 +468,13 @@ impl NonceRollbackInfo for NonceRollbackPartial {
|
||||
fn nonce_address(&self) -> &Pubkey {
|
||||
&self.nonce_address
|
||||
}
|
||||
fn nonce_account(&self) -> &Account {
|
||||
fn nonce_account(&self) -> &AccountSharedData {
|
||||
&self.nonce_account
|
||||
}
|
||||
fn fee_calculator(&self) -> Option<FeeCalculator> {
|
||||
nonce_account::fee_calculator_of(&self.nonce_account)
|
||||
}
|
||||
fn fee_account(&self) -> Option<&Account> {
|
||||
fn fee_account(&self) -> Option<&AccountSharedData> {
|
||||
None
|
||||
}
|
||||
}
|
||||
@ -482,16 +482,16 @@ impl NonceRollbackInfo for NonceRollbackPartial {
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct NonceRollbackFull {
|
||||
nonce_address: Pubkey,
|
||||
nonce_account: Account,
|
||||
fee_account: Option<Account>,
|
||||
nonce_account: AccountSharedData,
|
||||
fee_account: Option<AccountSharedData>,
|
||||
}
|
||||
|
||||
impl NonceRollbackFull {
|
||||
#[cfg(test)]
|
||||
pub fn new(
|
||||
nonce_address: Pubkey,
|
||||
nonce_account: Account,
|
||||
fee_account: Option<Account>,
|
||||
nonce_account: AccountSharedData,
|
||||
fee_account: Option<AccountSharedData>,
|
||||
) -> Self {
|
||||
Self {
|
||||
nonce_address,
|
||||
@ -502,7 +502,7 @@ impl NonceRollbackFull {
|
||||
pub fn from_partial(
|
||||
partial: NonceRollbackPartial,
|
||||
message: &Message,
|
||||
accounts: &[Account],
|
||||
accounts: &[AccountSharedData],
|
||||
) -> Result<Self> {
|
||||
let NonceRollbackPartial {
|
||||
nonce_address,
|
||||
@ -538,13 +538,13 @@ impl NonceRollbackInfo for NonceRollbackFull {
|
||||
fn nonce_address(&self) -> &Pubkey {
|
||||
&self.nonce_address
|
||||
}
|
||||
fn nonce_account(&self) -> &Account {
|
||||
fn nonce_account(&self) -> &AccountSharedData {
|
||||
&self.nonce_account
|
||||
}
|
||||
fn fee_calculator(&self) -> Option<FeeCalculator> {
|
||||
nonce_account::fee_calculator_of(&self.nonce_account)
|
||||
}
|
||||
fn fee_account(&self) -> Option<&Account> {
|
||||
fn fee_account(&self) -> Option<&AccountSharedData> {
|
||||
self.fee_account.as_ref()
|
||||
}
|
||||
}
|
||||
@ -1328,7 +1328,7 @@ impl Bank {
|
||||
|
||||
fn update_sysvar_account<F>(&self, pubkey: &Pubkey, updater: F)
|
||||
where
|
||||
F: Fn(&Option<Account>) -> Account,
|
||||
F: Fn(&Option<AccountSharedData>) -> AccountSharedData,
|
||||
{
|
||||
let old_account = self.get_sysvar_account(pubkey);
|
||||
let new_account = updater(&old_account);
|
||||
@ -1340,7 +1340,10 @@ impl Bank {
|
||||
}
|
||||
}
|
||||
|
||||
fn inherit_specially_retained_account_balance(&self, old_account: &Option<Account>) -> u64 {
|
||||
fn inherit_specially_retained_account_balance(
|
||||
&self,
|
||||
old_account: &Option<AccountSharedData>,
|
||||
) -> u64 {
|
||||
old_account.as_ref().map(|a| a.lamports).unwrap_or(1)
|
||||
}
|
||||
|
||||
@ -1431,7 +1434,7 @@ impl Bank {
|
||||
self.update_sysvar_account(&sysvar::slot_history::id(), |account| {
|
||||
let mut slot_history = account
|
||||
.as_ref()
|
||||
.map(|account| from_account::<SlotHistory>(&account).unwrap())
|
||||
.map(|account| from_account::<SlotHistory, _>(account).unwrap())
|
||||
.unwrap_or_default();
|
||||
slot_history.add(self.slot());
|
||||
create_account(
|
||||
@ -1445,7 +1448,7 @@ impl Bank {
|
||||
self.update_sysvar_account(&sysvar::slot_hashes::id(), |account| {
|
||||
let mut slot_hashes = account
|
||||
.as_ref()
|
||||
.map(|account| from_account::<SlotHashes>(&account).unwrap())
|
||||
.map(|account| from_account::<SlotHashes, _>(account).unwrap())
|
||||
.unwrap_or_default();
|
||||
slot_hashes.add(self.parent_slot, self.parent_hash);
|
||||
create_account(
|
||||
@ -1720,7 +1723,7 @@ impl Bank {
|
||||
fn stake_delegation_accounts(
|
||||
&self,
|
||||
reward_calc_tracer: &mut Option<impl FnMut(&RewardCalculationEvent)>,
|
||||
) -> HashMap<Pubkey, (Vec<(Pubkey, Account)>, Account)> {
|
||||
) -> HashMap<Pubkey, (Vec<(Pubkey, AccountSharedData)>, AccountSharedData)> {
|
||||
let mut accounts = HashMap::new();
|
||||
|
||||
self.stakes
|
||||
@ -2101,7 +2104,7 @@ impl Bank {
|
||||
if self.get_account(&pubkey).is_some() {
|
||||
panic!("{} repeated in genesis config", pubkey);
|
||||
}
|
||||
self.store_account(pubkey, account);
|
||||
self.store_account(pubkey, &AccountSharedData::from(account.clone()));
|
||||
self.capitalization.fetch_add(account.lamports, Relaxed);
|
||||
}
|
||||
// updating sysvars (the fees sysvar in this case) now depends on feature activations in
|
||||
@ -2112,7 +2115,7 @@ impl Bank {
|
||||
if self.get_account(&pubkey).is_some() {
|
||||
panic!("{} repeated in genesis config", pubkey);
|
||||
}
|
||||
self.store_account(pubkey, account);
|
||||
self.store_account(pubkey, &AccountSharedData::from(account.clone()));
|
||||
}
|
||||
|
||||
// highest staked node is the first collector
|
||||
@ -2560,7 +2563,7 @@ impl Bank {
|
||||
.check_hash_age(hash, max_age)
|
||||
}
|
||||
|
||||
pub fn check_tx_durable_nonce(&self, tx: &Transaction) -> Option<(Pubkey, Account)> {
|
||||
pub fn check_tx_durable_nonce(&self, tx: &Transaction) -> Option<(Pubkey, AccountSharedData)> {
|
||||
transaction::uses_durable_nonce(&tx)
|
||||
.and_then(|nonce_ix| transaction::get_nonce_pubkey_from_instruction(&nonce_ix, &tx))
|
||||
.and_then(|nonce_pubkey| {
|
||||
@ -2704,7 +2707,7 @@ impl Bank {
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts Accounts into RefCell<Account>, this involves moving
|
||||
/// Converts Accounts into RefCell<AccountSharedData>, this involves moving
|
||||
/// ownership by draining the source
|
||||
fn accounts_to_refcells(
|
||||
accounts: &mut TransactionAccounts,
|
||||
@ -2734,7 +2737,7 @@ impl Bank {
|
||||
(account_refcells, account_dep_refcells, loader_refcells)
|
||||
}
|
||||
|
||||
/// Converts back from RefCell<Account> to Account, this involves moving
|
||||
/// Converts back from RefCell<AccountSharedData> to AccountSharedData, this involves moving
|
||||
/// ownership by draining the sources
|
||||
fn refcells_to_accounts(
|
||||
accounts: &mut TransactionAccounts,
|
||||
@ -2771,7 +2774,7 @@ impl Bank {
|
||||
fn get_executors(
|
||||
&self,
|
||||
message: &Message,
|
||||
loaders: &[Vec<(Pubkey, Account)>],
|
||||
loaders: &[Vec<(Pubkey, AccountSharedData)>],
|
||||
) -> Rc<RefCell<Executors>> {
|
||||
let mut num_executors = message.account_keys.len();
|
||||
for instruction_loaders in loaders.iter() {
|
||||
@ -3352,7 +3355,7 @@ impl Bank {
|
||||
fn run_incinerator(&self) {
|
||||
if let Some((account, _)) = self.get_account_modified_since_parent(&incinerator::id()) {
|
||||
self.capitalization.fetch_sub(account.lamports, Relaxed);
|
||||
self.store_account(&incinerator::id(), &Account::default());
|
||||
self.store_account(&incinerator::id(), &AccountSharedData::default());
|
||||
}
|
||||
}
|
||||
|
||||
@ -3809,7 +3812,7 @@ impl Bank {
|
||||
self.process_transaction(&tx).map(|_| signature)
|
||||
}
|
||||
|
||||
pub fn read_balance(account: &Account) -> u64 {
|
||||
pub fn read_balance(account: &AccountSharedData) -> u64 {
|
||||
account.lamports
|
||||
}
|
||||
/// Each program would need to be able to introspect its own state
|
||||
@ -3838,7 +3841,7 @@ impl Bank {
|
||||
parents
|
||||
}
|
||||
|
||||
pub fn store_account(&self, pubkey: &Pubkey, account: &Account) {
|
||||
pub fn store_account(&self, pubkey: &Pubkey, account: &AccountSharedData) {
|
||||
assert!(!self.freeze_started());
|
||||
self.rc
|
||||
.accounts
|
||||
@ -3872,7 +3875,11 @@ impl Bank {
|
||||
self.rc.accounts.accounts_db.expire_old_recycle_stores()
|
||||
}
|
||||
|
||||
fn store_account_and_update_capitalization(&self, pubkey: &Pubkey, new_account: &Account) {
|
||||
fn store_account_and_update_capitalization(
|
||||
&self,
|
||||
pubkey: &Pubkey,
|
||||
new_account: &AccountSharedData,
|
||||
) {
|
||||
if let Some(old_account) = self.get_account(&pubkey) {
|
||||
match new_account.lamports.cmp(&old_account.lamports) {
|
||||
std::cmp::Ordering::Greater => {
|
||||
@ -3969,12 +3976,12 @@ impl Bank {
|
||||
self.hard_forks.clone()
|
||||
}
|
||||
|
||||
pub fn get_account(&self, pubkey: &Pubkey) -> Option<Account> {
|
||||
pub fn get_account(&self, pubkey: &Pubkey) -> Option<AccountSharedData> {
|
||||
self.get_account_modified_slot(pubkey)
|
||||
.map(|(acc, _slot)| acc)
|
||||
}
|
||||
|
||||
pub fn get_account_modified_slot(&self, pubkey: &Pubkey) -> Option<(Account, Slot)> {
|
||||
pub fn get_account_modified_slot(&self, pubkey: &Pubkey) -> Option<(AccountSharedData, Slot)> {
|
||||
self.rc.accounts.load_slow(&self.ancestors, pubkey)
|
||||
}
|
||||
|
||||
@ -3985,7 +3992,7 @@ impl Bank {
|
||||
// multiple times with the same parent_slot in the case of forking.
|
||||
//
|
||||
// Generally, all of sysvar update granularity should be slot boundaries.
|
||||
fn get_sysvar_account(&self, pubkey: &Pubkey) -> Option<Account> {
|
||||
fn get_sysvar_account(&self, pubkey: &Pubkey) -> Option<AccountSharedData> {
|
||||
let mut ancestors = self.ancestors.clone();
|
||||
ancestors.remove(&self.slot());
|
||||
self.rc
|
||||
@ -3994,40 +4001,40 @@ impl Bank {
|
||||
.map(|(acc, _slot)| acc)
|
||||
}
|
||||
|
||||
pub fn get_program_accounts(&self, program_id: &Pubkey) -> Vec<(Pubkey, Account)> {
|
||||
pub fn get_program_accounts(&self, program_id: &Pubkey) -> Vec<(Pubkey, AccountSharedData)> {
|
||||
self.rc
|
||||
.accounts
|
||||
.load_by_program(&self.ancestors, program_id)
|
||||
}
|
||||
|
||||
pub fn get_filtered_program_accounts<F: Fn(&Account) -> bool>(
|
||||
pub fn get_filtered_program_accounts<F: Fn(&AccountSharedData) -> bool>(
|
||||
&self,
|
||||
program_id: &Pubkey,
|
||||
filter: F,
|
||||
) -> Vec<(Pubkey, Account)> {
|
||||
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||
self.rc
|
||||
.accounts
|
||||
.load_by_program_with_filter(&self.ancestors, program_id, filter)
|
||||
}
|
||||
|
||||
pub fn get_filtered_indexed_accounts<F: Fn(&Account) -> bool>(
|
||||
pub fn get_filtered_indexed_accounts<F: Fn(&AccountSharedData) -> bool>(
|
||||
&self,
|
||||
index_key: &IndexKey,
|
||||
filter: F,
|
||||
) -> Vec<(Pubkey, Account)> {
|
||||
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||
self.rc
|
||||
.accounts
|
||||
.load_by_index_key_with_filter(&self.ancestors, index_key, filter)
|
||||
}
|
||||
|
||||
pub fn get_all_accounts_with_modified_slots(&self) -> Vec<(Pubkey, Account, Slot)> {
|
||||
pub fn get_all_accounts_with_modified_slots(&self) -> Vec<(Pubkey, AccountSharedData, Slot)> {
|
||||
self.rc.accounts.load_all(&self.ancestors)
|
||||
}
|
||||
|
||||
pub fn get_program_accounts_modified_since_parent(
|
||||
&self,
|
||||
program_id: &Pubkey,
|
||||
) -> Vec<(Pubkey, Account)> {
|
||||
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||
self.rc
|
||||
.accounts
|
||||
.load_by_program_slot(self.slot(), Some(program_id))
|
||||
@ -4053,11 +4060,14 @@ impl Bank {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_all_accounts_modified_since_parent(&self) -> Vec<(Pubkey, Account)> {
|
||||
pub fn get_all_accounts_modified_since_parent(&self) -> Vec<(Pubkey, AccountSharedData)> {
|
||||
self.rc.accounts.load_by_program_slot(self.slot(), None)
|
||||
}
|
||||
|
||||
pub fn get_account_modified_since_parent(&self, pubkey: &Pubkey) -> Option<(Account, Slot)> {
|
||||
pub fn get_account_modified_since_parent(
|
||||
&self,
|
||||
pubkey: &Pubkey,
|
||||
) -> Option<(AccountSharedData, Slot)> {
|
||||
let just_self: Ancestors = vec![(self.slot(), 0)].into_iter().collect();
|
||||
if let Some((account, slot)) = self.rc.accounts.load_slow(&just_self, pubkey) {
|
||||
if slot == self.slot() {
|
||||
@ -4765,7 +4775,7 @@ impl Bank {
|
||||
// Clear new token account
|
||||
self.store_account(
|
||||
&inline_spl_token_v2_0::new_token_program::id(),
|
||||
&Account::default(),
|
||||
&AccountSharedData::default(),
|
||||
);
|
||||
|
||||
self.remove_executor(&inline_spl_token_v2_0::id());
|
||||
@ -4815,7 +4825,7 @@ impl Bank {
|
||||
};
|
||||
|
||||
if reconfigure_token2_native_mint {
|
||||
let mut native_mint_account = solana_sdk::account::Account {
|
||||
let mut native_mint_account = solana_sdk::account::AccountSharedData {
|
||||
owner: inline_spl_token_v2_0::id(),
|
||||
data: inline_spl_token_v2_0::native_mint::ACCOUNT_DATA.to_vec(),
|
||||
lamports: sol_to_lamports(1.),
|
||||
@ -4952,6 +4962,7 @@ pub(crate) mod tests {
|
||||
};
|
||||
use crossbeam_channel::bounded;
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account_utils::StateMut,
|
||||
clock::{DEFAULT_SLOTS_PER_EPOCH, DEFAULT_TICKS_PER_SLOT},
|
||||
epoch_schedule::MINIMUM_SLOTS_PER_EPOCH,
|
||||
@ -4993,7 +5004,7 @@ pub(crate) mod tests {
|
||||
blockhash: Hash::new_unique(),
|
||||
fee_calculator: fee_calculator.clone(),
|
||||
}));
|
||||
let nonce_account = Account::new_data(43, &state, &system_program::id()).unwrap();
|
||||
let nonce_account = AccountSharedData::new_data(43, &state, &system_program::id()).unwrap();
|
||||
|
||||
// NonceRollbackPartial create + NonceRollbackInfo impl
|
||||
let partial = NonceRollbackPartial::new(nonce_address, nonce_account.clone());
|
||||
@ -5011,9 +5022,9 @@ pub(crate) mod tests {
|
||||
];
|
||||
let message = Message::new(&instructions, Some(&from_address));
|
||||
|
||||
let from_account = Account::new(44, 0, &Pubkey::default());
|
||||
let to_account = Account::new(45, 0, &Pubkey::default());
|
||||
let recent_blockhashes_sysvar_account = Account::new(4, 0, &Pubkey::default());
|
||||
let from_account = AccountSharedData::new(44, 0, &Pubkey::default());
|
||||
let to_account = AccountSharedData::new(45, 0, &Pubkey::default());
|
||||
let recent_blockhashes_sysvar_account = AccountSharedData::new(4, 0, &Pubkey::default());
|
||||
let accounts = [
|
||||
from_account.clone(),
|
||||
nonce_account.clone(),
|
||||
@ -5098,7 +5109,7 @@ pub(crate) mod tests {
|
||||
);
|
||||
|
||||
let rent_account = bank.get_account(&sysvar::rent::id()).unwrap();
|
||||
let rent = from_account::<sysvar::rent::Rent>(&rent_account).unwrap();
|
||||
let rent = from_account::<sysvar::rent::Rent, _>(&rent_account).unwrap();
|
||||
|
||||
assert_eq!(rent.burn_percent, 5);
|
||||
assert_eq!(rent.exemption_threshold, 1.2);
|
||||
@ -5240,12 +5251,12 @@ pub(crate) mod tests {
|
||||
assert_eq!(bank.last_blockhash(), genesis_config.hash());
|
||||
|
||||
// Initialize credit-debit and credit only accounts
|
||||
let account1 = Account::new(264, 0, &Pubkey::default());
|
||||
let account2 = Account::new(264, 1, &Pubkey::default());
|
||||
let account3 = Account::new(264, 0, &Pubkey::default());
|
||||
let account4 = Account::new(264, 1, &Pubkey::default());
|
||||
let account5 = Account::new(10, 0, &Pubkey::default());
|
||||
let account6 = Account::new(10, 1, &Pubkey::default());
|
||||
let account1 = AccountSharedData::new(264, 0, &Pubkey::default());
|
||||
let account2 = AccountSharedData::new(264, 1, &Pubkey::default());
|
||||
let account3 = AccountSharedData::new(264, 0, &Pubkey::default());
|
||||
let account4 = AccountSharedData::new(264, 1, &Pubkey::default());
|
||||
let account5 = AccountSharedData::new(10, 0, &Pubkey::default());
|
||||
let account6 = AccountSharedData::new(10, 1, &Pubkey::default());
|
||||
|
||||
bank.store_account(&keypair1.pubkey(), &account1);
|
||||
bank.store_account(&keypair2.pubkey(), &account2);
|
||||
@ -5359,10 +5370,11 @@ pub(crate) mod tests {
|
||||
mock_program_id: Pubkey,
|
||||
generic_rent_due_for_system_account: u64,
|
||||
) {
|
||||
let mut account_pairs: Vec<(Pubkey, Account)> = Vec::with_capacity(keypairs.len() - 1);
|
||||
let mut account_pairs: Vec<(Pubkey, AccountSharedData)> =
|
||||
Vec::with_capacity(keypairs.len() - 1);
|
||||
account_pairs.push((
|
||||
keypairs[0].pubkey(),
|
||||
Account::new(
|
||||
AccountSharedData::new(
|
||||
generic_rent_due_for_system_account + 2,
|
||||
0,
|
||||
&Pubkey::default(),
|
||||
@ -5370,7 +5382,7 @@ pub(crate) mod tests {
|
||||
));
|
||||
account_pairs.push((
|
||||
keypairs[1].pubkey(),
|
||||
Account::new(
|
||||
AccountSharedData::new(
|
||||
generic_rent_due_for_system_account + 2,
|
||||
0,
|
||||
&Pubkey::default(),
|
||||
@ -5378,7 +5390,7 @@ pub(crate) mod tests {
|
||||
));
|
||||
account_pairs.push((
|
||||
keypairs[2].pubkey(),
|
||||
Account::new(
|
||||
AccountSharedData::new(
|
||||
generic_rent_due_for_system_account + 2,
|
||||
0,
|
||||
&Pubkey::default(),
|
||||
@ -5386,7 +5398,7 @@ pub(crate) mod tests {
|
||||
));
|
||||
account_pairs.push((
|
||||
keypairs[3].pubkey(),
|
||||
Account::new(
|
||||
AccountSharedData::new(
|
||||
generic_rent_due_for_system_account + 2,
|
||||
0,
|
||||
&Pubkey::default(),
|
||||
@ -5394,15 +5406,15 @@ pub(crate) mod tests {
|
||||
));
|
||||
account_pairs.push((
|
||||
keypairs[4].pubkey(),
|
||||
Account::new(10, 0, &Pubkey::default()),
|
||||
AccountSharedData::new(10, 0, &Pubkey::default()),
|
||||
));
|
||||
account_pairs.push((
|
||||
keypairs[5].pubkey(),
|
||||
Account::new(10, 0, &Pubkey::default()),
|
||||
AccountSharedData::new(10, 0, &Pubkey::default()),
|
||||
));
|
||||
account_pairs.push((
|
||||
keypairs[6].pubkey(),
|
||||
Account::new(
|
||||
AccountSharedData::new(
|
||||
(2 * generic_rent_due_for_system_account) + 24,
|
||||
0,
|
||||
&Pubkey::default(),
|
||||
@ -5411,7 +5423,7 @@ pub(crate) mod tests {
|
||||
|
||||
account_pairs.push((
|
||||
keypairs[8].pubkey(),
|
||||
Account::new(
|
||||
AccountSharedData::new(
|
||||
generic_rent_due_for_system_account + 2 + 929,
|
||||
0,
|
||||
&Pubkey::default(),
|
||||
@ -5419,13 +5431,13 @@ pub(crate) mod tests {
|
||||
));
|
||||
account_pairs.push((
|
||||
keypairs[9].pubkey(),
|
||||
Account::new(10, 0, &Pubkey::default()),
|
||||
AccountSharedData::new(10, 0, &Pubkey::default()),
|
||||
));
|
||||
|
||||
// Feeding to MockProgram to test read only rent behaviour
|
||||
account_pairs.push((
|
||||
keypairs[10].pubkey(),
|
||||
Account::new(
|
||||
AccountSharedData::new(
|
||||
generic_rent_due_for_system_account + 3,
|
||||
0,
|
||||
&Pubkey::default(),
|
||||
@ -5433,15 +5445,15 @@ pub(crate) mod tests {
|
||||
));
|
||||
account_pairs.push((
|
||||
keypairs[11].pubkey(),
|
||||
Account::new(generic_rent_due_for_system_account + 3, 0, &mock_program_id),
|
||||
AccountSharedData::new(generic_rent_due_for_system_account + 3, 0, &mock_program_id),
|
||||
));
|
||||
account_pairs.push((
|
||||
keypairs[12].pubkey(),
|
||||
Account::new(generic_rent_due_for_system_account + 3, 0, &mock_program_id),
|
||||
AccountSharedData::new(generic_rent_due_for_system_account + 3, 0, &mock_program_id),
|
||||
));
|
||||
account_pairs.push((
|
||||
keypairs[13].pubkey(),
|
||||
Account::new(14, 22, &mock_program_id),
|
||||
AccountSharedData::new(14, 22, &mock_program_id),
|
||||
));
|
||||
|
||||
for account_pair in account_pairs.iter() {
|
||||
@ -5497,7 +5509,7 @@ pub(crate) mod tests {
|
||||
let pubkey = solana_sdk::pubkey::new_rand();
|
||||
|
||||
let some_lamports = 400;
|
||||
let account = Account::new(some_lamports, 0, &system_program::id());
|
||||
let account = AccountSharedData::new(some_lamports, 0, &system_program::id());
|
||||
|
||||
assert_capitalization_diff(
|
||||
&bank,
|
||||
@ -5515,7 +5527,7 @@ pub(crate) mod tests {
|
||||
let pubkey = mint_keypair.pubkey();
|
||||
|
||||
let new_lamports = 500;
|
||||
let account = Account::new(new_lamports, 0, &system_program::id());
|
||||
let account = AccountSharedData::new(new_lamports, 0, &system_program::id());
|
||||
|
||||
assert_capitalization_diff(
|
||||
&bank,
|
||||
@ -5533,7 +5545,7 @@ pub(crate) mod tests {
|
||||
let pubkey = mint_keypair.pubkey();
|
||||
|
||||
let new_lamports = 100;
|
||||
let account = Account::new(new_lamports, 0, &system_program::id());
|
||||
let account = AccountSharedData::new(new_lamports, 0, &system_program::id());
|
||||
|
||||
assert_capitalization_diff(
|
||||
&bank,
|
||||
@ -5550,7 +5562,7 @@ pub(crate) mod tests {
|
||||
let bank = Bank::new(&genesis_config);
|
||||
let pubkey = mint_keypair.pubkey();
|
||||
|
||||
let account = Account::new(lamports, 1, &system_program::id());
|
||||
let account = AccountSharedData::new(lamports, 1, &system_program::id());
|
||||
|
||||
assert_capitalization_diff(
|
||||
&bank,
|
||||
@ -5613,11 +5625,11 @@ pub(crate) mod tests {
|
||||
);
|
||||
genesis_config.accounts.insert(
|
||||
validator_1_staking_keypair.pubkey(),
|
||||
validator_1_stake_account,
|
||||
Account::from(validator_1_stake_account),
|
||||
);
|
||||
genesis_config.accounts.insert(
|
||||
validator_1_voting_keypair.pubkey(),
|
||||
validator_1_vote_account,
|
||||
Account::from(validator_1_vote_account),
|
||||
);
|
||||
|
||||
let validator_2_pubkey = solana_sdk::pubkey::new_rand();
|
||||
@ -5646,11 +5658,11 @@ pub(crate) mod tests {
|
||||
);
|
||||
genesis_config.accounts.insert(
|
||||
validator_2_staking_keypair.pubkey(),
|
||||
validator_2_stake_account,
|
||||
Account::from(validator_2_stake_account),
|
||||
);
|
||||
genesis_config.accounts.insert(
|
||||
validator_2_voting_keypair.pubkey(),
|
||||
validator_2_vote_account,
|
||||
Account::from(validator_2_vote_account),
|
||||
);
|
||||
|
||||
let validator_3_pubkey = solana_sdk::pubkey::new_rand();
|
||||
@ -5679,11 +5691,11 @@ pub(crate) mod tests {
|
||||
);
|
||||
genesis_config.accounts.insert(
|
||||
validator_3_staking_keypair.pubkey(),
|
||||
validator_3_stake_account,
|
||||
Account::from(validator_3_stake_account),
|
||||
);
|
||||
genesis_config.accounts.insert(
|
||||
validator_3_voting_keypair.pubkey(),
|
||||
validator_3_vote_account,
|
||||
Account::from(validator_3_vote_account),
|
||||
);
|
||||
|
||||
genesis_config.rent = Rent {
|
||||
@ -5699,11 +5711,11 @@ pub(crate) mod tests {
|
||||
bank.rent_collector.slots_per_year = 192.0;
|
||||
|
||||
let payer = Keypair::new();
|
||||
let payer_account = Account::new(400, 0, &system_program::id());
|
||||
let payer_account = AccountSharedData::new(400, 0, &system_program::id());
|
||||
bank.store_account_and_update_capitalization(&payer.pubkey(), &payer_account);
|
||||
|
||||
let payee = Keypair::new();
|
||||
let payee_account = Account::new(70, 1, &system_program::id());
|
||||
let payee_account = AccountSharedData::new(70, 1, &system_program::id());
|
||||
bank.store_account_and_update_capitalization(&payee.pubkey(), &payee_account);
|
||||
|
||||
let bootstrap_validator_initial_balance = bank.get_balance(&bootstrap_validator_pubkey);
|
||||
@ -5866,7 +5878,8 @@ pub(crate) mod tests {
|
||||
|
||||
let account_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let account_balance = 1;
|
||||
let mut account = Account::new(account_balance, 0, &solana_sdk::pubkey::new_rand());
|
||||
let mut account =
|
||||
AccountSharedData::new(account_balance, 0, &solana_sdk::pubkey::new_rand());
|
||||
account.executable = true;
|
||||
bank.store_account(&account_pubkey, &account);
|
||||
|
||||
@ -6710,15 +6723,15 @@ pub(crate) mod tests {
|
||||
|
||||
bank.store_account(
|
||||
&zero_lamport_pubkey,
|
||||
&Account::new(zero_lamports, 0, &Pubkey::default()),
|
||||
&AccountSharedData::new(zero_lamports, 0, &Pubkey::default()),
|
||||
);
|
||||
bank.store_account(
|
||||
&rent_due_pubkey,
|
||||
&Account::new(little_lamports, 0, &Pubkey::default()),
|
||||
&AccountSharedData::new(little_lamports, 0, &Pubkey::default()),
|
||||
);
|
||||
bank.store_account(
|
||||
&rent_exempt_pubkey,
|
||||
&Account::new(large_lamports, 0, &Pubkey::default()),
|
||||
&AccountSharedData::new(large_lamports, 0, &Pubkey::default()),
|
||||
);
|
||||
|
||||
let genesis_slot = 0;
|
||||
@ -6788,7 +6801,7 @@ pub(crate) mod tests {
|
||||
let bank1_without_zero = Arc::new(new_from_parent(&genesis_bank2));
|
||||
let zero_lamports = 0;
|
||||
|
||||
let account = Account::new(zero_lamports, 0, &Pubkey::default());
|
||||
let account = AccountSharedData::new(zero_lamports, 0, &Pubkey::default());
|
||||
bank1_with_zero.store_account(&zero_lamport_pubkey, &account);
|
||||
bank1_without_zero.store_account(&zero_lamport_pubkey, &account);
|
||||
|
||||
@ -6921,7 +6934,7 @@ pub(crate) mod tests {
|
||||
|
||||
let rewards = bank1
|
||||
.get_account(&sysvar::rewards::id())
|
||||
.map(|account| from_account::<Rewards>(&account).unwrap())
|
||||
.map(|account| from_account::<Rewards, _>(&account).unwrap())
|
||||
.unwrap();
|
||||
|
||||
// verify the stake and vote accounts are the right size
|
||||
@ -7351,7 +7364,7 @@ pub(crate) mod tests {
|
||||
|
||||
let min_balance = bank.get_minimum_balance_for_rent_exemption(nonce::State::size());
|
||||
let nonce = Keypair::new();
|
||||
let nonce_account = Account::new_data(
|
||||
let nonce_account = AccountSharedData::new_data(
|
||||
min_balance + 42,
|
||||
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
||||
nonce::state::Data::default(),
|
||||
@ -8235,7 +8248,7 @@ pub(crate) mod tests {
|
||||
let current_account = bank1.get_account(&dummy_clock_id).unwrap();
|
||||
assert_eq!(
|
||||
expected_previous_slot,
|
||||
from_account::<Clock>(¤t_account).unwrap().slot
|
||||
from_account::<Clock, _>(¤t_account).unwrap().slot
|
||||
);
|
||||
},
|
||||
|old, new| {
|
||||
@ -8275,7 +8288,7 @@ pub(crate) mod tests {
|
||||
&bank2,
|
||||
|| {
|
||||
bank2.update_sysvar_account(&dummy_clock_id, |optional_account| {
|
||||
let slot = from_account::<Clock>(optional_account.as_ref().unwrap())
|
||||
let slot = from_account::<Clock, _>(optional_account.as_ref().unwrap())
|
||||
.unwrap()
|
||||
.slot
|
||||
+ 1;
|
||||
@ -8291,7 +8304,7 @@ pub(crate) mod tests {
|
||||
let current_account = bank2.get_account(&dummy_clock_id).unwrap();
|
||||
assert_eq!(
|
||||
expected_next_slot,
|
||||
from_account::<Clock>(¤t_account).unwrap().slot
|
||||
from_account::<Clock, _>(¤t_account).unwrap().slot
|
||||
);
|
||||
},
|
||||
|old, new| {
|
||||
@ -8306,7 +8319,7 @@ pub(crate) mod tests {
|
||||
&bank2,
|
||||
|| {
|
||||
bank2.update_sysvar_account(&dummy_clock_id, |optional_account| {
|
||||
let slot = from_account::<Clock>(optional_account.as_ref().unwrap())
|
||||
let slot = from_account::<Clock, _>(optional_account.as_ref().unwrap())
|
||||
.unwrap()
|
||||
.slot
|
||||
+ 1;
|
||||
@ -8322,7 +8335,7 @@ pub(crate) mod tests {
|
||||
let current_account = bank2.get_account(&dummy_clock_id).unwrap();
|
||||
assert_eq!(
|
||||
expected_next_slot,
|
||||
from_account::<Clock>(¤t_account).unwrap().slot
|
||||
from_account::<Clock, _>(¤t_account).unwrap().slot
|
||||
);
|
||||
},
|
||||
|old, new| {
|
||||
@ -8685,7 +8698,7 @@ pub(crate) mod tests {
|
||||
let bank = Arc::new(Bank::new(&genesis_config));
|
||||
|
||||
let fees_account = bank.get_account(&sysvar::fees::id()).unwrap();
|
||||
let fees = from_account::<Fees>(&fees_account).unwrap();
|
||||
let fees = from_account::<Fees, _>(&fees_account).unwrap();
|
||||
assert_eq!(
|
||||
bank.fee_calculator.lamports_per_signature,
|
||||
fees.fee_calculator.lamports_per_signature
|
||||
@ -8751,7 +8764,7 @@ pub(crate) mod tests {
|
||||
let bank0 = Arc::new(new_from_parent(&parent));
|
||||
let pubkey0 = solana_sdk::pubkey::new_rand();
|
||||
let program_id = Pubkey::new(&[2; 32]);
|
||||
let account0 = Account::new(1, 0, &program_id);
|
||||
let account0 = AccountSharedData::new(1, 0, &program_id);
|
||||
bank0.store_account(&pubkey0, &account0);
|
||||
|
||||
assert_eq!(
|
||||
@ -8776,11 +8789,11 @@ pub(crate) mod tests {
|
||||
|
||||
let bank2 = Arc::new(new_from_parent(&bank1));
|
||||
let pubkey1 = solana_sdk::pubkey::new_rand();
|
||||
let account1 = Account::new(3, 0, &program_id);
|
||||
let account1 = AccountSharedData::new(3, 0, &program_id);
|
||||
bank2.store_account(&pubkey1, &account1);
|
||||
// Accounts with 0 lamports should be filtered out by Accounts::load_by_program()
|
||||
let pubkey2 = solana_sdk::pubkey::new_rand();
|
||||
let account2 = Account::new(0, 0, &program_id);
|
||||
let account2 = AccountSharedData::new(0, 0, &program_id);
|
||||
bank2.store_account(&pubkey2, &account2);
|
||||
|
||||
let bank3 = Arc::new(new_from_parent(&bank2));
|
||||
@ -8802,7 +8815,7 @@ pub(crate) mod tests {
|
||||
|
||||
let address = Pubkey::new_unique();
|
||||
let program_id = Pubkey::new_unique();
|
||||
let account = Account::new(1, 0, &program_id);
|
||||
let account = AccountSharedData::new(1, 0, &program_id);
|
||||
bank.store_account(&address, &account);
|
||||
|
||||
let indexed_accounts =
|
||||
@ -8814,7 +8827,7 @@ pub(crate) mod tests {
|
||||
// it is still present in the index under the original program id as well. This
|
||||
// demonstrates the need for a redundant post-processing filter.
|
||||
let another_program_id = Pubkey::new_unique();
|
||||
let new_account = Account::new(1, 0, &another_program_id);
|
||||
let new_account = AccountSharedData::new(1, 0, &another_program_id);
|
||||
let bank = Arc::new(new_from_parent(&bank));
|
||||
bank.store_account(&address, &new_account);
|
||||
let indexed_accounts =
|
||||
@ -9042,7 +9055,7 @@ pub(crate) mod tests {
|
||||
for i in 1..5 {
|
||||
let bhq_account = bank.get_account(&sysvar::recent_blockhashes::id()).unwrap();
|
||||
let recent_blockhashes =
|
||||
from_account::<sysvar::recent_blockhashes::RecentBlockhashes>(&bhq_account)
|
||||
from_account::<sysvar::recent_blockhashes::RecentBlockhashes, _>(&bhq_account)
|
||||
.unwrap();
|
||||
// Check length
|
||||
assert_eq!(recent_blockhashes.len(), i);
|
||||
@ -9062,7 +9075,7 @@ pub(crate) mod tests {
|
||||
|
||||
let bhq_account = bank.get_account(&sysvar::recent_blockhashes::id()).unwrap();
|
||||
let recent_blockhashes =
|
||||
from_account::<sysvar::recent_blockhashes::RecentBlockhashes>(&bhq_account).unwrap();
|
||||
from_account::<sysvar::recent_blockhashes::RecentBlockhashes, _>(&bhq_account).unwrap();
|
||||
|
||||
let sysvar_recent_blockhash = recent_blockhashes[0].blockhash;
|
||||
let bank_last_blockhash = bank.last_blockhash();
|
||||
@ -9353,7 +9366,7 @@ pub(crate) mod tests {
|
||||
let (genesis_config, _mint_keypair) = create_genesis_config(100_000_000);
|
||||
let bank = Arc::new(Bank::new(&genesis_config));
|
||||
let nonce = Keypair::new();
|
||||
let nonce_account = Account::new_data(
|
||||
let nonce_account = AccountSharedData::new_data(
|
||||
42_424_242,
|
||||
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
||||
nonce::state::Data::default(),
|
||||
@ -9606,9 +9619,9 @@ pub(crate) mod tests {
|
||||
let pubkey0 = solana_sdk::pubkey::new_rand();
|
||||
let pubkey1 = solana_sdk::pubkey::new_rand();
|
||||
let program_id = Pubkey::new(&[2; 32]);
|
||||
let keypair_account = Account::new(8, 0, &program_id);
|
||||
let account0 = Account::new(11, 0, &program_id);
|
||||
let program_account = Account::new(1, 10, &Pubkey::default());
|
||||
let keypair_account = AccountSharedData::new(8, 0, &program_id);
|
||||
let account0 = AccountSharedData::new(11, 0, &program_id);
|
||||
let program_account = AccountSharedData::new(1, 10, &Pubkey::default());
|
||||
bank0.store_account(&keypair.pubkey(), &keypair_account);
|
||||
bank0.store_account(&pubkey0, &account0);
|
||||
bank0.store_account(&program_id, &program_account);
|
||||
@ -9658,9 +9671,9 @@ pub(crate) mod tests {
|
||||
let pubkey0 = solana_sdk::pubkey::new_rand();
|
||||
let pubkey1 = solana_sdk::pubkey::new_rand();
|
||||
let pubkey2 = solana_sdk::pubkey::new_rand();
|
||||
let keypair0_account = Account::new(8, 0, &Pubkey::default());
|
||||
let keypair1_account = Account::new(9, 0, &Pubkey::default());
|
||||
let account0 = Account::new(11, 0, &&Pubkey::default());
|
||||
let keypair0_account = AccountSharedData::new(8, 0, &Pubkey::default());
|
||||
let keypair1_account = AccountSharedData::new(9, 0, &Pubkey::default());
|
||||
let account0 = AccountSharedData::new(11, 0, &&Pubkey::default());
|
||||
bank0.store_account(&keypair0.pubkey(), &keypair0_account);
|
||||
bank0.store_account(&keypair1.pubkey(), &keypair1_account);
|
||||
bank0.store_account(&pubkey0, &account0);
|
||||
@ -9735,8 +9748,8 @@ pub(crate) mod tests {
|
||||
let from_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let to_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let dup_pubkey = from_pubkey;
|
||||
let from_account = Account::new(100, 1, &mock_program_id);
|
||||
let to_account = Account::new(0, 1, &mock_program_id);
|
||||
let from_account = AccountSharedData::new(100, 1, &mock_program_id);
|
||||
let to_account = AccountSharedData::new(0, 1, &mock_program_id);
|
||||
bank.store_account(&from_pubkey, &from_account);
|
||||
bank.store_account(&to_pubkey, &to_account);
|
||||
|
||||
@ -9780,8 +9793,8 @@ pub(crate) mod tests {
|
||||
let from_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let to_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let dup_pubkey = from_pubkey;
|
||||
let from_account = Account::new(100, 1, &mock_program_id);
|
||||
let to_account = Account::new(0, 1, &mock_program_id);
|
||||
let from_account = AccountSharedData::new(100, 1, &mock_program_id);
|
||||
let to_account = AccountSharedData::new(0, 1, &mock_program_id);
|
||||
bank.store_account(&from_pubkey, &from_account);
|
||||
bank.store_account(&to_pubkey, &to_account);
|
||||
|
||||
@ -10028,7 +10041,7 @@ pub(crate) mod tests {
|
||||
};
|
||||
let space = thread_rng().gen_range(0, 10);
|
||||
let owner = Pubkey::default();
|
||||
let account = Account::new(lamports, space, &owner);
|
||||
let account = AccountSharedData::new(lamports, space, &owner);
|
||||
bank.store_account(&key, &account);
|
||||
lamports
|
||||
} else {
|
||||
@ -10160,7 +10173,7 @@ pub(crate) mod tests {
|
||||
let mut genesis_config = GenesisConfig::new(
|
||||
&[(
|
||||
Pubkey::new(&[42; 32]),
|
||||
Account::new(1_000_000_000_000, 0, &system_program::id()),
|
||||
AccountSharedData::new(1_000_000_000_000, 0, &system_program::id()),
|
||||
)],
|
||||
&[],
|
||||
);
|
||||
@ -10224,7 +10237,7 @@ pub(crate) mod tests {
|
||||
|
||||
// Add a new program owned by the first
|
||||
let program2_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let mut program2_account = Account::new(42, 1, &program1_pubkey);
|
||||
let mut program2_account = AccountSharedData::new(42, 1, &program1_pubkey);
|
||||
program2_account.executable = true;
|
||||
bank.store_account(&program2_pubkey, &program2_account);
|
||||
|
||||
@ -10283,7 +10296,7 @@ pub(crate) mod tests {
|
||||
|
||||
let pubkey0_size = get_shrink_account_size();
|
||||
|
||||
let account0 = Account::new(1000, pubkey0_size as usize, &Pubkey::new_unique());
|
||||
let account0 = AccountSharedData::new(1000, pubkey0_size as usize, &Pubkey::new_unique());
|
||||
bank0.store_account(&pubkey0, &account0);
|
||||
|
||||
goto_end_of_slot(Arc::<Bank>::get_mut(&mut bank0).unwrap());
|
||||
@ -10909,8 +10922,11 @@ pub(crate) mod tests {
|
||||
};
|
||||
|
||||
let loaders = &[
|
||||
vec![(key3, Account::default()), (key4, Account::default())],
|
||||
vec![(key1, Account::default())],
|
||||
vec![
|
||||
(key3, AccountSharedData::default()),
|
||||
(key4, AccountSharedData::default()),
|
||||
],
|
||||
vec![(key1, AccountSharedData::default())],
|
||||
];
|
||||
|
||||
// don't do any work if not dirty
|
||||
@ -10972,7 +10988,10 @@ pub(crate) mod tests {
|
||||
let key2 = solana_sdk::pubkey::new_rand();
|
||||
let executor: Arc<dyn Executor> = Arc::new(TestExecutor {});
|
||||
|
||||
let loaders = &[vec![(key1, Account::default()), (key2, Account::default())]];
|
||||
let loaders = &[vec![
|
||||
(key1, AccountSharedData::default()),
|
||||
(key2, AccountSharedData::default()),
|
||||
]];
|
||||
|
||||
// add one to root bank
|
||||
let mut executors = Executors::default();
|
||||
@ -11071,19 +11090,19 @@ pub(crate) mod tests {
|
||||
// Setup original token account
|
||||
bank.store_account_and_update_capitalization(
|
||||
&inline_spl_token_v2_0::id(),
|
||||
&Account {
|
||||
&AccountSharedData {
|
||||
lamports: 100,
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
},
|
||||
);
|
||||
assert_eq!(bank.get_balance(&inline_spl_token_v2_0::id()), 100);
|
||||
|
||||
// Setup new token account
|
||||
let new_token_account = Account {
|
||||
let new_token_account = AccountSharedData {
|
||||
lamports: 123,
|
||||
data: vec![1, 2, 3],
|
||||
executable: true,
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
};
|
||||
bank.store_account_and_update_capitalization(
|
||||
&inline_spl_token_v2_0::new_token_program::id(),
|
||||
@ -11138,12 +11157,12 @@ pub(crate) mod tests {
|
||||
// inhibit deprecated rewards sysvar creation altogether
|
||||
genesis_config.accounts.insert(
|
||||
feature_set::deprecate_rewards_sysvar::id(),
|
||||
feature::create_account(
|
||||
Account::from(feature::create_account(
|
||||
&Feature {
|
||||
activated_at: Some(0),
|
||||
},
|
||||
feature_balance,
|
||||
),
|
||||
)),
|
||||
);
|
||||
|
||||
let bank0 = Bank::new(&genesis_config);
|
||||
@ -11591,7 +11610,7 @@ pub(crate) mod tests {
|
||||
.collect();
|
||||
let program_id = system_program::id();
|
||||
let starting_lamports = 1;
|
||||
let starting_account = Account::new(starting_lamports, 0, &program_id);
|
||||
let starting_account = AccountSharedData::new(starting_lamports, 0, &program_id);
|
||||
|
||||
// Write accounts to the store
|
||||
for key in &all_pubkeys {
|
||||
@ -11696,7 +11715,7 @@ pub(crate) mod tests {
|
||||
&solana_sdk::pubkey::new_rand(),
|
||||
current_minor_fork_bank.slot() + 2,
|
||||
));
|
||||
let account = Account::new(lamports, 0, &program_id);
|
||||
let account = AccountSharedData::new(lamports, 0, &program_id);
|
||||
// Write partial updates to each of the banks in the minor fork so if any of them
|
||||
// get cleaned up, there will be keys with the wrong account value/missing.
|
||||
for key in pubkeys_to_modify {
|
||||
@ -11722,7 +11741,7 @@ pub(crate) mod tests {
|
||||
current_minor_fork_bank.slot() - 1,
|
||||
));
|
||||
let lamports = current_major_fork_bank.slot() + starting_lamports + 1;
|
||||
let account = Account::new(lamports, 0, &program_id);
|
||||
let account = AccountSharedData::new(lamports, 0, &program_id);
|
||||
for key in pubkeys_to_modify.iter() {
|
||||
// Store rooted updates to these pubkeys such that the minor
|
||||
// fork updates to the same keys will be deleted by clean
|
||||
@ -11768,7 +11787,7 @@ pub(crate) mod tests {
|
||||
let mut prev_bank = bank0;
|
||||
loop {
|
||||
let lamports_this_round = current_bank.slot() + starting_lamports + 1;
|
||||
let account = Account::new(lamports_this_round, 0, &program_id);
|
||||
let account = AccountSharedData::new(lamports_this_round, 0, &program_id);
|
||||
for key in pubkeys_to_modify.iter() {
|
||||
current_bank.store_account(key, &account);
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ impl SyncClient for BankClient {
|
||||
}
|
||||
|
||||
fn get_account(&self, pubkey: &Pubkey) -> Result<Option<Account>> {
|
||||
Ok(self.bank.get_account(pubkey))
|
||||
Ok(self.bank.get_account(pubkey).map(Account::from))
|
||||
}
|
||||
|
||||
fn get_account_with_commitment(
|
||||
@ -125,7 +125,7 @@ impl SyncClient for BankClient {
|
||||
pubkey: &Pubkey,
|
||||
_commitment_config: CommitmentConfig,
|
||||
) -> Result<Option<Account>> {
|
||||
Ok(self.bank.get_account(pubkey))
|
||||
Ok(self.bank.get_account(pubkey).map(Account::from))
|
||||
}
|
||||
|
||||
fn get_balance(&self, pubkey: &Pubkey) -> Result<u64> {
|
||||
|
@ -116,13 +116,13 @@ impl EpochStakes {
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests {
|
||||
use super::*;
|
||||
use solana_sdk::account::Account;
|
||||
use solana_sdk::account::AccountSharedData;
|
||||
use solana_vote_program::vote_state::create_account_with_authorized;
|
||||
use std::iter;
|
||||
|
||||
struct VoteAccountInfo {
|
||||
vote_account: Pubkey,
|
||||
account: Account,
|
||||
account: AccountSharedData,
|
||||
authorized_voter: Pubkey,
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account::AccountSharedData,
|
||||
feature::{self, Feature},
|
||||
feature_set::FeatureSet,
|
||||
fee_calculator::FeeRateGovernor,
|
||||
@ -110,13 +111,15 @@ pub fn create_genesis_config_with_vote_accounts_and_cluster_type(
|
||||
// Create accounts
|
||||
let node_account = Account::new(VALIDATOR_LAMPORTS, 0, &system_program::id());
|
||||
let vote_account = vote_state::create_account(&vote_pubkey, &node_pubkey, 0, *stake);
|
||||
let stake_account = stake_state::create_account(
|
||||
let stake_account = Account::from(stake_state::create_account(
|
||||
&stake_pubkey,
|
||||
&vote_pubkey,
|
||||
&vote_account,
|
||||
&genesis_config_info.genesis_config.rent,
|
||||
*stake,
|
||||
);
|
||||
));
|
||||
|
||||
let vote_account = Account::from(vote_account);
|
||||
|
||||
// Put newly created accounts into genesis
|
||||
genesis_config_info.genesis_config.accounts.extend(vec![
|
||||
@ -163,12 +166,12 @@ pub fn activate_all_features(genesis_config: &mut GenesisConfig) {
|
||||
for feature_id in FeatureSet::default().inactive {
|
||||
genesis_config.accounts.insert(
|
||||
feature_id,
|
||||
feature::create_account(
|
||||
Account::from(feature::create_account(
|
||||
&Feature {
|
||||
activated_at: Some(0),
|
||||
},
|
||||
std::cmp::max(genesis_config.rent.minimum_balance(Feature::size_of()), 1),
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -185,7 +188,7 @@ pub fn create_genesis_config_with_leader_ex(
|
||||
fee_rate_governor: FeeRateGovernor,
|
||||
rent: Rent,
|
||||
cluster_type: ClusterType,
|
||||
mut initial_accounts: Vec<(Pubkey, Account)>,
|
||||
mut initial_accounts: Vec<(Pubkey, AccountSharedData)>,
|
||||
) -> GenesisConfig {
|
||||
let validator_vote_account = vote_state::create_account(
|
||||
&validator_vote_account_pubkey,
|
||||
@ -204,17 +207,21 @@ pub fn create_genesis_config_with_leader_ex(
|
||||
|
||||
initial_accounts.push((
|
||||
*mint_pubkey,
|
||||
Account::new(mint_lamports, 0, &system_program::id()),
|
||||
AccountSharedData::new(mint_lamports, 0, &system_program::id()),
|
||||
));
|
||||
initial_accounts.push((
|
||||
*validator_pubkey,
|
||||
Account::new(validator_lamports, 0, &system_program::id()),
|
||||
AccountSharedData::new(validator_lamports, 0, &system_program::id()),
|
||||
));
|
||||
initial_accounts.push((*validator_vote_account_pubkey, validator_vote_account));
|
||||
initial_accounts.push((*validator_stake_account_pubkey, validator_stake_account));
|
||||
|
||||
let mut genesis_config = GenesisConfig {
|
||||
accounts: initial_accounts.iter().cloned().collect(),
|
||||
accounts: initial_accounts
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|(key, account)| (key, Account::from(account)))
|
||||
.collect(),
|
||||
fee_rate_governor,
|
||||
rent,
|
||||
cluster_type,
|
||||
|
@ -5,7 +5,7 @@ use crate::{
|
||||
use log::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account::AccountSharedData,
|
||||
account_utils::StateMut,
|
||||
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
||||
feature_set::{instructions_sysvar_enabled, track_writable_deescalation, FeatureSet},
|
||||
@ -83,11 +83,11 @@ impl ExecuteDetailsTimings {
|
||||
pub struct PreAccount {
|
||||
key: Pubkey,
|
||||
is_writable: bool,
|
||||
account: RefCell<Account>,
|
||||
account: RefCell<AccountSharedData>,
|
||||
changed: bool,
|
||||
}
|
||||
impl PreAccount {
|
||||
pub fn new(key: &Pubkey, account: &Account, is_writable: bool) -> Self {
|
||||
pub fn new(key: &Pubkey, account: &AccountSharedData, is_writable: bool) -> Self {
|
||||
Self {
|
||||
key: *key,
|
||||
is_writable,
|
||||
@ -101,7 +101,7 @@ impl PreAccount {
|
||||
program_id: &Pubkey,
|
||||
is_writable: Option<bool>,
|
||||
rent: &Rent,
|
||||
post: &Account,
|
||||
post: &AccountSharedData,
|
||||
timings: &mut ExecuteDetailsTimings,
|
||||
) -> Result<(), InstructionError> {
|
||||
let pre = self.account.borrow();
|
||||
@ -207,7 +207,7 @@ impl PreAccount {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn update(&mut self, account: &Account) {
|
||||
pub fn update(&mut self, account: &AccountSharedData) {
|
||||
let mut pre = self.account.borrow_mut();
|
||||
|
||||
pre.lamports = account.lamports;
|
||||
@ -262,7 +262,7 @@ pub struct ThisInvokeContext<'a> {
|
||||
program_ids: Vec<Pubkey>,
|
||||
rent: Rent,
|
||||
pre_accounts: Vec<PreAccount>,
|
||||
account_deps: &'a [(Pubkey, RefCell<Account>)],
|
||||
account_deps: &'a [(Pubkey, RefCell<AccountSharedData>)],
|
||||
programs: &'a [(Pubkey, ProcessInstructionWithContext)],
|
||||
logger: Rc<RefCell<dyn Logger>>,
|
||||
bpf_compute_budget: BpfComputeBudget,
|
||||
@ -278,7 +278,7 @@ impl<'a> ThisInvokeContext<'a> {
|
||||
program_id: &Pubkey,
|
||||
rent: Rent,
|
||||
pre_accounts: Vec<PreAccount>,
|
||||
account_deps: &'a [(Pubkey, RefCell<Account>)],
|
||||
account_deps: &'a [(Pubkey, RefCell<AccountSharedData>)],
|
||||
programs: &'a [(Pubkey, ProcessInstructionWithContext)],
|
||||
log_collector: Option<Rc<LogCollector>>,
|
||||
bpf_compute_budget: BpfComputeBudget,
|
||||
@ -328,7 +328,7 @@ impl<'a> InvokeContext for ThisInvokeContext<'a> {
|
||||
&mut self,
|
||||
message: &Message,
|
||||
instruction: &CompiledInstruction,
|
||||
accounts: &[Rc<RefCell<Account>>],
|
||||
accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||
caller_privileges: Option<&[bool]>,
|
||||
) -> Result<(), InstructionError> {
|
||||
let track_writable_deescalation =
|
||||
@ -379,7 +379,7 @@ impl<'a> InvokeContext for ThisInvokeContext<'a> {
|
||||
fn is_feature_active(&self, feature_id: &Pubkey) -> bool {
|
||||
self.feature_set.is_active(feature_id)
|
||||
}
|
||||
fn get_account(&self, pubkey: &Pubkey) -> Option<RefCell<Account>> {
|
||||
fn get_account(&self, pubkey: &Pubkey) -> Option<RefCell<AccountSharedData>> {
|
||||
if let Some(account) = self.pre_accounts.iter().find_map(|pre| {
|
||||
if pre.key == *pubkey {
|
||||
Some(pre.account.clone())
|
||||
@ -519,8 +519,8 @@ impl MessageProcessor {
|
||||
fn create_keyed_accounts<'a>(
|
||||
message: &'a Message,
|
||||
instruction: &'a CompiledInstruction,
|
||||
executable_accounts: &'a [(Pubkey, RefCell<Account>)],
|
||||
accounts: &'a [Rc<RefCell<Account>>],
|
||||
executable_accounts: &'a [(Pubkey, RefCell<AccountSharedData>)],
|
||||
accounts: &'a [Rc<RefCell<AccountSharedData>>],
|
||||
) -> Vec<KeyedAccount<'a>> {
|
||||
let mut keyed_accounts = create_keyed_readonly_accounts(&executable_accounts);
|
||||
let mut keyed_accounts2: Vec<_> = instruction
|
||||
@ -811,8 +811,8 @@ impl MessageProcessor {
|
||||
/// This method calls the instruction's program entrypoint function
|
||||
pub fn process_cross_program_instruction(
|
||||
message: &Message,
|
||||
executable_accounts: &[(Pubkey, RefCell<Account>)],
|
||||
accounts: &[Rc<RefCell<Account>>],
|
||||
executable_accounts: &[(Pubkey, RefCell<AccountSharedData>)],
|
||||
accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||
caller_privileges: &[bool],
|
||||
invoke_context: &mut dyn InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
@ -863,7 +863,7 @@ impl MessageProcessor {
|
||||
pub fn create_pre_accounts(
|
||||
message: &Message,
|
||||
instruction: &CompiledInstruction,
|
||||
accounts: &[Rc<RefCell<Account>>],
|
||||
accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||
) -> Vec<PreAccount> {
|
||||
let mut pre_accounts = Vec::with_capacity(instruction.accounts.len());
|
||||
{
|
||||
@ -881,7 +881,7 @@ impl MessageProcessor {
|
||||
|
||||
/// Verify there are no outstanding borrows
|
||||
pub fn verify_account_references(
|
||||
accounts: &[(Pubkey, RefCell<Account>)],
|
||||
accounts: &[(Pubkey, RefCell<AccountSharedData>)],
|
||||
) -> Result<(), InstructionError> {
|
||||
for (_, account) in accounts.iter() {
|
||||
account
|
||||
@ -896,8 +896,8 @@ impl MessageProcessor {
|
||||
message: &Message,
|
||||
instruction: &CompiledInstruction,
|
||||
pre_accounts: &[PreAccount],
|
||||
executable_accounts: &[(Pubkey, RefCell<Account>)],
|
||||
accounts: &[Rc<RefCell<Account>>],
|
||||
executable_accounts: &[(Pubkey, RefCell<AccountSharedData>)],
|
||||
accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||
rent: &Rent,
|
||||
timings: &mut ExecuteDetailsTimings,
|
||||
) -> Result<(), InstructionError> {
|
||||
@ -939,7 +939,7 @@ impl MessageProcessor {
|
||||
message: &Message,
|
||||
instruction: &CompiledInstruction,
|
||||
pre_accounts: &mut [PreAccount],
|
||||
accounts: &[Rc<RefCell<Account>>],
|
||||
accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||
program_id: &Pubkey,
|
||||
rent: &Rent,
|
||||
track_writable_deescalation: bool,
|
||||
@ -1000,9 +1000,9 @@ impl MessageProcessor {
|
||||
&self,
|
||||
message: &Message,
|
||||
instruction: &CompiledInstruction,
|
||||
executable_accounts: &[(Pubkey, RefCell<Account>)],
|
||||
accounts: &[Rc<RefCell<Account>>],
|
||||
account_deps: &[(Pubkey, RefCell<Account>)],
|
||||
executable_accounts: &[(Pubkey, RefCell<AccountSharedData>)],
|
||||
accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||
account_deps: &[(Pubkey, RefCell<AccountSharedData>)],
|
||||
rent_collector: &RentCollector,
|
||||
log_collector: Option<Rc<LogCollector>>,
|
||||
executors: Rc<RefCell<Executors>>,
|
||||
@ -1071,9 +1071,9 @@ impl MessageProcessor {
|
||||
pub fn process_message(
|
||||
&self,
|
||||
message: &Message,
|
||||
loaders: &[Vec<(Pubkey, RefCell<Account>)>],
|
||||
accounts: &[Rc<RefCell<Account>>],
|
||||
account_deps: &[(Pubkey, RefCell<Account>)],
|
||||
loaders: &[Vec<(Pubkey, RefCell<AccountSharedData>)>],
|
||||
accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||
account_deps: &[(Pubkey, RefCell<AccountSharedData>)],
|
||||
rent_collector: &RentCollector,
|
||||
log_collector: Option<Rc<LogCollector>>,
|
||||
executors: Rc<RefCell<Executors>>,
|
||||
@ -1126,14 +1126,14 @@ mod tests {
|
||||
for i in 0..MAX_DEPTH {
|
||||
program_ids.push(solana_sdk::pubkey::new_rand());
|
||||
keys.push(solana_sdk::pubkey::new_rand());
|
||||
accounts.push(Rc::new(RefCell::new(Account::new(
|
||||
accounts.push(Rc::new(RefCell::new(AccountSharedData::new(
|
||||
i as u64,
|
||||
1,
|
||||
&program_ids[i],
|
||||
))));
|
||||
pre_accounts.push(PreAccount::new(&keys[i], &accounts[i].borrow(), false))
|
||||
}
|
||||
let account = Account::new(1, 1, &solana_sdk::pubkey::Pubkey::default());
|
||||
let account = AccountSharedData::new(1, 1, &solana_sdk::pubkey::Pubkey::default());
|
||||
for program_id in program_ids.iter() {
|
||||
pre_accounts.push(PreAccount::new(program_id, &account.clone(), false));
|
||||
}
|
||||
@ -1181,7 +1181,7 @@ mod tests {
|
||||
// modify account owned by the program
|
||||
accounts[owned_index].borrow_mut().data[0] = (MAX_DEPTH + owned_index) as u8;
|
||||
let mut these_accounts = accounts[not_owned_index..owned_index + 1].to_vec();
|
||||
these_accounts.push(Rc::new(RefCell::new(Account::new(
|
||||
these_accounts.push(Rc::new(RefCell::new(AccountSharedData::new(
|
||||
1,
|
||||
1,
|
||||
&solana_sdk::pubkey::Pubkey::default(),
|
||||
@ -1248,7 +1248,7 @@ mod tests {
|
||||
fn test_verify_account_references() {
|
||||
let accounts = vec![(
|
||||
solana_sdk::pubkey::new_rand(),
|
||||
RefCell::new(Account::default()),
|
||||
RefCell::new(AccountSharedData::default()),
|
||||
)];
|
||||
|
||||
assert!(MessageProcessor::verify_account_references(&accounts).is_ok());
|
||||
@ -1265,7 +1265,7 @@ mod tests {
|
||||
is_writable: bool,
|
||||
rent: Rent,
|
||||
pre: PreAccount,
|
||||
post: Account,
|
||||
post: AccountSharedData,
|
||||
}
|
||||
impl Change {
|
||||
pub fn new(owner: &Pubkey, program_id: &Pubkey) -> Self {
|
||||
@ -1275,18 +1275,18 @@ mod tests {
|
||||
is_writable: true,
|
||||
pre: PreAccount::new(
|
||||
&solana_sdk::pubkey::new_rand(),
|
||||
&Account {
|
||||
&AccountSharedData {
|
||||
owner: *owner,
|
||||
lamports: std::u64::MAX,
|
||||
data: vec![],
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
},
|
||||
false,
|
||||
),
|
||||
post: Account {
|
||||
post: AccountSharedData {
|
||||
owner: *owner,
|
||||
lamports: std::u64::MAX,
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1686,13 +1686,13 @@ mod tests {
|
||||
let mut message_processor = MessageProcessor::default();
|
||||
message_processor.add_program(mock_system_program_id, mock_system_process_instruction);
|
||||
|
||||
let mut accounts: Vec<Rc<RefCell<Account>>> = Vec::new();
|
||||
let account = Account::new_ref(100, 1, &mock_system_program_id);
|
||||
let mut accounts: Vec<Rc<RefCell<AccountSharedData>>> = Vec::new();
|
||||
let account = AccountSharedData::new_ref(100, 1, &mock_system_program_id);
|
||||
accounts.push(account);
|
||||
let account = Account::new_ref(0, 1, &mock_system_program_id);
|
||||
let account = AccountSharedData::new_ref(0, 1, &mock_system_program_id);
|
||||
accounts.push(account);
|
||||
|
||||
let mut loaders: Vec<Vec<(Pubkey, RefCell<Account>)>> = Vec::new();
|
||||
let mut loaders: Vec<Vec<(Pubkey, RefCell<AccountSharedData>)>> = Vec::new();
|
||||
let account = RefCell::new(create_loadable_account("mock_system_program", 1));
|
||||
loaders.push(vec![(mock_system_program_id, account)]);
|
||||
|
||||
@ -1853,13 +1853,13 @@ mod tests {
|
||||
let mut message_processor = MessageProcessor::default();
|
||||
message_processor.add_program(mock_program_id, mock_system_process_instruction);
|
||||
|
||||
let mut accounts: Vec<Rc<RefCell<Account>>> = Vec::new();
|
||||
let account = Account::new_ref(100, 1, &mock_program_id);
|
||||
let mut accounts: Vec<Rc<RefCell<AccountSharedData>>> = Vec::new();
|
||||
let account = AccountSharedData::new_ref(100, 1, &mock_program_id);
|
||||
accounts.push(account);
|
||||
let account = Account::new_ref(0, 1, &mock_program_id);
|
||||
let account = AccountSharedData::new_ref(0, 1, &mock_program_id);
|
||||
accounts.push(account);
|
||||
|
||||
let mut loaders: Vec<Vec<(Pubkey, RefCell<Account>)>> = Vec::new();
|
||||
let mut loaders: Vec<Vec<(Pubkey, RefCell<AccountSharedData>)>> = Vec::new();
|
||||
let account = RefCell::new(create_loadable_account("mock_system_program", 1));
|
||||
loaders.push(vec![(mock_program_id, account)]);
|
||||
|
||||
@ -2001,17 +2001,17 @@ mod tests {
|
||||
let caller_program_id = solana_sdk::pubkey::new_rand();
|
||||
let callee_program_id = solana_sdk::pubkey::new_rand();
|
||||
|
||||
let mut program_account = Account::new(1, 0, &native_loader::id());
|
||||
let mut program_account = AccountSharedData::new(1, 0, &native_loader::id());
|
||||
program_account.executable = true;
|
||||
let executable_preaccount = PreAccount::new(&callee_program_id, &program_account, true);
|
||||
let executable_accounts = vec![(callee_program_id, RefCell::new(program_account.clone()))];
|
||||
|
||||
let owned_key = solana_sdk::pubkey::new_rand();
|
||||
let owned_account = Account::new(42, 1, &callee_program_id);
|
||||
let owned_account = AccountSharedData::new(42, 1, &callee_program_id);
|
||||
let owned_preaccount = PreAccount::new(&owned_key, &owned_account, true);
|
||||
|
||||
let not_owned_key = solana_sdk::pubkey::new_rand();
|
||||
let not_owned_account = Account::new(84, 1, &solana_sdk::pubkey::new_rand());
|
||||
let not_owned_account = AccountSharedData::new(84, 1, &solana_sdk::pubkey::new_rand());
|
||||
let not_owned_preaccount = PreAccount::new(¬_owned_key, ¬_owned_account, true);
|
||||
|
||||
#[allow(unused_mut)]
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! calculate and collect rent from Accounts
|
||||
use solana_sdk::{
|
||||
account::Account, clock::Epoch, epoch_schedule::EpochSchedule, genesis_config::GenesisConfig,
|
||||
incinerator, pubkey::Pubkey, rent::Rent, sysvar,
|
||||
account::AccountSharedData, clock::Epoch, epoch_schedule::EpochSchedule,
|
||||
genesis_config::GenesisConfig, incinerator, pubkey::Pubkey, rent::Rent, sysvar,
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, AbiExample)]
|
||||
@ -50,7 +50,11 @@ impl RentCollector {
|
||||
// the account rent collected, if any
|
||||
//
|
||||
#[must_use = "add to Bank::collected_rent"]
|
||||
pub fn collect_from_existing_account(&self, address: &Pubkey, account: &mut Account) -> u64 {
|
||||
pub fn collect_from_existing_account(
|
||||
&self,
|
||||
address: &Pubkey,
|
||||
account: &mut AccountSharedData,
|
||||
) -> u64 {
|
||||
if account.executable
|
||||
|| account.rent_epoch > self.epoch
|
||||
|| sysvar::check_id(&account.owner)
|
||||
@ -88,7 +92,7 @@ impl RentCollector {
|
||||
rent_due
|
||||
} else {
|
||||
let rent_charged = account.lamports;
|
||||
*account = Account::default();
|
||||
*account = AccountSharedData::default();
|
||||
rent_charged
|
||||
}
|
||||
} else {
|
||||
@ -99,7 +103,11 @@ impl RentCollector {
|
||||
}
|
||||
|
||||
#[must_use = "add to Bank::collected_rent"]
|
||||
pub fn collect_from_created_account(&self, address: &Pubkey, account: &mut Account) -> u64 {
|
||||
pub fn collect_from_created_account(
|
||||
&self,
|
||||
address: &Pubkey,
|
||||
account: &mut AccountSharedData,
|
||||
) -> u64 {
|
||||
// initialize rent_epoch as created at this epoch
|
||||
account.rent_epoch = self.epoch;
|
||||
self.collect_from_existing_account(address, account)
|
||||
@ -117,10 +125,10 @@ mod tests {
|
||||
let new_epoch = 3;
|
||||
|
||||
let (mut created_account, mut existing_account) = {
|
||||
let account = Account {
|
||||
let account = AccountSharedData {
|
||||
lamports: old_lamports,
|
||||
rent_epoch: old_epoch,
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
};
|
||||
|
||||
(account.clone(), account)
|
||||
@ -149,7 +157,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_rent_exempt_temporal_escape() {
|
||||
let mut account = Account::default();
|
||||
let mut account = AccountSharedData::default();
|
||||
let epoch = 3;
|
||||
let huge_lamports = 123_456_789_012;
|
||||
let tiny_lamports = 789_012;
|
||||
|
@ -9,7 +9,7 @@ use {
|
||||
bincode::serialize_into,
|
||||
rand::{thread_rng, Rng},
|
||||
solana_sdk::{
|
||||
account::Account,
|
||||
account::AccountSharedData,
|
||||
clock::Slot,
|
||||
genesis_config::{create_genesis_config, ClusterType},
|
||||
pubkey::Pubkey,
|
||||
@ -45,7 +45,7 @@ fn check_accounts(accounts: &Accounts, pubkeys: &[Pubkey], num: usize) {
|
||||
let ancestors = vec![(0, 0)].into_iter().collect();
|
||||
let account = accounts.load_slow(&ancestors, &pubkeys[idx]);
|
||||
let account1 = Some((
|
||||
Account::new((idx + 1) as u64, 0, &Account::default().owner),
|
||||
AccountSharedData::new((idx + 1) as u64, 0, &AccountSharedData::default().owner),
|
||||
0,
|
||||
));
|
||||
assert_eq!(account, account1);
|
||||
|
@ -2,7 +2,7 @@
|
||||
//! node stakes
|
||||
use crate::vote_account::{ArcVoteAccount, VoteAccounts};
|
||||
use solana_sdk::{
|
||||
account::Account, clock::Epoch, pubkey::Pubkey, sysvar::stake_history::StakeHistory,
|
||||
account::AccountSharedData, clock::Epoch, pubkey::Pubkey, sysvar::stake_history::StakeHistory,
|
||||
};
|
||||
use solana_stake_program::stake_state::{new_stake_history_entry, Delegation, StakeState};
|
||||
use solana_vote_program::vote_state::VoteState;
|
||||
@ -106,7 +106,7 @@ impl Stakes {
|
||||
.sum::<u64>()
|
||||
}
|
||||
|
||||
pub fn is_stake(account: &Account) -> bool {
|
||||
pub fn is_stake(account: &AccountSharedData) -> bool {
|
||||
solana_vote_program::check_id(&account.owner)
|
||||
|| solana_stake_program::check_id(&account.owner)
|
||||
&& account.data.len() >= std::mem::size_of::<StakeState>()
|
||||
@ -115,7 +115,7 @@ impl Stakes {
|
||||
pub fn store(
|
||||
&mut self,
|
||||
pubkey: &Pubkey,
|
||||
account: &Account,
|
||||
account: &AccountSharedData,
|
||||
fix_stake_deactivate: bool,
|
||||
check_vote_init: bool,
|
||||
) -> Option<ArcVoteAccount> {
|
||||
@ -232,7 +232,9 @@ pub mod tests {
|
||||
use solana_vote_program::vote_state::{self, VoteState, VoteStateVersions};
|
||||
|
||||
// set up some dummies for a staked node (( vote ) ( stake ))
|
||||
pub fn create_staked_node_accounts(stake: u64) -> ((Pubkey, Account), (Pubkey, Account)) {
|
||||
pub fn create_staked_node_accounts(
|
||||
stake: u64,
|
||||
) -> ((Pubkey, AccountSharedData), (Pubkey, AccountSharedData)) {
|
||||
let vote_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let vote_account =
|
||||
vote_state::create_account(&vote_pubkey, &solana_sdk::pubkey::new_rand(), 0, 1);
|
||||
@ -243,7 +245,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
// add stake to a vote_pubkey ( stake )
|
||||
pub fn create_stake_account(stake: u64, vote_pubkey: &Pubkey) -> (Pubkey, Account) {
|
||||
pub fn create_stake_account(stake: u64, vote_pubkey: &Pubkey) -> (Pubkey, AccountSharedData) {
|
||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||
(
|
||||
stake_pubkey,
|
||||
@ -260,7 +262,7 @@ pub mod tests {
|
||||
pub fn create_warming_staked_node_accounts(
|
||||
stake: u64,
|
||||
epoch: Epoch,
|
||||
) -> ((Pubkey, Account), (Pubkey, Account)) {
|
||||
) -> ((Pubkey, AccountSharedData), (Pubkey, AccountSharedData)) {
|
||||
let vote_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let vote_account =
|
||||
vote_state::create_account(&vote_pubkey, &solana_sdk::pubkey::new_rand(), 0, 1);
|
||||
@ -275,7 +277,7 @@ pub mod tests {
|
||||
stake: u64,
|
||||
epoch: Epoch,
|
||||
vote_pubkey: &Pubkey,
|
||||
) -> (Pubkey, Account) {
|
||||
) -> (Pubkey, AccountSharedData) {
|
||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||
(
|
||||
stake_pubkey,
|
||||
@ -557,7 +559,7 @@ pub mod tests {
|
||||
// not a stake account, and whacks above entry
|
||||
stakes.store(
|
||||
&stake_pubkey,
|
||||
&Account::new(1, 0, &solana_stake_program::id()),
|
||||
&AccountSharedData::new(1, 0, &solana_stake_program::id()),
|
||||
true,
|
||||
true,
|
||||
);
|
||||
|
@ -1,6 +1,6 @@
|
||||
use log::*;
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account::AccountSharedData,
|
||||
account_utils::StateMut,
|
||||
ic_msg,
|
||||
instruction::InstructionError,
|
||||
@ -62,7 +62,7 @@ impl Address {
|
||||
}
|
||||
|
||||
fn allocate(
|
||||
account: &mut Account,
|
||||
account: &mut AccountSharedData,
|
||||
address: &Address,
|
||||
space: u64,
|
||||
signers: &HashSet<Pubkey>,
|
||||
@ -104,7 +104,7 @@ fn allocate(
|
||||
}
|
||||
|
||||
fn assign(
|
||||
account: &mut Account,
|
||||
account: &mut AccountSharedData,
|
||||
address: &Address,
|
||||
owner: &Pubkey,
|
||||
signers: &HashSet<Pubkey>,
|
||||
@ -131,7 +131,7 @@ fn assign(
|
||||
}
|
||||
|
||||
fn allocate_and_assign(
|
||||
to: &mut Account,
|
||||
to: &mut AccountSharedData,
|
||||
to_address: &Address,
|
||||
space: u64,
|
||||
owner: &Pubkey,
|
||||
@ -421,7 +421,7 @@ pub enum SystemAccountKind {
|
||||
Nonce,
|
||||
}
|
||||
|
||||
pub fn get_system_account_kind(account: &Account) -> Option<SystemAccountKind> {
|
||||
pub fn get_system_account_kind(account: &AccountSharedData) -> Option<SystemAccountKind> {
|
||||
if system_program::check_id(&account.owner) {
|
||||
if account.data.is_empty() {
|
||||
Some(SystemAccountKind::System)
|
||||
@ -446,7 +446,7 @@ mod tests {
|
||||
use crate::{bank::Bank, bank_client::BankClient};
|
||||
use bincode::serialize;
|
||||
use solana_sdk::{
|
||||
account::{self, Account},
|
||||
account::{self, AccountSharedData},
|
||||
client::SyncClient,
|
||||
fee_calculator::FeeCalculator,
|
||||
genesis_config::create_genesis_config,
|
||||
@ -486,10 +486,10 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
fn create_default_account() -> RefCell<Account> {
|
||||
RefCell::new(Account::default())
|
||||
fn create_default_account() -> RefCell<AccountSharedData> {
|
||||
RefCell::new(AccountSharedData::default())
|
||||
}
|
||||
fn create_default_recent_blockhashes_account() -> RefCell<Account> {
|
||||
fn create_default_recent_blockhashes_account() -> RefCell<AccountSharedData> {
|
||||
RefCell::new(recent_blockhashes_account::create_account_with_data(
|
||||
1,
|
||||
vec![
|
||||
@ -499,8 +499,8 @@ mod tests {
|
||||
.into_iter(),
|
||||
))
|
||||
}
|
||||
fn create_default_rent_account() -> RefCell<Account> {
|
||||
RefCell::new(account::create_account(&Rent::free(), 1))
|
||||
fn create_default_rent_account() -> RefCell<AccountSharedData> {
|
||||
RefCell::new(account::create_account_shared_data(&Rent::free(), 1))
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -508,8 +508,8 @@ mod tests {
|
||||
let new_owner = Pubkey::new(&[9; 32]);
|
||||
let from = solana_sdk::pubkey::new_rand();
|
||||
let to = solana_sdk::pubkey::new_rand();
|
||||
let from_account = Account::new_ref(100, 0, &system_program::id());
|
||||
let to_account = Account::new_ref(0, 0, &Pubkey::default());
|
||||
let from_account = AccountSharedData::new_ref(100, 0, &system_program::id());
|
||||
let to_account = AccountSharedData::new_ref(0, 0, &Pubkey::default());
|
||||
|
||||
assert_eq!(
|
||||
process_instruction(
|
||||
@ -540,8 +540,8 @@ mod tests {
|
||||
let seed = "shiny pepper";
|
||||
let to = Pubkey::create_with_seed(&from, seed, &new_owner).unwrap();
|
||||
|
||||
let from_account = Account::new_ref(100, 0, &system_program::id());
|
||||
let to_account = Account::new_ref(0, 0, &Pubkey::default());
|
||||
let from_account = AccountSharedData::new_ref(100, 0, &system_program::id());
|
||||
let to_account = AccountSharedData::new_ref(0, 0, &Pubkey::default());
|
||||
|
||||
assert_eq!(
|
||||
process_instruction(
|
||||
@ -575,9 +575,9 @@ mod tests {
|
||||
let seed = "shiny pepper";
|
||||
let to = Pubkey::create_with_seed(&base, seed, &new_owner).unwrap();
|
||||
|
||||
let from_account = Account::new_ref(100, 0, &system_program::id());
|
||||
let to_account = Account::new_ref(0, 0, &Pubkey::default());
|
||||
let base_account = Account::new_ref(0, 0, &Pubkey::default());
|
||||
let from_account = AccountSharedData::new_ref(100, 0, &system_program::id());
|
||||
let to_account = AccountSharedData::new_ref(0, 0, &Pubkey::default());
|
||||
let base_account = AccountSharedData::new_ref(0, 0, &Pubkey::default());
|
||||
|
||||
assert_eq!(
|
||||
process_instruction(
|
||||
@ -628,8 +628,8 @@ mod tests {
|
||||
let seed = "dull boy";
|
||||
let to = Pubkey::create_with_seed(&from, seed, &new_owner).unwrap();
|
||||
|
||||
let from_account = Account::new_ref(100, 0, &system_program::id());
|
||||
let to_account = Account::new_ref(0, 0, &Pubkey::default());
|
||||
let from_account = AccountSharedData::new_ref(100, 0, &system_program::id());
|
||||
let to_account = AccountSharedData::new_ref(0, 0, &Pubkey::default());
|
||||
let to_address = Address::create(
|
||||
&to,
|
||||
Some((&from, seed, &new_owner)),
|
||||
@ -651,7 +651,7 @@ mod tests {
|
||||
Err(InstructionError::MissingRequiredSignature)
|
||||
);
|
||||
assert_eq!(from_account.borrow().lamports, 100);
|
||||
assert_eq!(*to_account.borrow(), Account::default());
|
||||
assert_eq!(*to_account.borrow(), AccountSharedData::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -659,10 +659,10 @@ mod tests {
|
||||
// create account with zero lamports transferred
|
||||
let new_owner = Pubkey::new(&[9; 32]);
|
||||
let from = solana_sdk::pubkey::new_rand();
|
||||
let from_account = Account::new_ref(100, 1, &solana_sdk::pubkey::new_rand()); // not from system account
|
||||
let from_account = AccountSharedData::new_ref(100, 1, &solana_sdk::pubkey::new_rand()); // not from system account
|
||||
|
||||
let to = solana_sdk::pubkey::new_rand();
|
||||
let to_account = Account::new_ref(0, 0, &Pubkey::default());
|
||||
let to_account = AccountSharedData::new_ref(0, 0, &Pubkey::default());
|
||||
|
||||
assert_eq!(
|
||||
create_account(
|
||||
@ -693,10 +693,10 @@ mod tests {
|
||||
// Attempt to create account with more lamports than remaining in from_account
|
||||
let new_owner = Pubkey::new(&[9; 32]);
|
||||
let from = solana_sdk::pubkey::new_rand();
|
||||
let from_account = Account::new_ref(100, 0, &system_program::id());
|
||||
let from_account = AccountSharedData::new_ref(100, 0, &system_program::id());
|
||||
|
||||
let to = solana_sdk::pubkey::new_rand();
|
||||
let to_account = Account::new_ref(0, 0, &Pubkey::default());
|
||||
let to_account = AccountSharedData::new_ref(0, 0, &Pubkey::default());
|
||||
|
||||
let result = create_account(
|
||||
&KeyedAccount::new(&from, true, &from_account),
|
||||
@ -713,9 +713,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_request_more_than_allowed_data_length() {
|
||||
let from_account = Account::new_ref(100, 0, &system_program::id());
|
||||
let from_account = AccountSharedData::new_ref(100, 0, &system_program::id());
|
||||
let from = solana_sdk::pubkey::new_rand();
|
||||
let to_account = Account::new_ref(0, 0, &system_program::id());
|
||||
let to_account = AccountSharedData::new_ref(0, 0, &system_program::id());
|
||||
let to = solana_sdk::pubkey::new_rand();
|
||||
|
||||
let signers = &[from, to].iter().cloned().collect::<HashSet<_>>();
|
||||
@ -762,11 +762,11 @@ mod tests {
|
||||
// Attempt to create system account in account already owned by another program
|
||||
let new_owner = Pubkey::new(&[9; 32]);
|
||||
let from = solana_sdk::pubkey::new_rand();
|
||||
let from_account = Account::new_ref(100, 0, &system_program::id());
|
||||
let from_account = AccountSharedData::new_ref(100, 0, &system_program::id());
|
||||
|
||||
let original_program_owner = Pubkey::new(&[5; 32]);
|
||||
let owned_key = solana_sdk::pubkey::new_rand();
|
||||
let owned_account = Account::new_ref(0, 0, &original_program_owner);
|
||||
let owned_account = AccountSharedData::new_ref(0, 0, &original_program_owner);
|
||||
let unchanged_account = owned_account.clone();
|
||||
|
||||
let signers = &[from, owned_key].iter().cloned().collect::<HashSet<_>>();
|
||||
@ -789,7 +789,7 @@ mod tests {
|
||||
assert_eq!(owned_account, unchanged_account);
|
||||
|
||||
// Attempt to create system account in account that already has data
|
||||
let owned_account = Account::new_ref(0, 1, &Pubkey::default());
|
||||
let owned_account = AccountSharedData::new_ref(0, 1, &Pubkey::default());
|
||||
let unchanged_account = owned_account.borrow().clone();
|
||||
let result = create_account(
|
||||
&KeyedAccount::new(&from, true, &from_account),
|
||||
@ -807,7 +807,7 @@ mod tests {
|
||||
assert_eq!(*owned_account.borrow(), unchanged_account);
|
||||
|
||||
// Attempt to create an account that already has lamports
|
||||
let owned_account = Account::new_ref(1, 0, &Pubkey::default());
|
||||
let owned_account = AccountSharedData::new_ref(1, 0, &Pubkey::default());
|
||||
let unchanged_account = owned_account.borrow().clone();
|
||||
let result = create_account(
|
||||
&KeyedAccount::new(&from, true, &from_account),
|
||||
@ -829,10 +829,10 @@ mod tests {
|
||||
// Attempt to create an account without signing the transfer
|
||||
let new_owner = Pubkey::new(&[9; 32]);
|
||||
let from = solana_sdk::pubkey::new_rand();
|
||||
let from_account = Account::new_ref(100, 0, &system_program::id());
|
||||
let from_account = AccountSharedData::new_ref(100, 0, &system_program::id());
|
||||
|
||||
let owned_key = solana_sdk::pubkey::new_rand();
|
||||
let owned_account = Account::new_ref(0, 0, &Pubkey::default());
|
||||
let owned_account = AccountSharedData::new_ref(0, 0, &Pubkey::default());
|
||||
|
||||
let owned_address = owned_key.into();
|
||||
|
||||
@ -850,7 +850,7 @@ mod tests {
|
||||
assert_eq!(result, Err(InstructionError::MissingRequiredSignature));
|
||||
|
||||
// Haven't signed to account
|
||||
let owned_account = Account::new_ref(0, 0, &Pubkey::default());
|
||||
let owned_account = AccountSharedData::new_ref(0, 0, &Pubkey::default());
|
||||
let result = create_account(
|
||||
&KeyedAccount::new(&from, true, &from_account),
|
||||
&KeyedAccount::new(&owned_key, true, &owned_account),
|
||||
@ -864,7 +864,7 @@ mod tests {
|
||||
assert_eq!(result, Err(InstructionError::MissingRequiredSignature));
|
||||
|
||||
// support creation/assignment with zero lamports (ephemeral account)
|
||||
let owned_account = Account::new_ref(0, 0, &Pubkey::default());
|
||||
let owned_account = AccountSharedData::new_ref(0, 0, &Pubkey::default());
|
||||
let result = create_account(
|
||||
&KeyedAccount::new(&from, false, &from_account),
|
||||
&KeyedAccount::new(&owned_key, false, &owned_account),
|
||||
@ -882,10 +882,10 @@ mod tests {
|
||||
fn test_create_sysvar_invalid_id() {
|
||||
// Attempt to create system account in account already owned by another program
|
||||
let from = solana_sdk::pubkey::new_rand();
|
||||
let from_account = Account::new_ref(100, 0, &system_program::id());
|
||||
let from_account = AccountSharedData::new_ref(100, 0, &system_program::id());
|
||||
|
||||
let to = solana_sdk::pubkey::new_rand();
|
||||
let to_account = Account::new_ref(0, 0, &system_program::id());
|
||||
let to_account = AccountSharedData::new_ref(0, 0, &system_program::id());
|
||||
|
||||
let signers = [from, to].iter().cloned().collect::<HashSet<_>>();
|
||||
let to_address = to.into();
|
||||
@ -910,12 +910,12 @@ mod tests {
|
||||
// Attempt to create system account in account with populated data
|
||||
let new_owner = Pubkey::new(&[9; 32]);
|
||||
let from = solana_sdk::pubkey::new_rand();
|
||||
let from_account = Account::new_ref(100, 0, &system_program::id());
|
||||
let from_account = AccountSharedData::new_ref(100, 0, &system_program::id());
|
||||
|
||||
let populated_key = solana_sdk::pubkey::new_rand();
|
||||
let populated_account = Account {
|
||||
let populated_account = AccountSharedData {
|
||||
data: vec![0, 1, 2, 3],
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
}
|
||||
.into();
|
||||
|
||||
@ -941,7 +941,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_create_from_account_is_nonce_fail() {
|
||||
let nonce = solana_sdk::pubkey::new_rand();
|
||||
let nonce_account = Account::new_ref_data(
|
||||
let nonce_account = AccountSharedData::new_ref_data(
|
||||
42,
|
||||
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
||||
nonce::state::Data::default(),
|
||||
@ -952,7 +952,7 @@ mod tests {
|
||||
let from = KeyedAccount::new(&nonce, true, &nonce_account);
|
||||
let new = solana_sdk::pubkey::new_rand();
|
||||
|
||||
let new_account = Account::new_ref(0, 0, &system_program::id());
|
||||
let new_account = AccountSharedData::new_ref(0, 0, &system_program::id());
|
||||
|
||||
let signers = [nonce, new].iter().cloned().collect::<HashSet<_>>();
|
||||
let new_address = new.into();
|
||||
@ -978,7 +978,7 @@ mod tests {
|
||||
let new_owner = Pubkey::new(&[9; 32]);
|
||||
|
||||
let pubkey = solana_sdk::pubkey::new_rand();
|
||||
let mut account = Account::new(100, 0, &system_program::id());
|
||||
let mut account = AccountSharedData::new(100, 0, &system_program::id());
|
||||
|
||||
assert_eq!(
|
||||
assign(
|
||||
@ -1018,7 +1018,7 @@ mod tests {
|
||||
let new_owner = sysvar::id();
|
||||
|
||||
let from = solana_sdk::pubkey::new_rand();
|
||||
let mut from_account = Account::new(100, 0, &system_program::id());
|
||||
let mut from_account = AccountSharedData::new(100, 0, &system_program::id());
|
||||
|
||||
assert_eq!(
|
||||
assign(
|
||||
@ -1043,7 +1043,7 @@ mod tests {
|
||||
assert_eq!(result, Err(InstructionError::NotEnoughAccountKeys));
|
||||
|
||||
let from = solana_sdk::pubkey::new_rand();
|
||||
let from_account = Account::new_ref(100, 0, &system_program::id());
|
||||
let from_account = AccountSharedData::new_ref(100, 0, &system_program::id());
|
||||
// Attempt to transfer with no destination
|
||||
let instruction = SystemInstruction::Transfer { lamports: 0 };
|
||||
let data = serialize(&instruction).unwrap();
|
||||
@ -1058,9 +1058,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_transfer_lamports() {
|
||||
let from = solana_sdk::pubkey::new_rand();
|
||||
let from_account = Account::new_ref(100, 0, &Pubkey::new(&[2; 32])); // account owner should not matter
|
||||
let from_account = AccountSharedData::new_ref(100, 0, &Pubkey::new(&[2; 32])); // account owner should not matter
|
||||
let to = Pubkey::new(&[3; 32]);
|
||||
let to_account = Account::new_ref(1, 0, &to); // account owner should not matter
|
||||
let to_account = AccountSharedData::new_ref(1, 0, &to); // account owner should not matter
|
||||
let from_keyed_account = KeyedAccount::new(&from, true, &from_account);
|
||||
let to_keyed_account = KeyedAccount::new(&to, false, &to_account);
|
||||
transfer(
|
||||
@ -1104,14 +1104,14 @@ mod tests {
|
||||
#[test]
|
||||
fn test_transfer_with_seed() {
|
||||
let base = solana_sdk::pubkey::new_rand();
|
||||
let base_account = Account::new_ref(100, 0, &Pubkey::new(&[2; 32])); // account owner should not matter
|
||||
let base_account = AccountSharedData::new_ref(100, 0, &Pubkey::new(&[2; 32])); // account owner should not matter
|
||||
let from_base_keyed_account = KeyedAccount::new(&base, true, &base_account);
|
||||
let from_seed = "42";
|
||||
let from_owner = system_program::id();
|
||||
let from = Pubkey::create_with_seed(&base, from_seed, &from_owner).unwrap();
|
||||
let from_account = Account::new_ref(100, 0, &Pubkey::new(&[2; 32])); // account owner should not matter
|
||||
let from_account = AccountSharedData::new_ref(100, 0, &Pubkey::new(&[2; 32])); // account owner should not matter
|
||||
let to = Pubkey::new(&[3; 32]);
|
||||
let to_account = Account::new_ref(1, 0, &to); // account owner should not matter
|
||||
let to_account = AccountSharedData::new_ref(1, 0, &to); // account owner should not matter
|
||||
let from_keyed_account = KeyedAccount::new(&from, true, &from_account);
|
||||
let to_keyed_account = KeyedAccount::new(&to, false, &to_account);
|
||||
transfer_with_seed(
|
||||
@ -1163,7 +1163,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_transfer_lamports_from_nonce_account_fail() {
|
||||
let from = solana_sdk::pubkey::new_rand();
|
||||
let from_account = Account::new_ref_data(
|
||||
let from_account = AccountSharedData::new_ref_data(
|
||||
100,
|
||||
&nonce::state::Versions::new_current(nonce::State::Initialized(nonce::state::Data {
|
||||
authority: from,
|
||||
@ -1178,7 +1178,7 @@ mod tests {
|
||||
);
|
||||
|
||||
let to = Pubkey::new(&[3; 32]);
|
||||
let to_account = Account::new_ref(1, 0, &to); // account owner should not matter
|
||||
let to_account = AccountSharedData::new_ref(1, 0, &to); // account owner should not matter
|
||||
assert_eq!(
|
||||
transfer(
|
||||
&KeyedAccount::new(&from, true, &from_account),
|
||||
@ -1377,9 +1377,9 @@ mod tests {
|
||||
RefCell::new(if sysvar::recent_blockhashes::check_id(&meta.pubkey) {
|
||||
create_default_recent_blockhashes_account().into_inner()
|
||||
} else if sysvar::rent::check_id(&meta.pubkey) {
|
||||
account::create_account(&Rent::free(), 1)
|
||||
account::create_account_shared_data(&Rent::free(), 1)
|
||||
} else {
|
||||
Account::default()
|
||||
AccountSharedData::default()
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
@ -1752,7 +1752,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_get_system_account_kind_system_ok() {
|
||||
let system_account = Account::default();
|
||||
let system_account = AccountSharedData::default();
|
||||
assert_eq!(
|
||||
get_system_account_kind(&system_account),
|
||||
Some(SystemAccountKind::System)
|
||||
@ -1761,7 +1761,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_get_system_account_kind_nonce_ok() {
|
||||
let nonce_account = Account::new_data(
|
||||
let nonce_account = AccountSharedData::new_data(
|
||||
42,
|
||||
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
||||
nonce::state::Data::default(),
|
||||
@ -1785,13 +1785,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_get_system_account_kind_system_owner_nonzero_nonnonce_data_fail() {
|
||||
let other_data_account = Account::new_data(42, b"other", &Pubkey::default()).unwrap();
|
||||
let other_data_account =
|
||||
AccountSharedData::new_data(42, b"other", &Pubkey::default()).unwrap();
|
||||
assert_eq!(get_system_account_kind(&other_data_account), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_system_account_kind_nonsystem_owner_with_nonce_data_fail() {
|
||||
let nonce_account = Account::new_data(
|
||||
let nonce_account = AccountSharedData::new_data(
|
||||
42,
|
||||
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
||||
nonce::state::Data::default(),
|
||||
|
@ -1,6 +1,8 @@
|
||||
use serde::de::{Deserialize, Deserializer};
|
||||
use serde::ser::{Serialize, Serializer};
|
||||
use solana_sdk::{account::Account, instruction::InstructionError, pubkey::Pubkey};
|
||||
use solana_sdk::{
|
||||
account::Account, account::AccountSharedData, instruction::InstructionError, pubkey::Pubkey,
|
||||
};
|
||||
use solana_vote_program::vote_state::VoteState;
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
@ -172,12 +174,27 @@ impl<'de> Deserialize<'de> for ArcVoteAccount {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AccountSharedData> for ArcVoteAccount {
|
||||
fn from(account: AccountSharedData) -> Self {
|
||||
Self(Arc::new(VoteAccount::from(account)))
|
||||
}
|
||||
}
|
||||
impl From<Account> for ArcVoteAccount {
|
||||
fn from(account: Account) -> Self {
|
||||
Self(Arc::new(VoteAccount::from(account)))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AccountSharedData> for VoteAccount {
|
||||
fn from(account: AccountSharedData) -> Self {
|
||||
Self {
|
||||
account: Account::from(account),
|
||||
vote_state: RwLock::new(INVALID_VOTE_STATE),
|
||||
vote_state_once: Once::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Account> for VoteAccount {
|
||||
fn from(account: Account) -> Self {
|
||||
Self {
|
||||
@ -299,7 +316,7 @@ mod tests {
|
||||
fn new_rand_vote_account<R: Rng>(
|
||||
rng: &mut R,
|
||||
node_pubkey: Option<Pubkey>,
|
||||
) -> (Account, VoteState) {
|
||||
) -> (AccountSharedData, VoteState) {
|
||||
let vote_init = VoteInit {
|
||||
node_pubkey: node_pubkey.unwrap_or_else(Pubkey::new_unique),
|
||||
authorized_voter: Pubkey::new_unique(),
|
||||
@ -314,7 +331,7 @@ mod tests {
|
||||
unix_timestamp: rng.gen(),
|
||||
};
|
||||
let vote_state = VoteState::new(&vote_init, &clock);
|
||||
let account = Account::new_data(
|
||||
let account = AccountSharedData::new_data(
|
||||
rng.gen(), // lamports
|
||||
&VoteStateVersions::new_current(vote_state.clone()),
|
||||
&Pubkey::new_unique(), // owner
|
||||
|
@ -3,7 +3,7 @@ use rand::{thread_rng, Rng};
|
||||
use rayon::prelude::*;
|
||||
use solana_runtime::{accounts_db::AccountsDb, accounts_index::Ancestors};
|
||||
use solana_sdk::genesis_config::ClusterType;
|
||||
use solana_sdk::{account::Account, clock::Slot, pubkey::Pubkey};
|
||||
use solana_sdk::{account::AccountSharedData, clock::Slot, pubkey::Pubkey};
|
||||
use std::collections::HashSet;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
@ -37,7 +37,7 @@ fn test_shrink_and_clean() {
|
||||
while alive_accounts.len() <= 10 {
|
||||
alive_accounts.push((
|
||||
solana_sdk::pubkey::new_rand(),
|
||||
Account::new(thread_rng().gen_range(0, 50), 0, &owner),
|
||||
AccountSharedData::new(thread_rng().gen_range(0, 50), 0, &owner),
|
||||
));
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ fn test_bad_bank_hash() {
|
||||
let key = Keypair::new().pubkey();
|
||||
let lamports = thread_rng().gen_range(0, 100);
|
||||
let some_data_len = thread_rng().gen_range(0, 1000);
|
||||
let account = Account::new(lamports, some_data_len, &key);
|
||||
let account = AccountSharedData::new(lamports, some_data_len, &key);
|
||||
(key, account)
|
||||
})
|
||||
.collect();
|
||||
|
@ -77,7 +77,7 @@ fn warmed_up(bank: &Bank, stake_pubkey: &Pubkey) -> bool {
|
||||
== stake.stake(
|
||||
bank.epoch(),
|
||||
Some(
|
||||
&from_account::<StakeHistory>(
|
||||
&from_account::<StakeHistory, _>(
|
||||
&bank.get_account(&sysvar::stake_history::id()).unwrap(),
|
||||
)
|
||||
.unwrap(),
|
||||
@ -92,7 +92,7 @@ fn get_staked(bank: &Bank, stake_pubkey: &Pubkey) -> u64 {
|
||||
.stake(
|
||||
bank.epoch(),
|
||||
Some(
|
||||
&from_account::<StakeHistory>(
|
||||
&from_account::<StakeHistory, _>(
|
||||
&bank.get_account(&sysvar::stake_history::id()).unwrap(),
|
||||
)
|
||||
.unwrap(),
|
||||
|
Reference in New Issue
Block a user