Account->AccountSharedData (#15691)

This commit is contained in:
Jeff Washington (jwash)
2021-03-09 15:06:07 -06:00
committed by GitHub
parent 61c7ce857e
commit 8a3135d17b
71 changed files with 2032 additions and 1161 deletions

View File

@ -19,7 +19,7 @@ use solana_runtime::{
loader_utils::load_program,
};
use solana_sdk::{
account::Account,
account::AccountSharedData,
bpf_loader,
client::SyncClient,
entrypoint::SUCCESS,
@ -198,7 +198,7 @@ fn bench_instruction_count_tuner(_bencher: &mut Bencher) {
let mut invoke_context = MockInvokeContext::default();
invoke_context.compute_meter.remaining = BUDGET;
let accounts = [RefCell::new(Account::new(
let accounts = [RefCell::new(AccountSharedData::new(
1,
10000001,
&solana_sdk::pubkey::new_rand(),

View File

@ -22,7 +22,7 @@ use solana_runtime::{
},
};
use solana_sdk::{
account::Account,
account::AccountSharedData,
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable,
client::SyncClient,
clock::{DEFAULT_SLOTS_PER_EPOCH, MAX_PROCESSING_AGE},
@ -544,10 +544,10 @@ fn test_program_bpf_duplicate_accounts() {
let bank = Arc::new(bank);
let bank_client = BankClient::new_shared(&bank);
let program_id = load_bpf_program(&bank_client, &bpf_loader::id(), &mint_keypair, program);
let payee_account = Account::new(10, 1, &program_id);
let payee_account = AccountSharedData::new(10, 1, &program_id);
let payee_pubkey = solana_sdk::pubkey::new_rand();
bank.store_account(&payee_pubkey, &payee_account);
let account = Account::new(10, 1, &program_id);
let account = AccountSharedData::new(10, 1, &program_id);
let pubkey = solana_sdk::pubkey::new_rand();
let account_metas = vec![
@ -780,15 +780,15 @@ fn test_program_bpf_invoke_sanity() {
load_bpf_program(&bank_client, &bpf_loader::id(), &mint_keypair, program.3);
let argument_keypair = Keypair::new();
let account = Account::new(42, 100, &invoke_program_id);
let account = AccountSharedData::new(42, 100, &invoke_program_id);
bank.store_account(&argument_keypair.pubkey(), &account);
let invoked_argument_keypair = Keypair::new();
let account = Account::new(10, 10, &invoked_program_id);
let account = AccountSharedData::new(10, 10, &invoked_program_id);
bank.store_account(&invoked_argument_keypair.pubkey(), &account);
let from_keypair = Keypair::new();
let account = Account::new(84, 0, &solana_sdk::system_program::id());
let account = AccountSharedData::new(84, 0, &solana_sdk::system_program::id());
bank.store_account(&from_keypair.pubkey(), &account);
let (derived_key1, bump_seed1) =
@ -996,9 +996,9 @@ fn test_program_bpf_invoke_sanity() {
}
// Attempt to realloc into unauthorized address space
let account = Account::new(84, 0, &solana_sdk::system_program::id());
let account = AccountSharedData::new(84, 0, &solana_sdk::system_program::id());
bank.store_account(&from_keypair.pubkey(), &account);
bank.store_account(&derived_key1, &Account::default());
bank.store_account(&derived_key1, &AccountSharedData::default());
let instruction = Instruction::new_with_bytes(
invoke_program_id,
&[
@ -1061,11 +1061,11 @@ fn test_program_bpf_program_id_spoofing() {
);
let from_pubkey = Pubkey::new_unique();
let account = Account::new(10, 0, &solana_sdk::system_program::id());
let account = AccountSharedData::new(10, 0, &solana_sdk::system_program::id());
bank.store_account(&from_pubkey, &account);
let to_pubkey = Pubkey::new_unique();
let account = Account::new(0, 0, &solana_sdk::system_program::id());
let account = AccountSharedData::new(0, 0, &solana_sdk::system_program::id());
bank.store_account(&to_pubkey, &account);
let account_metas = vec![
@ -1148,7 +1148,7 @@ fn test_program_bpf_ro_modify() {
);
let test_keypair = Keypair::new();
let account = Account::new(10, 0, &solana_sdk::system_program::id());
let account = AccountSharedData::new(10, 0, &solana_sdk::system_program::id());
bank.store_account(&test_keypair.pubkey(), &account);
let account_metas = vec![
@ -1261,7 +1261,7 @@ fn assert_instruction_count() {
println!("Test program: {:?}", program.0);
let program_id = solana_sdk::pubkey::new_rand();
let key = solana_sdk::pubkey::new_rand();
let mut account = RefCell::new(Account::default());
let mut account = RefCell::new(AccountSharedData::default());
let parameter_accounts = vec![KeyedAccount::new(&key, false, &mut account)];
let count = run_program(program.0, &program_id, &parameter_accounts[..], &[]).unwrap();
println!(" {} : {:?} ({:?})", program.0, count, program.1,);

View File

@ -866,7 +866,7 @@ mod tests {
message_processor::{Executors, ThisInvokeContext},
};
use solana_sdk::{
account::{create_account, Account},
account::{create_account_shared_data as create_account, AccountSharedData},
account_utils::StateMut,
client::SyncClient,
clock::Clock,
@ -933,7 +933,7 @@ mod tests {
fn test_bpf_loader_write() {
let program_id = bpf_loader::id();
let program_key = solana_sdk::pubkey::new_rand();
let program_account = Account::new_ref(1, 0, &program_id);
let program_account = AccountSharedData::new_ref(1, 0, &program_id);
let keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
let instruction_data = bincode::serialize(&LoaderInstruction::Write {
offset: 3,
@ -1004,7 +1004,8 @@ mod tests {
let mut elf = Vec::new();
let rent = Rent::default();
file.read_to_end(&mut elf).unwrap();
let program_account = Account::new_ref(rent.minimum_balance(elf.len()), 0, &program_id);
let program_account =
AccountSharedData::new_ref(rent.minimum_balance(elf.len()), 0, &program_id);
program_account.borrow_mut().data = elf;
let keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
let instruction_data = bincode::serialize(&LoaderInstruction::Finalize).unwrap();
@ -1069,7 +1070,7 @@ mod tests {
let mut file = File::open("test_elfs/noop_aligned.so").expect("file open failed");
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let program_account = Account::new_ref(1, 0, &program_id);
let program_account = AccountSharedData::new_ref(1, 0, &program_id);
program_account.borrow_mut().data = elf;
program_account.borrow_mut().executable = true;
@ -1098,7 +1099,7 @@ mod tests {
keyed_accounts[0].account.borrow_mut().executable = true;
// Case: With program and parameter account
let parameter_account = Account::new_ref(1, 0, &program_id);
let parameter_account = AccountSharedData::new_ref(1, 0, &program_id);
keyed_accounts.push(KeyedAccount::new(&program_key, false, &parameter_account));
assert_eq!(
Ok(()),
@ -1139,7 +1140,7 @@ mod tests {
// Case: With duplicate accounts
let duplicate_key = solana_sdk::pubkey::new_rand();
let parameter_account = Account::new_ref(1, 0, &program_id);
let parameter_account = AccountSharedData::new_ref(1, 0, &program_id);
let mut keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, &parameter_account));
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, &parameter_account));
@ -1163,13 +1164,13 @@ mod tests {
let mut file = File::open("test_elfs/noop_unaligned.so").expect("file open failed");
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let program_account = Account::new_ref(1, 0, &program_id);
let program_account = AccountSharedData::new_ref(1, 0, &program_id);
program_account.borrow_mut().data = elf;
program_account.borrow_mut().executable = true;
let mut keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
// Case: With program and parameter account
let parameter_account = Account::new_ref(1, 0, &program_id);
let parameter_account = AccountSharedData::new_ref(1, 0, &program_id);
keyed_accounts.push(KeyedAccount::new(&program_key, false, &parameter_account));
assert_eq!(
Ok(()),
@ -1183,7 +1184,7 @@ mod tests {
// Case: With duplicate accounts
let duplicate_key = solana_sdk::pubkey::new_rand();
let parameter_account = Account::new_ref(1, 0, &program_id);
let parameter_account = AccountSharedData::new_ref(1, 0, &program_id);
let mut keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, &parameter_account));
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, &parameter_account));
@ -1207,13 +1208,13 @@ mod tests {
let mut file = File::open("test_elfs/noop_aligned.so").expect("file open failed");
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let program_account = Account::new_ref(1, 0, &program_id);
let program_account = AccountSharedData::new_ref(1, 0, &program_id);
program_account.borrow_mut().data = elf;
program_account.borrow_mut().executable = true;
let mut keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
// Case: With program and parameter account
let parameter_account = Account::new_ref(1, 0, &program_id);
let parameter_account = AccountSharedData::new_ref(1, 0, &program_id);
keyed_accounts.push(KeyedAccount::new(&program_key, false, &parameter_account));
assert_eq!(
Ok(()),
@ -1227,7 +1228,7 @@ mod tests {
// Case: With duplicate accounts
let duplicate_key = solana_sdk::pubkey::new_rand();
let parameter_account = Account::new_ref(1, 0, &program_id);
let parameter_account = AccountSharedData::new_ref(1, 0, &program_id);
let mut keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, &parameter_account));
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, &parameter_account));
@ -1247,13 +1248,13 @@ mod tests {
let instruction =
bincode::serialize(&UpgradeableLoaderInstruction::InitializeBuffer).unwrap();
let buffer_address = Pubkey::new_unique();
let buffer_account = Account::new_ref(
let buffer_account = AccountSharedData::new_ref(
1,
UpgradeableLoaderState::buffer_len(9).unwrap(),
&bpf_loader_upgradeable::id(),
);
let authority_address = Pubkey::new_unique();
let authority_account = Account::new_ref(
let authority_account = AccountSharedData::new_ref(
1,
UpgradeableLoaderState::buffer_len(9).unwrap(),
&bpf_loader_upgradeable::id(),
@ -1305,7 +1306,7 @@ mod tests {
#[test]
fn test_bpf_loader_upgradeable_write() {
let buffer_address = Pubkey::new_unique();
let buffer_account = Account::new_ref(
let buffer_account = AccountSharedData::new_ref(
1,
UpgradeableLoaderState::buffer_len(9).unwrap(),
&bpf_loader_upgradeable::id(),
@ -1372,7 +1373,7 @@ mod tests {
bytes: vec![42; 6],
})
.unwrap();
let buffer_account = Account::new_ref(
let buffer_account = AccountSharedData::new_ref(
1,
UpgradeableLoaderState::buffer_len(9).unwrap(),
&bpf_loader_upgradeable::id(),
@ -1564,7 +1565,7 @@ mod tests {
UpgradeableLoaderState::programdata_len(elf.len()).unwrap(),
);
let buffer_address = Pubkey::new_unique();
let mut buffer_account = Account::new(
let mut buffer_account = AccountSharedData::new(
min_programdata_balance,
UpgradeableLoaderState::buffer_len(elf.len()).unwrap(),
&bpf_loader_upgradeable::id(),
@ -1576,12 +1577,12 @@ mod tests {
.unwrap();
buffer_account.data[UpgradeableLoaderState::buffer_data_offset().unwrap()..]
.copy_from_slice(&elf);
let program_account = Account::new(
let program_account = AccountSharedData::new(
min_programdata_balance,
UpgradeableLoaderState::program_len().unwrap(),
&bpf_loader_upgradeable::id(),
);
let programdata_account = Account::new(
let programdata_account = AccountSharedData::new(
1,
UpgradeableLoaderState::programdata_len(elf.len()).unwrap(),
&bpf_loader_upgradeable::id(),
@ -1590,8 +1591,8 @@ mod tests {
// Test successful deploy
bank.clear_signatures();
bank.store_account(&buffer_address, &buffer_account);
bank.store_account(&program_keypair.pubkey(), &Account::default());
bank.store_account(&programdata_address, &Account::default());
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
bank.store_account(&programdata_address, &AccountSharedData::default());
let before = bank.get_balance(&mint_keypair.pubkey());
let message = Message::new(
&bpf_loader_upgradeable::deploy_with_max_program_len(
@ -1683,7 +1684,7 @@ mod tests {
// Test initialized ProgramData account
bank.clear_signatures();
bank.store_account(&buffer_address, &buffer_account);
bank.store_account(&program_keypair.pubkey(), &Account::default());
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
let message = Message::new(
&bpf_loader_upgradeable::deploy_with_max_program_len(
&mint_keypair.pubkey(),
@ -1772,9 +1773,9 @@ mod tests {
// Test invalid Buffer account state
bank.clear_signatures();
bank.store_account(&buffer_address, &Account::default());
bank.store_account(&program_keypair.pubkey(), &Account::default());
bank.store_account(&programdata_address, &Account::default());
bank.store_account(&buffer_address, &AccountSharedData::default());
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
bank.store_account(&programdata_address, &AccountSharedData::default());
let message = Message::new(
&bpf_loader_upgradeable::deploy_with_max_program_len(
&mint_keypair.pubkey(),
@ -1801,8 +1802,8 @@ mod tests {
// Test program account not rent exempt
bank.clear_signatures();
bank.store_account(&buffer_address, &buffer_account);
bank.store_account(&program_keypair.pubkey(), &Account::default());
bank.store_account(&programdata_address, &Account::default());
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
bank.store_account(&programdata_address, &AccountSharedData::default());
let message = Message::new(
&bpf_loader_upgradeable::deploy_with_max_program_len(
&mint_keypair.pubkey(),
@ -1829,8 +1830,8 @@ mod tests {
// Test program account not rent exempt because data is larger than needed
bank.clear_signatures();
bank.store_account(&buffer_address, &buffer_account);
bank.store_account(&program_keypair.pubkey(), &Account::default());
bank.store_account(&programdata_address, &Account::default());
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
bank.store_account(&programdata_address, &AccountSharedData::default());
let mut instructions = bpf_loader_upgradeable::deploy_with_max_program_len(
&mint_keypair.pubkey(),
&program_keypair.pubkey(),
@ -1862,8 +1863,8 @@ mod tests {
// Test program account too small
bank.clear_signatures();
bank.store_account(&buffer_address, &buffer_account);
bank.store_account(&program_keypair.pubkey(), &Account::default());
bank.store_account(&programdata_address, &Account::default());
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
bank.store_account(&programdata_address, &AccountSharedData::default());
let mut instructions = bpf_loader_upgradeable::deploy_with_max_program_len(
&mint_keypair.pubkey(),
&program_keypair.pubkey(),
@ -1896,11 +1897,11 @@ mod tests {
bank.clear_signatures();
bank.store_account(
&mint_keypair.pubkey(),
&Account::new(min_program_balance, 0, &system_program::id()),
&AccountSharedData::new(min_program_balance, 0, &system_program::id()),
);
bank.store_account(&buffer_address, &buffer_account);
bank.store_account(&program_keypair.pubkey(), &Account::default());
bank.store_account(&programdata_address, &Account::default());
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
bank.store_account(&programdata_address, &AccountSharedData::default());
let message = Message::new(
&bpf_loader_upgradeable::deploy_with_max_program_len(
&mint_keypair.pubkey(),
@ -1925,14 +1926,14 @@ mod tests {
);
bank.store_account(
&mint_keypair.pubkey(),
&Account::new(1_000_000_000, 0, &system_program::id()),
&AccountSharedData::new(1_000_000_000, 0, &system_program::id()),
);
// Test max_data_len
bank.clear_signatures();
bank.store_account(&buffer_address, &buffer_account);
bank.store_account(&program_keypair.pubkey(), &Account::default());
bank.store_account(&programdata_address, &Account::default());
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
bank.store_account(&programdata_address, &AccountSharedData::default());
let message = Message::new(
&bpf_loader_upgradeable::deploy_with_max_program_len(
&mint_keypair.pubkey(),
@ -1960,13 +1961,13 @@ mod tests {
bank.clear_signatures();
bank.store_account(
&mint_keypair.pubkey(),
&Account::new(u64::MAX / 2, 0, &system_program::id()),
&AccountSharedData::new(u64::MAX / 2, 0, &system_program::id()),
);
let mut modified_buffer_account = buffer_account.clone();
modified_buffer_account.lamports = u64::MAX / 2;
bank.store_account(&buffer_address, &modified_buffer_account);
bank.store_account(&program_keypair.pubkey(), &Account::default());
bank.store_account(&programdata_address, &Account::default());
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
bank.store_account(&programdata_address, &AccountSharedData::default());
let message = Message::new(
&bpf_loader_upgradeable::deploy_with_max_program_len(
&mint_keypair.pubkey(),
@ -1993,8 +1994,8 @@ mod tests {
// Test not the system account
bank.clear_signatures();
bank.store_account(&buffer_address, &buffer_account);
bank.store_account(&program_keypair.pubkey(), &Account::default());
bank.store_account(&programdata_address, &Account::default());
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
bank.store_account(&programdata_address, &AccountSharedData::default());
let mut instructions = bpf_loader_upgradeable::deploy_with_max_program_len(
&mint_keypair.pubkey(),
&program_keypair.pubkey(),
@ -2024,8 +2025,8 @@ mod tests {
.data
.truncate(UpgradeableLoaderState::buffer_len(1).unwrap());
bank.store_account(&buffer_address, &modified_buffer_account);
bank.store_account(&program_keypair.pubkey(), &Account::default());
bank.store_account(&programdata_address, &Account::default());
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
bank.store_account(&programdata_address, &AccountSharedData::default());
let message = Message::new(
&bpf_loader_upgradeable::deploy_with_max_program_len(
&mint_keypair.pubkey(),
@ -2051,7 +2052,7 @@ mod tests {
// Test small buffer account
bank.clear_signatures();
let mut modified_buffer_account = Account::new(
let mut modified_buffer_account = AccountSharedData::new(
min_programdata_balance,
UpgradeableLoaderState::buffer_len(elf.len()).unwrap(),
&bpf_loader_upgradeable::id(),
@ -2065,8 +2066,8 @@ mod tests {
.copy_from_slice(&elf);
modified_buffer_account.data.truncate(5);
bank.store_account(&buffer_address, &modified_buffer_account);
bank.store_account(&program_keypair.pubkey(), &Account::default());
bank.store_account(&programdata_address, &Account::default());
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
bank.store_account(&programdata_address, &AccountSharedData::default());
let message = Message::new(
&bpf_loader_upgradeable::deploy_with_max_program_len(
&mint_keypair.pubkey(),
@ -2092,7 +2093,7 @@ mod tests {
// Mismatched buffer and program authority
bank.clear_signatures();
let mut modified_buffer_account = Account::new(
let mut modified_buffer_account = AccountSharedData::new(
min_programdata_balance,
UpgradeableLoaderState::buffer_len(elf.len()).unwrap(),
&bpf_loader_upgradeable::id(),
@ -2105,8 +2106,8 @@ mod tests {
modified_buffer_account.data[UpgradeableLoaderState::buffer_data_offset().unwrap()..]
.copy_from_slice(&elf);
bank.store_account(&buffer_address, &modified_buffer_account);
bank.store_account(&program_keypair.pubkey(), &Account::default());
bank.store_account(&programdata_address, &Account::default());
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
bank.store_account(&programdata_address, &AccountSharedData::default());
let message = Message::new(
&bpf_loader_upgradeable::deploy_with_max_program_len(
&mint_keypair.pubkey(),
@ -2132,7 +2133,7 @@ mod tests {
// Deploy buffer with mismatched None authority
bank.clear_signatures();
let mut modified_buffer_account = Account::new(
let mut modified_buffer_account = AccountSharedData::new(
min_programdata_balance,
UpgradeableLoaderState::buffer_len(elf.len()).unwrap(),
&bpf_loader_upgradeable::id(),
@ -2145,8 +2146,8 @@ mod tests {
modified_buffer_account.data[UpgradeableLoaderState::buffer_data_offset().unwrap()..]
.copy_from_slice(&elf);
bank.store_account(&buffer_address, &modified_buffer_account);
bank.store_account(&program_keypair.pubkey(), &Account::default());
bank.store_account(&programdata_address, &Account::default());
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
bank.store_account(&programdata_address, &AccountSharedData::default());
let message = Message::new(
&bpf_loader_upgradeable::deploy_with_max_program_len(
&mint_keypair.pubkey(),
@ -2202,7 +2203,7 @@ mod tests {
let (programdata_address, _) =
Pubkey::find_program_address(&[program_address.as_ref()], &id());
let spill_address = Pubkey::new_unique();
let upgrade_authority_account = Account::new_ref(1, 0, &Pubkey::new_unique());
let upgrade_authority_account = AccountSharedData::new_ref(1, 0, &Pubkey::new_unique());
#[allow(clippy::type_complexity)]
fn get_accounts(
@ -2215,12 +2216,12 @@ mod tests {
min_program_balance: u64,
min_programdata_balance: u64,
) -> (
Rc<RefCell<Account>>,
Rc<RefCell<Account>>,
Rc<RefCell<Account>>,
Rc<RefCell<Account>>,
Rc<RefCell<AccountSharedData>>,
Rc<RefCell<AccountSharedData>>,
Rc<RefCell<AccountSharedData>>,
Rc<RefCell<AccountSharedData>>,
) {
let buffer_account = Account::new_ref(
let buffer_account = AccountSharedData::new_ref(
1,
UpgradeableLoaderState::buffer_len(elf_new.len()).unwrap(),
&bpf_loader_upgradeable::id(),
@ -2234,7 +2235,7 @@ mod tests {
buffer_account.borrow_mut().data
[UpgradeableLoaderState::buffer_data_offset().unwrap()..]
.copy_from_slice(&elf_new);
let programdata_account = Account::new_ref(
let programdata_account = AccountSharedData::new_ref(
min_programdata_balance,
UpgradeableLoaderState::programdata_len(elf_orig.len().max(elf_new.len())).unwrap(),
&bpf_loader_upgradeable::id(),
@ -2246,7 +2247,7 @@ mod tests {
upgrade_authority_address: Some(*upgrade_authority_address),
})
.unwrap();
let program_account = Account::new_ref(
let program_account = AccountSharedData::new_ref(
min_program_balance,
UpgradeableLoaderState::program_len().unwrap(),
&bpf_loader_upgradeable::id(),
@ -2258,7 +2259,7 @@ mod tests {
programdata_address: *programdata_address,
})
.unwrap();
let spill_account = Account::new_ref(0, 0, &Pubkey::new_unique());
let spill_account = AccountSharedData::new_ref(0, 0, &Pubkey::new_unique());
(
buffer_account,
@ -2648,7 +2649,7 @@ mod tests {
min_program_balance,
min_programdata_balance,
);
let buffer_account = Account::new_ref(
let buffer_account = AccountSharedData::new_ref(
1,
UpgradeableLoaderState::buffer_len(elf_orig.len().max(elf_new.len()) + 1).unwrap(),
&bpf_loader_upgradeable::id(),
@ -2845,13 +2846,13 @@ mod tests {
let instruction = bincode::serialize(&UpgradeableLoaderInstruction::SetAuthority).unwrap();
let slot = 0;
let upgrade_authority_address = Pubkey::new_unique();
let upgrade_authority_account = Account::new_ref(1, 0, &Pubkey::new_unique());
let upgrade_authority_account = AccountSharedData::new_ref(1, 0, &Pubkey::new_unique());
let new_upgrade_authority_address = Pubkey::new_unique();
let new_upgrade_authority_account = Account::new_ref(1, 0, &Pubkey::new_unique());
let new_upgrade_authority_account = AccountSharedData::new_ref(1, 0, &Pubkey::new_unique());
let program_address = Pubkey::new_unique();
let (programdata_address, _) =
Pubkey::find_program_address(&[program_address.as_ref()], &id());
let programdata_account = Account::new_ref(
let programdata_account = AccountSharedData::new_ref(
1,
UpgradeableLoaderState::programdata_len(0).unwrap(),
&bpf_loader_upgradeable::id(),
@ -3037,11 +3038,11 @@ mod tests {
fn test_bpf_loader_upgradeable_set_buffer_authority() {
let instruction = bincode::serialize(&UpgradeableLoaderInstruction::SetAuthority).unwrap();
let authority_address = Pubkey::new_unique();
let authority_account = Account::new_ref(1, 0, &Pubkey::new_unique());
let authority_account = AccountSharedData::new_ref(1, 0, &Pubkey::new_unique());
let new_authority_address = Pubkey::new_unique();
let new_authority_account = Account::new_ref(1, 0, &Pubkey::new_unique());
let new_authority_account = AccountSharedData::new_ref(1, 0, &Pubkey::new_unique());
let buffer_address = Pubkey::new_unique();
let buffer_account = Account::new_ref(
let buffer_account = AccountSharedData::new_ref(
1,
UpgradeableLoaderState::buffer_len(0).unwrap(),
&bpf_loader_upgradeable::id(),
@ -3264,11 +3265,11 @@ mod tests {
0..elf.len(),
0..255,
|bytes: &mut [u8]| {
let program_account = Account::new_ref(1, 0, &program_id);
let program_account = AccountSharedData::new_ref(1, 0, &program_id);
program_account.borrow_mut().data = bytes.to_vec();
program_account.borrow_mut().executable = true;
let parameter_account = Account::new_ref(1, 0, &program_id);
let parameter_account = AccountSharedData::new_ref(1, 0, &program_id);
let keyed_accounts = vec![
KeyedAccount::new(&program_key, false, &program_account),
KeyedAccount::new(&program_key, false, &parameter_account),

View File

@ -243,7 +243,7 @@ pub fn deserialize_parameters_aligned(
mod tests {
use super::*;
use solana_sdk::{
account::Account, account_info::AccountInfo, bpf_loader, entrypoint::deserialize,
account::AccountSharedData, account_info::AccountInfo, bpf_loader, entrypoint::deserialize,
};
use std::{
cell::RefCell,
@ -263,7 +263,7 @@ mod tests {
solana_sdk::pubkey::new_rand(),
];
let accounts = [
RefCell::new(Account {
RefCell::new(AccountSharedData {
lamports: 1,
data: vec![1u8, 2, 3, 4, 5],
owner: bpf_loader::id(),
@ -271,21 +271,21 @@ mod tests {
rent_epoch: 100,
}),
// dup of first
RefCell::new(Account {
RefCell::new(AccountSharedData {
lamports: 1,
data: vec![1u8, 2, 3, 4, 5],
owner: bpf_loader::id(),
executable: false,
rent_epoch: 100,
}),
RefCell::new(Account {
RefCell::new(AccountSharedData {
lamports: 2,
data: vec![11u8, 12, 13, 14, 15, 16, 17, 18, 19],
owner: bpf_loader::id(),
executable: true,
rent_epoch: 200,
}),
RefCell::new(Account {
RefCell::new(AccountSharedData {
lamports: 3,
data: vec![],
owner: bpf_loader::id(),

View File

@ -10,7 +10,7 @@ use solana_rbpf::{
};
use solana_runtime::message_processor::MessageProcessor;
use solana_sdk::{
account::Account,
account::AccountSharedData,
account_info::AccountInfo,
account_utils::StateMut,
bpf_loader, bpf_loader_deprecated,
@ -851,9 +851,12 @@ struct AccountReferences<'a> {
ref_to_len_in_vm: &'a mut u64,
serialized_len_ptr: &'a mut u64,
}
type TranslatedAccount<'a> = (Rc<RefCell<Account>>, Option<AccountReferences<'a>>);
type TranslatedAccount<'a> = (
Rc<RefCell<AccountSharedData>>,
Option<AccountReferences<'a>>,
);
type TranslatedAccounts<'a> = (
Vec<Rc<RefCell<Account>>>,
Vec<Rc<RefCell<AccountSharedData>>>,
Vec<Option<AccountReferences<'a>>>,
);
@ -1018,7 +1021,7 @@ impl<'a> SyscallInvokeSigned<'a> for SyscallInvokeSignedRust<'a> {
};
Ok((
Rc::new(RefCell::new(Account {
Rc::new(RefCell::new(AccountSharedData {
lamports: *lamports,
data: data.to_vec(),
executable: account_info.executable,
@ -1301,7 +1304,7 @@ impl<'a> SyscallInvokeSigned<'a> for SyscallInvokeSignedC<'a> {
)?;
Ok((
Rc::new(RefCell::new(Account {
Rc::new(RefCell::new(AccountSharedData {
lamports: *lamports,
data: data.to_vec(),
executable: account_info.executable,
@ -1512,9 +1515,9 @@ fn check_authorized_program(
fn get_upgradeable_executable(
callee_program_id: &Pubkey,
program_account: &RefCell<Account>,
program_account: &RefCell<AccountSharedData>,
invoke_context: &Ref<&mut dyn InvokeContext>,
) -> Result<Option<(Pubkey, RefCell<Account>)>, EbpfError<BpfError>> {
) -> Result<Option<(Pubkey, RefCell<AccountSharedData>)>, EbpfError<BpfError>> {
if program_account.borrow().owner == bpf_loader_upgradeable::id() {
match program_account.borrow().state() {
Ok(UpgradeableLoaderState::Program {

View File

@ -229,7 +229,7 @@ mod tests {
use crate::id;
use solana_runtime::bank::Bank;
use solana_runtime::bank_client::BankClient;
use solana_sdk::account::Account;
use solana_sdk::account::AccountSharedData;
use solana_sdk::client::SyncClient;
use solana_sdk::genesis_config::create_genesis_config;
use solana_sdk::hash::hash;
@ -522,10 +522,10 @@ mod tests {
fn test_pay_when_account_data() {
let (bank, alice_keypair) = create_bank(42);
let game_pubkey = solana_sdk::pubkey::new_rand();
let game_account = Account {
let game_account = AccountSharedData {
lamports: 1,
data: vec![1, 2, 3],
..Account::default()
..AccountSharedData::default()
};
bank.store_account(&game_pubkey, &game_account);
assert_eq!(bank.get_account(&game_pubkey).unwrap().data, vec![1, 2, 3]);

View File

@ -130,7 +130,7 @@ mod tests {
use bincode::serialized_size;
use serde_derive::{Deserialize, Serialize};
use solana_sdk::{
account::Account,
account::AccountSharedData,
keyed_account::create_keyed_is_signer_accounts,
process_instruction::MockInvokeContext,
signature::{Keypair, Signer},
@ -162,7 +162,7 @@ mod tests {
}
}
fn create_config_account(keys: Vec<(Pubkey, bool)>) -> (Keypair, RefCell<Account>) {
fn create_config_account(keys: Vec<(Pubkey, bool)>) -> (Keypair, RefCell<AccountSharedData>) {
let from_pubkey = solana_sdk::pubkey::new_rand();
let config_keypair = Keypair::new();
let config_pubkey = config_keypair.pubkey();
@ -179,10 +179,10 @@ mod tests {
} => space,
_ => panic!("Not a CreateAccount system instruction"),
};
let config_account = RefCell::new(Account {
let config_account = RefCell::new(AccountSharedData {
data: vec![0; space as usize],
owner: id(),
..Account::default()
..AccountSharedData::default()
});
let accounts = vec![(&config_pubkey, true, &config_account)];
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
@ -298,8 +298,8 @@ mod tests {
let my_config = MyConfig::new(42);
let instruction = config_instruction::store(&config_pubkey, true, keys.clone(), &my_config);
let signer0_account = RefCell::new(Account::default());
let signer1_account = RefCell::new(Account::default());
let signer0_account = RefCell::new(AccountSharedData::default());
let signer1_account = RefCell::new(AccountSharedData::default());
let accounts = vec![
(&config_pubkey, true, &config_account),
(&signer0_pubkey, true, &signer0_account),
@ -334,9 +334,9 @@ mod tests {
let my_config = MyConfig::new(42);
let instruction = config_instruction::store(&config_pubkey, false, keys, &my_config);
let signer0_account = RefCell::new(Account {
let signer0_account = RefCell::new(AccountSharedData {
owner: id(),
..Account::default()
..AccountSharedData::default()
});
let accounts = vec![(&signer0_pubkey, true, &signer0_account)];
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
@ -356,8 +356,8 @@ mod tests {
solana_logger::setup();
let signer0_pubkey = solana_sdk::pubkey::new_rand();
let signer1_pubkey = solana_sdk::pubkey::new_rand();
let signer0_account = RefCell::new(Account::default());
let signer1_account = RefCell::new(Account::default());
let signer0_account = RefCell::new(AccountSharedData::default());
let signer1_account = RefCell::new(AccountSharedData::default());
let keys = vec![(signer0_pubkey, true)];
let (config_keypair, config_account) = create_config_account(keys.clone());
let config_pubkey = config_keypair.pubkey();
@ -405,9 +405,9 @@ mod tests {
let signer0_pubkey = solana_sdk::pubkey::new_rand();
let signer1_pubkey = solana_sdk::pubkey::new_rand();
let signer2_pubkey = solana_sdk::pubkey::new_rand();
let signer0_account = RefCell::new(Account::default());
let signer1_account = RefCell::new(Account::default());
let signer2_account = RefCell::new(Account::default());
let signer0_account = RefCell::new(AccountSharedData::default());
let signer1_account = RefCell::new(AccountSharedData::default());
let signer2_account = RefCell::new(AccountSharedData::default());
let keys = vec![
(pubkey, false),
(signer0_pubkey, true),
@ -508,7 +508,7 @@ mod tests {
solana_logger::setup();
let pubkey = solana_sdk::pubkey::new_rand();
let signer0_pubkey = solana_sdk::pubkey::new_rand();
let signer0_account = RefCell::new(Account::default());
let signer0_account = RefCell::new(AccountSharedData::default());
let keys = vec![
(pubkey, false),
(signer0_pubkey, true),
@ -606,8 +606,8 @@ mod tests {
let config_pubkey = solana_sdk::pubkey::new_rand();
let new_config = MyConfig::new(84);
let signer0_pubkey = solana_sdk::pubkey::new_rand();
let signer0_account = RefCell::new(Account::default());
let config_account = RefCell::new(Account::default());
let signer0_account = RefCell::new(AccountSharedData::default());
let config_account = RefCell::new(AccountSharedData::default());
let keys = vec![
(from_pubkey, false),
(signer0_pubkey, true),

View File

@ -5,7 +5,7 @@ pub mod date_instruction;
use bincode::{deserialize, serialize, serialized_size};
use serde_derive::{Deserialize, Serialize};
use solana_sdk::{account::Account, pubkey::Pubkey, short_vec};
use solana_sdk::{account::AccountSharedData, pubkey::Pubkey, short_vec};
solana_sdk::declare_id!("Config1111111111111111111111111111111111111");
@ -40,13 +40,13 @@ pub fn create_config_account<T: ConfigState>(
keys: Vec<(Pubkey, bool)>,
config_data: &T,
lamports: u64,
) -> Account {
) -> AccountSharedData {
let mut data = serialize(&ConfigKeys { keys }).unwrap();
data.extend_from_slice(&serialize(config_data).unwrap());
Account {
AccountSharedData {
lamports,
data,
owner: id(),
..Account::default()
..AccountSharedData::default()
}
}

View File

@ -61,7 +61,7 @@ mod tests {
use crate::ownable_instruction;
use solana_runtime::{bank::Bank, bank_client::BankClient};
use solana_sdk::{
account::Account,
account::AccountSharedData,
client::SyncClient,
genesis_config::create_genesis_config,
message::Message,
@ -156,7 +156,7 @@ mod tests {
let mut account_owner_pubkey = solana_sdk::pubkey::new_rand();
let owner_pubkey = account_owner_pubkey;
let new_owner_pubkey = solana_sdk::pubkey::new_rand();
let account = Account::new_ref(1, 0, &system_program::id());
let account = AccountSharedData::new_ref(1, 0, &system_program::id());
let owner_keyed_account = KeyedAccount::new(&owner_pubkey, false, &account); // <-- Attack! Setting owner without the original owner's signature.
let err = set_owner(
&mut account_owner_pubkey,
@ -171,7 +171,7 @@ mod tests {
fn test_ownable_incorrect_owner() {
let mut account_owner_pubkey = solana_sdk::pubkey::new_rand();
let new_owner_pubkey = solana_sdk::pubkey::new_rand();
let account = Account::new_ref(1, 0, &system_program::id());
let account = AccountSharedData::new_ref(1, 0, &system_program::id());
let mallory_pubkey = solana_sdk::pubkey::new_rand(); // <-- Attack! Signing with wrong pubkey
let owner_keyed_account = KeyedAccount::new(&mallory_pubkey, true, &account);
let err = set_owner(

View File

@ -4,7 +4,9 @@ use bincode::{deserialize, serialized_size};
use serde_derive::{Deserialize, Serialize};
use solana_config_program::{create_config_account, get_config_data, ConfigState};
use solana_sdk::{
account::Account, genesis_config::GenesisConfig, instruction::InstructionError,
account::{AccountSharedData, ReadableAccount},
genesis_config::GenesisConfig,
instruction::InstructionError,
keyed_account::KeyedAccount,
};
@ -25,8 +27,8 @@ pub struct Config {
}
impl Config {
pub fn from(account: &Account) -> Option<Self> {
get_config_data(&account.data)
pub fn from<T: ReadableAccount>(account: &T) -> Option<Self> {
get_config_data(&account.data())
.ok()
.and_then(|data| deserialize(data).ok())
}
@ -58,7 +60,7 @@ pub fn add_genesis_account(genesis_config: &mut GenesisConfig) -> u64 {
lamports
}
pub fn create_account(lamports: u64, config: &Config) -> Account {
pub fn create_account(lamports: u64, config: &Config) -> AccountSharedData {
create_config_account(vec![], config, lamports)
}

View File

@ -622,7 +622,7 @@ mod tests {
use super::*;
use bincode::serialize;
use solana_sdk::{
account::{self, Account},
account::{self, AccountSharedData},
process_instruction::MockInvokeContext,
rent::Rent,
sysvar::stake_history::StakeHistory,
@ -630,14 +630,14 @@ mod tests {
use std::cell::RefCell;
use std::str::FromStr;
fn create_default_account() -> RefCell<Account> {
RefCell::new(Account::default())
fn create_default_account() -> RefCell<AccountSharedData> {
RefCell::new(AccountSharedData::default())
}
fn create_default_stake_account() -> RefCell<Account> {
RefCell::new(Account {
fn create_default_stake_account() -> RefCell<AccountSharedData> {
RefCell::new(AccountSharedData {
owner: id(),
..Account::default()
..AccountSharedData::default()
})
}
@ -663,34 +663,34 @@ mod tests {
.iter()
.map(|meta| {
RefCell::new(if sysvar::clock::check_id(&meta.pubkey) {
account::create_account(&sysvar::clock::Clock::default(), 1)
account::create_account_shared_data(&sysvar::clock::Clock::default(), 1)
} else if sysvar::rewards::check_id(&meta.pubkey) {
account::create_account(&sysvar::rewards::Rewards::new(0.0), 1)
account::create_account_shared_data(&sysvar::rewards::Rewards::new(0.0), 1)
} else if sysvar::stake_history::check_id(&meta.pubkey) {
account::create_account(&StakeHistory::default(), 1)
account::create_account_shared_data(&StakeHistory::default(), 1)
} else if config::check_id(&meta.pubkey) {
config::create_account(0, &config::Config::default())
} else if sysvar::rent::check_id(&meta.pubkey) {
account::create_account(&Rent::default(), 1)
account::create_account_shared_data(&Rent::default(), 1)
} else if meta.pubkey == invalid_stake_state_pubkey() {
Account {
AccountSharedData {
owner: id(),
..Account::default()
..AccountSharedData::default()
}
} else if meta.pubkey == invalid_vote_state_pubkey() {
Account {
AccountSharedData {
owner: solana_vote_program::id(),
..Account::default()
..AccountSharedData::default()
}
} else if meta.pubkey == spoofed_stake_state_pubkey() {
Account {
AccountSharedData {
owner: spoofed_stake_program_id(),
..Account::default()
..AccountSharedData::default()
}
} else {
Account {
AccountSharedData {
owner: id(),
..Account::default()
..AccountSharedData::default()
}
})
})
@ -973,7 +973,7 @@ mod tests {
KeyedAccount::new(
&sysvar::rent::id(),
false,
&RefCell::new(account::create_account(&Rent::default(), 0))
&RefCell::new(account::create_account_shared_data(&Rent::default(), 0))
)
],
&serialize(&StakeInstruction::Initialize(
@ -1028,12 +1028,15 @@ mod tests {
KeyedAccount::new(
&sysvar::clock::id(),
false,
&RefCell::new(account::create_account(&sysvar::clock::Clock::default(), 1))
&RefCell::new(account::create_account_shared_data(
&sysvar::clock::Clock::default(),
1
))
),
KeyedAccount::new(
&sysvar::stake_history::id(),
false,
&RefCell::new(account::create_account(
&RefCell::new(account::create_account_shared_data(
&sysvar::stake_history::StakeHistory::default(),
1
))
@ -1060,7 +1063,7 @@ mod tests {
KeyedAccount::new(
&sysvar::rewards::id(),
false,
&RefCell::new(account::create_account(
&RefCell::new(account::create_account_shared_data(
&sysvar::rewards::Rewards::new(0.0),
1
))
@ -1068,7 +1071,10 @@ mod tests {
KeyedAccount::new(
&sysvar::stake_history::id(),
false,
&RefCell::new(account::create_account(&StakeHistory::default(), 1,))
&RefCell::new(account::create_account_shared_data(
&StakeHistory::default(),
1,
))
),
],
&serialize(&StakeInstruction::Withdraw(42)).unwrap(),
@ -1101,7 +1107,7 @@ mod tests {
KeyedAccount::new(
&sysvar::rewards::id(),
false,
&RefCell::new(account::create_account(
&RefCell::new(account::create_account_shared_data(
&sysvar::rewards::Rewards::new(0.0),
1
))

View File

@ -10,7 +10,8 @@ use crate::{
};
use serde_derive::{Deserialize, Serialize};
use solana_sdk::{
account::Account,
account::AccountSharedData,
account::ReadableAccount,
account_utils::{State, StateMut},
clock::{Clock, Epoch, UnixTimestamp},
ic_msg,
@ -76,11 +77,11 @@ impl StakeState {
}
// utility function, used by Stakes, tests
pub fn from(account: &Account) -> Option<StakeState> {
pub fn from<T: ReadableAccount + StateMut<StakeState>>(account: &T) -> Option<StakeState> {
account.state().ok()
}
pub fn stake_from(account: &Account) -> Option<Stake> {
pub fn stake_from<T: ReadableAccount + StateMut<StakeState>>(account: &T) -> Option<Stake> {
Self::from(account).and_then(|state: Self| state.stake())
}
pub fn stake(&self) -> Option<Stake> {
@ -90,7 +91,7 @@ impl StakeState {
}
}
pub fn delegation_from(account: &Account) -> Option<Delegation> {
pub fn delegation_from(account: &AccountSharedData) -> Option<Delegation> {
Self::from(account).and_then(|state: Self| state.delegation())
}
pub fn delegation(&self) -> Option<Delegation> {
@ -100,7 +101,7 @@ impl StakeState {
}
}
pub fn authorized_from(account: &Account) -> Option<Authorized> {
pub fn authorized_from(account: &AccountSharedData) -> Option<Authorized> {
Self::from(account).and_then(|state: Self| state.authorized())
}
@ -112,7 +113,7 @@ impl StakeState {
}
}
pub fn lockup_from(account: &Account) -> Option<Lockup> {
pub fn lockup_from<T: ReadableAccount + StateMut<StakeState>>(account: &T) -> Option<Lockup> {
Self::from(account).and_then(|state: Self| state.lockup())
}
@ -120,7 +121,7 @@ impl StakeState {
self.meta().map(|meta| meta.lockup)
}
pub fn meta_from(account: &Account) -> Option<Meta> {
pub fn meta_from(account: &AccountSharedData) -> Option<Meta> {
Self::from(account).and_then(|state: Self| state.meta())
}
@ -1453,8 +1454,8 @@ impl MergeKind {
// returns a tuple of (stakers_reward,voters_reward)
pub fn redeem_rewards(
rewarded_epoch: Epoch,
stake_account: &mut Account,
vote_account: &mut Account,
stake_account: &mut AccountSharedData,
vote_account: &mut AccountSharedData,
point_value: &PointValue,
stake_history: Option<&StakeHistory>,
inflation_point_calc_tracer: &mut Option<impl FnMut(&InflationPointCalculationEvent)>,
@ -1502,8 +1503,8 @@ pub fn redeem_rewards(
// utility function, used by runtime
pub fn calculate_points(
stake_account: &Account,
vote_account: &Account,
stake_account: &AccountSharedData,
vote_account: &AccountSharedData,
stake_history: Option<&StakeHistory>,
fix_stake_deactivate: bool,
) -> Result<u128, InstructionError> {
@ -1538,7 +1539,7 @@ fn calculate_split_rent_exempt_reserve(
pub type RewriteStakeStatus = (&'static str, (u64, u64), (u64, u64));
pub fn rewrite_stakes(
stake_account: &mut Account,
stake_account: &mut AccountSharedData,
rent: &Rent,
) -> Result<RewriteStakeStatus, InstructionError> {
match stake_account.state()? {
@ -1608,8 +1609,9 @@ pub fn create_lockup_stake_account(
lockup: &Lockup,
rent: &Rent,
lamports: u64,
) -> Account {
let mut stake_account = Account::new(lamports, std::mem::size_of::<StakeState>(), &id());
) -> AccountSharedData {
let mut stake_account =
AccountSharedData::new(lamports, std::mem::size_of::<StakeState>(), &id());
let rent_exempt_reserve = rent.minimum_balance(stake_account.data.len());
assert!(
@ -1634,10 +1636,10 @@ pub fn create_lockup_stake_account(
pub fn create_account(
authorized: &Pubkey,
voter_pubkey: &Pubkey,
vote_account: &Account,
vote_account: &AccountSharedData,
rent: &Rent,
lamports: u64,
) -> Account {
) -> AccountSharedData {
do_create_account(
authorized,
voter_pubkey,
@ -1652,11 +1654,11 @@ pub fn create_account(
pub fn create_account_with_activation_epoch(
authorized: &Pubkey,
voter_pubkey: &Pubkey,
vote_account: &Account,
vote_account: &AccountSharedData,
rent: &Rent,
lamports: u64,
activation_epoch: Epoch,
) -> Account {
) -> AccountSharedData {
do_create_account(
authorized,
voter_pubkey,
@ -1670,12 +1672,13 @@ pub fn create_account_with_activation_epoch(
fn do_create_account(
authorized: &Pubkey,
voter_pubkey: &Pubkey,
vote_account: &Account,
vote_account: &AccountSharedData,
rent: &Rent,
lamports: u64,
activation_epoch: Epoch,
) -> Account {
let mut stake_account = Account::new(lamports, std::mem::size_of::<StakeState>(), &id());
) -> AccountSharedData {
let mut stake_account =
AccountSharedData::new(lamports, std::mem::size_of::<StakeState>(), &id());
let vote_state = VoteState::from(vote_account).expect("vote_state");
@ -1706,8 +1709,8 @@ mod tests {
use super::*;
use crate::id;
use solana_sdk::{
account::Account, native_token, process_instruction::MockInvokeContext, pubkey::Pubkey,
system_program,
account::AccountSharedData, native_token, process_instruction::MockInvokeContext,
pubkey::Pubkey, system_program,
};
use solana_vote_program::vote_state;
use std::{cell::RefCell, iter::FromIterator};
@ -1861,7 +1864,7 @@ mod tests {
#[test]
fn test_stake_state_stake_from_fail() {
let mut stake_account = Account::new(0, std::mem::size_of::<StakeState>(), &id());
let mut stake_account = AccountSharedData::new(0, std::mem::size_of::<StakeState>(), &id());
stake_account
.set_state(&StakeState::default())
@ -1917,7 +1920,7 @@ mod tests {
let stake_pubkey = solana_sdk::pubkey::new_rand();
let stake_lamports = 42;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Initialized(Meta {
authorized: Authorized {
@ -2679,7 +2682,7 @@ mod tests {
let stake_pubkey = solana_sdk::pubkey::new_rand();
let stake_lamports = 42;
let stake_account =
Account::new_ref(stake_lamports, std::mem::size_of::<StakeState>(), &id());
AccountSharedData::new_ref(stake_lamports, std::mem::size_of::<StakeState>(), &id());
// unsigned keyed account
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, false, &stake_account);
@ -2742,8 +2745,11 @@ mod tests {
fn test_initialize_incorrect_account_sizes() {
let stake_pubkey = solana_sdk::pubkey::new_rand();
let stake_lamports = 42;
let stake_account =
Account::new_ref(stake_lamports, std::mem::size_of::<StakeState>() + 1, &id());
let stake_account = AccountSharedData::new_ref(
stake_lamports,
std::mem::size_of::<StakeState>() + 1,
&id(),
);
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, false, &stake_account);
assert_eq!(
@ -2758,8 +2764,11 @@ mod tests {
Err(InstructionError::InvalidAccountData)
);
let stake_account =
Account::new_ref(stake_lamports, std::mem::size_of::<StakeState>() - 1, &id());
let stake_account = AccountSharedData::new_ref(
stake_lamports,
std::mem::size_of::<StakeState>() - 1,
&id(),
);
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, false, &stake_account);
assert_eq!(
@ -2779,7 +2788,7 @@ mod tests {
fn test_deactivate() {
let stake_pubkey = solana_sdk::pubkey::new_rand();
let stake_lamports = 42;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Initialized(Meta::auto(&stake_pubkey)),
std::mem::size_of::<StakeState>(),
@ -2845,7 +2854,7 @@ mod tests {
fn test_set_lockup() {
let stake_pubkey = solana_sdk::pubkey::new_rand();
let stake_lamports = 42;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>(),
@ -2942,7 +2951,7 @@ mod tests {
fn test_optional_lockup() {
let stake_pubkey = solana_sdk::pubkey::new_rand();
let stake_lamports = 42;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>(),
@ -3056,7 +3065,7 @@ mod tests {
fn test_withdraw_stake() {
let stake_pubkey = solana_sdk::pubkey::new_rand();
let stake_lamports = 42;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>(),
@ -3067,7 +3076,7 @@ mod tests {
let mut clock = Clock::default();
let to = solana_sdk::pubkey::new_rand();
let to_account = Account::new_ref(1, 0, &system_program::id());
let to_account = AccountSharedData::new_ref(1, 0, &system_program::id());
let to_keyed_account = KeyedAccount::new(&to, false, &to_account);
// no signers, should fail
@ -3232,7 +3241,7 @@ mod tests {
let rent_exempt_reserve = rent.minimum_balance(std::mem::size_of::<StakeState>());
let authority_pubkey = Pubkey::new_unique();
let stake_pubkey = Pubkey::new_unique();
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
1_000_000_000,
&StakeState::Initialized(Meta {
rent_exempt_reserve,
@ -3248,7 +3257,7 @@ mod tests {
.expect("stake_account");
let stake2_pubkey = Pubkey::new_unique();
let stake2_account = Account::new_ref_data_with_space(
let stake2_account = AccountSharedData::new_ref_data_with_space(
1_000_000_000,
&StakeState::Initialized(Meta {
rent_exempt_reserve,
@ -3265,7 +3274,7 @@ mod tests {
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
let stake2_keyed_account = KeyedAccount::new(&stake2_pubkey, false, &stake2_account);
let authority_account = Account::new_ref(42, 0, &system_program::id());
let authority_account = AccountSharedData::new_ref(42, 0, &system_program::id());
let authority_keyed_account =
KeyedAccount::new(&authority_pubkey, true, &authority_account);
@ -3287,7 +3296,7 @@ mod tests {
let stake_pubkey = solana_sdk::pubkey::new_rand();
let total_lamports = 100;
let stake_lamports = 42;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
total_lamports,
&StakeState::Initialized(Meta::auto(&stake_pubkey)),
std::mem::size_of::<StakeState>(),
@ -3300,7 +3309,7 @@ mod tests {
future.epoch += 16;
let to = solana_sdk::pubkey::new_rand();
let to_account = Account::new_ref(1, 0, &system_program::id());
let to_account = AccountSharedData::new_ref(1, 0, &system_program::id());
let to_keyed_account = KeyedAccount::new(&to, false, &to_account);
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
@ -3357,7 +3366,7 @@ mod tests {
fn test_withdraw_stake_invalid_state() {
let stake_pubkey = solana_sdk::pubkey::new_rand();
let total_lamports = 100;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
total_lamports,
&StakeState::RewardsPool,
std::mem::size_of::<StakeState>(),
@ -3366,7 +3375,7 @@ mod tests {
.expect("stake_account");
let to = solana_sdk::pubkey::new_rand();
let to_account = Account::new_ref(1, 0, &system_program::id());
let to_account = AccountSharedData::new_ref(1, 0, &system_program::id());
let to_keyed_account = KeyedAccount::new(&to, false, &to_account);
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
assert_eq!(
@ -3387,7 +3396,7 @@ mod tests {
let stake_pubkey = solana_sdk::pubkey::new_rand();
let custodian = solana_sdk::pubkey::new_rand();
let total_lamports = 100;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
total_lamports,
&StakeState::Initialized(Meta {
lockup: Lockup {
@ -3403,7 +3412,7 @@ mod tests {
.expect("stake_account");
let to = solana_sdk::pubkey::new_rand();
let to_account = Account::new_ref(1, 0, &system_program::id());
let to_account = AccountSharedData::new_ref(1, 0, &system_program::id());
let to_keyed_account = KeyedAccount::new(&to, false, &to_account);
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
@ -3424,7 +3433,7 @@ mod tests {
);
{
let custodian_account = Account::new_ref(1, 0, &system_program::id());
let custodian_account = AccountSharedData::new_ref(1, 0, &system_program::id());
let custodian_keyed_account = KeyedAccount::new(&custodian, true, &custodian_account);
assert_eq!(
stake_keyed_account.withdraw(
@ -3463,7 +3472,7 @@ mod tests {
let stake_pubkey = solana_sdk::pubkey::new_rand();
let custodian = stake_pubkey;
let total_lamports = 100;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
total_lamports,
&StakeState::Initialized(Meta {
lockup: Lockup {
@ -3479,7 +3488,7 @@ mod tests {
.expect("stake_account");
let to = solana_sdk::pubkey::new_rand();
let to_account = Account::new_ref(1, 0, &system_program::id());
let to_account = AccountSharedData::new_ref(1, 0, &system_program::id());
let to_keyed_account = KeyedAccount::new(&to, false, &to_account);
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
@ -3816,7 +3825,7 @@ mod tests {
fn test_authorize_uninit() {
let new_authority = solana_sdk::pubkey::new_rand();
let stake_lamports = 42;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::default(),
std::mem::size_of::<StakeState>(),
@ -3843,7 +3852,7 @@ mod tests {
fn test_authorize_lockup() {
let stake_authority = solana_sdk::pubkey::new_rand();
let stake_lamports = 42;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Initialized(Meta::auto(&stake_authority)),
std::mem::size_of::<StakeState>(),
@ -3852,7 +3861,7 @@ mod tests {
.expect("stake_account");
let to = solana_sdk::pubkey::new_rand();
let to_account = Account::new_ref(1, 0, &system_program::id());
let to_account = AccountSharedData::new_ref(1, 0, &system_program::id());
let to_keyed_account = KeyedAccount::new(&to, false, &to_account);
let clock = Clock::default();
@ -3980,7 +3989,7 @@ mod tests {
let seed = "42";
let withdrawer_pubkey = Pubkey::create_with_seed(&base_pubkey, &seed, &id()).unwrap();
let stake_lamports = 42;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Initialized(Meta::auto(&withdrawer_pubkey)),
std::mem::size_of::<StakeState>(),
@ -3988,7 +3997,7 @@ mod tests {
)
.expect("stake_account");
let base_account = Account::new_ref(1, 0, &id());
let base_account = AccountSharedData::new_ref(1, 0, &id());
let base_keyed_account = KeyedAccount::new(&base_pubkey, true, &base_account);
let stake_keyed_account = KeyedAccount::new(&withdrawer_pubkey, true, &stake_account);
@ -4075,7 +4084,7 @@ mod tests {
fn test_authorize_override() {
let withdrawer_pubkey = solana_sdk::pubkey::new_rand();
let stake_lamports = 42;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Initialized(Meta::auto(&withdrawer_pubkey)),
std::mem::size_of::<StakeState>(),
@ -4162,7 +4171,7 @@ mod tests {
fn test_split_source_uninitialized() {
let stake_pubkey = solana_sdk::pubkey::new_rand();
let stake_lamports = 42;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>(),
@ -4171,7 +4180,7 @@ mod tests {
.expect("stake_account");
let split_stake_pubkey = solana_sdk::pubkey::new_rand();
let split_stake_account = Account::new_ref_data_with_space(
let split_stake_account = AccountSharedData::new_ref_data_with_space(
0,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>(),
@ -4209,7 +4218,7 @@ mod tests {
fn test_split_split_not_uninitialized() {
let stake_pubkey = solana_sdk::pubkey::new_rand();
let stake_lamports = 42;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Stake(Meta::auto(&stake_pubkey), Stake::just_stake(stake_lamports)),
std::mem::size_of::<StakeState>(),
@ -4218,7 +4227,7 @@ mod tests {
.expect("stake_account");
let split_stake_pubkey = solana_sdk::pubkey::new_rand();
let split_stake_account = Account::new_ref_data_with_space(
let split_stake_account = AccountSharedData::new_ref_data_with_space(
0,
&StakeState::Initialized(Meta::auto(&stake_pubkey)),
std::mem::size_of::<StakeState>(),
@ -4251,7 +4260,7 @@ mod tests {
fn test_split_more_than_staked() {
let stake_pubkey = solana_sdk::pubkey::new_rand();
let stake_lamports = 42;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Stake(
Meta::auto(&stake_pubkey),
@ -4263,7 +4272,7 @@ mod tests {
.expect("stake_account");
let split_stake_pubkey = solana_sdk::pubkey::new_rand();
let split_stake_account = Account::new_ref_data_with_space(
let split_stake_account = AccountSharedData::new_ref_data_with_space(
0,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>(),
@ -4303,7 +4312,7 @@ mod tests {
Stake::just_stake(stake_lamports - rent_exempt_reserve),
),
] {
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
state,
std::mem::size_of::<StakeState>(),
@ -4313,7 +4322,7 @@ mod tests {
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
let split_stake_account = Account::new_ref_data_with_space(
let split_stake_account = AccountSharedData::new_ref_data_with_space(
0,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>(),
@ -4395,7 +4404,7 @@ mod tests {
StakeState::Initialized(Meta::auto(&stake_pubkey)),
StakeState::Stake(Meta::auto(&stake_pubkey), Stake::just_stake(stake_lamports)),
] {
let split_stake_account = Account::new_ref_data_with_space(
let split_stake_account = AccountSharedData::new_ref_data_with_space(
0,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>(),
@ -4406,7 +4415,7 @@ mod tests {
let split_stake_keyed_account =
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_account);
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
state,
std::mem::size_of::<StakeState>(),
@ -4482,7 +4491,7 @@ mod tests {
let split_stake_pubkey = solana_sdk::pubkey::new_rand();
let signers = vec![stake_pubkey].into_iter().collect();
let split_stake_account = Account::new_ref_data_with_space(
let split_stake_account = AccountSharedData::new_ref_data_with_space(
0,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>(),
@ -4493,7 +4502,7 @@ mod tests {
let split_stake_keyed_account =
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_account);
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Stake(Meta::auto(&stake_pubkey), Stake::just_stake(stake_lamports)),
std::mem::size_of::<StakeState>(),
@ -4533,7 +4542,7 @@ mod tests {
// test_split, since that test uses a Meta with rent_exempt_reserve = 0
let split_lamport_balances = vec![0, 1, rent_exempt_reserve, rent_exempt_reserve + 1];
for initial_balance in split_lamport_balances {
let split_stake_account = Account::new_ref_data_with_space(
let split_stake_account = AccountSharedData::new_ref_data_with_space(
initial_balance,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>(),
@ -4544,7 +4553,7 @@ mod tests {
let split_stake_keyed_account =
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_account);
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&state,
std::mem::size_of::<StakeState>(),
@ -4648,7 +4657,7 @@ mod tests {
expected_rent_exempt_reserve + 1,
];
for initial_balance in split_lamport_balances {
let split_stake_account = Account::new_ref_data_with_space(
let split_stake_account = AccountSharedData::new_ref_data_with_space(
initial_balance,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>(),
@ -4659,7 +4668,7 @@ mod tests {
let split_stake_keyed_account =
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_account);
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&state,
std::mem::size_of::<StakeState>() + 100,
@ -4766,7 +4775,7 @@ mod tests {
expected_rent_exempt_reserve + 1,
];
for initial_balance in split_lamport_balances {
let split_stake_account = Account::new_ref_data_with_space(
let split_stake_account = AccountSharedData::new_ref_data_with_space(
initial_balance,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>() + 100,
@ -4777,7 +4786,7 @@ mod tests {
let split_stake_keyed_account =
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_account);
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&state,
std::mem::size_of::<StakeState>(),
@ -4822,7 +4831,7 @@ mod tests {
Stake::just_stake(stake_lamports - rent_exempt_reserve),
),
] {
let split_stake_account = Account::new_ref_data_with_space(
let split_stake_account = AccountSharedData::new_ref_data_with_space(
0,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>(),
@ -4833,7 +4842,7 @@ mod tests {
let split_stake_keyed_account =
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_account);
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
state,
std::mem::size_of::<StakeState>(),
@ -4909,7 +4918,7 @@ mod tests {
// covered in test_split_100_percent_of_source, but included here as well for readability
let split_lamport_balances = vec![0, 1, rent_exempt_reserve, rent_exempt_reserve + 1];
for initial_balance in split_lamport_balances {
let split_stake_account = Account::new_ref_data_with_space(
let split_stake_account = AccountSharedData::new_ref_data_with_space(
initial_balance,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>(),
@ -4920,7 +4929,7 @@ mod tests {
let split_stake_keyed_account =
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_account);
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&state,
std::mem::size_of::<StakeState>(),
@ -4985,7 +4994,7 @@ mod tests {
),
] {
// Test that splitting to a larger account fails
let split_stake_account = Account::new_ref_data_with_space(
let split_stake_account = AccountSharedData::new_ref_data_with_space(
0,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>() + 10000,
@ -4995,7 +5004,7 @@ mod tests {
let split_stake_keyed_account =
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_account);
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&state,
std::mem::size_of::<StakeState>(),
@ -5011,7 +5020,7 @@ mod tests {
// Test that splitting from a larger account to a smaller one works.
// Split amount should not matter, assuming other fund criteria are met
let split_stake_account = Account::new_ref_data_with_space(
let split_stake_account = AccountSharedData::new_ref_data_with_space(
0,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>(),
@ -5021,7 +5030,7 @@ mod tests {
let split_stake_keyed_account =
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_account);
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&state,
std::mem::size_of::<StakeState>() + 100,
@ -5114,7 +5123,7 @@ mod tests {
Stake::just_stake(stake_lamports),
),
] {
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
state,
std::mem::size_of::<StakeState>(),
@ -5123,7 +5132,7 @@ mod tests {
.expect("stake_account");
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
let source_stake_account = Account::new_ref_data_with_space(
let source_stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
source_state,
std::mem::size_of::<StakeState>(),
@ -5227,7 +5236,7 @@ mod tests {
},
..Stake::default()
};
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Stake(meta, stake),
std::mem::size_of::<StakeState>(),
@ -5274,7 +5283,7 @@ mod tests {
Stake::just_stake(stake_lamports),
),
] {
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
state,
std::mem::size_of::<StakeState>(),
@ -5283,7 +5292,7 @@ mod tests {
.expect("stake_account");
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
let source_stake_account = Account::new_ref_data_with_space(
let source_stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
source_state,
std::mem::size_of::<StakeState>(),
@ -5337,7 +5346,7 @@ mod tests {
),
] {
for source_state in &[StakeState::Uninitialized, StakeState::RewardsPool] {
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
state,
std::mem::size_of::<StakeState>(),
@ -5346,7 +5355,7 @@ mod tests {
.expect("stake_account");
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
let source_stake_account = Account::new_ref_data_with_space(
let source_stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
source_state,
std::mem::size_of::<StakeState>(),
@ -5380,7 +5389,7 @@ mod tests {
let signers = vec![authorized_pubkey].into_iter().collect();
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Stake(
Meta::auto(&authorized_pubkey),
@ -5392,7 +5401,7 @@ mod tests {
.expect("stake_account");
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
let source_stake_account = Account::new_ref_data_with_space(
let source_stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Stake(
Meta::auto(&authorized_pubkey),
@ -5444,7 +5453,7 @@ mod tests {
},
..Stake::default()
};
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Stake(meta, stake),
std::mem::size_of::<StakeState>(),
@ -5462,7 +5471,7 @@ mod tests {
},
..stake
};
let source_account = Account::new_ref_data_with_space(
let source_account = AccountSharedData::new_ref_data_with_space(
source_lamports,
&StakeState::Stake(meta, source_stake),
std::mem::size_of::<StakeState>(),
@ -5768,7 +5777,7 @@ mod tests {
fn test_authorize_delegated_stake() {
let stake_pubkey = solana_sdk::pubkey::new_rand();
let stake_lamports = 42;
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Initialized(Meta::auto(&stake_pubkey)),
std::mem::size_of::<StakeState>(),
@ -5879,7 +5888,7 @@ mod tests {
rent_exempt_reserve,
..Meta::auto(&withdrawer_pubkey)
};
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Initialized(meta),
std::mem::size_of::<StakeState>(),
@ -5916,7 +5925,7 @@ mod tests {
clock.epoch += 1;
let to = Pubkey::new_unique();
let to_account = Account::new_ref(1, 0, &system_program::id());
let to_account = AccountSharedData::new_ref(1, 0, &system_program::id());
let to_keyed_account = KeyedAccount::new(&to, false, &to_account);
let withdraw_lamports = initial_lamports / 2;
stake_keyed_account
@ -6052,7 +6061,7 @@ mod tests {
rent_exempt_reserve: rent_exempt_reserve + offset,
..Meta::default()
};
let mut account = Account::new(account_balance, right_data_len, &id());
let mut account = AccountSharedData::new(account_balance, right_data_len, &id());
account.set_state(&StakeState::Initialized(meta)).unwrap();
let result = rewrite_stakes(&mut account, &rent);
match expected_rewrite {
@ -6088,7 +6097,7 @@ mod tests {
}),
..Stake::default()
};
let mut account = Account::new(account_balance, right_data_len, &id());
let mut account = AccountSharedData::new(account_balance, right_data_len, &id());
account.set_state(&StakeState::Stake(meta, stake)).unwrap();
let result = rewrite_stakes(&mut account, &rent);
match expected_rewrite {
@ -6318,7 +6327,7 @@ mod tests {
rent_exempt_reserve,
..Meta::auto(&authority_pubkey)
};
let stake_account = Account::new_ref_data_with_space(
let stake_account = AccountSharedData::new_ref_data_with_space(
stake_lamports,
&StakeState::Uninitialized,
std::mem::size_of::<StakeState>(),

View File

@ -7,7 +7,7 @@ use chrono::prelude::*;
use solana_config_program::date_instruction::DateConfig;
use solana_config_program::get_config_data;
use solana_sdk::{
account::Account,
account::AccountSharedData,
feature_set,
instruction::InstructionError,
keyed_account::{next_keyed_account, KeyedAccount},
@ -38,7 +38,7 @@ fn verify_date_account(
fn verify_account<'a>(
keyed_account: &'a KeyedAccount,
expected_pubkey: &Pubkey,
) -> Result<RefMut<'a, Account>, InstructionError> {
) -> Result<RefMut<'a, AccountSharedData>, InstructionError> {
if keyed_account.unsigned_key() != expected_pubkey {
return Err(VestError::Unauthorized.into());
}
@ -49,7 +49,7 @@ fn verify_account<'a>(
fn verify_signed_account<'a>(
keyed_account: &'a KeyedAccount,
expected_pubkey: &Pubkey,
) -> Result<RefMut<'a, Account>, InstructionError> {
) -> Result<RefMut<'a, AccountSharedData>, InstructionError> {
if keyed_account.signer_key().is_none() {
return Err(InstructionError::MissingRequiredSignature);
}
@ -270,7 +270,7 @@ mod tests {
fn test_verify_account_unauthorized() {
// Ensure client can't sneak in with an untrusted date account.
let date_pubkey = solana_sdk::pubkey::new_rand();
let account = Account::new_ref(1, 0, &solana_config_program::id());
let account = AccountSharedData::new_ref(1, 0, &solana_config_program::id());
let keyed_account = KeyedAccount::new(&date_pubkey, false, &account);
let mallory_pubkey = solana_sdk::pubkey::new_rand(); // <-- Attack! Not the expected account.
@ -284,7 +284,7 @@ mod tests {
fn test_verify_signed_account_missing_signature() {
// Ensure client can't sneak in with an unsigned account.
let date_pubkey = solana_sdk::pubkey::new_rand();
let account = Account::new_ref(1, 0, &solana_config_program::id());
let account = AccountSharedData::new_ref(1, 0, &solana_config_program::id());
let keyed_account = KeyedAccount::new(&date_pubkey, false, &account); // <-- Attack! Unsigned transaction.
assert_eq!(
@ -297,7 +297,7 @@ mod tests {
fn test_verify_date_account_incorrect_program_id() {
// Ensure client can't sneak in with a non-Config account.
let date_pubkey = solana_sdk::pubkey::new_rand();
let account = Account::new_ref(1, 0, &id()); // <-- Attack! Pass Vest account where Config account is expected.
let account = AccountSharedData::new_ref(1, 0, &id()); // <-- Attack! Pass Vest account where Config account is expected.
let keyed_account = KeyedAccount::new(&date_pubkey, false, &account);
assert_eq!(
verify_date_account(&keyed_account, &date_pubkey).unwrap_err(),
@ -309,7 +309,7 @@ mod tests {
fn test_verify_date_account_uninitialized_config() {
// Ensure no panic when `get_config_data()` returns an error.
let date_pubkey = solana_sdk::pubkey::new_rand();
let account = Account::new_ref(1, 0, &solana_config_program::id()); // <-- Attack! Zero space.
let account = AccountSharedData::new_ref(1, 0, &solana_config_program::id()); // <-- Attack! Zero space.
let keyed_account = KeyedAccount::new(&date_pubkey, false, &account);
assert_eq!(
verify_date_account(&keyed_account, &date_pubkey).unwrap_err(),
@ -321,7 +321,7 @@ mod tests {
fn test_verify_date_account_invalid_date_config() {
// Ensure no panic when `deserialize::<DateConfig>()` returns an error.
let date_pubkey = solana_sdk::pubkey::new_rand();
let account = Account::new_ref(1, 1, &solana_config_program::id()); // Attack! 1 byte, enough to sneak by `get_config_data()`, but not DateConfig deserialize.
let account = AccountSharedData::new_ref(1, 1, &solana_config_program::id()); // Attack! 1 byte, enough to sneak by `get_config_data()`, but not DateConfig deserialize.
let keyed_account = KeyedAccount::new(&date_pubkey, false, &account);
assert_eq!(
verify_date_account(&keyed_account, &date_pubkey).unwrap_err(),
@ -333,7 +333,7 @@ mod tests {
fn test_verify_date_account_deserialize() {
// Ensure no panic when `deserialize::<DateConfig>()` returns an error.
let date_pubkey = solana_sdk::pubkey::new_rand();
let account = Account::new_ref(1, 1, &solana_config_program::id()); // Attack! 1 byte, enough to sneak by `get_config_data()`, but not DateConfig deserialize.
let account = AccountSharedData::new_ref(1, 1, &solana_config_program::id()); // Attack! 1 byte, enough to sneak by `get_config_data()`, but not DateConfig deserialize.
let keyed_account = KeyedAccount::new(&date_pubkey, false, &account);
assert_eq!(
verify_date_account(&keyed_account, &date_pubkey).unwrap_err(),

View File

@ -7,7 +7,7 @@ use chrono::{
serde::ts_seconds,
};
use serde_derive::{Deserialize, Serialize};
use solana_sdk::{account::Account, instruction::InstructionError, pubkey::Pubkey};
use solana_sdk::{account::AccountSharedData, instruction::InstructionError, pubkey::Pubkey};
use std::cmp::min;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
@ -82,9 +82,9 @@ impl VestState {
/// Redeem vested tokens.
pub fn redeem_tokens(
&mut self,
contract_account: &mut Account,
contract_account: &mut AccountSharedData,
current_date: Date<Utc>,
payee_account: &mut Account,
payee_account: &mut AccountSharedData,
) {
let vested_lamports = self.calc_vested_lamports(current_date);
let redeemable_lamports = vested_lamports.saturating_sub(self.redeemed_lamports);
@ -98,8 +98,8 @@ impl VestState {
/// Renege on the given number of tokens and send them to the given payee.
pub fn renege(
&mut self,
contract_account: &mut Account,
payee_account: &mut Account,
contract_account: &mut AccountSharedData,
payee_account: &mut AccountSharedData,
lamports: u64,
) {
let reneged_lamports = min(contract_account.lamports, lamports);
@ -119,12 +119,12 @@ impl VestState {
mod test {
use super::*;
use crate::id;
use solana_sdk::account::Account;
use solana_sdk::account::AccountSharedData;
use solana_sdk::system_program;
#[test]
fn test_serializer() {
let mut a = Account::new(0, 512, &id());
let mut a = AccountSharedData::new(0, 512, &id());
let b = VestState::default();
b.serialize(&mut a.data).unwrap();
let c = VestState::deserialize(&a.data).unwrap();
@ -133,7 +133,7 @@ mod test {
#[test]
fn test_serializer_data_too_small() {
let mut a = Account::new(0, 1, &id());
let mut a = AccountSharedData::new(0, 1, &id());
let b = VestState::default();
assert_eq!(
b.serialize(&mut a.data),
@ -144,8 +144,8 @@ mod test {
#[test]
fn test_schedule_after_renege() {
let total_lamports = 3;
let mut contract_account = Account::new(total_lamports, 512, &id());
let mut payee_account = Account::new(0, 0, &system_program::id());
let mut contract_account = AccountSharedData::new(total_lamports, 512, &id());
let mut payee_account = AccountSharedData::new(0, 0, &system_program::id());
let mut vest_state = VestState {
total_lamports,
start_date_time: Utc.ymd(2019, 1, 1).and_hms(0, 0, 0),
@ -171,7 +171,7 @@ mod test {
#[test]
fn test_vest_all() {
let total_lamports = 3;
let mut contract_account = Account::new(total_lamports, 512, &id());
let mut contract_account = AccountSharedData::new(total_lamports, 512, &id());
let mut vest_state = VestState {
total_lamports,
start_date_time: Utc.ymd(2019, 1, 1).and_hms(0, 0, 0),

View File

@ -342,7 +342,7 @@ pub fn process_instruction(
mod tests {
use super::*;
use solana_sdk::{
account::{self, Account},
account::{self, AccountSharedData},
process_instruction::MockInvokeContext,
rent::Rent,
};
@ -370,27 +370,27 @@ mod tests {
.iter()
.map(|meta| {
RefCell::new(if sysvar::clock::check_id(&meta.pubkey) {
account::create_account(&Clock::default(), 1)
account::create_account_shared_data(&Clock::default(), 1)
} else if sysvar::slot_hashes::check_id(&meta.pubkey) {
account::create_account(&SlotHashes::default(), 1)
account::create_account_shared_data(&SlotHashes::default(), 1)
} else if sysvar::rent::check_id(&meta.pubkey) {
account::create_account(&Rent::free(), 1)
account::create_account_shared_data(&Rent::free(), 1)
} else if meta.pubkey == invalid_vote_state_pubkey() {
Account {
AccountSharedData {
owner: invalid_vote_state_pubkey(),
..Account::default()
..AccountSharedData::default()
}
} else {
Account {
AccountSharedData {
owner: id(),
..Account::default()
..AccountSharedData::default()
}
})
})
.collect();
for _ in 0..instruction.accounts.len() {
accounts.push(RefCell::new(Account::default()));
accounts.push(RefCell::new(AccountSharedData::default()));
}
{
let keyed_accounts: Vec<_> = instruction

View File

@ -6,7 +6,7 @@ use bincode::{deserialize, serialize_into, serialized_size, ErrorKind};
use log::*;
use serde_derive::{Deserialize, Serialize};
use solana_sdk::{
account::Account,
account::{AccountSharedData, ReadableAccount, WritableAccount},
account_utils::State,
clock::{Epoch, Slot, UnixTimestamp},
epoch_schedule::MAX_LEADER_SCHEDULE_EPOCH_OFFSET,
@ -223,13 +223,13 @@ impl VoteState {
}
// utility function, used by Stakes, tests
pub fn from(account: &Account) -> Option<VoteState> {
Self::deserialize(&account.data).ok()
pub fn from<T: ReadableAccount>(account: &T) -> Option<VoteState> {
Self::deserialize(&account.data()).ok()
}
// utility function, used by Stakes, tests
pub fn to(versioned: &VoteStateVersions, account: &mut Account) -> Option<()> {
Self::serialize(versioned, &mut account.data).ok()
pub fn to<T: WritableAccount>(versioned: &VoteStateVersions, account: &mut T) -> Option<()> {
Self::serialize(versioned, &mut account.data_as_mut_slice()).ok()
}
pub fn deserialize(input: &[u8]) -> Result<Self, InstructionError> {
@ -248,7 +248,7 @@ impl VoteState {
})
}
pub fn credits_from(account: &Account) -> Option<u64> {
pub fn credits_from<T: ReadableAccount>(account: &T) -> Option<u64> {
Self::from(account).map(|state| state.credits())
}
@ -747,8 +747,8 @@ pub fn create_account_with_authorized(
authorized_withdrawer: &Pubkey,
commission: u8,
lamports: u64,
) -> Account {
let mut vote_account = Account::new(lamports, VoteState::size_of(), &id());
) -> AccountSharedData {
let mut vote_account = AccountSharedData::new(lamports, VoteState::size_of(), &id());
let vote_state = VoteState::new(
&VoteInit {
@ -772,7 +772,7 @@ pub fn create_account(
node_pubkey: &Pubkey,
commission: u8,
lamports: u64,
) -> Account {
) -> AccountSharedData {
create_account_with_authorized(node_pubkey, vote_pubkey, vote_pubkey, commission, lamports)
}
@ -781,7 +781,7 @@ mod tests {
use super::*;
use crate::vote_state;
use solana_sdk::{
account::Account,
account::AccountSharedData,
account_utils::StateMut,
hash::hash,
keyed_account::{get_signers, next_keyed_account},
@ -807,11 +807,11 @@ mod tests {
#[test]
fn test_initialize_vote_account() {
let vote_account_pubkey = solana_sdk::pubkey::new_rand();
let vote_account = Account::new_ref(100, VoteState::size_of(), &id());
let vote_account = AccountSharedData::new_ref(100, VoteState::size_of(), &id());
let vote_account = KeyedAccount::new(&vote_account_pubkey, false, &vote_account);
let node_pubkey = solana_sdk::pubkey::new_rand();
let node_account = RefCell::new(Account::default());
let node_account = RefCell::new(AccountSharedData::default());
let keyed_accounts = &[];
let signers: HashSet<Pubkey> = get_signers(keyed_accounts);
@ -864,7 +864,7 @@ mod tests {
assert_eq!(res, Err(InstructionError::AccountAlreadyInitialized));
//init should fail, account is too big
let large_vote_account = Account::new_ref(100, 2 * VoteState::size_of(), &id());
let large_vote_account = AccountSharedData::new_ref(100, 2 * VoteState::size_of(), &id());
let large_vote_account =
KeyedAccount::new(&vote_account_pubkey, false, &large_vote_account);
let res = initialize_account(
@ -882,7 +882,7 @@ mod tests {
assert_eq!(res, Err(InstructionError::InvalidAccountData));
}
fn create_test_account() -> (Pubkey, RefCell<Account>) {
fn create_test_account() -> (Pubkey, RefCell<AccountSharedData>) {
let vote_pubkey = solana_sdk::pubkey::new_rand();
(
vote_pubkey,
@ -895,7 +895,8 @@ mod tests {
)
}
fn create_test_account_with_authorized() -> (Pubkey, Pubkey, Pubkey, RefCell<Account>) {
fn create_test_account_with_authorized() -> (Pubkey, Pubkey, Pubkey, RefCell<AccountSharedData>)
{
let vote_pubkey = solana_sdk::pubkey::new_rand();
let authorized_voter = solana_sdk::pubkey::new_rand();
let authorized_withdrawer = solana_sdk::pubkey::new_rand();
@ -916,7 +917,7 @@ mod tests {
fn simulate_process_vote(
vote_pubkey: &Pubkey,
vote_account: &RefCell<Account>,
vote_account: &RefCell<AccountSharedData>,
vote: &Vote,
slot_hashes: &[SlotHash],
epoch: Epoch,
@ -940,7 +941,7 @@ mod tests {
/// exercises all the keyed accounts stuff
fn simulate_process_vote_unchecked(
vote_pubkey: &Pubkey,
vote_account: &RefCell<Account>,
vote_account: &RefCell<AccountSharedData>,
vote: &Vote,
) -> Result<VoteState, InstructionError> {
simulate_process_vote(
@ -1035,8 +1036,8 @@ mod tests {
create_test_account_with_authorized();
let node_pubkey = solana_sdk::pubkey::new_rand();
let node_account = RefCell::new(Account::default());
let authorized_withdrawer_account = RefCell::new(Account::default());
let node_account = RefCell::new(AccountSharedData::default());
let authorized_withdrawer_account = RefCell::new(AccountSharedData::default());
let keyed_accounts = &[
KeyedAccount::new(&vote_pubkey, true, &vote_account),
@ -1083,7 +1084,7 @@ mod tests {
let (vote_pubkey, _authorized_voter, authorized_withdrawer, vote_account) =
create_test_account_with_authorized();
let authorized_withdrawer_account = RefCell::new(Account::default());
let authorized_withdrawer_account = RefCell::new(AccountSharedData::default());
let keyed_accounts = &[
KeyedAccount::new(&vote_pubkey, true, &vote_account),
@ -1207,7 +1208,7 @@ mod tests {
assert_eq!(res, Err(VoteError::TooSoonToReauthorize.into()));
// verify authorized_voter_pubkey can authorize authorized_voter_pubkey ;)
let authorized_voter_account = RefCell::new(Account::default());
let authorized_voter_account = RefCell::new(AccountSharedData::default());
let keyed_accounts = &[
KeyedAccount::new(&vote_pubkey, false, &vote_account),
KeyedAccount::new(&authorized_voter_pubkey, true, &authorized_voter_account),
@ -1247,7 +1248,7 @@ mod tests {
assert_eq!(res, Ok(()));
// verify authorized_withdrawer can authorize authorized_withdrawer ;)
let withdrawer_account = RefCell::new(Account::default());
let withdrawer_account = RefCell::new(AccountSharedData::default());
let keyed_accounts = &[
KeyedAccount::new(&vote_pubkey, false, &vote_account),
KeyedAccount::new(&authorized_withdrawer_pubkey, true, &withdrawer_account),
@ -1284,7 +1285,7 @@ mod tests {
assert_eq!(res, Err(InstructionError::MissingRequiredSignature));
// signed by authorized voter
let authorized_voter_account = RefCell::new(Account::default());
let authorized_voter_account = RefCell::new(AccountSharedData::default());
let keyed_accounts = &[
KeyedAccount::new(&vote_pubkey, false, &vote_account),
KeyedAccount::new(&authorized_voter_pubkey, true, &authorized_voter_account),
@ -1308,7 +1309,7 @@ mod tests {
#[test]
fn test_vote_without_initialization() {
let vote_pubkey = solana_sdk::pubkey::new_rand();
let vote_account = RefCell::new(Account::new(100, VoteState::size_of(), &id()));
let vote_account = RefCell::new(AccountSharedData::new(100, VoteState::size_of(), &id()));
let res = simulate_process_vote_unchecked(
&vote_pubkey,
@ -1646,7 +1647,7 @@ mod tests {
&KeyedAccount::new(
&solana_sdk::pubkey::new_rand(),
false,
&RefCell::new(Account::default()),
&RefCell::new(AccountSharedData::default()),
),
&signers,
);
@ -1661,14 +1662,14 @@ mod tests {
&KeyedAccount::new(
&solana_sdk::pubkey::new_rand(),
false,
&RefCell::new(Account::default()),
&RefCell::new(AccountSharedData::default()),
),
&signers,
);
assert_eq!(res, Err(InstructionError::InsufficientFunds));
// all good
let to_account = RefCell::new(Account::default());
let to_account = RefCell::new(AccountSharedData::default());
let lamports = vote_account.borrow().lamports;
let keyed_accounts = &[KeyedAccount::new(&vote_pubkey, true, &vote_account)];
let signers: HashSet<Pubkey> = get_signers(keyed_accounts);
@ -1704,7 +1705,7 @@ mod tests {
assert_eq!(res, Ok(()));
// withdraw using authorized_withdrawer to authorized_withdrawer's account
let withdrawer_account = RefCell::new(Account::default());
let withdrawer_account = RefCell::new(AccountSharedData::default());
let keyed_accounts = &[
KeyedAccount::new(&vote_pubkey, false, &vote_account),
KeyedAccount::new(&authorized_withdrawer_pubkey, true, &withdrawer_account),