Account->AccountSharedData (#15691)
This commit is contained in:
parent
61c7ce857e
commit
8a3135d17b
|
@ -16,7 +16,10 @@ pub mod validator_info;
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::parse_account_data::{parse_account_data, AccountAdditionalData, ParsedAccount},
|
crate::parse_account_data::{parse_account_data, AccountAdditionalData, ParsedAccount},
|
||||||
solana_sdk::{account::Account, clock::Epoch, fee_calculator::FeeCalculator, pubkey::Pubkey},
|
solana_sdk::{
|
||||||
|
account::ReadableAccount, account::WritableAccount, clock::Epoch,
|
||||||
|
fee_calculator::FeeCalculator, pubkey::Pubkey,
|
||||||
|
},
|
||||||
std::{
|
std::{
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
|
@ -57,58 +60,61 @@ pub enum UiAccountEncoding {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UiAccount {
|
impl UiAccount {
|
||||||
pub fn encode(
|
pub fn encode<T: ReadableAccount>(
|
||||||
pubkey: &Pubkey,
|
pubkey: &Pubkey,
|
||||||
account: Account,
|
account: T,
|
||||||
encoding: UiAccountEncoding,
|
encoding: UiAccountEncoding,
|
||||||
additional_data: Option<AccountAdditionalData>,
|
additional_data: Option<AccountAdditionalData>,
|
||||||
data_slice_config: Option<UiDataSliceConfig>,
|
data_slice_config: Option<UiDataSliceConfig>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let data = match encoding {
|
let data = match encoding {
|
||||||
UiAccountEncoding::Binary => UiAccountData::LegacyBinary(
|
UiAccountEncoding::Binary => UiAccountData::LegacyBinary(
|
||||||
bs58::encode(slice_data(&account.data, data_slice_config)).into_string(),
|
bs58::encode(slice_data(&account.data(), data_slice_config)).into_string(),
|
||||||
),
|
),
|
||||||
UiAccountEncoding::Base58 => UiAccountData::Binary(
|
UiAccountEncoding::Base58 => UiAccountData::Binary(
|
||||||
bs58::encode(slice_data(&account.data, data_slice_config)).into_string(),
|
bs58::encode(slice_data(&account.data(), data_slice_config)).into_string(),
|
||||||
encoding,
|
encoding,
|
||||||
),
|
),
|
||||||
UiAccountEncoding::Base64 => UiAccountData::Binary(
|
UiAccountEncoding::Base64 => UiAccountData::Binary(
|
||||||
base64::encode(slice_data(&account.data, data_slice_config)),
|
base64::encode(slice_data(&account.data(), data_slice_config)),
|
||||||
encoding,
|
encoding,
|
||||||
),
|
),
|
||||||
UiAccountEncoding::Base64Zstd => {
|
UiAccountEncoding::Base64Zstd => {
|
||||||
let mut encoder = zstd::stream::write::Encoder::new(Vec::new(), 0).unwrap();
|
let mut encoder = zstd::stream::write::Encoder::new(Vec::new(), 0).unwrap();
|
||||||
match encoder
|
match encoder
|
||||||
.write_all(slice_data(&account.data, data_slice_config))
|
.write_all(slice_data(&account.data(), data_slice_config))
|
||||||
.and_then(|()| encoder.finish())
|
.and_then(|()| encoder.finish())
|
||||||
{
|
{
|
||||||
Ok(zstd_data) => UiAccountData::Binary(base64::encode(zstd_data), encoding),
|
Ok(zstd_data) => UiAccountData::Binary(base64::encode(zstd_data), encoding),
|
||||||
Err(_) => UiAccountData::Binary(
|
Err(_) => UiAccountData::Binary(
|
||||||
base64::encode(slice_data(&account.data, data_slice_config)),
|
base64::encode(slice_data(&account.data(), data_slice_config)),
|
||||||
UiAccountEncoding::Base64,
|
UiAccountEncoding::Base64,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UiAccountEncoding::JsonParsed => {
|
UiAccountEncoding::JsonParsed => {
|
||||||
if let Ok(parsed_data) =
|
if let Ok(parsed_data) =
|
||||||
parse_account_data(pubkey, &account.owner, &account.data, additional_data)
|
parse_account_data(pubkey, &account.owner(), &account.data(), additional_data)
|
||||||
{
|
{
|
||||||
UiAccountData::Json(parsed_data)
|
UiAccountData::Json(parsed_data)
|
||||||
} else {
|
} else {
|
||||||
UiAccountData::Binary(base64::encode(&account.data), UiAccountEncoding::Base64)
|
UiAccountData::Binary(
|
||||||
|
base64::encode(&account.data()),
|
||||||
|
UiAccountEncoding::Base64,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
UiAccount {
|
UiAccount {
|
||||||
lamports: account.lamports,
|
lamports: account.lamports(),
|
||||||
data,
|
data,
|
||||||
owner: account.owner.to_string(),
|
owner: account.owner().to_string(),
|
||||||
executable: account.executable,
|
executable: account.executable(),
|
||||||
rent_epoch: account.rent_epoch,
|
rent_epoch: account.rent_epoch(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decode(&self) -> Option<Account> {
|
pub fn decode<T: WritableAccount>(&self) -> Option<T> {
|
||||||
let data = match &self.data {
|
let data = match &self.data {
|
||||||
UiAccountData::Json(_) => None,
|
UiAccountData::Json(_) => None,
|
||||||
UiAccountData::LegacyBinary(blob) => bs58::decode(blob).into_vec().ok(),
|
UiAccountData::LegacyBinary(blob) => bs58::decode(blob).into_vec().ok(),
|
||||||
|
@ -128,13 +134,13 @@ impl UiAccount {
|
||||||
UiAccountEncoding::Binary | UiAccountEncoding::JsonParsed => None,
|
UiAccountEncoding::Binary | UiAccountEncoding::JsonParsed => None,
|
||||||
},
|
},
|
||||||
}?;
|
}?;
|
||||||
Some(Account {
|
Some(T::create(
|
||||||
lamports: self.lamports,
|
self.lamports,
|
||||||
data,
|
data,
|
||||||
owner: Pubkey::from_str(&self.owner).ok()?,
|
Pubkey::from_str(&self.owner).ok()?,
|
||||||
executable: self.executable,
|
self.executable,
|
||||||
rent_epoch: self.rent_epoch,
|
self.rent_epoch,
|
||||||
})
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,6 +190,7 @@ fn slice_data(data: &[u8], data_slice_config: Option<UiDataSliceConfig>) -> &[u8
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use solana_sdk::account::{Account, AccountSharedData};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_slice_data() {
|
fn test_slice_data() {
|
||||||
|
@ -217,9 +224,9 @@ mod test {
|
||||||
fn test_base64_zstd() {
|
fn test_base64_zstd() {
|
||||||
let encoded_account = UiAccount::encode(
|
let encoded_account = UiAccount::encode(
|
||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
Account {
|
AccountSharedData {
|
||||||
data: vec![0; 1024],
|
data: vec![0; 1024],
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
},
|
},
|
||||||
UiAccountEncoding::Base64Zstd,
|
UiAccountEncoding::Base64Zstd,
|
||||||
None,
|
None,
|
||||||
|
@ -230,7 +237,9 @@ mod test {
|
||||||
UiAccountData::Binary(_, UiAccountEncoding::Base64Zstd)
|
UiAccountData::Binary(_, UiAccountEncoding::Base64Zstd)
|
||||||
));
|
));
|
||||||
|
|
||||||
let decoded_account = encoded_account.decode().unwrap();
|
let decoded_account = encoded_account.decode::<Account>().unwrap();
|
||||||
|
assert_eq!(decoded_account.data, vec![0; 1024]);
|
||||||
|
let decoded_account = encoded_account.decode::<AccountSharedData>().unwrap();
|
||||||
assert_eq!(decoded_account.data, vec![0; 1024]);
|
assert_eq!(decoded_account.data, vec![0; 1024]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ impl BanksClient {
|
||||||
self.get_account(sysvar::rent::id()).map(|result| {
|
self.get_account(sysvar::rent::id()).map(|result| {
|
||||||
let rent_sysvar = result?
|
let rent_sysvar = result?
|
||||||
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Rent sysvar not present"))?;
|
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Rent sysvar not present"))?;
|
||||||
from_account::<Rent>(&rent_sysvar).ok_or_else(|| {
|
from_account::<Rent, _>(&rent_sysvar).ok_or_else(|| {
|
||||||
io::Error::new(io::ErrorKind::Other, "Failed to deserialize Rent sysvar")
|
io::Error::new(io::ErrorKind::Other, "Failed to deserialize Rent sysvar")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -242,7 +242,7 @@ impl Banks for BanksServer {
|
||||||
commitment: CommitmentLevel,
|
commitment: CommitmentLevel,
|
||||||
) -> Option<Account> {
|
) -> Option<Account> {
|
||||||
let bank = self.bank(commitment);
|
let bank = self.bank(commitment);
|
||||||
bank.get_account(&address)
|
bank.get_account(&address).map(Account::from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1747,7 +1747,8 @@ pub fn process_show_stake_history(
|
||||||
use_lamports_unit: bool,
|
use_lamports_unit: bool,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let stake_history_account = rpc_client.get_account(&stake_history::id())?;
|
let stake_history_account = rpc_client.get_account(&stake_history::id())?;
|
||||||
let stake_history = from_account::<StakeHistory>(&stake_history_account).ok_or_else(|| {
|
let stake_history =
|
||||||
|
from_account::<StakeHistory, _>(&stake_history_account).ok_or_else(|| {
|
||||||
CliError::RpcRequestError("Failed to deserialize stake history".to_string())
|
CliError::RpcRequestError("Failed to deserialize stake history".to_string())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::rpc_client::RpcClient;
|
use crate::rpc_client::RpcClient;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::{Account, ReadableAccount},
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
commitment_config::CommitmentConfig,
|
commitment_config::CommitmentConfig,
|
||||||
nonce::{
|
nonce::{
|
||||||
|
@ -52,24 +52,28 @@ pub fn get_account_with_commitment(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn account_identity_ok(account: &Account) -> Result<(), Error> {
|
pub fn account_identity_ok<T: ReadableAccount>(account: &T) -> Result<(), Error> {
|
||||||
if account.owner != system_program::id() {
|
if account.owner() != &system_program::id() {
|
||||||
Err(Error::InvalidAccountOwner)
|
Err(Error::InvalidAccountOwner)
|
||||||
} else if account.data.is_empty() {
|
} else if account.data().is_empty() {
|
||||||
Err(Error::UnexpectedDataSize)
|
Err(Error::UnexpectedDataSize)
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn state_from_account(account: &Account) -> Result<State, Error> {
|
pub fn state_from_account<T: ReadableAccount + StateMut<Versions>>(
|
||||||
|
account: &T,
|
||||||
|
) -> Result<State, Error> {
|
||||||
account_identity_ok(account)?;
|
account_identity_ok(account)?;
|
||||||
StateMut::<Versions>::state(account)
|
StateMut::<Versions>::state(account)
|
||||||
.map_err(|_| Error::InvalidAccountData)
|
.map_err(|_| Error::InvalidAccountData)
|
||||||
.map(|v| v.convert_to_current())
|
.map(|v| v.convert_to_current())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn data_from_account(account: &Account) -> Result<Data, Error> {
|
pub fn data_from_account<T: ReadableAccount + StateMut<Versions>>(
|
||||||
|
account: &T,
|
||||||
|
) -> Result<Data, Error> {
|
||||||
account_identity_ok(account)?;
|
account_identity_ok(account)?;
|
||||||
state_from_account(account).and_then(|ref s| data_from_state(s).map(|d| d.clone()))
|
state_from_account(account).and_then(|ref s| data_from_state(s).map(|d| d.clone()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,7 +253,7 @@ mod tests {
|
||||||
bank_forks::BankForks,
|
bank_forks::BankForks,
|
||||||
genesis_utils::{create_genesis_config_with_vote_accounts, ValidatorVoteKeypairs},
|
genesis_utils::{create_genesis_config_with_vote_accounts, ValidatorVoteKeypairs},
|
||||||
};
|
};
|
||||||
use solana_sdk::{pubkey::Pubkey, signature::Signer};
|
use solana_sdk::{account::Account, pubkey::Pubkey, signature::Signer};
|
||||||
use solana_stake_program::stake_state;
|
use solana_stake_program::stake_state;
|
||||||
use solana_vote_program::{
|
use solana_vote_program::{
|
||||||
vote_state::{self, VoteStateVersions},
|
vote_state::{self, VoteStateVersions},
|
||||||
|
@ -411,7 +411,8 @@ mod tests {
|
||||||
rooted_stake_amount,
|
rooted_stake_amount,
|
||||||
);
|
);
|
||||||
|
|
||||||
genesis_config.accounts.extend(vec![
|
genesis_config.accounts.extend(
|
||||||
|
vec![
|
||||||
(pk1, vote_account1.clone()),
|
(pk1, vote_account1.clone()),
|
||||||
(sk1, stake_account1),
|
(sk1, stake_account1),
|
||||||
(pk2, vote_account2.clone()),
|
(pk2, vote_account2.clone()),
|
||||||
|
@ -420,7 +421,10 @@ mod tests {
|
||||||
(sk3, stake_account3),
|
(sk3, stake_account3),
|
||||||
(pk4, vote_account4.clone()),
|
(pk4, vote_account4.clone()),
|
||||||
(sk4, stake_account4),
|
(sk4, stake_account4),
|
||||||
]);
|
]
|
||||||
|
.into_iter()
|
||||||
|
.map(|(key, account)| (key, Account::from(account))),
|
||||||
|
);
|
||||||
|
|
||||||
// Create bank
|
// Create bank
|
||||||
let bank = Arc::new(Bank::new(&genesis_config));
|
let bank = Arc::new(Bank::new(&genesis_config));
|
||||||
|
|
|
@ -1253,7 +1253,7 @@ pub mod test {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account, clock::Slot, hash::Hash, pubkey::Pubkey, signature::Signer,
|
account::AccountSharedData, clock::Slot, hash::Hash, pubkey::Pubkey, signature::Signer,
|
||||||
slot_history::SlotHistory,
|
slot_history::SlotHistory,
|
||||||
};
|
};
|
||||||
use solana_vote_program::{
|
use solana_vote_program::{
|
||||||
|
@ -1571,10 +1571,10 @@ pub mod test {
|
||||||
fn gen_stakes(stake_votes: &[(u64, &[u64])]) -> Vec<(Pubkey, (u64, ArcVoteAccount))> {
|
fn gen_stakes(stake_votes: &[(u64, &[u64])]) -> Vec<(Pubkey, (u64, ArcVoteAccount))> {
|
||||||
let mut stakes = vec![];
|
let mut stakes = vec![];
|
||||||
for (lamports, votes) in stake_votes {
|
for (lamports, votes) in stake_votes {
|
||||||
let mut account = Account {
|
let mut account = AccountSharedData {
|
||||||
data: vec![0; VoteState::size_of()],
|
data: vec![0; VoteState::size_of()],
|
||||||
lamports: *lamports,
|
lamports: *lamports,
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
};
|
};
|
||||||
let mut vote_state = VoteState::default();
|
let mut vote_state = VoteState::default();
|
||||||
for slot in *votes {
|
for slot in *votes {
|
||||||
|
@ -2251,9 +2251,9 @@ pub mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_stake_is_updated_for_entire_branch() {
|
fn test_stake_is_updated_for_entire_branch() {
|
||||||
let mut voted_stakes = HashMap::new();
|
let mut voted_stakes = HashMap::new();
|
||||||
let account = Account {
|
let account = AccountSharedData {
|
||||||
lamports: 1,
|
lamports: 1,
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
};
|
};
|
||||||
let set: HashSet<u64> = vec![0u64, 1u64].into_iter().collect();
|
let set: HashSet<u64> = vec![0u64, 1u64].into_iter().collect();
|
||||||
let ancestors: HashMap<u64, HashSet<u64>> = [(2u64, set)].iter().cloned().collect();
|
let ancestors: HashMap<u64, HashSet<u64>> = [(2u64, set)].iter().cloned().collect();
|
||||||
|
|
|
@ -40,7 +40,7 @@ pub fn calculate_non_circulating_supply(bank: &Arc<Bank>) -> NonCirculatingSuppl
|
||||||
bank.get_program_accounts(&solana_stake_program::id())
|
bank.get_program_accounts(&solana_stake_program::id())
|
||||||
};
|
};
|
||||||
for (pubkey, account) in stake_accounts.iter() {
|
for (pubkey, account) in stake_accounts.iter() {
|
||||||
let stake_account = StakeState::from(&account).unwrap_or_default();
|
let stake_account = StakeState::from(account).unwrap_or_default();
|
||||||
match stake_account {
|
match stake_account {
|
||||||
StakeState::Initialized(meta) => {
|
StakeState::Initialized(meta) => {
|
||||||
if meta.lockup.is_in_force(&clock, None)
|
if meta.lockup.is_in_force(&clock, None)
|
||||||
|
@ -138,6 +138,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::Account,
|
||||||
|
account::AccountSharedData,
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
genesis_config::{ClusterType, GenesisConfig},
|
genesis_config::{ClusterType, GenesisConfig},
|
||||||
};
|
};
|
||||||
|
@ -212,7 +213,10 @@ mod tests {
|
||||||
bank = Arc::new(new_from_parent(&bank));
|
bank = Arc::new(new_from_parent(&bank));
|
||||||
let new_balance = 11;
|
let new_balance = 11;
|
||||||
for key in non_circulating_accounts {
|
for key in non_circulating_accounts {
|
||||||
bank.store_account(&key, &Account::new(new_balance, 0, &Pubkey::default()));
|
bank.store_account(
|
||||||
|
&key,
|
||||||
|
&AccountSharedData::new(new_balance, 0, &Pubkey::default()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
let non_circulating_supply = calculate_non_circulating_supply(&bank);
|
let non_circulating_supply = calculate_non_circulating_supply(&bank);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -49,7 +49,7 @@ use solana_runtime::{
|
||||||
snapshot_utils::get_highest_snapshot_archive_path,
|
snapshot_utils::get_highest_snapshot_archive_path,
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
clock::{Slot, UnixTimestamp, MAX_RECENT_BLOCKHASHES},
|
clock::{Slot, UnixTimestamp, MAX_RECENT_BLOCKHASHES},
|
||||||
commitment_config::{CommitmentConfig, CommitmentLevel},
|
commitment_config::{CommitmentConfig, CommitmentLevel},
|
||||||
|
@ -1157,7 +1157,7 @@ impl JsonRpcRequestProcessor {
|
||||||
.get_account(&stake_history::id())
|
.get_account(&stake_history::id())
|
||||||
.ok_or_else(Error::internal_error)?;
|
.ok_or_else(Error::internal_error)?;
|
||||||
let stake_history =
|
let stake_history =
|
||||||
solana_sdk::account::from_account::<StakeHistory>(&stake_history_account)
|
solana_sdk::account::from_account::<StakeHistory, _>(&stake_history_account)
|
||||||
.ok_or_else(Error::internal_error)?;
|
.ok_or_else(Error::internal_error)?;
|
||||||
|
|
||||||
let (active, activating, deactivating) = delegation.stake_activating_and_deactivating(
|
let (active, activating, deactivating) = delegation.stake_activating_and_deactivating(
|
||||||
|
@ -1381,8 +1381,8 @@ impl JsonRpcRequestProcessor {
|
||||||
bank: &Arc<Bank>,
|
bank: &Arc<Bank>,
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
filters: Vec<RpcFilterType>,
|
filters: Vec<RpcFilterType>,
|
||||||
) -> Vec<(Pubkey, Account)> {
|
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||||
let filter_closure = |account: &Account| {
|
let filter_closure = |account: &AccountSharedData| {
|
||||||
filters.iter().all(|filter_type| match filter_type {
|
filters.iter().all(|filter_type| match filter_type {
|
||||||
RpcFilterType::DataSize(size) => account.data.len() as u64 == *size,
|
RpcFilterType::DataSize(size) => account.data.len() as u64 == *size,
|
||||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data),
|
RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data),
|
||||||
|
@ -1396,7 +1396,7 @@ impl JsonRpcRequestProcessor {
|
||||||
bank.get_filtered_indexed_accounts(&IndexKey::ProgramId(*program_id), |account| {
|
bank.get_filtered_indexed_accounts(&IndexKey::ProgramId(*program_id), |account| {
|
||||||
// The program-id account index checks for Account owner on inclusion. However, due
|
// The program-id account index checks for Account owner on inclusion. However, due
|
||||||
// to the current AccountsDb implementation, an account may remain in storage as a
|
// to the current AccountsDb implementation, an account may remain in storage as a
|
||||||
// zero-lamport Account::Default() after being wiped and reinitialized in later
|
// zero-lamport AccountSharedData::Default() after being wiped and reinitialized in later
|
||||||
// updates. We include the redundant filters here to avoid returning these
|
// updates. We include the redundant filters here to avoid returning these
|
||||||
// accounts.
|
// accounts.
|
||||||
account.owner == *program_id && filter_closure(account)
|
account.owner == *program_id && filter_closure(account)
|
||||||
|
@ -1412,10 +1412,10 @@ impl JsonRpcRequestProcessor {
|
||||||
bank: &Arc<Bank>,
|
bank: &Arc<Bank>,
|
||||||
owner_key: &Pubkey,
|
owner_key: &Pubkey,
|
||||||
mut filters: Vec<RpcFilterType>,
|
mut filters: Vec<RpcFilterType>,
|
||||||
) -> Vec<(Pubkey, Account)> {
|
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||||
// The by-owner accounts index checks for Token Account state and Owner address on
|
// The by-owner accounts index checks for Token Account state and Owner address on
|
||||||
// inclusion. However, due to the current AccountsDb implementation, an account may remain
|
// inclusion. However, due to the current AccountsDb implementation, an account may remain
|
||||||
// in storage as a zero-lamport Account::Default() after being wiped and reinitialized in
|
// in storage as a zero-lamport AccountSharedData::Default() after being wiped and reinitialized in
|
||||||
// later updates. We include the redundant filters here to avoid returning these accounts.
|
// later updates. We include the redundant filters here to avoid returning these accounts.
|
||||||
//
|
//
|
||||||
// Filter on Token Account state
|
// Filter on Token Account state
|
||||||
|
@ -1452,10 +1452,10 @@ impl JsonRpcRequestProcessor {
|
||||||
bank: &Arc<Bank>,
|
bank: &Arc<Bank>,
|
||||||
mint_key: &Pubkey,
|
mint_key: &Pubkey,
|
||||||
mut filters: Vec<RpcFilterType>,
|
mut filters: Vec<RpcFilterType>,
|
||||||
) -> Vec<(Pubkey, Account)> {
|
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||||
// The by-mint accounts index checks for Token Account state and Mint address on inclusion.
|
// The by-mint accounts index checks for Token Account state and Mint address on inclusion.
|
||||||
// However, due to the current AccountsDb implementation, an account may remain in storage
|
// However, due to the current AccountsDb implementation, an account may remain in storage
|
||||||
// as be zero-lamport Account::Default() after being wiped and reinitialized in later
|
// as be zero-lamport AccountSharedData::Default() after being wiped and reinitialized in later
|
||||||
// updates. We include the redundant filters here to avoid returning these accounts.
|
// updates. We include the redundant filters here to avoid returning these accounts.
|
||||||
//
|
//
|
||||||
// Filter on Token Account state
|
// Filter on Token Account state
|
||||||
|
@ -1641,7 +1641,7 @@ fn get_spl_token_mint_filter(program_id: &Pubkey, filters: &[RpcFilterType]) ->
|
||||||
pub(crate) fn get_parsed_token_account(
|
pub(crate) fn get_parsed_token_account(
|
||||||
bank: Arc<Bank>,
|
bank: Arc<Bank>,
|
||||||
pubkey: &Pubkey,
|
pubkey: &Pubkey,
|
||||||
account: Account,
|
account: AccountSharedData,
|
||||||
) -> UiAccount {
|
) -> UiAccount {
|
||||||
let additional_data = get_token_account_mint(&account.data)
|
let additional_data = get_token_account_mint(&account.data)
|
||||||
.and_then(|mint_pubkey| get_mint_owner_and_decimals(&bank, &mint_pubkey).ok())
|
.and_then(|mint_pubkey| get_mint_owner_and_decimals(&bank, &mint_pubkey).ok())
|
||||||
|
@ -1663,7 +1663,7 @@ pub(crate) fn get_parsed_token_accounts<I>(
|
||||||
keyed_accounts: I,
|
keyed_accounts: I,
|
||||||
) -> impl Iterator<Item = RpcKeyedAccount>
|
) -> impl Iterator<Item = RpcKeyedAccount>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = (Pubkey, Account)>,
|
I: Iterator<Item = (Pubkey, AccountSharedData)>,
|
||||||
{
|
{
|
||||||
let mut mint_decimals: HashMap<Pubkey, u8> = HashMap::new();
|
let mut mint_decimals: HashMap<Pubkey, u8> = HashMap::new();
|
||||||
keyed_accounts.filter_map(move |(pubkey, account)| {
|
keyed_accounts.filter_map(move |(pubkey, account)| {
|
||||||
|
@ -3216,7 +3216,10 @@ pub mod tests {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_root(*root, &AbsRequestSender::default(), Some(0));
|
.set_root(*root, &AbsRequestSender::default(), Some(0));
|
||||||
let mut stakes = HashMap::new();
|
let mut stakes = HashMap::new();
|
||||||
stakes.insert(leader_vote_keypair.pubkey(), (1, Account::default()));
|
stakes.insert(
|
||||||
|
leader_vote_keypair.pubkey(),
|
||||||
|
(1, AccountSharedData::default()),
|
||||||
|
);
|
||||||
let block_time = bank_forks
|
let block_time = bank_forks
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -3822,7 +3825,7 @@ pub mod tests {
|
||||||
|
|
||||||
let address = solana_sdk::pubkey::new_rand();
|
let address = solana_sdk::pubkey::new_rand();
|
||||||
let data = vec![1, 2, 3, 4, 5];
|
let data = vec![1, 2, 3, 4, 5];
|
||||||
let mut account = Account::new(42, 5, &Pubkey::default());
|
let mut account = AccountSharedData::new(42, 5, &Pubkey::default());
|
||||||
account.data = data.clone();
|
account.data = data.clone();
|
||||||
bank.store_account(&address, &account);
|
bank.store_account(&address, &account);
|
||||||
|
|
||||||
|
@ -3879,7 +3882,7 @@ pub mod tests {
|
||||||
|
|
||||||
let address = Pubkey::new(&[9; 32]);
|
let address = Pubkey::new(&[9; 32]);
|
||||||
let data = vec![1, 2, 3, 4, 5];
|
let data = vec![1, 2, 3, 4, 5];
|
||||||
let mut account = Account::new(42, 5, &Pubkey::default());
|
let mut account = AccountSharedData::new(42, 5, &Pubkey::default());
|
||||||
account.data = data.clone();
|
account.data = data.clone();
|
||||||
bank.store_account(&address, &account);
|
bank.store_account(&address, &account);
|
||||||
|
|
||||||
|
@ -5611,11 +5614,11 @@ pub mod tests {
|
||||||
close_authority: COption::Some(owner),
|
close_authority: COption::Some(owner),
|
||||||
};
|
};
|
||||||
TokenAccount::pack(token_account, &mut account_data).unwrap();
|
TokenAccount::pack(token_account, &mut account_data).unwrap();
|
||||||
let token_account = Account {
|
let token_account = AccountSharedData {
|
||||||
lamports: 111,
|
lamports: 111,
|
||||||
data: account_data.to_vec(),
|
data: account_data.to_vec(),
|
||||||
owner: spl_token_id_v2_0(),
|
owner: spl_token_id_v2_0(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
};
|
};
|
||||||
let token_account_pubkey = solana_sdk::pubkey::new_rand();
|
let token_account_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
bank.store_account(&token_account_pubkey, &token_account);
|
bank.store_account(&token_account_pubkey, &token_account);
|
||||||
|
@ -5630,11 +5633,11 @@ pub mod tests {
|
||||||
freeze_authority: COption::Some(owner),
|
freeze_authority: COption::Some(owner),
|
||||||
};
|
};
|
||||||
Mint::pack(mint_state, &mut mint_data).unwrap();
|
Mint::pack(mint_state, &mut mint_data).unwrap();
|
||||||
let mint_account = Account {
|
let mint_account = AccountSharedData {
|
||||||
lamports: 111,
|
lamports: 111,
|
||||||
data: mint_data.to_vec(),
|
data: mint_data.to_vec(),
|
||||||
owner: spl_token_id_v2_0(),
|
owner: spl_token_id_v2_0(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
};
|
};
|
||||||
bank.store_account(&Pubkey::from_str(&mint.to_string()).unwrap(), &mint_account);
|
bank.store_account(&Pubkey::from_str(&mint.to_string()).unwrap(), &mint_account);
|
||||||
|
|
||||||
|
@ -5707,11 +5710,11 @@ pub mod tests {
|
||||||
close_authority: COption::Some(owner),
|
close_authority: COption::Some(owner),
|
||||||
};
|
};
|
||||||
TokenAccount::pack(token_account, &mut account_data).unwrap();
|
TokenAccount::pack(token_account, &mut account_data).unwrap();
|
||||||
let token_account = Account {
|
let token_account = AccountSharedData {
|
||||||
lamports: 111,
|
lamports: 111,
|
||||||
data: account_data.to_vec(),
|
data: account_data.to_vec(),
|
||||||
owner: spl_token_id_v2_0(),
|
owner: spl_token_id_v2_0(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
};
|
};
|
||||||
let token_with_different_mint_pubkey = solana_sdk::pubkey::new_rand();
|
let token_with_different_mint_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
bank.store_account(&token_with_different_mint_pubkey, &token_account);
|
bank.store_account(&token_with_different_mint_pubkey, &token_account);
|
||||||
|
@ -5926,11 +5929,11 @@ pub mod tests {
|
||||||
freeze_authority: COption::Some(owner),
|
freeze_authority: COption::Some(owner),
|
||||||
};
|
};
|
||||||
Mint::pack(mint_state, &mut mint_data).unwrap();
|
Mint::pack(mint_state, &mut mint_data).unwrap();
|
||||||
let mint_account = Account {
|
let mint_account = AccountSharedData {
|
||||||
lamports: 111,
|
lamports: 111,
|
||||||
data: mint_data.to_vec(),
|
data: mint_data.to_vec(),
|
||||||
owner: spl_token_id_v2_0(),
|
owner: spl_token_id_v2_0(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
};
|
};
|
||||||
bank.store_account(
|
bank.store_account(
|
||||||
&Pubkey::from_str(&new_mint.to_string()).unwrap(),
|
&Pubkey::from_str(&new_mint.to_string()).unwrap(),
|
||||||
|
@ -5948,11 +5951,11 @@ pub mod tests {
|
||||||
close_authority: COption::Some(owner),
|
close_authority: COption::Some(owner),
|
||||||
};
|
};
|
||||||
TokenAccount::pack(token_account, &mut account_data).unwrap();
|
TokenAccount::pack(token_account, &mut account_data).unwrap();
|
||||||
let token_account = Account {
|
let token_account = AccountSharedData {
|
||||||
lamports: 111,
|
lamports: 111,
|
||||||
data: account_data.to_vec(),
|
data: account_data.to_vec(),
|
||||||
owner: spl_token_id_v2_0(),
|
owner: spl_token_id_v2_0(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
};
|
};
|
||||||
let token_with_smaller_balance = solana_sdk::pubkey::new_rand();
|
let token_with_smaller_balance = solana_sdk::pubkey::new_rand();
|
||||||
bank.store_account(&token_with_smaller_balance, &token_account);
|
bank.store_account(&token_with_smaller_balance, &token_account);
|
||||||
|
@ -6012,11 +6015,11 @@ pub mod tests {
|
||||||
close_authority: COption::Some(owner),
|
close_authority: COption::Some(owner),
|
||||||
};
|
};
|
||||||
TokenAccount::pack(token_account, &mut account_data).unwrap();
|
TokenAccount::pack(token_account, &mut account_data).unwrap();
|
||||||
let token_account = Account {
|
let token_account = AccountSharedData {
|
||||||
lamports: 111,
|
lamports: 111,
|
||||||
data: account_data.to_vec(),
|
data: account_data.to_vec(),
|
||||||
owner: spl_token_id_v2_0(),
|
owner: spl_token_id_v2_0(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
};
|
};
|
||||||
let token_account_pubkey = solana_sdk::pubkey::new_rand();
|
let token_account_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
bank.store_account(&token_account_pubkey, &token_account);
|
bank.store_account(&token_account_pubkey, &token_account);
|
||||||
|
@ -6031,11 +6034,11 @@ pub mod tests {
|
||||||
freeze_authority: COption::Some(owner),
|
freeze_authority: COption::Some(owner),
|
||||||
};
|
};
|
||||||
Mint::pack(mint_state, &mut mint_data).unwrap();
|
Mint::pack(mint_state, &mut mint_data).unwrap();
|
||||||
let mint_account = Account {
|
let mint_account = AccountSharedData {
|
||||||
lamports: 111,
|
lamports: 111,
|
||||||
data: mint_data.to_vec(),
|
data: mint_data.to_vec(),
|
||||||
owner: spl_token_id_v2_0(),
|
owner: spl_token_id_v2_0(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
};
|
};
|
||||||
bank.store_account(&Pubkey::from_str(&mint.to_string()).unwrap(), &mint_account);
|
bank.store_account(&Pubkey::from_str(&mint.to_string()).unwrap(), &mint_account);
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ use solana_runtime::{
|
||||||
commitment::{BlockCommitmentCache, CommitmentSlots},
|
commitment::{BlockCommitmentCache, CommitmentSlots},
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
clock::{Slot, UnixTimestamp},
|
clock::{Slot, UnixTimestamp},
|
||||||
commitment_config::CommitmentConfig,
|
commitment_config::CommitmentConfig,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
|
@ -276,7 +276,7 @@ impl RpcNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filter_account_result(
|
fn filter_account_result(
|
||||||
result: Option<(Account, Slot)>,
|
result: Option<(AccountSharedData, Slot)>,
|
||||||
pubkey: &Pubkey,
|
pubkey: &Pubkey,
|
||||||
last_notified_slot: Slot,
|
last_notified_slot: Slot,
|
||||||
encoding: Option<UiAccountEncoding>,
|
encoding: Option<UiAccountEncoding>,
|
||||||
|
@ -320,7 +320,7 @@ fn filter_signature_result(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filter_program_results(
|
fn filter_program_results(
|
||||||
accounts: Vec<(Pubkey, Account)>,
|
accounts: Vec<(Pubkey, AccountSharedData)>,
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
last_notified_slot: Slot,
|
last_notified_slot: Slot,
|
||||||
config: Option<ProgramConfig>,
|
config: Option<ProgramConfig>,
|
||||||
|
|
|
@ -321,7 +321,7 @@ mod test {
|
||||||
create_genesis_config_with_vote_accounts, GenesisConfigInfo, ValidatorVoteKeypairs,
|
create_genesis_config_with_vote_accounts, GenesisConfigInfo, ValidatorVoteKeypairs,
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
fee_calculator::FeeCalculator,
|
fee_calculator::FeeCalculator,
|
||||||
genesis_config::create_genesis_config,
|
genesis_config::create_genesis_config,
|
||||||
nonce,
|
nonce,
|
||||||
|
@ -529,7 +529,8 @@ mod test {
|
||||||
blockhash: durable_nonce,
|
blockhash: durable_nonce,
|
||||||
fee_calculator: FeeCalculator::new(42),
|
fee_calculator: FeeCalculator::new(42),
|
||||||
}));
|
}));
|
||||||
let nonce_account = Account::new_data(43, &nonce_state, &system_program::id()).unwrap();
|
let nonce_account =
|
||||||
|
AccountSharedData::new_data(43, &nonce_state, &system_program::id()).unwrap();
|
||||||
root_bank.store_account(&nonce_address, &nonce_account);
|
root_bank.store_account(&nonce_address, &nonce_account);
|
||||||
|
|
||||||
let working_bank = Arc::new(Bank::new_from_parent(&root_bank, &Pubkey::default(), 2));
|
let working_bank = Arc::new(Bank::new_from_parent(&root_bank, &Pubkey::default(), 2));
|
||||||
|
@ -753,7 +754,8 @@ mod test {
|
||||||
blockhash: new_durable_nonce,
|
blockhash: new_durable_nonce,
|
||||||
fee_calculator: FeeCalculator::new(42),
|
fee_calculator: FeeCalculator::new(42),
|
||||||
}));
|
}));
|
||||||
let nonce_account = Account::new_data(43, &new_nonce_state, &system_program::id()).unwrap();
|
let nonce_account =
|
||||||
|
AccountSharedData::new_data(43, &new_nonce_state, &system_program::id()).unwrap();
|
||||||
working_bank.store_account(&nonce_address, &nonce_account);
|
working_bank.store_account(&nonce_address, &nonce_account);
|
||||||
let result = SendTransactionService::process_transactions(
|
let result = SendTransactionService::process_transactions(
|
||||||
&working_bank,
|
&working_bank,
|
||||||
|
|
|
@ -13,7 +13,7 @@ use {
|
||||||
hardened_unpack::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
|
hardened_unpack::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
|
||||||
},
|
},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
clock::{Slot, DEFAULT_MS_PER_SLOT},
|
clock::{Slot, DEFAULT_MS_PER_SLOT},
|
||||||
commitment_config::CommitmentConfig,
|
commitment_config::CommitmentConfig,
|
||||||
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
||||||
|
@ -50,7 +50,7 @@ pub struct TestValidatorGenesis {
|
||||||
rpc_ports: Option<(u16, u16)>, // (JsonRpc, JsonRpcPubSub), None == random ports
|
rpc_ports: Option<(u16, u16)>, // (JsonRpc, JsonRpcPubSub), None == random ports
|
||||||
warp_slot: Option<Slot>,
|
warp_slot: Option<Slot>,
|
||||||
no_bpf_jit: bool,
|
no_bpf_jit: bool,
|
||||||
accounts: HashMap<Pubkey, Account>,
|
accounts: HashMap<Pubkey, AccountSharedData>,
|
||||||
programs: Vec<ProgramInfo>,
|
programs: Vec<ProgramInfo>,
|
||||||
pub validator_exit: Arc<RwLock<ValidatorExit>>,
|
pub validator_exit: Arc<RwLock<ValidatorExit>>,
|
||||||
pub start_progress: Arc<RwLock<ValidatorStartProgress>>,
|
pub start_progress: Arc<RwLock<ValidatorStartProgress>>,
|
||||||
|
@ -93,14 +93,14 @@ impl TestValidatorGenesis {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add an account to the test environment
|
/// Add an account to the test environment
|
||||||
pub fn add_account(&mut self, address: Pubkey, account: Account) -> &mut Self {
|
pub fn add_account(&mut self, address: Pubkey, account: AccountSharedData) -> &mut Self {
|
||||||
self.accounts.insert(address, account);
|
self.accounts.insert(address, account);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_accounts<T>(&mut self, accounts: T) -> &mut Self
|
pub fn add_accounts<T>(&mut self, accounts: T) -> &mut Self
|
||||||
where
|
where
|
||||||
T: IntoIterator<Item = (Pubkey, Account)>,
|
T: IntoIterator<Item = (Pubkey, AccountSharedData)>,
|
||||||
{
|
{
|
||||||
for (address, account) in accounts {
|
for (address, account) in accounts {
|
||||||
self.add_account(address, account);
|
self.add_account(address, account);
|
||||||
|
@ -118,7 +118,7 @@ impl TestValidatorGenesis {
|
||||||
error!("Failed to fetch {}: {}", address, err);
|
error!("Failed to fetch {}: {}", address, err);
|
||||||
crate::validator::abort();
|
crate::validator::abort();
|
||||||
});
|
});
|
||||||
self.add_account(address, account);
|
self.add_account(address, AccountSharedData::from(account));
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ impl TestValidatorGenesis {
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.add_account(
|
self.add_account(
|
||||||
address,
|
address,
|
||||||
Account {
|
AccountSharedData {
|
||||||
lamports,
|
lamports,
|
||||||
data: solana_program_test::read_file(
|
data: solana_program_test::read_file(
|
||||||
solana_program_test::find_file(filename).unwrap_or_else(|| {
|
solana_program_test::find_file(filename).unwrap_or_else(|| {
|
||||||
|
@ -158,7 +158,7 @@ impl TestValidatorGenesis {
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.add_account(
|
self.add_account(
|
||||||
address,
|
address,
|
||||||
Account {
|
AccountSharedData {
|
||||||
lamports,
|
lamports,
|
||||||
data: base64::decode(data_base64)
|
data: base64::decode(data_base64)
|
||||||
.unwrap_or_else(|err| panic!("Failed to base64 decode: {}", err)),
|
.unwrap_or_else(|err| panic!("Failed to base64 decode: {}", err)),
|
||||||
|
@ -285,7 +285,7 @@ impl TestValidator {
|
||||||
let data = solana_program_test::read_file(&program.program_path);
|
let data = solana_program_test::read_file(&program.program_path);
|
||||||
accounts.insert(
|
accounts.insert(
|
||||||
program.program_id,
|
program.program_id,
|
||||||
Account {
|
AccountSharedData {
|
||||||
lamports: Rent::default().minimum_balance(data.len()).min(1),
|
lamports: Rent::default().minimum_balance(data.len()).min(1),
|
||||||
data,
|
data,
|
||||||
owner: program.loader,
|
owner: program.loader,
|
||||||
|
|
|
@ -868,7 +868,7 @@ impl Validator {
|
||||||
|
|
||||||
fn active_vote_account_exists_in_bank(bank: &Arc<Bank>, vote_account: &Pubkey) -> bool {
|
fn active_vote_account_exists_in_bank(bank: &Arc<Bank>, vote_account: &Pubkey) -> bool {
|
||||||
if let Some(account) = &bank.get_account(vote_account) {
|
if let Some(account) = &bank.get_account(vote_account) {
|
||||||
if let Some(vote_state) = VoteState::from(&account) {
|
if let Some(vote_state) = VoteState::from(account) {
|
||||||
return !vote_state.votes.is_empty();
|
return !vote_state.votes.is_empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ use solana_ledger::{
|
||||||
};
|
};
|
||||||
use solana_runtime::hardened_unpack::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE;
|
use solana_runtime::hardened_unpack::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
clock,
|
clock,
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
fee_calculator::FeeRateGovernor,
|
fee_calculator::FeeRateGovernor,
|
||||||
|
@ -82,7 +82,7 @@ pub fn load_genesis_accounts(file: &str, genesis_config: &mut GenesisConfig) ->
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mut account = Account::new(account_details.balance, 0, &owner_program_id);
|
let mut account = AccountSharedData::new(account_details.balance, 0, &owner_program_id);
|
||||||
if account_details.data != "~" {
|
if account_details.data != "~" {
|
||||||
account.data = base64::decode(account_details.data.as_str()).map_err(|err| {
|
account.data = base64::decode(account_details.data.as_str()).map_err(|err| {
|
||||||
io::Error::new(
|
io::Error::new(
|
||||||
|
@ -534,7 +534,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
|
|
||||||
genesis_config.add_account(
|
genesis_config.add_account(
|
||||||
*identity_pubkey,
|
*identity_pubkey,
|
||||||
Account::new(bootstrap_validator_lamports, 0, &system_program::id()),
|
AccountSharedData::new(bootstrap_validator_lamports, 0, &system_program::id()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let vote_account = vote_state::create_account_with_authorized(
|
let vote_account = vote_state::create_account_with_authorized(
|
||||||
|
@ -568,7 +568,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
if let Some(faucet_pubkey) = faucet_pubkey {
|
if let Some(faucet_pubkey) = faucet_pubkey {
|
||||||
genesis_config.add_account(
|
genesis_config.add_account(
|
||||||
faucet_pubkey,
|
faucet_pubkey,
|
||||||
Account::new(faucet_lamports, 0, &system_program::id()),
|
AccountSharedData::new(faucet_lamports, 0, &system_program::id()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,7 +618,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
});
|
});
|
||||||
genesis_config.add_account(
|
genesis_config.add_account(
|
||||||
address,
|
address,
|
||||||
Account {
|
AccountSharedData {
|
||||||
lamports: genesis_config.rent.minimum_balance(program_data.len()),
|
lamports: genesis_config.rent.minimum_balance(program_data.len()),
|
||||||
data: program_data,
|
data: program_data,
|
||||||
executable: true,
|
executable: true,
|
||||||
|
|
|
@ -31,7 +31,7 @@ use solana_runtime::{
|
||||||
snapshot_utils::SnapshotVersion,
|
snapshot_utils::SnapshotVersion,
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
clock::{Epoch, Slot},
|
clock::{Epoch, Slot},
|
||||||
feature::{self, Feature},
|
feature::{self, Feature},
|
||||||
feature_set,
|
feature_set,
|
||||||
|
@ -1876,7 +1876,7 @@ fn main() {
|
||||||
if let Some(faucet_pubkey) = faucet_pubkey {
|
if let Some(faucet_pubkey) = faucet_pubkey {
|
||||||
bank.store_account(
|
bank.store_account(
|
||||||
&faucet_pubkey,
|
&faucet_pubkey,
|
||||||
&Account::new(faucet_lamports, 0, &system_program::id()),
|
&AccountSharedData::new(faucet_lamports, 0, &system_program::id()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1936,7 +1936,7 @@ fn main() {
|
||||||
|
|
||||||
bank.store_account(
|
bank.store_account(
|
||||||
identity_pubkey,
|
identity_pubkey,
|
||||||
&Account::new(
|
&AccountSharedData::new(
|
||||||
bootstrap_validator_lamports,
|
bootstrap_validator_lamports,
|
||||||
0,
|
0,
|
||||||
&system_program::id(),
|
&system_program::id(),
|
||||||
|
@ -2253,7 +2253,7 @@ fn main() {
|
||||||
// capitalizaion, which doesn't affect inflation behavior!
|
// capitalizaion, which doesn't affect inflation behavior!
|
||||||
base_bank.store_account(
|
base_bank.store_account(
|
||||||
&feature_set::secp256k1_program_enabled::id(),
|
&feature_set::secp256k1_program_enabled::id(),
|
||||||
&Account::default(),
|
&AccountSharedData::default(),
|
||||||
);
|
);
|
||||||
force_enabled_count -= 1;
|
force_enabled_count -= 1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2270,7 +2270,7 @@ fn main() {
|
||||||
// capitalizaion, which doesn't affect inflation behavior!
|
// capitalizaion, which doesn't affect inflation behavior!
|
||||||
base_bank.store_account(
|
base_bank.store_account(
|
||||||
&feature_set::instructions_sysvar_enabled::id(),
|
&feature_set::instructions_sysvar_enabled::id(),
|
||||||
&Account::default(),
|
&AccountSharedData::default(),
|
||||||
);
|
);
|
||||||
force_enabled_count -= 1;
|
force_enabled_count -= 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1209,7 +1209,7 @@ pub mod tests {
|
||||||
self, create_genesis_config_with_vote_accounts, ValidatorVoteKeypairs,
|
self, create_genesis_config_with_vote_accounts, ValidatorVoteKeypairs,
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
|
@ -2458,7 +2458,7 @@ pub mod tests {
|
||||||
let mut hash = bank.last_blockhash();
|
let mut hash = bank.last_blockhash();
|
||||||
|
|
||||||
let present_account_key = Keypair::new();
|
let present_account_key = Keypair::new();
|
||||||
let present_account = Account::new(1, 10, &Pubkey::default());
|
let present_account = AccountSharedData::new(1, 10, &Pubkey::default());
|
||||||
bank.store_account(&present_account_key.pubkey(), &present_account);
|
bank.store_account(&present_account_key.pubkey(), &present_account);
|
||||||
|
|
||||||
let entries: Vec<_> = (0..NUM_TRANSFERS)
|
let entries: Vec<_> = (0..NUM_TRANSFERS)
|
||||||
|
@ -2840,7 +2840,7 @@ pub mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
let present_account_key = Keypair::new();
|
let present_account_key = Keypair::new();
|
||||||
let present_account = Account::new(1, 10, &Pubkey::default());
|
let present_account = AccountSharedData::new(1, 10, &Pubkey::default());
|
||||||
bank.store_account(&present_account_key.pubkey(), &present_account);
|
bank.store_account(&present_account_key.pubkey(), &present_account);
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
@ -3013,7 +3013,7 @@ pub mod tests {
|
||||||
let bank = Arc::new(Bank::new(&genesis_config));
|
let bank = Arc::new(Bank::new(&genesis_config));
|
||||||
|
|
||||||
let present_account_key = Keypair::new();
|
let present_account_key = Keypair::new();
|
||||||
let present_account = Account::new(1, 10, &Pubkey::default());
|
let present_account = AccountSharedData::new(1, 10, &Pubkey::default());
|
||||||
bank.store_account(&present_account_key.pubkey(), &present_account);
|
bank.store_account(&present_account_key.pubkey(), &present_account);
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
|
@ -3347,8 +3347,11 @@ pub mod tests {
|
||||||
.map(|(root, stake)| {
|
.map(|(root, stake)| {
|
||||||
let mut vote_state = VoteState::default();
|
let mut vote_state = VoteState::default();
|
||||||
vote_state.root_slot = Some(root);
|
vote_state.root_slot = Some(root);
|
||||||
let mut vote_account =
|
let mut vote_account = AccountSharedData::new(
|
||||||
Account::new(1, VoteState::size_of(), &solana_vote_program::id());
|
1,
|
||||||
|
VoteState::size_of(),
|
||||||
|
&solana_vote_program::id(),
|
||||||
|
);
|
||||||
let versioned = VoteStateVersions::new_current(vote_state);
|
let versioned = VoteStateVersions::new_current(vote_state);
|
||||||
VoteState::serialize(&versioned, &mut vote_account.data).unwrap();
|
VoteState::serialize(&versioned, &mut vote_account.data).unwrap();
|
||||||
(
|
(
|
||||||
|
|
|
@ -68,7 +68,7 @@ pub(crate) mod tests {
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use solana_runtime::vote_account::{ArcVoteAccount, VoteAccounts};
|
use solana_runtime::vote_account::{ArcVoteAccount, VoteAccounts};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{from_account, Account},
|
account::{from_account, AccountSharedData},
|
||||||
clock::Clock,
|
clock::Clock,
|
||||||
instruction::Instruction,
|
instruction::Instruction,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
|
@ -212,7 +212,8 @@ pub(crate) mod tests {
|
||||||
let mut result: Vec<_> = epoch_stakes_and_lockouts(&bank, next_leader_schedule_epoch);
|
let mut result: Vec<_> = epoch_stakes_and_lockouts(&bank, next_leader_schedule_epoch);
|
||||||
result.sort();
|
result.sort();
|
||||||
let stake_history =
|
let stake_history =
|
||||||
from_account::<StakeHistory>(&bank.get_account(&stake_history::id()).unwrap()).unwrap();
|
from_account::<StakeHistory, _>(&bank.get_account(&stake_history::id()).unwrap())
|
||||||
|
.unwrap();
|
||||||
let mut expected = vec![
|
let mut expected = vec![
|
||||||
(
|
(
|
||||||
leader_stake.stake(bank.epoch(), Some(&stake_history), true),
|
leader_stake.stake(bank.epoch(), Some(&stake_history), true),
|
||||||
|
@ -309,7 +310,7 @@ pub(crate) mod tests {
|
||||||
));
|
));
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let vote_accounts = stakes.into_iter().map(|(stake, vote_state)| {
|
let vote_accounts = stakes.into_iter().map(|(stake, vote_state)| {
|
||||||
let account = Account::new_data(
|
let account = AccountSharedData::new_data(
|
||||||
rng.gen(), // lamports
|
rng.gen(), // lamports
|
||||||
&VoteStateVersions::new_current(vote_state),
|
&VoteStateVersions::new_current(vote_state),
|
||||||
&Pubkey::new_unique(), // owner
|
&Pubkey::new_unique(), // owner
|
||||||
|
|
|
@ -19,6 +19,7 @@ use solana_runtime::genesis_utils::{
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::Account,
|
||||||
|
account::AccountSharedData,
|
||||||
client::SyncClient,
|
client::SyncClient,
|
||||||
clock::{DEFAULT_DEV_SLOTS_PER_EPOCH, DEFAULT_TICKS_PER_SLOT},
|
clock::{DEFAULT_DEV_SLOTS_PER_EPOCH, DEFAULT_TICKS_PER_SLOT},
|
||||||
commitment_config::CommitmentConfig,
|
commitment_config::CommitmentConfig,
|
||||||
|
@ -69,7 +70,7 @@ pub struct ClusterConfig {
|
||||||
pub native_instruction_processors: Vec<(String, Pubkey)>,
|
pub native_instruction_processors: Vec<(String, Pubkey)>,
|
||||||
pub cluster_type: ClusterType,
|
pub cluster_type: ClusterType,
|
||||||
pub poh_config: PohConfig,
|
pub poh_config: PohConfig,
|
||||||
pub additional_accounts: Vec<(Pubkey, Account)>,
|
pub additional_accounts: Vec<(Pubkey, AccountSharedData)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ClusterConfig {
|
impl Default for ClusterConfig {
|
||||||
|
@ -169,9 +170,12 @@ impl LocalCluster {
|
||||||
stakes_in_genesis,
|
stakes_in_genesis,
|
||||||
config.cluster_type,
|
config.cluster_type,
|
||||||
);
|
);
|
||||||
genesis_config
|
genesis_config.accounts.extend(
|
||||||
.accounts
|
config
|
||||||
.extend(config.additional_accounts.drain(..));
|
.additional_accounts
|
||||||
|
.drain(..)
|
||||||
|
.map(|(key, account)| (key, Account::from(account))),
|
||||||
|
);
|
||||||
genesis_config.ticks_per_slot = config.ticks_per_slot;
|
genesis_config.ticks_per_slot = config.ticks_per_slot;
|
||||||
genesis_config.epoch_schedule = EpochSchedule::custom(
|
genesis_config.epoch_schedule = EpochSchedule::custom(
|
||||||
config.slots_per_epoch,
|
config.slots_per_epoch,
|
||||||
|
|
|
@ -38,7 +38,7 @@ use solana_runtime::{
|
||||||
snapshot_utils,
|
snapshot_utils,
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
client::{AsyncClient, SyncClient},
|
client::{AsyncClient, SyncClient},
|
||||||
clock::{self, Slot},
|
clock::{self, Slot},
|
||||||
commitment_config::CommitmentConfig,
|
commitment_config::CommitmentConfig,
|
||||||
|
@ -286,7 +286,7 @@ fn run_cluster_partition<E, F>(
|
||||||
leader_schedule: Option<(LeaderSchedule, Vec<Arc<Keypair>>)>,
|
leader_schedule: Option<(LeaderSchedule, Vec<Arc<Keypair>>)>,
|
||||||
on_partition_start: E,
|
on_partition_start: E,
|
||||||
on_partition_resolved: F,
|
on_partition_resolved: F,
|
||||||
additional_accounts: Vec<(Pubkey, Account)>,
|
additional_accounts: Vec<(Pubkey, AccountSharedData)>,
|
||||||
) where
|
) where
|
||||||
E: FnOnce(&mut LocalCluster),
|
E: FnOnce(&mut LocalCluster),
|
||||||
F: FnOnce(&mut LocalCluster),
|
F: FnOnce(&mut LocalCluster),
|
||||||
|
@ -2240,7 +2240,11 @@ fn setup_transfer_scan_threads(
|
||||||
scan_commitment: CommitmentConfig,
|
scan_commitment: CommitmentConfig,
|
||||||
update_client_receiver: Receiver<ThinClient>,
|
update_client_receiver: Receiver<ThinClient>,
|
||||||
scan_client_receiver: Receiver<ThinClient>,
|
scan_client_receiver: Receiver<ThinClient>,
|
||||||
) -> (JoinHandle<()>, JoinHandle<()>, Vec<(Pubkey, Account)>) {
|
) -> (
|
||||||
|
JoinHandle<()>,
|
||||||
|
JoinHandle<()>,
|
||||||
|
Vec<(Pubkey, AccountSharedData)>,
|
||||||
|
) {
|
||||||
let exit_ = exit.clone();
|
let exit_ = exit.clone();
|
||||||
let starting_keypairs: Arc<Vec<Keypair>> = Arc::new(
|
let starting_keypairs: Arc<Vec<Keypair>> = Arc::new(
|
||||||
iter::repeat_with(Keypair::new)
|
iter::repeat_with(Keypair::new)
|
||||||
|
@ -2252,9 +2256,14 @@ fn setup_transfer_scan_threads(
|
||||||
.take(num_starting_accounts)
|
.take(num_starting_accounts)
|
||||||
.collect(),
|
.collect(),
|
||||||
);
|
);
|
||||||
let starting_accounts: Vec<(Pubkey, Account)> = starting_keypairs
|
let starting_accounts: Vec<(Pubkey, AccountSharedData)> = starting_keypairs
|
||||||
.iter()
|
.iter()
|
||||||
.map(|k| (k.pubkey(), Account::new(1, 0, &system_program::id())))
|
.map(|k| {
|
||||||
|
(
|
||||||
|
k.pubkey(),
|
||||||
|
AccountSharedData::new(1, 0, &system_program::id()),
|
||||||
|
)
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let starting_keypairs_ = starting_keypairs.clone();
|
let starting_keypairs_ = starting_keypairs.clone();
|
||||||
|
|
|
@ -20,7 +20,7 @@ use {
|
||||||
genesis_utils::{create_genesis_config_with_leader, GenesisConfigInfo},
|
genesis_utils::{create_genesis_config_with_leader, GenesisConfigInfo},
|
||||||
},
|
},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
clock::Slot,
|
clock::Slot,
|
||||||
genesis_config::GenesisConfig,
|
genesis_config::GenesisConfig,
|
||||||
keyed_account::KeyedAccount,
|
keyed_account::KeyedAccount,
|
||||||
|
@ -111,7 +111,7 @@ pub fn builtin_process_instruction(
|
||||||
set_invoke_context(invoke_context);
|
set_invoke_context(invoke_context);
|
||||||
|
|
||||||
// Copy all the accounts into a HashMap to ensure there are no duplicates
|
// Copy all the accounts into a HashMap to ensure there are no duplicates
|
||||||
let mut accounts: HashMap<Pubkey, Account> = keyed_accounts
|
let mut accounts: HashMap<Pubkey, AccountSharedData> = keyed_accounts
|
||||||
.iter()
|
.iter()
|
||||||
.map(|ka| (*ka.unsigned_key(), ka.account.borrow().clone()))
|
.map(|ka| (*ka.unsigned_key(), ka.account.borrow().clone()))
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -238,8 +238,8 @@ impl program_stubs::SyscallStubs for SyscallStubs {
|
||||||
|
|
||||||
stable_log::program_invoke(&logger, &program_id, invoke_context.invoke_depth());
|
stable_log::program_invoke(&logger, &program_id, invoke_context.invoke_depth());
|
||||||
|
|
||||||
fn ai_to_a(ai: &AccountInfo) -> Account {
|
fn ai_to_a(ai: &AccountInfo) -> AccountSharedData {
|
||||||
Account {
|
AccountSharedData {
|
||||||
lamports: ai.lamports(),
|
lamports: ai.lamports(),
|
||||||
data: ai.try_borrow_data().unwrap().to_vec(),
|
data: ai.try_borrow_data().unwrap().to_vec(),
|
||||||
owner: *ai.owner,
|
owner: *ai.owner,
|
||||||
|
@ -409,7 +409,7 @@ fn setup_fee_calculator(bank: Bank) -> Bank {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ProgramTest {
|
pub struct ProgramTest {
|
||||||
accounts: Vec<(Pubkey, Account)>,
|
accounts: Vec<(Pubkey, AccountSharedData)>,
|
||||||
builtins: Vec<Builtin>,
|
builtins: Vec<Builtin>,
|
||||||
bpf_compute_max_units: Option<u64>,
|
bpf_compute_max_units: Option<u64>,
|
||||||
prefer_bpf: bool,
|
prefer_bpf: bool,
|
||||||
|
@ -468,7 +468,7 @@ impl ProgramTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add an account to the test environment
|
/// Add an account to the test environment
|
||||||
pub fn add_account(&mut self, address: Pubkey, account: Account) {
|
pub fn add_account(&mut self, address: Pubkey, account: AccountSharedData) {
|
||||||
self.accounts.push((address, account));
|
self.accounts.push((address, account));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,7 +482,7 @@ impl ProgramTest {
|
||||||
) {
|
) {
|
||||||
self.add_account(
|
self.add_account(
|
||||||
address,
|
address,
|
||||||
Account {
|
AccountSharedData {
|
||||||
lamports,
|
lamports,
|
||||||
data: read_file(find_file(filename).unwrap_or_else(|| {
|
data: read_file(find_file(filename).unwrap_or_else(|| {
|
||||||
panic!("Unable to locate {}", filename);
|
panic!("Unable to locate {}", filename);
|
||||||
|
@ -505,7 +505,7 @@ impl ProgramTest {
|
||||||
) {
|
) {
|
||||||
self.add_account(
|
self.add_account(
|
||||||
address,
|
address,
|
||||||
Account {
|
AccountSharedData {
|
||||||
lamports,
|
lamports,
|
||||||
data: base64::decode(data_base64)
|
data: base64::decode(data_base64)
|
||||||
.unwrap_or_else(|err| panic!("Failed to base64 decode: {}", err)),
|
.unwrap_or_else(|err| panic!("Failed to base64 decode: {}", err)),
|
||||||
|
@ -568,7 +568,7 @@ impl ProgramTest {
|
||||||
|
|
||||||
self.add_account(
|
self.add_account(
|
||||||
program_id,
|
program_id,
|
||||||
Account {
|
AccountSharedData {
|
||||||
lamports: Rent::default().minimum_balance(data.len()).min(1),
|
lamports: Rent::default().minimum_balance(data.len()).min(1),
|
||||||
data,
|
data,
|
||||||
owner: loader,
|
owner: loader,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use solana_sdk::{account::Account, pubkey::Pubkey, rent::Rent};
|
use solana_sdk::{account::AccountSharedData, pubkey::Pubkey, rent::Rent};
|
||||||
|
|
||||||
mod spl_token {
|
mod spl_token {
|
||||||
solana_sdk::declare_id!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
solana_sdk::declare_id!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
||||||
|
@ -29,13 +29,13 @@ static SPL_PROGRAMS: &[(Pubkey, &[u8])] = &[
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
pub fn spl_programs(rent: &Rent) -> Vec<(Pubkey, Account)> {
|
pub fn spl_programs(rent: &Rent) -> Vec<(Pubkey, AccountSharedData)> {
|
||||||
SPL_PROGRAMS
|
SPL_PROGRAMS
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(program_id, elf)| {
|
.map(|(program_id, elf)| {
|
||||||
(
|
(
|
||||||
*program_id,
|
*program_id,
|
||||||
Account {
|
AccountSharedData {
|
||||||
lamports: rent.minimum_balance(elf.len()).min(1),
|
lamports: rent.minimum_balance(elf.len()).min(1),
|
||||||
data: elf.to_vec(),
|
data: elf.to_vec(),
|
||||||
owner: solana_program::bpf_loader::id(),
|
owner: solana_program::bpf_loader::id(),
|
||||||
|
|
|
@ -19,7 +19,7 @@ use solana_runtime::{
|
||||||
loader_utils::load_program,
|
loader_utils::load_program,
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
bpf_loader,
|
bpf_loader,
|
||||||
client::SyncClient,
|
client::SyncClient,
|
||||||
entrypoint::SUCCESS,
|
entrypoint::SUCCESS,
|
||||||
|
@ -198,7 +198,7 @@ fn bench_instruction_count_tuner(_bencher: &mut Bencher) {
|
||||||
let mut invoke_context = MockInvokeContext::default();
|
let mut invoke_context = MockInvokeContext::default();
|
||||||
invoke_context.compute_meter.remaining = BUDGET;
|
invoke_context.compute_meter.remaining = BUDGET;
|
||||||
|
|
||||||
let accounts = [RefCell::new(Account::new(
|
let accounts = [RefCell::new(AccountSharedData::new(
|
||||||
1,
|
1,
|
||||||
10000001,
|
10000001,
|
||||||
&solana_sdk::pubkey::new_rand(),
|
&solana_sdk::pubkey::new_rand(),
|
||||||
|
|
|
@ -22,7 +22,7 @@ use solana_runtime::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable,
|
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable,
|
||||||
client::SyncClient,
|
client::SyncClient,
|
||||||
clock::{DEFAULT_SLOTS_PER_EPOCH, MAX_PROCESSING_AGE},
|
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 = Arc::new(bank);
|
||||||
let bank_client = BankClient::new_shared(&bank);
|
let bank_client = BankClient::new_shared(&bank);
|
||||||
let program_id = load_bpf_program(&bank_client, &bpf_loader::id(), &mint_keypair, program);
|
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();
|
let payee_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
bank.store_account(&payee_pubkey, &payee_account);
|
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 pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let account_metas = vec![
|
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);
|
load_bpf_program(&bank_client, &bpf_loader::id(), &mint_keypair, program.3);
|
||||||
|
|
||||||
let argument_keypair = Keypair::new();
|
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);
|
bank.store_account(&argument_keypair.pubkey(), &account);
|
||||||
|
|
||||||
let invoked_argument_keypair = Keypair::new();
|
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);
|
bank.store_account(&invoked_argument_keypair.pubkey(), &account);
|
||||||
|
|
||||||
let from_keypair = Keypair::new();
|
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);
|
bank.store_account(&from_keypair.pubkey(), &account);
|
||||||
|
|
||||||
let (derived_key1, bump_seed1) =
|
let (derived_key1, bump_seed1) =
|
||||||
|
@ -996,9 +996,9 @@ fn test_program_bpf_invoke_sanity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to realloc into unauthorized address space
|
// 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(&from_keypair.pubkey(), &account);
|
||||||
bank.store_account(&derived_key1, &Account::default());
|
bank.store_account(&derived_key1, &AccountSharedData::default());
|
||||||
let instruction = Instruction::new_with_bytes(
|
let instruction = Instruction::new_with_bytes(
|
||||||
invoke_program_id,
|
invoke_program_id,
|
||||||
&[
|
&[
|
||||||
|
@ -1061,11 +1061,11 @@ fn test_program_bpf_program_id_spoofing() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let from_pubkey = Pubkey::new_unique();
|
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);
|
bank.store_account(&from_pubkey, &account);
|
||||||
|
|
||||||
let to_pubkey = Pubkey::new_unique();
|
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);
|
bank.store_account(&to_pubkey, &account);
|
||||||
|
|
||||||
let account_metas = vec![
|
let account_metas = vec![
|
||||||
|
@ -1148,7 +1148,7 @@ fn test_program_bpf_ro_modify() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let test_keypair = Keypair::new();
|
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);
|
bank.store_account(&test_keypair.pubkey(), &account);
|
||||||
|
|
||||||
let account_metas = vec![
|
let account_metas = vec![
|
||||||
|
@ -1261,7 +1261,7 @@ fn assert_instruction_count() {
|
||||||
println!("Test program: {:?}", program.0);
|
println!("Test program: {:?}", program.0);
|
||||||
let program_id = solana_sdk::pubkey::new_rand();
|
let program_id = solana_sdk::pubkey::new_rand();
|
||||||
let key = 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 parameter_accounts = vec![KeyedAccount::new(&key, false, &mut account)];
|
||||||
let count = run_program(program.0, &program_id, ¶meter_accounts[..], &[]).unwrap();
|
let count = run_program(program.0, &program_id, ¶meter_accounts[..], &[]).unwrap();
|
||||||
println!(" {} : {:?} ({:?})", program.0, count, program.1,);
|
println!(" {} : {:?} ({:?})", program.0, count, program.1,);
|
||||||
|
|
|
@ -866,7 +866,7 @@ mod tests {
|
||||||
message_processor::{Executors, ThisInvokeContext},
|
message_processor::{Executors, ThisInvokeContext},
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{create_account, Account},
|
account::{create_account_shared_data as create_account, AccountSharedData},
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
client::SyncClient,
|
client::SyncClient,
|
||||||
clock::Clock,
|
clock::Clock,
|
||||||
|
@ -933,7 +933,7 @@ mod tests {
|
||||||
fn test_bpf_loader_write() {
|
fn test_bpf_loader_write() {
|
||||||
let program_id = bpf_loader::id();
|
let program_id = bpf_loader::id();
|
||||||
let program_key = solana_sdk::pubkey::new_rand();
|
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 keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
|
||||||
let instruction_data = bincode::serialize(&LoaderInstruction::Write {
|
let instruction_data = bincode::serialize(&LoaderInstruction::Write {
|
||||||
offset: 3,
|
offset: 3,
|
||||||
|
@ -1004,7 +1004,8 @@ mod tests {
|
||||||
let mut elf = Vec::new();
|
let mut elf = Vec::new();
|
||||||
let rent = Rent::default();
|
let rent = Rent::default();
|
||||||
file.read_to_end(&mut elf).unwrap();
|
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;
|
program_account.borrow_mut().data = elf;
|
||||||
let keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
|
let keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
|
||||||
let instruction_data = bincode::serialize(&LoaderInstruction::Finalize).unwrap();
|
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 file = File::open("test_elfs/noop_aligned.so").expect("file open failed");
|
||||||
let mut elf = Vec::new();
|
let mut elf = Vec::new();
|
||||||
file.read_to_end(&mut elf).unwrap();
|
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().data = elf;
|
||||||
program_account.borrow_mut().executable = true;
|
program_account.borrow_mut().executable = true;
|
||||||
|
|
||||||
|
@ -1098,7 +1099,7 @@ mod tests {
|
||||||
keyed_accounts[0].account.borrow_mut().executable = true;
|
keyed_accounts[0].account.borrow_mut().executable = true;
|
||||||
|
|
||||||
// Case: With program and parameter 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, ¶meter_account));
|
keyed_accounts.push(KeyedAccount::new(&program_key, false, ¶meter_account));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Ok(()),
|
Ok(()),
|
||||||
|
@ -1139,7 +1140,7 @@ mod tests {
|
||||||
|
|
||||||
// Case: With duplicate accounts
|
// Case: With duplicate accounts
|
||||||
let duplicate_key = solana_sdk::pubkey::new_rand();
|
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)];
|
let mut keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
|
||||||
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, ¶meter_account));
|
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, ¶meter_account));
|
||||||
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, ¶meter_account));
|
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, ¶meter_account));
|
||||||
|
@ -1163,13 +1164,13 @@ mod tests {
|
||||||
let mut file = File::open("test_elfs/noop_unaligned.so").expect("file open failed");
|
let mut file = File::open("test_elfs/noop_unaligned.so").expect("file open failed");
|
||||||
let mut elf = Vec::new();
|
let mut elf = Vec::new();
|
||||||
file.read_to_end(&mut elf).unwrap();
|
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().data = elf;
|
||||||
program_account.borrow_mut().executable = true;
|
program_account.borrow_mut().executable = true;
|
||||||
let mut keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
|
let mut keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
|
||||||
|
|
||||||
// Case: With program and parameter 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, ¶meter_account));
|
keyed_accounts.push(KeyedAccount::new(&program_key, false, ¶meter_account));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Ok(()),
|
Ok(()),
|
||||||
|
@ -1183,7 +1184,7 @@ mod tests {
|
||||||
|
|
||||||
// Case: With duplicate accounts
|
// Case: With duplicate accounts
|
||||||
let duplicate_key = solana_sdk::pubkey::new_rand();
|
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)];
|
let mut keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
|
||||||
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, ¶meter_account));
|
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, ¶meter_account));
|
||||||
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, ¶meter_account));
|
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, ¶meter_account));
|
||||||
|
@ -1207,13 +1208,13 @@ mod tests {
|
||||||
let mut file = File::open("test_elfs/noop_aligned.so").expect("file open failed");
|
let mut file = File::open("test_elfs/noop_aligned.so").expect("file open failed");
|
||||||
let mut elf = Vec::new();
|
let mut elf = Vec::new();
|
||||||
file.read_to_end(&mut elf).unwrap();
|
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().data = elf;
|
||||||
program_account.borrow_mut().executable = true;
|
program_account.borrow_mut().executable = true;
|
||||||
let mut keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
|
let mut keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
|
||||||
|
|
||||||
// Case: With program and parameter 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, ¶meter_account));
|
keyed_accounts.push(KeyedAccount::new(&program_key, false, ¶meter_account));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Ok(()),
|
Ok(()),
|
||||||
|
@ -1227,7 +1228,7 @@ mod tests {
|
||||||
|
|
||||||
// Case: With duplicate accounts
|
// Case: With duplicate accounts
|
||||||
let duplicate_key = solana_sdk::pubkey::new_rand();
|
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)];
|
let mut keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
|
||||||
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, ¶meter_account));
|
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, ¶meter_account));
|
||||||
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, ¶meter_account));
|
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, ¶meter_account));
|
||||||
|
@ -1247,13 +1248,13 @@ mod tests {
|
||||||
let instruction =
|
let instruction =
|
||||||
bincode::serialize(&UpgradeableLoaderInstruction::InitializeBuffer).unwrap();
|
bincode::serialize(&UpgradeableLoaderInstruction::InitializeBuffer).unwrap();
|
||||||
let buffer_address = Pubkey::new_unique();
|
let buffer_address = Pubkey::new_unique();
|
||||||
let buffer_account = Account::new_ref(
|
let buffer_account = AccountSharedData::new_ref(
|
||||||
1,
|
1,
|
||||||
UpgradeableLoaderState::buffer_len(9).unwrap(),
|
UpgradeableLoaderState::buffer_len(9).unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
);
|
);
|
||||||
let authority_address = Pubkey::new_unique();
|
let authority_address = Pubkey::new_unique();
|
||||||
let authority_account = Account::new_ref(
|
let authority_account = AccountSharedData::new_ref(
|
||||||
1,
|
1,
|
||||||
UpgradeableLoaderState::buffer_len(9).unwrap(),
|
UpgradeableLoaderState::buffer_len(9).unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
|
@ -1305,7 +1306,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bpf_loader_upgradeable_write() {
|
fn test_bpf_loader_upgradeable_write() {
|
||||||
let buffer_address = Pubkey::new_unique();
|
let buffer_address = Pubkey::new_unique();
|
||||||
let buffer_account = Account::new_ref(
|
let buffer_account = AccountSharedData::new_ref(
|
||||||
1,
|
1,
|
||||||
UpgradeableLoaderState::buffer_len(9).unwrap(),
|
UpgradeableLoaderState::buffer_len(9).unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
|
@ -1372,7 +1373,7 @@ mod tests {
|
||||||
bytes: vec![42; 6],
|
bytes: vec![42; 6],
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let buffer_account = Account::new_ref(
|
let buffer_account = AccountSharedData::new_ref(
|
||||||
1,
|
1,
|
||||||
UpgradeableLoaderState::buffer_len(9).unwrap(),
|
UpgradeableLoaderState::buffer_len(9).unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
|
@ -1564,7 +1565,7 @@ mod tests {
|
||||||
UpgradeableLoaderState::programdata_len(elf.len()).unwrap(),
|
UpgradeableLoaderState::programdata_len(elf.len()).unwrap(),
|
||||||
);
|
);
|
||||||
let buffer_address = Pubkey::new_unique();
|
let buffer_address = Pubkey::new_unique();
|
||||||
let mut buffer_account = Account::new(
|
let mut buffer_account = AccountSharedData::new(
|
||||||
min_programdata_balance,
|
min_programdata_balance,
|
||||||
UpgradeableLoaderState::buffer_len(elf.len()).unwrap(),
|
UpgradeableLoaderState::buffer_len(elf.len()).unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
|
@ -1576,12 +1577,12 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
buffer_account.data[UpgradeableLoaderState::buffer_data_offset().unwrap()..]
|
buffer_account.data[UpgradeableLoaderState::buffer_data_offset().unwrap()..]
|
||||||
.copy_from_slice(&elf);
|
.copy_from_slice(&elf);
|
||||||
let program_account = Account::new(
|
let program_account = AccountSharedData::new(
|
||||||
min_programdata_balance,
|
min_programdata_balance,
|
||||||
UpgradeableLoaderState::program_len().unwrap(),
|
UpgradeableLoaderState::program_len().unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
);
|
);
|
||||||
let programdata_account = Account::new(
|
let programdata_account = AccountSharedData::new(
|
||||||
1,
|
1,
|
||||||
UpgradeableLoaderState::programdata_len(elf.len()).unwrap(),
|
UpgradeableLoaderState::programdata_len(elf.len()).unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
|
@ -1590,8 +1591,8 @@ mod tests {
|
||||||
// Test successful deploy
|
// Test successful deploy
|
||||||
bank.clear_signatures();
|
bank.clear_signatures();
|
||||||
bank.store_account(&buffer_address, &buffer_account);
|
bank.store_account(&buffer_address, &buffer_account);
|
||||||
bank.store_account(&program_keypair.pubkey(), &Account::default());
|
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
|
||||||
bank.store_account(&programdata_address, &Account::default());
|
bank.store_account(&programdata_address, &AccountSharedData::default());
|
||||||
let before = bank.get_balance(&mint_keypair.pubkey());
|
let before = bank.get_balance(&mint_keypair.pubkey());
|
||||||
let message = Message::new(
|
let message = Message::new(
|
||||||
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
||||||
|
@ -1683,7 +1684,7 @@ mod tests {
|
||||||
// Test initialized ProgramData account
|
// Test initialized ProgramData account
|
||||||
bank.clear_signatures();
|
bank.clear_signatures();
|
||||||
bank.store_account(&buffer_address, &buffer_account);
|
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(
|
let message = Message::new(
|
||||||
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
|
@ -1772,9 +1773,9 @@ mod tests {
|
||||||
|
|
||||||
// Test invalid Buffer account state
|
// Test invalid Buffer account state
|
||||||
bank.clear_signatures();
|
bank.clear_signatures();
|
||||||
bank.store_account(&buffer_address, &Account::default());
|
bank.store_account(&buffer_address, &AccountSharedData::default());
|
||||||
bank.store_account(&program_keypair.pubkey(), &Account::default());
|
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
|
||||||
bank.store_account(&programdata_address, &Account::default());
|
bank.store_account(&programdata_address, &AccountSharedData::default());
|
||||||
let message = Message::new(
|
let message = Message::new(
|
||||||
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
|
@ -1801,8 +1802,8 @@ mod tests {
|
||||||
// Test program account not rent exempt
|
// Test program account not rent exempt
|
||||||
bank.clear_signatures();
|
bank.clear_signatures();
|
||||||
bank.store_account(&buffer_address, &buffer_account);
|
bank.store_account(&buffer_address, &buffer_account);
|
||||||
bank.store_account(&program_keypair.pubkey(), &Account::default());
|
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
|
||||||
bank.store_account(&programdata_address, &Account::default());
|
bank.store_account(&programdata_address, &AccountSharedData::default());
|
||||||
let message = Message::new(
|
let message = Message::new(
|
||||||
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
|
@ -1829,8 +1830,8 @@ mod tests {
|
||||||
// Test program account not rent exempt because data is larger than needed
|
// Test program account not rent exempt because data is larger than needed
|
||||||
bank.clear_signatures();
|
bank.clear_signatures();
|
||||||
bank.store_account(&buffer_address, &buffer_account);
|
bank.store_account(&buffer_address, &buffer_account);
|
||||||
bank.store_account(&program_keypair.pubkey(), &Account::default());
|
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
|
||||||
bank.store_account(&programdata_address, &Account::default());
|
bank.store_account(&programdata_address, &AccountSharedData::default());
|
||||||
let mut instructions = bpf_loader_upgradeable::deploy_with_max_program_len(
|
let mut instructions = bpf_loader_upgradeable::deploy_with_max_program_len(
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
&program_keypair.pubkey(),
|
&program_keypair.pubkey(),
|
||||||
|
@ -1862,8 +1863,8 @@ mod tests {
|
||||||
// Test program account too small
|
// Test program account too small
|
||||||
bank.clear_signatures();
|
bank.clear_signatures();
|
||||||
bank.store_account(&buffer_address, &buffer_account);
|
bank.store_account(&buffer_address, &buffer_account);
|
||||||
bank.store_account(&program_keypair.pubkey(), &Account::default());
|
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
|
||||||
bank.store_account(&programdata_address, &Account::default());
|
bank.store_account(&programdata_address, &AccountSharedData::default());
|
||||||
let mut instructions = bpf_loader_upgradeable::deploy_with_max_program_len(
|
let mut instructions = bpf_loader_upgradeable::deploy_with_max_program_len(
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
&program_keypair.pubkey(),
|
&program_keypair.pubkey(),
|
||||||
|
@ -1896,11 +1897,11 @@ mod tests {
|
||||||
bank.clear_signatures();
|
bank.clear_signatures();
|
||||||
bank.store_account(
|
bank.store_account(
|
||||||
&mint_keypair.pubkey(),
|
&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(&buffer_address, &buffer_account);
|
||||||
bank.store_account(&program_keypair.pubkey(), &Account::default());
|
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
|
||||||
bank.store_account(&programdata_address, &Account::default());
|
bank.store_account(&programdata_address, &AccountSharedData::default());
|
||||||
let message = Message::new(
|
let message = Message::new(
|
||||||
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
|
@ -1925,14 +1926,14 @@ mod tests {
|
||||||
);
|
);
|
||||||
bank.store_account(
|
bank.store_account(
|
||||||
&mint_keypair.pubkey(),
|
&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
|
// Test max_data_len
|
||||||
bank.clear_signatures();
|
bank.clear_signatures();
|
||||||
bank.store_account(&buffer_address, &buffer_account);
|
bank.store_account(&buffer_address, &buffer_account);
|
||||||
bank.store_account(&program_keypair.pubkey(), &Account::default());
|
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
|
||||||
bank.store_account(&programdata_address, &Account::default());
|
bank.store_account(&programdata_address, &AccountSharedData::default());
|
||||||
let message = Message::new(
|
let message = Message::new(
|
||||||
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
|
@ -1960,13 +1961,13 @@ mod tests {
|
||||||
bank.clear_signatures();
|
bank.clear_signatures();
|
||||||
bank.store_account(
|
bank.store_account(
|
||||||
&mint_keypair.pubkey(),
|
&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();
|
let mut modified_buffer_account = buffer_account.clone();
|
||||||
modified_buffer_account.lamports = u64::MAX / 2;
|
modified_buffer_account.lamports = u64::MAX / 2;
|
||||||
bank.store_account(&buffer_address, &modified_buffer_account);
|
bank.store_account(&buffer_address, &modified_buffer_account);
|
||||||
bank.store_account(&program_keypair.pubkey(), &Account::default());
|
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
|
||||||
bank.store_account(&programdata_address, &Account::default());
|
bank.store_account(&programdata_address, &AccountSharedData::default());
|
||||||
let message = Message::new(
|
let message = Message::new(
|
||||||
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
|
@ -1993,8 +1994,8 @@ mod tests {
|
||||||
// Test not the system account
|
// Test not the system account
|
||||||
bank.clear_signatures();
|
bank.clear_signatures();
|
||||||
bank.store_account(&buffer_address, &buffer_account);
|
bank.store_account(&buffer_address, &buffer_account);
|
||||||
bank.store_account(&program_keypair.pubkey(), &Account::default());
|
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
|
||||||
bank.store_account(&programdata_address, &Account::default());
|
bank.store_account(&programdata_address, &AccountSharedData::default());
|
||||||
let mut instructions = bpf_loader_upgradeable::deploy_with_max_program_len(
|
let mut instructions = bpf_loader_upgradeable::deploy_with_max_program_len(
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
&program_keypair.pubkey(),
|
&program_keypair.pubkey(),
|
||||||
|
@ -2024,8 +2025,8 @@ mod tests {
|
||||||
.data
|
.data
|
||||||
.truncate(UpgradeableLoaderState::buffer_len(1).unwrap());
|
.truncate(UpgradeableLoaderState::buffer_len(1).unwrap());
|
||||||
bank.store_account(&buffer_address, &modified_buffer_account);
|
bank.store_account(&buffer_address, &modified_buffer_account);
|
||||||
bank.store_account(&program_keypair.pubkey(), &Account::default());
|
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
|
||||||
bank.store_account(&programdata_address, &Account::default());
|
bank.store_account(&programdata_address, &AccountSharedData::default());
|
||||||
let message = Message::new(
|
let message = Message::new(
|
||||||
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
|
@ -2051,7 +2052,7 @@ mod tests {
|
||||||
|
|
||||||
// Test small buffer account
|
// Test small buffer account
|
||||||
bank.clear_signatures();
|
bank.clear_signatures();
|
||||||
let mut modified_buffer_account = Account::new(
|
let mut modified_buffer_account = AccountSharedData::new(
|
||||||
min_programdata_balance,
|
min_programdata_balance,
|
||||||
UpgradeableLoaderState::buffer_len(elf.len()).unwrap(),
|
UpgradeableLoaderState::buffer_len(elf.len()).unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
|
@ -2065,8 +2066,8 @@ mod tests {
|
||||||
.copy_from_slice(&elf);
|
.copy_from_slice(&elf);
|
||||||
modified_buffer_account.data.truncate(5);
|
modified_buffer_account.data.truncate(5);
|
||||||
bank.store_account(&buffer_address, &modified_buffer_account);
|
bank.store_account(&buffer_address, &modified_buffer_account);
|
||||||
bank.store_account(&program_keypair.pubkey(), &Account::default());
|
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
|
||||||
bank.store_account(&programdata_address, &Account::default());
|
bank.store_account(&programdata_address, &AccountSharedData::default());
|
||||||
let message = Message::new(
|
let message = Message::new(
|
||||||
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
|
@ -2092,7 +2093,7 @@ mod tests {
|
||||||
|
|
||||||
// Mismatched buffer and program authority
|
// Mismatched buffer and program authority
|
||||||
bank.clear_signatures();
|
bank.clear_signatures();
|
||||||
let mut modified_buffer_account = Account::new(
|
let mut modified_buffer_account = AccountSharedData::new(
|
||||||
min_programdata_balance,
|
min_programdata_balance,
|
||||||
UpgradeableLoaderState::buffer_len(elf.len()).unwrap(),
|
UpgradeableLoaderState::buffer_len(elf.len()).unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
|
@ -2105,8 +2106,8 @@ mod tests {
|
||||||
modified_buffer_account.data[UpgradeableLoaderState::buffer_data_offset().unwrap()..]
|
modified_buffer_account.data[UpgradeableLoaderState::buffer_data_offset().unwrap()..]
|
||||||
.copy_from_slice(&elf);
|
.copy_from_slice(&elf);
|
||||||
bank.store_account(&buffer_address, &modified_buffer_account);
|
bank.store_account(&buffer_address, &modified_buffer_account);
|
||||||
bank.store_account(&program_keypair.pubkey(), &Account::default());
|
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
|
||||||
bank.store_account(&programdata_address, &Account::default());
|
bank.store_account(&programdata_address, &AccountSharedData::default());
|
||||||
let message = Message::new(
|
let message = Message::new(
|
||||||
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
|
@ -2132,7 +2133,7 @@ mod tests {
|
||||||
|
|
||||||
// Deploy buffer with mismatched None authority
|
// Deploy buffer with mismatched None authority
|
||||||
bank.clear_signatures();
|
bank.clear_signatures();
|
||||||
let mut modified_buffer_account = Account::new(
|
let mut modified_buffer_account = AccountSharedData::new(
|
||||||
min_programdata_balance,
|
min_programdata_balance,
|
||||||
UpgradeableLoaderState::buffer_len(elf.len()).unwrap(),
|
UpgradeableLoaderState::buffer_len(elf.len()).unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
|
@ -2145,8 +2146,8 @@ mod tests {
|
||||||
modified_buffer_account.data[UpgradeableLoaderState::buffer_data_offset().unwrap()..]
|
modified_buffer_account.data[UpgradeableLoaderState::buffer_data_offset().unwrap()..]
|
||||||
.copy_from_slice(&elf);
|
.copy_from_slice(&elf);
|
||||||
bank.store_account(&buffer_address, &modified_buffer_account);
|
bank.store_account(&buffer_address, &modified_buffer_account);
|
||||||
bank.store_account(&program_keypair.pubkey(), &Account::default());
|
bank.store_account(&program_keypair.pubkey(), &AccountSharedData::default());
|
||||||
bank.store_account(&programdata_address, &Account::default());
|
bank.store_account(&programdata_address, &AccountSharedData::default());
|
||||||
let message = Message::new(
|
let message = Message::new(
|
||||||
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
&bpf_loader_upgradeable::deploy_with_max_program_len(
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
|
@ -2202,7 +2203,7 @@ mod tests {
|
||||||
let (programdata_address, _) =
|
let (programdata_address, _) =
|
||||||
Pubkey::find_program_address(&[program_address.as_ref()], &id());
|
Pubkey::find_program_address(&[program_address.as_ref()], &id());
|
||||||
let spill_address = Pubkey::new_unique();
|
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)]
|
#[allow(clippy::type_complexity)]
|
||||||
fn get_accounts(
|
fn get_accounts(
|
||||||
|
@ -2215,12 +2216,12 @@ mod tests {
|
||||||
min_program_balance: u64,
|
min_program_balance: u64,
|
||||||
min_programdata_balance: u64,
|
min_programdata_balance: u64,
|
||||||
) -> (
|
) -> (
|
||||||
Rc<RefCell<Account>>,
|
Rc<RefCell<AccountSharedData>>,
|
||||||
Rc<RefCell<Account>>,
|
Rc<RefCell<AccountSharedData>>,
|
||||||
Rc<RefCell<Account>>,
|
Rc<RefCell<AccountSharedData>>,
|
||||||
Rc<RefCell<Account>>,
|
Rc<RefCell<AccountSharedData>>,
|
||||||
) {
|
) {
|
||||||
let buffer_account = Account::new_ref(
|
let buffer_account = AccountSharedData::new_ref(
|
||||||
1,
|
1,
|
||||||
UpgradeableLoaderState::buffer_len(elf_new.len()).unwrap(),
|
UpgradeableLoaderState::buffer_len(elf_new.len()).unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
|
@ -2234,7 +2235,7 @@ mod tests {
|
||||||
buffer_account.borrow_mut().data
|
buffer_account.borrow_mut().data
|
||||||
[UpgradeableLoaderState::buffer_data_offset().unwrap()..]
|
[UpgradeableLoaderState::buffer_data_offset().unwrap()..]
|
||||||
.copy_from_slice(&elf_new);
|
.copy_from_slice(&elf_new);
|
||||||
let programdata_account = Account::new_ref(
|
let programdata_account = AccountSharedData::new_ref(
|
||||||
min_programdata_balance,
|
min_programdata_balance,
|
||||||
UpgradeableLoaderState::programdata_len(elf_orig.len().max(elf_new.len())).unwrap(),
|
UpgradeableLoaderState::programdata_len(elf_orig.len().max(elf_new.len())).unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
|
@ -2246,7 +2247,7 @@ mod tests {
|
||||||
upgrade_authority_address: Some(*upgrade_authority_address),
|
upgrade_authority_address: Some(*upgrade_authority_address),
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let program_account = Account::new_ref(
|
let program_account = AccountSharedData::new_ref(
|
||||||
min_program_balance,
|
min_program_balance,
|
||||||
UpgradeableLoaderState::program_len().unwrap(),
|
UpgradeableLoaderState::program_len().unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
|
@ -2258,7 +2259,7 @@ mod tests {
|
||||||
programdata_address: *programdata_address,
|
programdata_address: *programdata_address,
|
||||||
})
|
})
|
||||||
.unwrap();
|
.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,
|
buffer_account,
|
||||||
|
@ -2648,7 +2649,7 @@ mod tests {
|
||||||
min_program_balance,
|
min_program_balance,
|
||||||
min_programdata_balance,
|
min_programdata_balance,
|
||||||
);
|
);
|
||||||
let buffer_account = Account::new_ref(
|
let buffer_account = AccountSharedData::new_ref(
|
||||||
1,
|
1,
|
||||||
UpgradeableLoaderState::buffer_len(elf_orig.len().max(elf_new.len()) + 1).unwrap(),
|
UpgradeableLoaderState::buffer_len(elf_orig.len().max(elf_new.len()) + 1).unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
|
@ -2845,13 +2846,13 @@ mod tests {
|
||||||
let instruction = bincode::serialize(&UpgradeableLoaderInstruction::SetAuthority).unwrap();
|
let instruction = bincode::serialize(&UpgradeableLoaderInstruction::SetAuthority).unwrap();
|
||||||
let slot = 0;
|
let slot = 0;
|
||||||
let upgrade_authority_address = Pubkey::new_unique();
|
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_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 program_address = Pubkey::new_unique();
|
||||||
let (programdata_address, _) =
|
let (programdata_address, _) =
|
||||||
Pubkey::find_program_address(&[program_address.as_ref()], &id());
|
Pubkey::find_program_address(&[program_address.as_ref()], &id());
|
||||||
let programdata_account = Account::new_ref(
|
let programdata_account = AccountSharedData::new_ref(
|
||||||
1,
|
1,
|
||||||
UpgradeableLoaderState::programdata_len(0).unwrap(),
|
UpgradeableLoaderState::programdata_len(0).unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
|
@ -3037,11 +3038,11 @@ mod tests {
|
||||||
fn test_bpf_loader_upgradeable_set_buffer_authority() {
|
fn test_bpf_loader_upgradeable_set_buffer_authority() {
|
||||||
let instruction = bincode::serialize(&UpgradeableLoaderInstruction::SetAuthority).unwrap();
|
let instruction = bincode::serialize(&UpgradeableLoaderInstruction::SetAuthority).unwrap();
|
||||||
let authority_address = Pubkey::new_unique();
|
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_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_address = Pubkey::new_unique();
|
||||||
let buffer_account = Account::new_ref(
|
let buffer_account = AccountSharedData::new_ref(
|
||||||
1,
|
1,
|
||||||
UpgradeableLoaderState::buffer_len(0).unwrap(),
|
UpgradeableLoaderState::buffer_len(0).unwrap(),
|
||||||
&bpf_loader_upgradeable::id(),
|
&bpf_loader_upgradeable::id(),
|
||||||
|
@ -3264,11 +3265,11 @@ mod tests {
|
||||||
0..elf.len(),
|
0..elf.len(),
|
||||||
0..255,
|
0..255,
|
||||||
|bytes: &mut [u8]| {
|
|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().data = bytes.to_vec();
|
||||||
program_account.borrow_mut().executable = true;
|
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![
|
let keyed_accounts = vec![
|
||||||
KeyedAccount::new(&program_key, false, &program_account),
|
KeyedAccount::new(&program_key, false, &program_account),
|
||||||
KeyedAccount::new(&program_key, false, ¶meter_account),
|
KeyedAccount::new(&program_key, false, ¶meter_account),
|
||||||
|
|
|
@ -243,7 +243,7 @@ pub fn deserialize_parameters_aligned(
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account, account_info::AccountInfo, bpf_loader, entrypoint::deserialize,
|
account::AccountSharedData, account_info::AccountInfo, bpf_loader, entrypoint::deserialize,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
cell::RefCell,
|
cell::RefCell,
|
||||||
|
@ -263,7 +263,7 @@ mod tests {
|
||||||
solana_sdk::pubkey::new_rand(),
|
solana_sdk::pubkey::new_rand(),
|
||||||
];
|
];
|
||||||
let accounts = [
|
let accounts = [
|
||||||
RefCell::new(Account {
|
RefCell::new(AccountSharedData {
|
||||||
lamports: 1,
|
lamports: 1,
|
||||||
data: vec![1u8, 2, 3, 4, 5],
|
data: vec![1u8, 2, 3, 4, 5],
|
||||||
owner: bpf_loader::id(),
|
owner: bpf_loader::id(),
|
||||||
|
@ -271,21 +271,21 @@ mod tests {
|
||||||
rent_epoch: 100,
|
rent_epoch: 100,
|
||||||
}),
|
}),
|
||||||
// dup of first
|
// dup of first
|
||||||
RefCell::new(Account {
|
RefCell::new(AccountSharedData {
|
||||||
lamports: 1,
|
lamports: 1,
|
||||||
data: vec![1u8, 2, 3, 4, 5],
|
data: vec![1u8, 2, 3, 4, 5],
|
||||||
owner: bpf_loader::id(),
|
owner: bpf_loader::id(),
|
||||||
executable: false,
|
executable: false,
|
||||||
rent_epoch: 100,
|
rent_epoch: 100,
|
||||||
}),
|
}),
|
||||||
RefCell::new(Account {
|
RefCell::new(AccountSharedData {
|
||||||
lamports: 2,
|
lamports: 2,
|
||||||
data: vec![11u8, 12, 13, 14, 15, 16, 17, 18, 19],
|
data: vec![11u8, 12, 13, 14, 15, 16, 17, 18, 19],
|
||||||
owner: bpf_loader::id(),
|
owner: bpf_loader::id(),
|
||||||
executable: true,
|
executable: true,
|
||||||
rent_epoch: 200,
|
rent_epoch: 200,
|
||||||
}),
|
}),
|
||||||
RefCell::new(Account {
|
RefCell::new(AccountSharedData {
|
||||||
lamports: 3,
|
lamports: 3,
|
||||||
data: vec![],
|
data: vec![],
|
||||||
owner: bpf_loader::id(),
|
owner: bpf_loader::id(),
|
||||||
|
|
|
@ -10,7 +10,7 @@ use solana_rbpf::{
|
||||||
};
|
};
|
||||||
use solana_runtime::message_processor::MessageProcessor;
|
use solana_runtime::message_processor::MessageProcessor;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
account_info::AccountInfo,
|
account_info::AccountInfo,
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
bpf_loader, bpf_loader_deprecated,
|
bpf_loader, bpf_loader_deprecated,
|
||||||
|
@ -851,9 +851,12 @@ struct AccountReferences<'a> {
|
||||||
ref_to_len_in_vm: &'a mut u64,
|
ref_to_len_in_vm: &'a mut u64,
|
||||||
serialized_len_ptr: &'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> = (
|
type TranslatedAccounts<'a> = (
|
||||||
Vec<Rc<RefCell<Account>>>,
|
Vec<Rc<RefCell<AccountSharedData>>>,
|
||||||
Vec<Option<AccountReferences<'a>>>,
|
Vec<Option<AccountReferences<'a>>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1018,7 +1021,7 @@ impl<'a> SyscallInvokeSigned<'a> for SyscallInvokeSignedRust<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
Rc::new(RefCell::new(Account {
|
Rc::new(RefCell::new(AccountSharedData {
|
||||||
lamports: *lamports,
|
lamports: *lamports,
|
||||||
data: data.to_vec(),
|
data: data.to_vec(),
|
||||||
executable: account_info.executable,
|
executable: account_info.executable,
|
||||||
|
@ -1301,7 +1304,7 @@ impl<'a> SyscallInvokeSigned<'a> for SyscallInvokeSignedC<'a> {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
Rc::new(RefCell::new(Account {
|
Rc::new(RefCell::new(AccountSharedData {
|
||||||
lamports: *lamports,
|
lamports: *lamports,
|
||||||
data: data.to_vec(),
|
data: data.to_vec(),
|
||||||
executable: account_info.executable,
|
executable: account_info.executable,
|
||||||
|
@ -1512,9 +1515,9 @@ fn check_authorized_program(
|
||||||
|
|
||||||
fn get_upgradeable_executable(
|
fn get_upgradeable_executable(
|
||||||
callee_program_id: &Pubkey,
|
callee_program_id: &Pubkey,
|
||||||
program_account: &RefCell<Account>,
|
program_account: &RefCell<AccountSharedData>,
|
||||||
invoke_context: &Ref<&mut dyn InvokeContext>,
|
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() {
|
if program_account.borrow().owner == bpf_loader_upgradeable::id() {
|
||||||
match program_account.borrow().state() {
|
match program_account.borrow().state() {
|
||||||
Ok(UpgradeableLoaderState::Program {
|
Ok(UpgradeableLoaderState::Program {
|
||||||
|
|
|
@ -229,7 +229,7 @@ mod tests {
|
||||||
use crate::id;
|
use crate::id;
|
||||||
use solana_runtime::bank::Bank;
|
use solana_runtime::bank::Bank;
|
||||||
use solana_runtime::bank_client::BankClient;
|
use solana_runtime::bank_client::BankClient;
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::AccountSharedData;
|
||||||
use solana_sdk::client::SyncClient;
|
use solana_sdk::client::SyncClient;
|
||||||
use solana_sdk::genesis_config::create_genesis_config;
|
use solana_sdk::genesis_config::create_genesis_config;
|
||||||
use solana_sdk::hash::hash;
|
use solana_sdk::hash::hash;
|
||||||
|
@ -522,10 +522,10 @@ mod tests {
|
||||||
fn test_pay_when_account_data() {
|
fn test_pay_when_account_data() {
|
||||||
let (bank, alice_keypair) = create_bank(42);
|
let (bank, alice_keypair) = create_bank(42);
|
||||||
let game_pubkey = solana_sdk::pubkey::new_rand();
|
let game_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let game_account = Account {
|
let game_account = AccountSharedData {
|
||||||
lamports: 1,
|
lamports: 1,
|
||||||
data: vec![1, 2, 3],
|
data: vec![1, 2, 3],
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
};
|
};
|
||||||
bank.store_account(&game_pubkey, &game_account);
|
bank.store_account(&game_pubkey, &game_account);
|
||||||
assert_eq!(bank.get_account(&game_pubkey).unwrap().data, vec![1, 2, 3]);
|
assert_eq!(bank.get_account(&game_pubkey).unwrap().data, vec![1, 2, 3]);
|
||||||
|
|
|
@ -130,7 +130,7 @@ mod tests {
|
||||||
use bincode::serialized_size;
|
use bincode::serialized_size;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
keyed_account::create_keyed_is_signer_accounts,
|
keyed_account::create_keyed_is_signer_accounts,
|
||||||
process_instruction::MockInvokeContext,
|
process_instruction::MockInvokeContext,
|
||||||
signature::{Keypair, Signer},
|
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 from_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let config_keypair = Keypair::new();
|
let config_keypair = Keypair::new();
|
||||||
let config_pubkey = config_keypair.pubkey();
|
let config_pubkey = config_keypair.pubkey();
|
||||||
|
@ -179,10 +179,10 @@ mod tests {
|
||||||
} => space,
|
} => space,
|
||||||
_ => panic!("Not a CreateAccount system instruction"),
|
_ => panic!("Not a CreateAccount system instruction"),
|
||||||
};
|
};
|
||||||
let config_account = RefCell::new(Account {
|
let config_account = RefCell::new(AccountSharedData {
|
||||||
data: vec![0; space as usize],
|
data: vec![0; space as usize],
|
||||||
owner: id(),
|
owner: id(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
});
|
});
|
||||||
let accounts = vec![(&config_pubkey, true, &config_account)];
|
let accounts = vec![(&config_pubkey, true, &config_account)];
|
||||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||||
|
@ -298,8 +298,8 @@ mod tests {
|
||||||
let my_config = MyConfig::new(42);
|
let my_config = MyConfig::new(42);
|
||||||
|
|
||||||
let instruction = config_instruction::store(&config_pubkey, true, keys.clone(), &my_config);
|
let instruction = config_instruction::store(&config_pubkey, true, keys.clone(), &my_config);
|
||||||
let signer0_account = RefCell::new(Account::default());
|
let signer0_account = RefCell::new(AccountSharedData::default());
|
||||||
let signer1_account = RefCell::new(Account::default());
|
let signer1_account = RefCell::new(AccountSharedData::default());
|
||||||
let accounts = vec![
|
let accounts = vec![
|
||||||
(&config_pubkey, true, &config_account),
|
(&config_pubkey, true, &config_account),
|
||||||
(&signer0_pubkey, true, &signer0_account),
|
(&signer0_pubkey, true, &signer0_account),
|
||||||
|
@ -334,9 +334,9 @@ mod tests {
|
||||||
let my_config = MyConfig::new(42);
|
let my_config = MyConfig::new(42);
|
||||||
|
|
||||||
let instruction = config_instruction::store(&config_pubkey, false, keys, &my_config);
|
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(),
|
owner: id(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
});
|
});
|
||||||
let accounts = vec![(&signer0_pubkey, true, &signer0_account)];
|
let accounts = vec![(&signer0_pubkey, true, &signer0_account)];
|
||||||
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
let keyed_accounts = create_keyed_is_signer_accounts(&accounts);
|
||||||
|
@ -356,8 +356,8 @@ mod tests {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let signer0_pubkey = solana_sdk::pubkey::new_rand();
|
let signer0_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let signer1_pubkey = solana_sdk::pubkey::new_rand();
|
let signer1_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let signer0_account = RefCell::new(Account::default());
|
let signer0_account = RefCell::new(AccountSharedData::default());
|
||||||
let signer1_account = RefCell::new(Account::default());
|
let signer1_account = RefCell::new(AccountSharedData::default());
|
||||||
let keys = vec![(signer0_pubkey, true)];
|
let keys = vec![(signer0_pubkey, true)];
|
||||||
let (config_keypair, config_account) = create_config_account(keys.clone());
|
let (config_keypair, config_account) = create_config_account(keys.clone());
|
||||||
let config_pubkey = config_keypair.pubkey();
|
let config_pubkey = config_keypair.pubkey();
|
||||||
|
@ -405,9 +405,9 @@ mod tests {
|
||||||
let signer0_pubkey = solana_sdk::pubkey::new_rand();
|
let signer0_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let signer1_pubkey = solana_sdk::pubkey::new_rand();
|
let signer1_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let signer2_pubkey = solana_sdk::pubkey::new_rand();
|
let signer2_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let signer0_account = RefCell::new(Account::default());
|
let signer0_account = RefCell::new(AccountSharedData::default());
|
||||||
let signer1_account = RefCell::new(Account::default());
|
let signer1_account = RefCell::new(AccountSharedData::default());
|
||||||
let signer2_account = RefCell::new(Account::default());
|
let signer2_account = RefCell::new(AccountSharedData::default());
|
||||||
let keys = vec![
|
let keys = vec![
|
||||||
(pubkey, false),
|
(pubkey, false),
|
||||||
(signer0_pubkey, true),
|
(signer0_pubkey, true),
|
||||||
|
@ -508,7 +508,7 @@ mod tests {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let pubkey = solana_sdk::pubkey::new_rand();
|
let pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let signer0_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![
|
let keys = vec![
|
||||||
(pubkey, false),
|
(pubkey, false),
|
||||||
(signer0_pubkey, true),
|
(signer0_pubkey, true),
|
||||||
|
@ -606,8 +606,8 @@ mod tests {
|
||||||
let config_pubkey = solana_sdk::pubkey::new_rand();
|
let config_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let new_config = MyConfig::new(84);
|
let new_config = MyConfig::new(84);
|
||||||
let signer0_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 config_account = RefCell::new(Account::default());
|
let config_account = RefCell::new(AccountSharedData::default());
|
||||||
let keys = vec![
|
let keys = vec![
|
||||||
(from_pubkey, false),
|
(from_pubkey, false),
|
||||||
(signer0_pubkey, true),
|
(signer0_pubkey, true),
|
||||||
|
|
|
@ -5,7 +5,7 @@ pub mod date_instruction;
|
||||||
|
|
||||||
use bincode::{deserialize, serialize, serialized_size};
|
use bincode::{deserialize, serialize, serialized_size};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
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");
|
solana_sdk::declare_id!("Config1111111111111111111111111111111111111");
|
||||||
|
|
||||||
|
@ -40,13 +40,13 @@ pub fn create_config_account<T: ConfigState>(
|
||||||
keys: Vec<(Pubkey, bool)>,
|
keys: Vec<(Pubkey, bool)>,
|
||||||
config_data: &T,
|
config_data: &T,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Account {
|
) -> AccountSharedData {
|
||||||
let mut data = serialize(&ConfigKeys { keys }).unwrap();
|
let mut data = serialize(&ConfigKeys { keys }).unwrap();
|
||||||
data.extend_from_slice(&serialize(config_data).unwrap());
|
data.extend_from_slice(&serialize(config_data).unwrap());
|
||||||
Account {
|
AccountSharedData {
|
||||||
lamports,
|
lamports,
|
||||||
data,
|
data,
|
||||||
owner: id(),
|
owner: id(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ mod tests {
|
||||||
use crate::ownable_instruction;
|
use crate::ownable_instruction;
|
||||||
use solana_runtime::{bank::Bank, bank_client::BankClient};
|
use solana_runtime::{bank::Bank, bank_client::BankClient};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
client::SyncClient,
|
client::SyncClient,
|
||||||
genesis_config::create_genesis_config,
|
genesis_config::create_genesis_config,
|
||||||
message::Message,
|
message::Message,
|
||||||
|
@ -156,7 +156,7 @@ mod tests {
|
||||||
let mut account_owner_pubkey = solana_sdk::pubkey::new_rand();
|
let mut account_owner_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let owner_pubkey = account_owner_pubkey;
|
let owner_pubkey = account_owner_pubkey;
|
||||||
let new_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 owner_keyed_account = KeyedAccount::new(&owner_pubkey, false, &account); // <-- Attack! Setting owner without the original owner's signature.
|
let owner_keyed_account = KeyedAccount::new(&owner_pubkey, false, &account); // <-- Attack! Setting owner without the original owner's signature.
|
||||||
let err = set_owner(
|
let err = set_owner(
|
||||||
&mut account_owner_pubkey,
|
&mut account_owner_pubkey,
|
||||||
|
@ -171,7 +171,7 @@ mod tests {
|
||||||
fn test_ownable_incorrect_owner() {
|
fn test_ownable_incorrect_owner() {
|
||||||
let mut account_owner_pubkey = solana_sdk::pubkey::new_rand();
|
let mut account_owner_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let new_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 mallory_pubkey = solana_sdk::pubkey::new_rand(); // <-- Attack! Signing with wrong pubkey
|
||||||
let owner_keyed_account = KeyedAccount::new(&mallory_pubkey, true, &account);
|
let owner_keyed_account = KeyedAccount::new(&mallory_pubkey, true, &account);
|
||||||
let err = set_owner(
|
let err = set_owner(
|
||||||
|
|
|
@ -4,7 +4,9 @@ use bincode::{deserialize, serialized_size};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_config_program::{create_config_account, get_config_data, ConfigState};
|
use solana_config_program::{create_config_account, get_config_data, ConfigState};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account, genesis_config::GenesisConfig, instruction::InstructionError,
|
account::{AccountSharedData, ReadableAccount},
|
||||||
|
genesis_config::GenesisConfig,
|
||||||
|
instruction::InstructionError,
|
||||||
keyed_account::KeyedAccount,
|
keyed_account::KeyedAccount,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,8 +27,8 @@ pub struct Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn from(account: &Account) -> Option<Self> {
|
pub fn from<T: ReadableAccount>(account: &T) -> Option<Self> {
|
||||||
get_config_data(&account.data)
|
get_config_data(&account.data())
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|data| deserialize(data).ok())
|
.and_then(|data| deserialize(data).ok())
|
||||||
}
|
}
|
||||||
|
@ -58,7 +60,7 @@ pub fn add_genesis_account(genesis_config: &mut GenesisConfig) -> u64 {
|
||||||
lamports
|
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)
|
create_config_account(vec![], config, lamports)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -622,7 +622,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{self, Account},
|
account::{self, AccountSharedData},
|
||||||
process_instruction::MockInvokeContext,
|
process_instruction::MockInvokeContext,
|
||||||
rent::Rent,
|
rent::Rent,
|
||||||
sysvar::stake_history::StakeHistory,
|
sysvar::stake_history::StakeHistory,
|
||||||
|
@ -630,14 +630,14 @@ mod tests {
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
fn create_default_account() -> RefCell<Account> {
|
fn create_default_account() -> RefCell<AccountSharedData> {
|
||||||
RefCell::new(Account::default())
|
RefCell::new(AccountSharedData::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_default_stake_account() -> RefCell<Account> {
|
fn create_default_stake_account() -> RefCell<AccountSharedData> {
|
||||||
RefCell::new(Account {
|
RefCell::new(AccountSharedData {
|
||||||
owner: id(),
|
owner: id(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -663,34 +663,34 @@ mod tests {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|meta| {
|
.map(|meta| {
|
||||||
RefCell::new(if sysvar::clock::check_id(&meta.pubkey) {
|
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) {
|
} 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) {
|
} 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) {
|
} else if config::check_id(&meta.pubkey) {
|
||||||
config::create_account(0, &config::Config::default())
|
config::create_account(0, &config::Config::default())
|
||||||
} else if sysvar::rent::check_id(&meta.pubkey) {
|
} 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() {
|
} else if meta.pubkey == invalid_stake_state_pubkey() {
|
||||||
Account {
|
AccountSharedData {
|
||||||
owner: id(),
|
owner: id(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
}
|
}
|
||||||
} else if meta.pubkey == invalid_vote_state_pubkey() {
|
} else if meta.pubkey == invalid_vote_state_pubkey() {
|
||||||
Account {
|
AccountSharedData {
|
||||||
owner: solana_vote_program::id(),
|
owner: solana_vote_program::id(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
}
|
}
|
||||||
} else if meta.pubkey == spoofed_stake_state_pubkey() {
|
} else if meta.pubkey == spoofed_stake_state_pubkey() {
|
||||||
Account {
|
AccountSharedData {
|
||||||
owner: spoofed_stake_program_id(),
|
owner: spoofed_stake_program_id(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Account {
|
AccountSharedData {
|
||||||
owner: id(),
|
owner: id(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -973,7 +973,7 @@ mod tests {
|
||||||
KeyedAccount::new(
|
KeyedAccount::new(
|
||||||
&sysvar::rent::id(),
|
&sysvar::rent::id(),
|
||||||
false,
|
false,
|
||||||
&RefCell::new(account::create_account(&Rent::default(), 0))
|
&RefCell::new(account::create_account_shared_data(&Rent::default(), 0))
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
&serialize(&StakeInstruction::Initialize(
|
&serialize(&StakeInstruction::Initialize(
|
||||||
|
@ -1028,12 +1028,15 @@ mod tests {
|
||||||
KeyedAccount::new(
|
KeyedAccount::new(
|
||||||
&sysvar::clock::id(),
|
&sysvar::clock::id(),
|
||||||
false,
|
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(
|
KeyedAccount::new(
|
||||||
&sysvar::stake_history::id(),
|
&sysvar::stake_history::id(),
|
||||||
false,
|
false,
|
||||||
&RefCell::new(account::create_account(
|
&RefCell::new(account::create_account_shared_data(
|
||||||
&sysvar::stake_history::StakeHistory::default(),
|
&sysvar::stake_history::StakeHistory::default(),
|
||||||
1
|
1
|
||||||
))
|
))
|
||||||
|
@ -1060,7 +1063,7 @@ mod tests {
|
||||||
KeyedAccount::new(
|
KeyedAccount::new(
|
||||||
&sysvar::rewards::id(),
|
&sysvar::rewards::id(),
|
||||||
false,
|
false,
|
||||||
&RefCell::new(account::create_account(
|
&RefCell::new(account::create_account_shared_data(
|
||||||
&sysvar::rewards::Rewards::new(0.0),
|
&sysvar::rewards::Rewards::new(0.0),
|
||||||
1
|
1
|
||||||
))
|
))
|
||||||
|
@ -1068,7 +1071,10 @@ mod tests {
|
||||||
KeyedAccount::new(
|
KeyedAccount::new(
|
||||||
&sysvar::stake_history::id(),
|
&sysvar::stake_history::id(),
|
||||||
false,
|
false,
|
||||||
&RefCell::new(account::create_account(&StakeHistory::default(), 1,))
|
&RefCell::new(account::create_account_shared_data(
|
||||||
|
&StakeHistory::default(),
|
||||||
|
1,
|
||||||
|
))
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
&serialize(&StakeInstruction::Withdraw(42)).unwrap(),
|
&serialize(&StakeInstruction::Withdraw(42)).unwrap(),
|
||||||
|
@ -1101,7 +1107,7 @@ mod tests {
|
||||||
KeyedAccount::new(
|
KeyedAccount::new(
|
||||||
&sysvar::rewards::id(),
|
&sysvar::rewards::id(),
|
||||||
false,
|
false,
|
||||||
&RefCell::new(account::create_account(
|
&RefCell::new(account::create_account_shared_data(
|
||||||
&sysvar::rewards::Rewards::new(0.0),
|
&sysvar::rewards::Rewards::new(0.0),
|
||||||
1
|
1
|
||||||
))
|
))
|
||||||
|
|
|
@ -10,7 +10,8 @@ use crate::{
|
||||||
};
|
};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
|
account::ReadableAccount,
|
||||||
account_utils::{State, StateMut},
|
account_utils::{State, StateMut},
|
||||||
clock::{Clock, Epoch, UnixTimestamp},
|
clock::{Clock, Epoch, UnixTimestamp},
|
||||||
ic_msg,
|
ic_msg,
|
||||||
|
@ -76,11 +77,11 @@ impl StakeState {
|
||||||
}
|
}
|
||||||
|
|
||||||
// utility function, used by Stakes, tests
|
// 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()
|
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())
|
Self::from(account).and_then(|state: Self| state.stake())
|
||||||
}
|
}
|
||||||
pub fn stake(&self) -> Option<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())
|
Self::from(account).and_then(|state: Self| state.delegation())
|
||||||
}
|
}
|
||||||
pub fn delegation(&self) -> Option<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())
|
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())
|
Self::from(account).and_then(|state: Self| state.lockup())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +121,7 @@ impl StakeState {
|
||||||
self.meta().map(|meta| meta.lockup)
|
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())
|
Self::from(account).and_then(|state: Self| state.meta())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1453,8 +1454,8 @@ impl MergeKind {
|
||||||
// returns a tuple of (stakers_reward,voters_reward)
|
// returns a tuple of (stakers_reward,voters_reward)
|
||||||
pub fn redeem_rewards(
|
pub fn redeem_rewards(
|
||||||
rewarded_epoch: Epoch,
|
rewarded_epoch: Epoch,
|
||||||
stake_account: &mut Account,
|
stake_account: &mut AccountSharedData,
|
||||||
vote_account: &mut Account,
|
vote_account: &mut AccountSharedData,
|
||||||
point_value: &PointValue,
|
point_value: &PointValue,
|
||||||
stake_history: Option<&StakeHistory>,
|
stake_history: Option<&StakeHistory>,
|
||||||
inflation_point_calc_tracer: &mut Option<impl FnMut(&InflationPointCalculationEvent)>,
|
inflation_point_calc_tracer: &mut Option<impl FnMut(&InflationPointCalculationEvent)>,
|
||||||
|
@ -1502,8 +1503,8 @@ pub fn redeem_rewards(
|
||||||
|
|
||||||
// utility function, used by runtime
|
// utility function, used by runtime
|
||||||
pub fn calculate_points(
|
pub fn calculate_points(
|
||||||
stake_account: &Account,
|
stake_account: &AccountSharedData,
|
||||||
vote_account: &Account,
|
vote_account: &AccountSharedData,
|
||||||
stake_history: Option<&StakeHistory>,
|
stake_history: Option<&StakeHistory>,
|
||||||
fix_stake_deactivate: bool,
|
fix_stake_deactivate: bool,
|
||||||
) -> Result<u128, InstructionError> {
|
) -> Result<u128, InstructionError> {
|
||||||
|
@ -1538,7 +1539,7 @@ fn calculate_split_rent_exempt_reserve(
|
||||||
pub type RewriteStakeStatus = (&'static str, (u64, u64), (u64, u64));
|
pub type RewriteStakeStatus = (&'static str, (u64, u64), (u64, u64));
|
||||||
|
|
||||||
pub fn rewrite_stakes(
|
pub fn rewrite_stakes(
|
||||||
stake_account: &mut Account,
|
stake_account: &mut AccountSharedData,
|
||||||
rent: &Rent,
|
rent: &Rent,
|
||||||
) -> Result<RewriteStakeStatus, InstructionError> {
|
) -> Result<RewriteStakeStatus, InstructionError> {
|
||||||
match stake_account.state()? {
|
match stake_account.state()? {
|
||||||
|
@ -1608,8 +1609,9 @@ pub fn create_lockup_stake_account(
|
||||||
lockup: &Lockup,
|
lockup: &Lockup,
|
||||||
rent: &Rent,
|
rent: &Rent,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Account {
|
) -> AccountSharedData {
|
||||||
let mut stake_account = Account::new(lamports, std::mem::size_of::<StakeState>(), &id());
|
let mut stake_account =
|
||||||
|
AccountSharedData::new(lamports, std::mem::size_of::<StakeState>(), &id());
|
||||||
|
|
||||||
let rent_exempt_reserve = rent.minimum_balance(stake_account.data.len());
|
let rent_exempt_reserve = rent.minimum_balance(stake_account.data.len());
|
||||||
assert!(
|
assert!(
|
||||||
|
@ -1634,10 +1636,10 @@ pub fn create_lockup_stake_account(
|
||||||
pub fn create_account(
|
pub fn create_account(
|
||||||
authorized: &Pubkey,
|
authorized: &Pubkey,
|
||||||
voter_pubkey: &Pubkey,
|
voter_pubkey: &Pubkey,
|
||||||
vote_account: &Account,
|
vote_account: &AccountSharedData,
|
||||||
rent: &Rent,
|
rent: &Rent,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Account {
|
) -> AccountSharedData {
|
||||||
do_create_account(
|
do_create_account(
|
||||||
authorized,
|
authorized,
|
||||||
voter_pubkey,
|
voter_pubkey,
|
||||||
|
@ -1652,11 +1654,11 @@ pub fn create_account(
|
||||||
pub fn create_account_with_activation_epoch(
|
pub fn create_account_with_activation_epoch(
|
||||||
authorized: &Pubkey,
|
authorized: &Pubkey,
|
||||||
voter_pubkey: &Pubkey,
|
voter_pubkey: &Pubkey,
|
||||||
vote_account: &Account,
|
vote_account: &AccountSharedData,
|
||||||
rent: &Rent,
|
rent: &Rent,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
activation_epoch: Epoch,
|
activation_epoch: Epoch,
|
||||||
) -> Account {
|
) -> AccountSharedData {
|
||||||
do_create_account(
|
do_create_account(
|
||||||
authorized,
|
authorized,
|
||||||
voter_pubkey,
|
voter_pubkey,
|
||||||
|
@ -1670,12 +1672,13 @@ pub fn create_account_with_activation_epoch(
|
||||||
fn do_create_account(
|
fn do_create_account(
|
||||||
authorized: &Pubkey,
|
authorized: &Pubkey,
|
||||||
voter_pubkey: &Pubkey,
|
voter_pubkey: &Pubkey,
|
||||||
vote_account: &Account,
|
vote_account: &AccountSharedData,
|
||||||
rent: &Rent,
|
rent: &Rent,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
activation_epoch: Epoch,
|
activation_epoch: Epoch,
|
||||||
) -> Account {
|
) -> AccountSharedData {
|
||||||
let mut stake_account = Account::new(lamports, std::mem::size_of::<StakeState>(), &id());
|
let mut stake_account =
|
||||||
|
AccountSharedData::new(lamports, std::mem::size_of::<StakeState>(), &id());
|
||||||
|
|
||||||
let vote_state = VoteState::from(vote_account).expect("vote_state");
|
let vote_state = VoteState::from(vote_account).expect("vote_state");
|
||||||
|
|
||||||
|
@ -1706,8 +1709,8 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::id;
|
use crate::id;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account, native_token, process_instruction::MockInvokeContext, pubkey::Pubkey,
|
account::AccountSharedData, native_token, process_instruction::MockInvokeContext,
|
||||||
system_program,
|
pubkey::Pubkey, system_program,
|
||||||
};
|
};
|
||||||
use solana_vote_program::vote_state;
|
use solana_vote_program::vote_state;
|
||||||
use std::{cell::RefCell, iter::FromIterator};
|
use std::{cell::RefCell, iter::FromIterator};
|
||||||
|
@ -1861,7 +1864,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_stake_state_stake_from_fail() {
|
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
|
stake_account
|
||||||
.set_state(&StakeState::default())
|
.set_state(&StakeState::default())
|
||||||
|
@ -1917,7 +1920,7 @@ mod tests {
|
||||||
|
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Initialized(Meta {
|
&StakeState::Initialized(Meta {
|
||||||
authorized: Authorized {
|
authorized: Authorized {
|
||||||
|
@ -2679,7 +2682,7 @@ mod tests {
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account =
|
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
|
// unsigned keyed account
|
||||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, false, &stake_account);
|
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, false, &stake_account);
|
||||||
|
@ -2742,8 +2745,11 @@ mod tests {
|
||||||
fn test_initialize_incorrect_account_sizes() {
|
fn test_initialize_incorrect_account_sizes() {
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account =
|
let stake_account = AccountSharedData::new_ref(
|
||||||
Account::new_ref(stake_lamports, std::mem::size_of::<StakeState>() + 1, &id());
|
stake_lamports,
|
||||||
|
std::mem::size_of::<StakeState>() + 1,
|
||||||
|
&id(),
|
||||||
|
);
|
||||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, false, &stake_account);
|
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, false, &stake_account);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -2758,8 +2764,11 @@ mod tests {
|
||||||
Err(InstructionError::InvalidAccountData)
|
Err(InstructionError::InvalidAccountData)
|
||||||
);
|
);
|
||||||
|
|
||||||
let stake_account =
|
let stake_account = AccountSharedData::new_ref(
|
||||||
Account::new_ref(stake_lamports, std::mem::size_of::<StakeState>() - 1, &id());
|
stake_lamports,
|
||||||
|
std::mem::size_of::<StakeState>() - 1,
|
||||||
|
&id(),
|
||||||
|
);
|
||||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, false, &stake_account);
|
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, false, &stake_account);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -2779,7 +2788,7 @@ mod tests {
|
||||||
fn test_deactivate() {
|
fn test_deactivate() {
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Initialized(Meta::auto(&stake_pubkey)),
|
&StakeState::Initialized(Meta::auto(&stake_pubkey)),
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -2845,7 +2854,7 @@ mod tests {
|
||||||
fn test_set_lockup() {
|
fn test_set_lockup() {
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -2942,7 +2951,7 @@ mod tests {
|
||||||
fn test_optional_lockup() {
|
fn test_optional_lockup() {
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -3056,7 +3065,7 @@ mod tests {
|
||||||
fn test_withdraw_stake() {
|
fn test_withdraw_stake() {
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -3067,7 +3076,7 @@ mod tests {
|
||||||
let mut clock = Clock::default();
|
let mut clock = Clock::default();
|
||||||
|
|
||||||
let to = solana_sdk::pubkey::new_rand();
|
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 to_keyed_account = KeyedAccount::new(&to, false, &to_account);
|
||||||
|
|
||||||
// no signers, should fail
|
// no signers, should fail
|
||||||
|
@ -3232,7 +3241,7 @@ mod tests {
|
||||||
let rent_exempt_reserve = rent.minimum_balance(std::mem::size_of::<StakeState>());
|
let rent_exempt_reserve = rent.minimum_balance(std::mem::size_of::<StakeState>());
|
||||||
let authority_pubkey = Pubkey::new_unique();
|
let authority_pubkey = Pubkey::new_unique();
|
||||||
let stake_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,
|
1_000_000_000,
|
||||||
&StakeState::Initialized(Meta {
|
&StakeState::Initialized(Meta {
|
||||||
rent_exempt_reserve,
|
rent_exempt_reserve,
|
||||||
|
@ -3248,7 +3257,7 @@ mod tests {
|
||||||
.expect("stake_account");
|
.expect("stake_account");
|
||||||
|
|
||||||
let stake2_pubkey = Pubkey::new_unique();
|
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,
|
1_000_000_000,
|
||||||
&StakeState::Initialized(Meta {
|
&StakeState::Initialized(Meta {
|
||||||
rent_exempt_reserve,
|
rent_exempt_reserve,
|
||||||
|
@ -3265,7 +3274,7 @@ mod tests {
|
||||||
|
|
||||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
|
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
|
||||||
let stake2_keyed_account = KeyedAccount::new(&stake2_pubkey, false, &stake2_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 =
|
let authority_keyed_account =
|
||||||
KeyedAccount::new(&authority_pubkey, true, &authority_account);
|
KeyedAccount::new(&authority_pubkey, true, &authority_account);
|
||||||
|
|
||||||
|
@ -3287,7 +3296,7 @@ mod tests {
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let total_lamports = 100;
|
let total_lamports = 100;
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
total_lamports,
|
total_lamports,
|
||||||
&StakeState::Initialized(Meta::auto(&stake_pubkey)),
|
&StakeState::Initialized(Meta::auto(&stake_pubkey)),
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -3300,7 +3309,7 @@ mod tests {
|
||||||
future.epoch += 16;
|
future.epoch += 16;
|
||||||
|
|
||||||
let to = solana_sdk::pubkey::new_rand();
|
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 to_keyed_account = KeyedAccount::new(&to, false, &to_account);
|
||||||
|
|
||||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
|
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
|
||||||
|
@ -3357,7 +3366,7 @@ mod tests {
|
||||||
fn test_withdraw_stake_invalid_state() {
|
fn test_withdraw_stake_invalid_state() {
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let total_lamports = 100;
|
let total_lamports = 100;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
total_lamports,
|
total_lamports,
|
||||||
&StakeState::RewardsPool,
|
&StakeState::RewardsPool,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -3366,7 +3375,7 @@ mod tests {
|
||||||
.expect("stake_account");
|
.expect("stake_account");
|
||||||
|
|
||||||
let to = solana_sdk::pubkey::new_rand();
|
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 to_keyed_account = KeyedAccount::new(&to, false, &to_account);
|
||||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
|
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -3387,7 +3396,7 @@ mod tests {
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let custodian = solana_sdk::pubkey::new_rand();
|
let custodian = solana_sdk::pubkey::new_rand();
|
||||||
let total_lamports = 100;
|
let total_lamports = 100;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
total_lamports,
|
total_lamports,
|
||||||
&StakeState::Initialized(Meta {
|
&StakeState::Initialized(Meta {
|
||||||
lockup: Lockup {
|
lockup: Lockup {
|
||||||
|
@ -3403,7 +3412,7 @@ mod tests {
|
||||||
.expect("stake_account");
|
.expect("stake_account");
|
||||||
|
|
||||||
let to = solana_sdk::pubkey::new_rand();
|
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 to_keyed_account = KeyedAccount::new(&to, false, &to_account);
|
||||||
|
|
||||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_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);
|
let custodian_keyed_account = KeyedAccount::new(&custodian, true, &custodian_account);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stake_keyed_account.withdraw(
|
stake_keyed_account.withdraw(
|
||||||
|
@ -3463,7 +3472,7 @@ mod tests {
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let custodian = stake_pubkey;
|
let custodian = stake_pubkey;
|
||||||
let total_lamports = 100;
|
let total_lamports = 100;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
total_lamports,
|
total_lamports,
|
||||||
&StakeState::Initialized(Meta {
|
&StakeState::Initialized(Meta {
|
||||||
lockup: Lockup {
|
lockup: Lockup {
|
||||||
|
@ -3479,7 +3488,7 @@ mod tests {
|
||||||
.expect("stake_account");
|
.expect("stake_account");
|
||||||
|
|
||||||
let to = solana_sdk::pubkey::new_rand();
|
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 to_keyed_account = KeyedAccount::new(&to, false, &to_account);
|
||||||
|
|
||||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
|
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
|
||||||
|
@ -3816,7 +3825,7 @@ mod tests {
|
||||||
fn test_authorize_uninit() {
|
fn test_authorize_uninit() {
|
||||||
let new_authority = solana_sdk::pubkey::new_rand();
|
let new_authority = solana_sdk::pubkey::new_rand();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::default(),
|
&StakeState::default(),
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -3843,7 +3852,7 @@ mod tests {
|
||||||
fn test_authorize_lockup() {
|
fn test_authorize_lockup() {
|
||||||
let stake_authority = solana_sdk::pubkey::new_rand();
|
let stake_authority = solana_sdk::pubkey::new_rand();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Initialized(Meta::auto(&stake_authority)),
|
&StakeState::Initialized(Meta::auto(&stake_authority)),
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -3852,7 +3861,7 @@ mod tests {
|
||||||
.expect("stake_account");
|
.expect("stake_account");
|
||||||
|
|
||||||
let to = solana_sdk::pubkey::new_rand();
|
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 to_keyed_account = KeyedAccount::new(&to, false, &to_account);
|
||||||
|
|
||||||
let clock = Clock::default();
|
let clock = Clock::default();
|
||||||
|
@ -3980,7 +3989,7 @@ mod tests {
|
||||||
let seed = "42";
|
let seed = "42";
|
||||||
let withdrawer_pubkey = Pubkey::create_with_seed(&base_pubkey, &seed, &id()).unwrap();
|
let withdrawer_pubkey = Pubkey::create_with_seed(&base_pubkey, &seed, &id()).unwrap();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Initialized(Meta::auto(&withdrawer_pubkey)),
|
&StakeState::Initialized(Meta::auto(&withdrawer_pubkey)),
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -3988,7 +3997,7 @@ mod tests {
|
||||||
)
|
)
|
||||||
.expect("stake_account");
|
.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 base_keyed_account = KeyedAccount::new(&base_pubkey, true, &base_account);
|
||||||
|
|
||||||
let stake_keyed_account = KeyedAccount::new(&withdrawer_pubkey, true, &stake_account);
|
let stake_keyed_account = KeyedAccount::new(&withdrawer_pubkey, true, &stake_account);
|
||||||
|
@ -4075,7 +4084,7 @@ mod tests {
|
||||||
fn test_authorize_override() {
|
fn test_authorize_override() {
|
||||||
let withdrawer_pubkey = solana_sdk::pubkey::new_rand();
|
let withdrawer_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Initialized(Meta::auto(&withdrawer_pubkey)),
|
&StakeState::Initialized(Meta::auto(&withdrawer_pubkey)),
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4162,7 +4171,7 @@ mod tests {
|
||||||
fn test_split_source_uninitialized() {
|
fn test_split_source_uninitialized() {
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4171,7 +4180,7 @@ mod tests {
|
||||||
.expect("stake_account");
|
.expect("stake_account");
|
||||||
|
|
||||||
let split_stake_pubkey = solana_sdk::pubkey::new_rand();
|
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,
|
0,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4209,7 +4218,7 @@ mod tests {
|
||||||
fn test_split_split_not_uninitialized() {
|
fn test_split_split_not_uninitialized() {
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Stake(Meta::auto(&stake_pubkey), Stake::just_stake(stake_lamports)),
|
&StakeState::Stake(Meta::auto(&stake_pubkey), Stake::just_stake(stake_lamports)),
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4218,7 +4227,7 @@ mod tests {
|
||||||
.expect("stake_account");
|
.expect("stake_account");
|
||||||
|
|
||||||
let split_stake_pubkey = solana_sdk::pubkey::new_rand();
|
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,
|
0,
|
||||||
&StakeState::Initialized(Meta::auto(&stake_pubkey)),
|
&StakeState::Initialized(Meta::auto(&stake_pubkey)),
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4251,7 +4260,7 @@ mod tests {
|
||||||
fn test_split_more_than_staked() {
|
fn test_split_more_than_staked() {
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Stake(
|
&StakeState::Stake(
|
||||||
Meta::auto(&stake_pubkey),
|
Meta::auto(&stake_pubkey),
|
||||||
|
@ -4263,7 +4272,7 @@ mod tests {
|
||||||
.expect("stake_account");
|
.expect("stake_account");
|
||||||
|
|
||||||
let split_stake_pubkey = solana_sdk::pubkey::new_rand();
|
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,
|
0,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4303,7 +4312,7 @@ mod tests {
|
||||||
Stake::just_stake(stake_lamports - rent_exempt_reserve),
|
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,
|
stake_lamports,
|
||||||
state,
|
state,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4313,7 +4322,7 @@ mod tests {
|
||||||
|
|
||||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
|
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,
|
0,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4395,7 +4404,7 @@ mod tests {
|
||||||
StakeState::Initialized(Meta::auto(&stake_pubkey)),
|
StakeState::Initialized(Meta::auto(&stake_pubkey)),
|
||||||
StakeState::Stake(Meta::auto(&stake_pubkey), Stake::just_stake(stake_lamports)),
|
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,
|
0,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4406,7 +4415,7 @@ mod tests {
|
||||||
let split_stake_keyed_account =
|
let split_stake_keyed_account =
|
||||||
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_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,
|
stake_lamports,
|
||||||
state,
|
state,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4482,7 +4491,7 @@ mod tests {
|
||||||
let split_stake_pubkey = solana_sdk::pubkey::new_rand();
|
let split_stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let signers = vec![stake_pubkey].into_iter().collect();
|
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,
|
0,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4493,7 +4502,7 @@ mod tests {
|
||||||
let split_stake_keyed_account =
|
let split_stake_keyed_account =
|
||||||
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_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,
|
stake_lamports,
|
||||||
&StakeState::Stake(Meta::auto(&stake_pubkey), Stake::just_stake(stake_lamports)),
|
&StakeState::Stake(Meta::auto(&stake_pubkey), Stake::just_stake(stake_lamports)),
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4533,7 +4542,7 @@ mod tests {
|
||||||
// test_split, since that test uses a Meta with rent_exempt_reserve = 0
|
// 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];
|
let split_lamport_balances = vec![0, 1, rent_exempt_reserve, rent_exempt_reserve + 1];
|
||||||
for initial_balance in split_lamport_balances {
|
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,
|
initial_balance,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4544,7 +4553,7 @@ mod tests {
|
||||||
let split_stake_keyed_account =
|
let split_stake_keyed_account =
|
||||||
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_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,
|
stake_lamports,
|
||||||
&state,
|
&state,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4648,7 +4657,7 @@ mod tests {
|
||||||
expected_rent_exempt_reserve + 1,
|
expected_rent_exempt_reserve + 1,
|
||||||
];
|
];
|
||||||
for initial_balance in split_lamport_balances {
|
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,
|
initial_balance,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4659,7 +4668,7 @@ mod tests {
|
||||||
let split_stake_keyed_account =
|
let split_stake_keyed_account =
|
||||||
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_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,
|
stake_lamports,
|
||||||
&state,
|
&state,
|
||||||
std::mem::size_of::<StakeState>() + 100,
|
std::mem::size_of::<StakeState>() + 100,
|
||||||
|
@ -4766,7 +4775,7 @@ mod tests {
|
||||||
expected_rent_exempt_reserve + 1,
|
expected_rent_exempt_reserve + 1,
|
||||||
];
|
];
|
||||||
for initial_balance in split_lamport_balances {
|
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,
|
initial_balance,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>() + 100,
|
std::mem::size_of::<StakeState>() + 100,
|
||||||
|
@ -4777,7 +4786,7 @@ mod tests {
|
||||||
let split_stake_keyed_account =
|
let split_stake_keyed_account =
|
||||||
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_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,
|
stake_lamports,
|
||||||
&state,
|
&state,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4822,7 +4831,7 @@ mod tests {
|
||||||
Stake::just_stake(stake_lamports - rent_exempt_reserve),
|
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,
|
0,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4833,7 +4842,7 @@ mod tests {
|
||||||
let split_stake_keyed_account =
|
let split_stake_keyed_account =
|
||||||
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_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,
|
stake_lamports,
|
||||||
state,
|
state,
|
||||||
std::mem::size_of::<StakeState>(),
|
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
|
// 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];
|
let split_lamport_balances = vec![0, 1, rent_exempt_reserve, rent_exempt_reserve + 1];
|
||||||
for initial_balance in split_lamport_balances {
|
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,
|
initial_balance,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4920,7 +4929,7 @@ mod tests {
|
||||||
let split_stake_keyed_account =
|
let split_stake_keyed_account =
|
||||||
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_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,
|
stake_lamports,
|
||||||
&state,
|
&state,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -4985,7 +4994,7 @@ mod tests {
|
||||||
),
|
),
|
||||||
] {
|
] {
|
||||||
// Test that splitting to a larger account fails
|
// 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,
|
0,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>() + 10000,
|
std::mem::size_of::<StakeState>() + 10000,
|
||||||
|
@ -4995,7 +5004,7 @@ mod tests {
|
||||||
let split_stake_keyed_account =
|
let split_stake_keyed_account =
|
||||||
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_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,
|
stake_lamports,
|
||||||
&state,
|
&state,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -5011,7 +5020,7 @@ mod tests {
|
||||||
|
|
||||||
// Test that splitting from a larger account to a smaller one works.
|
// Test that splitting from a larger account to a smaller one works.
|
||||||
// Split amount should not matter, assuming other fund criteria are met
|
// 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,
|
0,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -5021,7 +5030,7 @@ mod tests {
|
||||||
let split_stake_keyed_account =
|
let split_stake_keyed_account =
|
||||||
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_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,
|
stake_lamports,
|
||||||
&state,
|
&state,
|
||||||
std::mem::size_of::<StakeState>() + 100,
|
std::mem::size_of::<StakeState>() + 100,
|
||||||
|
@ -5114,7 +5123,7 @@ mod tests {
|
||||||
Stake::just_stake(stake_lamports),
|
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,
|
stake_lamports,
|
||||||
state,
|
state,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -5123,7 +5132,7 @@ mod tests {
|
||||||
.expect("stake_account");
|
.expect("stake_account");
|
||||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &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,
|
stake_lamports,
|
||||||
source_state,
|
source_state,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -5227,7 +5236,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
..Stake::default()
|
..Stake::default()
|
||||||
};
|
};
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Stake(meta, stake),
|
&StakeState::Stake(meta, stake),
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -5274,7 +5283,7 @@ mod tests {
|
||||||
Stake::just_stake(stake_lamports),
|
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,
|
stake_lamports,
|
||||||
state,
|
state,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -5283,7 +5292,7 @@ mod tests {
|
||||||
.expect("stake_account");
|
.expect("stake_account");
|
||||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &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,
|
stake_lamports,
|
||||||
source_state,
|
source_state,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -5337,7 +5346,7 @@ mod tests {
|
||||||
),
|
),
|
||||||
] {
|
] {
|
||||||
for source_state in &[StakeState::Uninitialized, StakeState::RewardsPool] {
|
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,
|
stake_lamports,
|
||||||
state,
|
state,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -5346,7 +5355,7 @@ mod tests {
|
||||||
.expect("stake_account");
|
.expect("stake_account");
|
||||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &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,
|
stake_lamports,
|
||||||
source_state,
|
source_state,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -5380,7 +5389,7 @@ mod tests {
|
||||||
|
|
||||||
let signers = vec![authorized_pubkey].into_iter().collect();
|
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,
|
stake_lamports,
|
||||||
&StakeState::Stake(
|
&StakeState::Stake(
|
||||||
Meta::auto(&authorized_pubkey),
|
Meta::auto(&authorized_pubkey),
|
||||||
|
@ -5392,7 +5401,7 @@ mod tests {
|
||||||
.expect("stake_account");
|
.expect("stake_account");
|
||||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &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,
|
stake_lamports,
|
||||||
&StakeState::Stake(
|
&StakeState::Stake(
|
||||||
Meta::auto(&authorized_pubkey),
|
Meta::auto(&authorized_pubkey),
|
||||||
|
@ -5444,7 +5453,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
..Stake::default()
|
..Stake::default()
|
||||||
};
|
};
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Stake(meta, stake),
|
&StakeState::Stake(meta, stake),
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -5462,7 +5471,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
..stake
|
..stake
|
||||||
};
|
};
|
||||||
let source_account = Account::new_ref_data_with_space(
|
let source_account = AccountSharedData::new_ref_data_with_space(
|
||||||
source_lamports,
|
source_lamports,
|
||||||
&StakeState::Stake(meta, source_stake),
|
&StakeState::Stake(meta, source_stake),
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -5768,7 +5777,7 @@ mod tests {
|
||||||
fn test_authorize_delegated_stake() {
|
fn test_authorize_delegated_stake() {
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Initialized(Meta::auto(&stake_pubkey)),
|
&StakeState::Initialized(Meta::auto(&stake_pubkey)),
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -5879,7 +5888,7 @@ mod tests {
|
||||||
rent_exempt_reserve,
|
rent_exempt_reserve,
|
||||||
..Meta::auto(&withdrawer_pubkey)
|
..Meta::auto(&withdrawer_pubkey)
|
||||||
};
|
};
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Initialized(meta),
|
&StakeState::Initialized(meta),
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
@ -5916,7 +5925,7 @@ mod tests {
|
||||||
|
|
||||||
clock.epoch += 1;
|
clock.epoch += 1;
|
||||||
let to = Pubkey::new_unique();
|
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 to_keyed_account = KeyedAccount::new(&to, false, &to_account);
|
||||||
let withdraw_lamports = initial_lamports / 2;
|
let withdraw_lamports = initial_lamports / 2;
|
||||||
stake_keyed_account
|
stake_keyed_account
|
||||||
|
@ -6052,7 +6061,7 @@ mod tests {
|
||||||
rent_exempt_reserve: rent_exempt_reserve + offset,
|
rent_exempt_reserve: rent_exempt_reserve + offset,
|
||||||
..Meta::default()
|
..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();
|
account.set_state(&StakeState::Initialized(meta)).unwrap();
|
||||||
let result = rewrite_stakes(&mut account, &rent);
|
let result = rewrite_stakes(&mut account, &rent);
|
||||||
match expected_rewrite {
|
match expected_rewrite {
|
||||||
|
@ -6088,7 +6097,7 @@ mod tests {
|
||||||
}),
|
}),
|
||||||
..Stake::default()
|
..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();
|
account.set_state(&StakeState::Stake(meta, stake)).unwrap();
|
||||||
let result = rewrite_stakes(&mut account, &rent);
|
let result = rewrite_stakes(&mut account, &rent);
|
||||||
match expected_rewrite {
|
match expected_rewrite {
|
||||||
|
@ -6318,7 +6327,7 @@ mod tests {
|
||||||
rent_exempt_reserve,
|
rent_exempt_reserve,
|
||||||
..Meta::auto(&authority_pubkey)
|
..Meta::auto(&authority_pubkey)
|
||||||
};
|
};
|
||||||
let stake_account = Account::new_ref_data_with_space(
|
let stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
stake_lamports,
|
stake_lamports,
|
||||||
&StakeState::Uninitialized,
|
&StakeState::Uninitialized,
|
||||||
std::mem::size_of::<StakeState>(),
|
std::mem::size_of::<StakeState>(),
|
||||||
|
|
|
@ -7,7 +7,7 @@ use chrono::prelude::*;
|
||||||
use solana_config_program::date_instruction::DateConfig;
|
use solana_config_program::date_instruction::DateConfig;
|
||||||
use solana_config_program::get_config_data;
|
use solana_config_program::get_config_data;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
feature_set,
|
feature_set,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
keyed_account::{next_keyed_account, KeyedAccount},
|
keyed_account::{next_keyed_account, KeyedAccount},
|
||||||
|
@ -38,7 +38,7 @@ fn verify_date_account(
|
||||||
fn verify_account<'a>(
|
fn verify_account<'a>(
|
||||||
keyed_account: &'a KeyedAccount,
|
keyed_account: &'a KeyedAccount,
|
||||||
expected_pubkey: &Pubkey,
|
expected_pubkey: &Pubkey,
|
||||||
) -> Result<RefMut<'a, Account>, InstructionError> {
|
) -> Result<RefMut<'a, AccountSharedData>, InstructionError> {
|
||||||
if keyed_account.unsigned_key() != expected_pubkey {
|
if keyed_account.unsigned_key() != expected_pubkey {
|
||||||
return Err(VestError::Unauthorized.into());
|
return Err(VestError::Unauthorized.into());
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ fn verify_account<'a>(
|
||||||
fn verify_signed_account<'a>(
|
fn verify_signed_account<'a>(
|
||||||
keyed_account: &'a KeyedAccount,
|
keyed_account: &'a KeyedAccount,
|
||||||
expected_pubkey: &Pubkey,
|
expected_pubkey: &Pubkey,
|
||||||
) -> Result<RefMut<'a, Account>, InstructionError> {
|
) -> Result<RefMut<'a, AccountSharedData>, InstructionError> {
|
||||||
if keyed_account.signer_key().is_none() {
|
if keyed_account.signer_key().is_none() {
|
||||||
return Err(InstructionError::MissingRequiredSignature);
|
return Err(InstructionError::MissingRequiredSignature);
|
||||||
}
|
}
|
||||||
|
@ -270,7 +270,7 @@ mod tests {
|
||||||
fn test_verify_account_unauthorized() {
|
fn test_verify_account_unauthorized() {
|
||||||
// Ensure client can't sneak in with an untrusted date account.
|
// Ensure client can't sneak in with an untrusted date account.
|
||||||
let date_pubkey = solana_sdk::pubkey::new_rand();
|
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 keyed_account = KeyedAccount::new(&date_pubkey, false, &account);
|
||||||
|
|
||||||
let mallory_pubkey = solana_sdk::pubkey::new_rand(); // <-- Attack! Not the expected 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() {
|
fn test_verify_signed_account_missing_signature() {
|
||||||
// Ensure client can't sneak in with an unsigned account.
|
// Ensure client can't sneak in with an unsigned account.
|
||||||
let date_pubkey = solana_sdk::pubkey::new_rand();
|
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.
|
let keyed_account = KeyedAccount::new(&date_pubkey, false, &account); // <-- Attack! Unsigned transaction.
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -297,7 +297,7 @@ mod tests {
|
||||||
fn test_verify_date_account_incorrect_program_id() {
|
fn test_verify_date_account_incorrect_program_id() {
|
||||||
// Ensure client can't sneak in with a non-Config account.
|
// Ensure client can't sneak in with a non-Config account.
|
||||||
let date_pubkey = solana_sdk::pubkey::new_rand();
|
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);
|
let keyed_account = KeyedAccount::new(&date_pubkey, false, &account);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
verify_date_account(&keyed_account, &date_pubkey).unwrap_err(),
|
verify_date_account(&keyed_account, &date_pubkey).unwrap_err(),
|
||||||
|
@ -309,7 +309,7 @@ mod tests {
|
||||||
fn test_verify_date_account_uninitialized_config() {
|
fn test_verify_date_account_uninitialized_config() {
|
||||||
// Ensure no panic when `get_config_data()` returns an error.
|
// Ensure no panic when `get_config_data()` returns an error.
|
||||||
let date_pubkey = solana_sdk::pubkey::new_rand();
|
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);
|
let keyed_account = KeyedAccount::new(&date_pubkey, false, &account);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
verify_date_account(&keyed_account, &date_pubkey).unwrap_err(),
|
verify_date_account(&keyed_account, &date_pubkey).unwrap_err(),
|
||||||
|
@ -321,7 +321,7 @@ mod tests {
|
||||||
fn test_verify_date_account_invalid_date_config() {
|
fn test_verify_date_account_invalid_date_config() {
|
||||||
// Ensure no panic when `deserialize::<DateConfig>()` returns an error.
|
// Ensure no panic when `deserialize::<DateConfig>()` returns an error.
|
||||||
let date_pubkey = solana_sdk::pubkey::new_rand();
|
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);
|
let keyed_account = KeyedAccount::new(&date_pubkey, false, &account);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
verify_date_account(&keyed_account, &date_pubkey).unwrap_err(),
|
verify_date_account(&keyed_account, &date_pubkey).unwrap_err(),
|
||||||
|
@ -333,7 +333,7 @@ mod tests {
|
||||||
fn test_verify_date_account_deserialize() {
|
fn test_verify_date_account_deserialize() {
|
||||||
// Ensure no panic when `deserialize::<DateConfig>()` returns an error.
|
// Ensure no panic when `deserialize::<DateConfig>()` returns an error.
|
||||||
let date_pubkey = solana_sdk::pubkey::new_rand();
|
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);
|
let keyed_account = KeyedAccount::new(&date_pubkey, false, &account);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
verify_date_account(&keyed_account, &date_pubkey).unwrap_err(),
|
verify_date_account(&keyed_account, &date_pubkey).unwrap_err(),
|
||||||
|
|
|
@ -7,7 +7,7 @@ use chrono::{
|
||||||
serde::ts_seconds,
|
serde::ts_seconds,
|
||||||
};
|
};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
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;
|
use std::cmp::min;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||||
|
@ -82,9 +82,9 @@ impl VestState {
|
||||||
/// Redeem vested tokens.
|
/// Redeem vested tokens.
|
||||||
pub fn redeem_tokens(
|
pub fn redeem_tokens(
|
||||||
&mut self,
|
&mut self,
|
||||||
contract_account: &mut Account,
|
contract_account: &mut AccountSharedData,
|
||||||
current_date: Date<Utc>,
|
current_date: Date<Utc>,
|
||||||
payee_account: &mut Account,
|
payee_account: &mut AccountSharedData,
|
||||||
) {
|
) {
|
||||||
let vested_lamports = self.calc_vested_lamports(current_date);
|
let vested_lamports = self.calc_vested_lamports(current_date);
|
||||||
let redeemable_lamports = vested_lamports.saturating_sub(self.redeemed_lamports);
|
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.
|
/// Renege on the given number of tokens and send them to the given payee.
|
||||||
pub fn renege(
|
pub fn renege(
|
||||||
&mut self,
|
&mut self,
|
||||||
contract_account: &mut Account,
|
contract_account: &mut AccountSharedData,
|
||||||
payee_account: &mut Account,
|
payee_account: &mut AccountSharedData,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) {
|
) {
|
||||||
let reneged_lamports = min(contract_account.lamports, lamports);
|
let reneged_lamports = min(contract_account.lamports, lamports);
|
||||||
|
@ -119,12 +119,12 @@ impl VestState {
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::id;
|
use crate::id;
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::AccountSharedData;
|
||||||
use solana_sdk::system_program;
|
use solana_sdk::system_program;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serializer() {
|
fn test_serializer() {
|
||||||
let mut a = Account::new(0, 512, &id());
|
let mut a = AccountSharedData::new(0, 512, &id());
|
||||||
let b = VestState::default();
|
let b = VestState::default();
|
||||||
b.serialize(&mut a.data).unwrap();
|
b.serialize(&mut a.data).unwrap();
|
||||||
let c = VestState::deserialize(&a.data).unwrap();
|
let c = VestState::deserialize(&a.data).unwrap();
|
||||||
|
@ -133,7 +133,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serializer_data_too_small() {
|
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();
|
let b = VestState::default();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
b.serialize(&mut a.data),
|
b.serialize(&mut a.data),
|
||||||
|
@ -144,8 +144,8 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_schedule_after_renege() {
|
fn test_schedule_after_renege() {
|
||||||
let total_lamports = 3;
|
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 payee_account = Account::new(0, 0, &system_program::id());
|
let mut payee_account = AccountSharedData::new(0, 0, &system_program::id());
|
||||||
let mut vest_state = VestState {
|
let mut vest_state = VestState {
|
||||||
total_lamports,
|
total_lamports,
|
||||||
start_date_time: Utc.ymd(2019, 1, 1).and_hms(0, 0, 0),
|
start_date_time: Utc.ymd(2019, 1, 1).and_hms(0, 0, 0),
|
||||||
|
@ -171,7 +171,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vest_all() {
|
fn test_vest_all() {
|
||||||
let total_lamports = 3;
|
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 {
|
let mut vest_state = VestState {
|
||||||
total_lamports,
|
total_lamports,
|
||||||
start_date_time: Utc.ymd(2019, 1, 1).and_hms(0, 0, 0),
|
start_date_time: Utc.ymd(2019, 1, 1).and_hms(0, 0, 0),
|
||||||
|
|
|
@ -342,7 +342,7 @@ pub fn process_instruction(
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{self, Account},
|
account::{self, AccountSharedData},
|
||||||
process_instruction::MockInvokeContext,
|
process_instruction::MockInvokeContext,
|
||||||
rent::Rent,
|
rent::Rent,
|
||||||
};
|
};
|
||||||
|
@ -370,27 +370,27 @@ mod tests {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|meta| {
|
.map(|meta| {
|
||||||
RefCell::new(if sysvar::clock::check_id(&meta.pubkey) {
|
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) {
|
} 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) {
|
} 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() {
|
} else if meta.pubkey == invalid_vote_state_pubkey() {
|
||||||
Account {
|
AccountSharedData {
|
||||||
owner: invalid_vote_state_pubkey(),
|
owner: invalid_vote_state_pubkey(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Account {
|
AccountSharedData {
|
||||||
owner: id(),
|
owner: id(),
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for _ in 0..instruction.accounts.len() {
|
for _ in 0..instruction.accounts.len() {
|
||||||
accounts.push(RefCell::new(Account::default()));
|
accounts.push(RefCell::new(AccountSharedData::default()));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let keyed_accounts: Vec<_> = instruction
|
let keyed_accounts: Vec<_> = instruction
|
||||||
|
|
|
@ -6,7 +6,7 @@ use bincode::{deserialize, serialize_into, serialized_size, ErrorKind};
|
||||||
use log::*;
|
use log::*;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::{AccountSharedData, ReadableAccount, WritableAccount},
|
||||||
account_utils::State,
|
account_utils::State,
|
||||||
clock::{Epoch, Slot, UnixTimestamp},
|
clock::{Epoch, Slot, UnixTimestamp},
|
||||||
epoch_schedule::MAX_LEADER_SCHEDULE_EPOCH_OFFSET,
|
epoch_schedule::MAX_LEADER_SCHEDULE_EPOCH_OFFSET,
|
||||||
|
@ -223,13 +223,13 @@ impl VoteState {
|
||||||
}
|
}
|
||||||
|
|
||||||
// utility function, used by Stakes, tests
|
// utility function, used by Stakes, tests
|
||||||
pub fn from(account: &Account) -> Option<VoteState> {
|
pub fn from<T: ReadableAccount>(account: &T) -> Option<VoteState> {
|
||||||
Self::deserialize(&account.data).ok()
|
Self::deserialize(&account.data()).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
// utility function, used by Stakes, tests
|
// utility function, used by Stakes, tests
|
||||||
pub fn to(versioned: &VoteStateVersions, account: &mut Account) -> Option<()> {
|
pub fn to<T: WritableAccount>(versioned: &VoteStateVersions, account: &mut T) -> Option<()> {
|
||||||
Self::serialize(versioned, &mut account.data).ok()
|
Self::serialize(versioned, &mut account.data_as_mut_slice()).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deserialize(input: &[u8]) -> Result<Self, InstructionError> {
|
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())
|
Self::from(account).map(|state| state.credits())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -747,8 +747,8 @@ pub fn create_account_with_authorized(
|
||||||
authorized_withdrawer: &Pubkey,
|
authorized_withdrawer: &Pubkey,
|
||||||
commission: u8,
|
commission: u8,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Account {
|
) -> AccountSharedData {
|
||||||
let mut vote_account = Account::new(lamports, VoteState::size_of(), &id());
|
let mut vote_account = AccountSharedData::new(lamports, VoteState::size_of(), &id());
|
||||||
|
|
||||||
let vote_state = VoteState::new(
|
let vote_state = VoteState::new(
|
||||||
&VoteInit {
|
&VoteInit {
|
||||||
|
@ -772,7 +772,7 @@ pub fn create_account(
|
||||||
node_pubkey: &Pubkey,
|
node_pubkey: &Pubkey,
|
||||||
commission: u8,
|
commission: u8,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Account {
|
) -> AccountSharedData {
|
||||||
create_account_with_authorized(node_pubkey, vote_pubkey, vote_pubkey, commission, lamports)
|
create_account_with_authorized(node_pubkey, vote_pubkey, vote_pubkey, commission, lamports)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -781,7 +781,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::vote_state;
|
use crate::vote_state;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
hash::hash,
|
hash::hash,
|
||||||
keyed_account::{get_signers, next_keyed_account},
|
keyed_account::{get_signers, next_keyed_account},
|
||||||
|
@ -807,11 +807,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_initialize_vote_account() {
|
fn test_initialize_vote_account() {
|
||||||
let vote_account_pubkey = solana_sdk::pubkey::new_rand();
|
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 vote_account = KeyedAccount::new(&vote_account_pubkey, false, &vote_account);
|
||||||
|
|
||||||
let node_pubkey = solana_sdk::pubkey::new_rand();
|
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 keyed_accounts = &[];
|
||||||
let signers: HashSet<Pubkey> = get_signers(keyed_accounts);
|
let signers: HashSet<Pubkey> = get_signers(keyed_accounts);
|
||||||
|
|
||||||
|
@ -864,7 +864,7 @@ mod tests {
|
||||||
assert_eq!(res, Err(InstructionError::AccountAlreadyInitialized));
|
assert_eq!(res, Err(InstructionError::AccountAlreadyInitialized));
|
||||||
|
|
||||||
//init should fail, account is too big
|
//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 =
|
let large_vote_account =
|
||||||
KeyedAccount::new(&vote_account_pubkey, false, &large_vote_account);
|
KeyedAccount::new(&vote_account_pubkey, false, &large_vote_account);
|
||||||
let res = initialize_account(
|
let res = initialize_account(
|
||||||
|
@ -882,7 +882,7 @@ mod tests {
|
||||||
assert_eq!(res, Err(InstructionError::InvalidAccountData));
|
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();
|
let vote_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
(
|
(
|
||||||
vote_pubkey,
|
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 vote_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let authorized_voter = solana_sdk::pubkey::new_rand();
|
let authorized_voter = solana_sdk::pubkey::new_rand();
|
||||||
let authorized_withdrawer = solana_sdk::pubkey::new_rand();
|
let authorized_withdrawer = solana_sdk::pubkey::new_rand();
|
||||||
|
@ -916,7 +917,7 @@ mod tests {
|
||||||
|
|
||||||
fn simulate_process_vote(
|
fn simulate_process_vote(
|
||||||
vote_pubkey: &Pubkey,
|
vote_pubkey: &Pubkey,
|
||||||
vote_account: &RefCell<Account>,
|
vote_account: &RefCell<AccountSharedData>,
|
||||||
vote: &Vote,
|
vote: &Vote,
|
||||||
slot_hashes: &[SlotHash],
|
slot_hashes: &[SlotHash],
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
|
@ -940,7 +941,7 @@ mod tests {
|
||||||
/// exercises all the keyed accounts stuff
|
/// exercises all the keyed accounts stuff
|
||||||
fn simulate_process_vote_unchecked(
|
fn simulate_process_vote_unchecked(
|
||||||
vote_pubkey: &Pubkey,
|
vote_pubkey: &Pubkey,
|
||||||
vote_account: &RefCell<Account>,
|
vote_account: &RefCell<AccountSharedData>,
|
||||||
vote: &Vote,
|
vote: &Vote,
|
||||||
) -> Result<VoteState, InstructionError> {
|
) -> Result<VoteState, InstructionError> {
|
||||||
simulate_process_vote(
|
simulate_process_vote(
|
||||||
|
@ -1035,8 +1036,8 @@ mod tests {
|
||||||
create_test_account_with_authorized();
|
create_test_account_with_authorized();
|
||||||
|
|
||||||
let node_pubkey = solana_sdk::pubkey::new_rand();
|
let node_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let node_account = RefCell::new(Account::default());
|
let node_account = RefCell::new(AccountSharedData::default());
|
||||||
let authorized_withdrawer_account = RefCell::new(Account::default());
|
let authorized_withdrawer_account = RefCell::new(AccountSharedData::default());
|
||||||
|
|
||||||
let keyed_accounts = &[
|
let keyed_accounts = &[
|
||||||
KeyedAccount::new(&vote_pubkey, true, &vote_account),
|
KeyedAccount::new(&vote_pubkey, true, &vote_account),
|
||||||
|
@ -1083,7 +1084,7 @@ mod tests {
|
||||||
let (vote_pubkey, _authorized_voter, authorized_withdrawer, vote_account) =
|
let (vote_pubkey, _authorized_voter, authorized_withdrawer, vote_account) =
|
||||||
create_test_account_with_authorized();
|
create_test_account_with_authorized();
|
||||||
|
|
||||||
let authorized_withdrawer_account = RefCell::new(Account::default());
|
let authorized_withdrawer_account = RefCell::new(AccountSharedData::default());
|
||||||
|
|
||||||
let keyed_accounts = &[
|
let keyed_accounts = &[
|
||||||
KeyedAccount::new(&vote_pubkey, true, &vote_account),
|
KeyedAccount::new(&vote_pubkey, true, &vote_account),
|
||||||
|
@ -1207,7 +1208,7 @@ mod tests {
|
||||||
assert_eq!(res, Err(VoteError::TooSoonToReauthorize.into()));
|
assert_eq!(res, Err(VoteError::TooSoonToReauthorize.into()));
|
||||||
|
|
||||||
// verify authorized_voter_pubkey can authorize authorized_voter_pubkey ;)
|
// 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 = &[
|
let keyed_accounts = &[
|
||||||
KeyedAccount::new(&vote_pubkey, false, &vote_account),
|
KeyedAccount::new(&vote_pubkey, false, &vote_account),
|
||||||
KeyedAccount::new(&authorized_voter_pubkey, true, &authorized_voter_account),
|
KeyedAccount::new(&authorized_voter_pubkey, true, &authorized_voter_account),
|
||||||
|
@ -1247,7 +1248,7 @@ mod tests {
|
||||||
assert_eq!(res, Ok(()));
|
assert_eq!(res, Ok(()));
|
||||||
|
|
||||||
// verify authorized_withdrawer can authorize authorized_withdrawer ;)
|
// verify authorized_withdrawer can authorize authorized_withdrawer ;)
|
||||||
let withdrawer_account = RefCell::new(Account::default());
|
let withdrawer_account = RefCell::new(AccountSharedData::default());
|
||||||
let keyed_accounts = &[
|
let keyed_accounts = &[
|
||||||
KeyedAccount::new(&vote_pubkey, false, &vote_account),
|
KeyedAccount::new(&vote_pubkey, false, &vote_account),
|
||||||
KeyedAccount::new(&authorized_withdrawer_pubkey, true, &withdrawer_account),
|
KeyedAccount::new(&authorized_withdrawer_pubkey, true, &withdrawer_account),
|
||||||
|
@ -1284,7 +1285,7 @@ mod tests {
|
||||||
assert_eq!(res, Err(InstructionError::MissingRequiredSignature));
|
assert_eq!(res, Err(InstructionError::MissingRequiredSignature));
|
||||||
|
|
||||||
// signed by authorized voter
|
// signed by authorized voter
|
||||||
let authorized_voter_account = RefCell::new(Account::default());
|
let authorized_voter_account = RefCell::new(AccountSharedData::default());
|
||||||
let keyed_accounts = &[
|
let keyed_accounts = &[
|
||||||
KeyedAccount::new(&vote_pubkey, false, &vote_account),
|
KeyedAccount::new(&vote_pubkey, false, &vote_account),
|
||||||
KeyedAccount::new(&authorized_voter_pubkey, true, &authorized_voter_account),
|
KeyedAccount::new(&authorized_voter_pubkey, true, &authorized_voter_account),
|
||||||
|
@ -1308,7 +1309,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vote_without_initialization() {
|
fn test_vote_without_initialization() {
|
||||||
let vote_pubkey = solana_sdk::pubkey::new_rand();
|
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(
|
let res = simulate_process_vote_unchecked(
|
||||||
&vote_pubkey,
|
&vote_pubkey,
|
||||||
|
@ -1646,7 +1647,7 @@ mod tests {
|
||||||
&KeyedAccount::new(
|
&KeyedAccount::new(
|
||||||
&solana_sdk::pubkey::new_rand(),
|
&solana_sdk::pubkey::new_rand(),
|
||||||
false,
|
false,
|
||||||
&RefCell::new(Account::default()),
|
&RefCell::new(AccountSharedData::default()),
|
||||||
),
|
),
|
||||||
&signers,
|
&signers,
|
||||||
);
|
);
|
||||||
|
@ -1661,14 +1662,14 @@ mod tests {
|
||||||
&KeyedAccount::new(
|
&KeyedAccount::new(
|
||||||
&solana_sdk::pubkey::new_rand(),
|
&solana_sdk::pubkey::new_rand(),
|
||||||
false,
|
false,
|
||||||
&RefCell::new(Account::default()),
|
&RefCell::new(AccountSharedData::default()),
|
||||||
),
|
),
|
||||||
&signers,
|
&signers,
|
||||||
);
|
);
|
||||||
assert_eq!(res, Err(InstructionError::InsufficientFunds));
|
assert_eq!(res, Err(InstructionError::InsufficientFunds));
|
||||||
|
|
||||||
// all good
|
// all good
|
||||||
let to_account = RefCell::new(Account::default());
|
let to_account = RefCell::new(AccountSharedData::default());
|
||||||
let lamports = vote_account.borrow().lamports;
|
let lamports = vote_account.borrow().lamports;
|
||||||
let keyed_accounts = &[KeyedAccount::new(&vote_pubkey, true, &vote_account)];
|
let keyed_accounts = &[KeyedAccount::new(&vote_pubkey, true, &vote_account)];
|
||||||
let signers: HashSet<Pubkey> = get_signers(keyed_accounts);
|
let signers: HashSet<Pubkey> = get_signers(keyed_accounts);
|
||||||
|
@ -1704,7 +1705,7 @@ mod tests {
|
||||||
assert_eq!(res, Ok(()));
|
assert_eq!(res, Ok(()));
|
||||||
|
|
||||||
// withdraw using authorized_withdrawer to authorized_withdrawer's account
|
// 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 = &[
|
let keyed_accounts = &[
|
||||||
KeyedAccount::new(&vote_pubkey, false, &vote_account),
|
KeyedAccount::new(&vote_pubkey, false, &vote_account),
|
||||||
KeyedAccount::new(&authorized_withdrawer_pubkey, true, &withdrawer_account),
|
KeyedAccount::new(&authorized_withdrawer_pubkey, true, &withdrawer_account),
|
||||||
|
|
|
@ -52,7 +52,7 @@ fn calculate_stake_warmup(mut stake_entry: StakeHistoryEntry, stake_config: &Sta
|
||||||
|
|
||||||
fn stake_history_entry(epoch: Epoch, rpc_client: &RpcClient) -> Option<StakeHistoryEntry> {
|
fn stake_history_entry(epoch: Epoch, rpc_client: &RpcClient) -> Option<StakeHistoryEntry> {
|
||||||
let stake_history_account = rpc_client.get_account(&stake_history::id()).ok()?;
|
let stake_history_account = rpc_client.get_account(&stake_history::id()).ok()?;
|
||||||
let stake_history = from_account::<StakeHistory>(&stake_history_account)?;
|
let stake_history = from_account::<StakeHistory, _>(&stake_history_account)?;
|
||||||
stake_history.get(&epoch).cloned()
|
stake_history.get(&epoch).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ use solana_runtime::{
|
||||||
bank::*,
|
bank::*,
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
genesis_config::{create_genesis_config, ClusterType},
|
genesis_config::{create_genesis_config, ClusterType},
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
|
@ -27,7 +27,8 @@ use test::Bencher;
|
||||||
fn deposit_many(bank: &Bank, pubkeys: &mut Vec<Pubkey>, num: usize) {
|
fn deposit_many(bank: &Bank, pubkeys: &mut Vec<Pubkey>, num: usize) {
|
||||||
for t in 0..num {
|
for t in 0..num {
|
||||||
let pubkey = solana_sdk::pubkey::new_rand();
|
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);
|
pubkeys.push(pubkey);
|
||||||
assert!(bank.get_account(&pubkey).is_none());
|
assert!(bank.get_account(&pubkey).is_none());
|
||||||
bank.deposit(&pubkey, (t + 1) as u64);
|
bank.deposit(&pubkey, (t + 1) as u64);
|
||||||
|
@ -157,10 +158,11 @@ fn bench_delete_dependencies(bencher: &mut Bencher) {
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
let mut old_pubkey = Pubkey::default();
|
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 {
|
for i in 0..1000 {
|
||||||
let pubkey = solana_sdk::pubkey::new_rand();
|
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, &pubkey, &account);
|
||||||
accounts.store_slow_uncached(i, &old_pubkey, &zero_account);
|
accounts.store_slow_uncached(i, &old_pubkey, &zero_account);
|
||||||
old_pubkey = pubkey;
|
old_pubkey = pubkey;
|
||||||
|
@ -195,7 +197,7 @@ fn store_accounts_with_possible_contention<F: 'static>(
|
||||||
(0..num_keys)
|
(0..num_keys)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let pubkey = solana_sdk::pubkey::new_rand();
|
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);
|
accounts.store_slow_uncached(slot, &pubkey, &account);
|
||||||
pubkey
|
pubkey
|
||||||
})
|
})
|
||||||
|
@ -215,7 +217,7 @@ fn store_accounts_with_possible_contention<F: 'static>(
|
||||||
|
|
||||||
let num_new_keys = 1000;
|
let num_new_keys = 1000;
|
||||||
let new_accounts: Vec<_> = (0..num_new_keys)
|
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();
|
.collect();
|
||||||
bencher.iter(|| {
|
bencher.iter(|| {
|
||||||
for account in &new_accounts {
|
for account in &new_accounts {
|
||||||
|
@ -247,7 +249,9 @@ fn bench_concurrent_read_write(bencher: &mut Bencher) {
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn bench_concurrent_scan_write(bencher: &mut Bencher) {
|
fn bench_concurrent_scan_write(bencher: &mut Bencher) {
|
||||||
store_accounts_with_possible_contention("concurrent_scan_write", bencher, |accounts, _| loop {
|
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(
|
let accounts = Arc::new(Accounts::new_with_config(
|
||||||
vec![
|
vec![
|
||||||
PathBuf::from(std::env::var("FARF_DIR").unwrap_or_else(|_| "farf".to_string()))
|
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(
|
dashmap.insert(
|
||||||
Pubkey::new_unique(),
|
Pubkey::new_unique(),
|
||||||
(
|
(
|
||||||
Account::new(1, 0, &Account::default().owner),
|
AccountSharedData::new(1, 0, &AccountSharedData::default().owner),
|
||||||
Hash::new_unique(),
|
Hash::new_unique(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,7 +4,7 @@ extern crate test;
|
||||||
|
|
||||||
use log::*;
|
use log::*;
|
||||||
use solana_runtime::message_processor::{ExecuteDetailsTimings, PreAccount};
|
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;
|
use test::Bencher;
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
|
@ -15,10 +15,10 @@ fn bench_verify_account_changes_data(bencher: &mut Bencher) {
|
||||||
let non_owner = pubkey::new_rand();
|
let non_owner = pubkey::new_rand();
|
||||||
let pre = PreAccount::new(
|
let pre = PreAccount::new(
|
||||||
&pubkey::new_rand(),
|
&pubkey::new_rand(),
|
||||||
&Account::new(0, BUFSIZE, &owner),
|
&AccountSharedData::new(0, BUFSIZE, &owner),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
let post = Account::new(0, BUFSIZE, &owner);
|
let post = AccountSharedData::new(0, BUFSIZE, &owner);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
pre.verify(
|
pre.verify(
|
||||||
&owner,
|
&owner,
|
||||||
|
@ -52,7 +52,7 @@ fn bench_verify_account_changes_data(bencher: &mut Bencher) {
|
||||||
|
|
||||||
let pre = PreAccount::new(
|
let pre = PreAccount::new(
|
||||||
&pubkey::new_rand(),
|
&pubkey::new_rand(),
|
||||||
&Account::new(0, BUFSIZE, &owner),
|
&AccountSharedData::new(0, BUFSIZE, &owner),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
bencher.iter(|| {
|
bencher.iter(|| {
|
||||||
|
|
|
@ -16,7 +16,7 @@ use dashmap::{
|
||||||
use log::*;
|
use log::*;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
||||||
clock::Slot,
|
clock::Slot,
|
||||||
|
@ -92,10 +92,10 @@ pub struct Accounts {
|
||||||
}
|
}
|
||||||
|
|
||||||
// for the load instructions
|
// for the load instructions
|
||||||
pub type TransactionAccounts = Vec<Account>;
|
pub type TransactionAccounts = Vec<AccountSharedData>;
|
||||||
pub type TransactionAccountDeps = Vec<(Pubkey, Account)>;
|
pub type TransactionAccountDeps = Vec<(Pubkey, AccountSharedData)>;
|
||||||
pub type TransactionRent = u64;
|
pub type TransactionRent = u64;
|
||||||
pub type TransactionLoaders = Vec<Vec<(Pubkey, Account)>>;
|
pub type TransactionLoaders = Vec<Vec<(Pubkey, AccountSharedData)>>;
|
||||||
#[derive(PartialEq, Debug, Clone)]
|
#[derive(PartialEq, Debug, Clone)]
|
||||||
pub struct LoadedTransaction {
|
pub struct LoadedTransaction {
|
||||||
pub accounts: TransactionAccounts,
|
pub accounts: TransactionAccounts,
|
||||||
|
@ -162,13 +162,13 @@ impl Accounts {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn construct_instructions_account(message: &Message) -> Account {
|
fn construct_instructions_account(message: &Message) -> AccountSharedData {
|
||||||
let mut data = message.serialize_instructions();
|
let mut data = message.serialize_instructions();
|
||||||
// add room for current instruction index.
|
// add room for current instruction index.
|
||||||
data.resize(data.len() + 2, 0);
|
data.resize(data.len() + 2, 0);
|
||||||
Account {
|
AccountSharedData {
|
||||||
data,
|
data,
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ impl Accounts {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Fill in an empty account for the program slots.
|
// Fill in an empty account for the program slots.
|
||||||
Account::default()
|
AccountSharedData::default()
|
||||||
};
|
};
|
||||||
accounts.push(account);
|
accounts.push(account);
|
||||||
}
|
}
|
||||||
|
@ -318,7 +318,7 @@ impl Accounts {
|
||||||
ancestors: &Ancestors,
|
ancestors: &Ancestors,
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
error_counters: &mut ErrorCounters,
|
error_counters: &mut ErrorCounters,
|
||||||
) -> Result<Vec<(Pubkey, Account)>> {
|
) -> Result<Vec<(Pubkey, AccountSharedData)>> {
|
||||||
let mut accounts = Vec::new();
|
let mut accounts = Vec::new();
|
||||||
let mut depth = 0;
|
let mut depth = 0;
|
||||||
let mut program_id = *program_id;
|
let mut program_id = *program_id;
|
||||||
|
@ -448,7 +448,11 @@ impl Accounts {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Slow because lock is held for 1 operation instead of many
|
/// 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)?;
|
let (account, slot) = self.accounts_db.load_slow(ancestors, pubkey)?;
|
||||||
|
|
||||||
if account.lamports > 0 {
|
if account.lamports > 0 {
|
||||||
|
@ -512,7 +516,7 @@ impl Accounts {
|
||||||
&self,
|
&self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
program_id: Option<&Pubkey>,
|
program_id: Option<&Pubkey>,
|
||||||
) -> Vec<(Pubkey, Account)> {
|
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||||
self.scan_slot(slot, |stored_account| {
|
self.scan_slot(slot, |stored_account| {
|
||||||
let hit = match program_id {
|
let hit = match program_id {
|
||||||
None => true,
|
None => true,
|
||||||
|
@ -611,9 +615,9 @@ impl Accounts {
|
||||||
lamports > 0
|
lamports > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_while_filtering<F: Fn(&Account) -> bool>(
|
fn load_while_filtering<F: Fn(&AccountSharedData) -> bool>(
|
||||||
collector: &mut Vec<(Pubkey, Account)>,
|
collector: &mut Vec<(Pubkey, AccountSharedData)>,
|
||||||
some_account_tuple: Option<(&Pubkey, Account, Slot)>,
|
some_account_tuple: Option<(&Pubkey, AccountSharedData, Slot)>,
|
||||||
filter: F,
|
filter: F,
|
||||||
) {
|
) {
|
||||||
if let Some(mapped_account_tuple) = some_account_tuple
|
if let Some(mapped_account_tuple) = some_account_tuple
|
||||||
|
@ -628,10 +632,10 @@ impl Accounts {
|
||||||
&self,
|
&self,
|
||||||
ancestors: &Ancestors,
|
ancestors: &Ancestors,
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
) -> Vec<(Pubkey, Account)> {
|
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||||
self.accounts_db.scan_accounts(
|
self.accounts_db.scan_accounts(
|
||||||
ancestors,
|
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| {
|
Self::load_while_filtering(collector, some_account_tuple, |account| {
|
||||||
account.owner == *program_id
|
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,
|
&self,
|
||||||
ancestors: &Ancestors,
|
ancestors: &Ancestors,
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
filter: F,
|
filter: F,
|
||||||
) -> Vec<(Pubkey, Account)> {
|
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||||
self.accounts_db.scan_accounts(
|
self.accounts_db.scan_accounts(
|
||||||
ancestors,
|
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| {
|
Self::load_while_filtering(collector, some_account_tuple, |account| {
|
||||||
account.owner == *program_id && filter(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,
|
&self,
|
||||||
ancestors: &Ancestors,
|
ancestors: &Ancestors,
|
||||||
index_key: &IndexKey,
|
index_key: &IndexKey,
|
||||||
filter: F,
|
filter: F,
|
||||||
) -> Vec<(Pubkey, Account)> {
|
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||||
self.accounts_db.index_scan_accounts(
|
self.accounts_db.index_scan_accounts(
|
||||||
ancestors,
|
ancestors,
|
||||||
*index_key,
|
*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))
|
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(
|
self.accounts_db.scan_accounts(
|
||||||
ancestors,
|
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)) =
|
if let Some((pubkey, account, slot)) =
|
||||||
some_account_tuple.filter(|(_, account, _)| Self::is_loadable(account.lamports))
|
some_account_tuple.filter(|(_, account, _)| Self::is_loadable(account.lamports))
|
||||||
{
|
{
|
||||||
|
@ -687,12 +691,12 @@ impl Accounts {
|
||||||
&self,
|
&self,
|
||||||
ancestors: &Ancestors,
|
ancestors: &Ancestors,
|
||||||
range: R,
|
range: R,
|
||||||
) -> Vec<(Pubkey, Account)> {
|
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||||
self.accounts_db.range_scan_accounts(
|
self.accounts_db.range_scan_accounts(
|
||||||
"load_to_collect_rent_eagerly_scan_elapsed",
|
"load_to_collect_rent_eagerly_scan_elapsed",
|
||||||
ancestors,
|
ancestors,
|
||||||
range,
|
range,
|
||||||
|collector: &mut Vec<(Pubkey, Account)>, option| {
|
|collector: &mut Vec<(Pubkey, AccountSharedData)>, option| {
|
||||||
Self::load_while_filtering(collector, option, |_| true)
|
Self::load_while_filtering(collector, option, |_| true)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -701,11 +705,11 @@ impl Accounts {
|
||||||
/// Slow because lock is held for 1 operation instead of many.
|
/// Slow because lock is held for 1 operation instead of many.
|
||||||
/// WARNING: This noncached version is only to be used for tests/benchmarking
|
/// WARNING: This noncached version is only to be used for tests/benchmarking
|
||||||
/// as bypassing the cache in general is not supported
|
/// 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)]);
|
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)]);
|
self.accounts_db.store_cached(slot, &[(pubkey, account)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -865,7 +869,7 @@ impl Accounts {
|
||||||
rent_collector: &RentCollector,
|
rent_collector: &RentCollector,
|
||||||
last_blockhash_with_fee_calculator: &(Hash, FeeCalculator),
|
last_blockhash_with_fee_calculator: &(Hash, FeeCalculator),
|
||||||
fix_recent_blockhashes_sysvar_delay: bool,
|
fix_recent_blockhashes_sysvar_delay: bool,
|
||||||
) -> Vec<(&'a Pubkey, &'a Account)> {
|
) -> Vec<(&'a Pubkey, &'a AccountSharedData)> {
|
||||||
let mut accounts = Vec::with_capacity(loaded.len());
|
let mut accounts = Vec::with_capacity(loaded.len());
|
||||||
for (i, ((raccs, _nonce_rollback), (_, tx))) in loaded
|
for (i, ((raccs, _nonce_rollback), (_, tx))) in loaded
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
|
@ -945,10 +949,10 @@ impl Accounts {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prepare_if_nonce_account(
|
pub fn prepare_if_nonce_account(
|
||||||
account: &mut Account,
|
account: &mut AccountSharedData,
|
||||||
account_pubkey: &Pubkey,
|
account_pubkey: &Pubkey,
|
||||||
tx_result: &Result<()>,
|
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),
|
last_blockhash_with_fee_calculator: &(Hash, FeeCalculator),
|
||||||
fix_recent_blockhashes_sysvar_delay: bool,
|
fix_recent_blockhashes_sysvar_delay: bool,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
@ -994,7 +998,8 @@ pub fn create_test_accounts(
|
||||||
) {
|
) {
|
||||||
for t in 0..num {
|
for t in 0..num {
|
||||||
let pubkey = solana_sdk::pubkey::new_rand();
|
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);
|
accounts.store_slow_uncached(slot, &pubkey, &account);
|
||||||
pubkeys.push(pubkey);
|
pubkeys.push(pubkey);
|
||||||
}
|
}
|
||||||
|
@ -1005,7 +1010,7 @@ pub fn create_test_accounts(
|
||||||
pub fn update_accounts_bench(accounts: &Accounts, pubkeys: &[Pubkey], slot: u64) {
|
pub fn update_accounts_bench(accounts: &Accounts, pubkeys: &[Pubkey], slot: u64) {
|
||||||
for pubkey in pubkeys {
|
for pubkey in pubkeys {
|
||||||
let amount = thread_rng().gen_range(0, 10);
|
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);
|
accounts.store_slow_uncached(slot, &pubkey, &account);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1015,7 +1020,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::rent_collector::RentCollector;
|
use crate::rent_collector::RentCollector;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
fee_calculator::FeeCalculator,
|
fee_calculator::FeeCalculator,
|
||||||
genesis_config::ClusterType,
|
genesis_config::ClusterType,
|
||||||
|
@ -1034,7 +1039,7 @@ mod tests {
|
||||||
|
|
||||||
fn load_accounts_with_fee_and_rent(
|
fn load_accounts_with_fee_and_rent(
|
||||||
tx: Transaction,
|
tx: Transaction,
|
||||||
ka: &[(Pubkey, Account)],
|
ka: &[(Pubkey, AccountSharedData)],
|
||||||
fee_calculator: &FeeCalculator,
|
fee_calculator: &FeeCalculator,
|
||||||
rent_collector: &RentCollector,
|
rent_collector: &RentCollector,
|
||||||
error_counters: &mut ErrorCounters,
|
error_counters: &mut ErrorCounters,
|
||||||
|
@ -1062,7 +1067,7 @@ mod tests {
|
||||||
|
|
||||||
fn load_accounts_with_fee(
|
fn load_accounts_with_fee(
|
||||||
tx: Transaction,
|
tx: Transaction,
|
||||||
ka: &[(Pubkey, Account)],
|
ka: &[(Pubkey, AccountSharedData)],
|
||||||
fee_calculator: &FeeCalculator,
|
fee_calculator: &FeeCalculator,
|
||||||
error_counters: &mut ErrorCounters,
|
error_counters: &mut ErrorCounters,
|
||||||
) -> Vec<TransactionLoadResult> {
|
) -> Vec<TransactionLoadResult> {
|
||||||
|
@ -1072,7 +1077,7 @@ mod tests {
|
||||||
|
|
||||||
fn load_accounts(
|
fn load_accounts(
|
||||||
tx: Transaction,
|
tx: Transaction,
|
||||||
ka: &[(Pubkey, Account)],
|
ka: &[(Pubkey, AccountSharedData)],
|
||||||
error_counters: &mut ErrorCounters,
|
error_counters: &mut ErrorCounters,
|
||||||
) -> Vec<TransactionLoadResult> {
|
) -> Vec<TransactionLoadResult> {
|
||||||
let fee_calculator = FeeCalculator::default();
|
let fee_calculator = FeeCalculator::default();
|
||||||
|
@ -1081,7 +1086,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_accounts_no_key() {
|
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 mut error_counters = ErrorCounters::default();
|
||||||
|
|
||||||
let instructions = vec![CompiledInstruction::new(0, &(), vec![0])];
|
let instructions = vec![CompiledInstruction::new(0, &(), vec![0])];
|
||||||
|
@ -1105,7 +1110,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_accounts_no_account_0_exists() {
|
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 mut error_counters = ErrorCounters::default();
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
|
@ -1131,17 +1136,17 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_accounts_unknown_program_id() {
|
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 mut error_counters = ErrorCounters::default();
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let key0 = keypair.pubkey();
|
let key0 = keypair.pubkey();
|
||||||
let key1 = Pubkey::new(&[5u8; 32]);
|
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));
|
accounts.push((key0, account));
|
||||||
|
|
||||||
let account = Account::new(2, 1, &Pubkey::default());
|
let account = AccountSharedData::new(2, 1, &Pubkey::default());
|
||||||
accounts.push((key1, account));
|
accounts.push((key1, account));
|
||||||
|
|
||||||
let instructions = vec![CompiledInstruction::new(1, &(), vec![0])];
|
let instructions = vec![CompiledInstruction::new(1, &(), vec![0])];
|
||||||
|
@ -1165,13 +1170,13 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_accounts_insufficient_funds() {
|
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 mut error_counters = ErrorCounters::default();
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let key0 = keypair.pubkey();
|
let key0 = keypair.pubkey();
|
||||||
|
|
||||||
let account = Account::new(1, 0, &Pubkey::default());
|
let account = AccountSharedData::new(1, 0, &Pubkey::default());
|
||||||
accounts.push((key0, account));
|
accounts.push((key0, account));
|
||||||
|
|
||||||
let instructions = vec![CompiledInstruction::new(1, &(), vec![0])];
|
let instructions = vec![CompiledInstruction::new(1, &(), vec![0])];
|
||||||
|
@ -1199,13 +1204,13 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_accounts_invalid_account_for_fee() {
|
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 mut error_counters = ErrorCounters::default();
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let key0 = keypair.pubkey();
|
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));
|
accounts.push((key0, account));
|
||||||
|
|
||||||
let instructions = vec![CompiledInstruction::new(1, &(), vec![0])];
|
let instructions = vec![CompiledInstruction::new(1, &(), vec![0])];
|
||||||
|
@ -1244,7 +1249,7 @@ mod tests {
|
||||||
let nonce = Keypair::new();
|
let nonce = Keypair::new();
|
||||||
let mut accounts = vec![(
|
let mut accounts = vec![(
|
||||||
nonce.pubkey(),
|
nonce.pubkey(),
|
||||||
Account::new_data(
|
AccountSharedData::new_data(
|
||||||
min_balance * 2,
|
min_balance * 2,
|
||||||
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
||||||
nonce::state::Data::default(),
|
nonce::state::Data::default(),
|
||||||
|
@ -1304,18 +1309,18 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_accounts_no_loaders() {
|
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 mut error_counters = ErrorCounters::default();
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let key0 = keypair.pubkey();
|
let key0 = keypair.pubkey();
|
||||||
let key1 = Pubkey::new(&[5u8; 32]);
|
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;
|
account.rent_epoch = 1;
|
||||||
accounts.push((key0, account));
|
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;
|
account.rent_epoch = 1;
|
||||||
accounts.push((key1, account));
|
accounts.push((key1, account));
|
||||||
|
|
||||||
|
@ -1345,7 +1350,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_accounts_max_call_depth() {
|
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 mut error_counters = ErrorCounters::default();
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
|
@ -1357,35 +1362,35 @@ mod tests {
|
||||||
let key5 = Pubkey::new(&[9u8; 32]);
|
let key5 = Pubkey::new(&[9u8; 32]);
|
||||||
let key6 = Pubkey::new(&[10u8; 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));
|
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.executable = true;
|
||||||
account.owner = native_loader::id();
|
account.owner = native_loader::id();
|
||||||
accounts.push((key1, account));
|
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.executable = true;
|
||||||
account.owner = key1;
|
account.owner = key1;
|
||||||
accounts.push((key2, account));
|
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.executable = true;
|
||||||
account.owner = key2;
|
account.owner = key2;
|
||||||
accounts.push((key3, account));
|
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.executable = true;
|
||||||
account.owner = key3;
|
account.owner = key3;
|
||||||
accounts.push((key4, account));
|
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.executable = true;
|
||||||
account.owner = key4;
|
account.owner = key4;
|
||||||
accounts.push((key5, account));
|
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.executable = true;
|
||||||
account.owner = key5;
|
account.owner = key5;
|
||||||
accounts.push((key6, account));
|
accounts.push((key6, account));
|
||||||
|
@ -1411,17 +1416,17 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_accounts_bad_program_id() {
|
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 mut error_counters = ErrorCounters::default();
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let key0 = keypair.pubkey();
|
let key0 = keypair.pubkey();
|
||||||
let key1 = Pubkey::new(&[5u8; 32]);
|
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));
|
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;
|
account.executable = true;
|
||||||
accounts.push((key1, account));
|
accounts.push((key1, account));
|
||||||
|
|
||||||
|
@ -1446,17 +1451,17 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_accounts_bad_owner() {
|
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 mut error_counters = ErrorCounters::default();
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let key0 = keypair.pubkey();
|
let key0 = keypair.pubkey();
|
||||||
let key1 = Pubkey::new(&[5u8; 32]);
|
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));
|
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.executable = true;
|
||||||
accounts.push((key1, account));
|
accounts.push((key1, account));
|
||||||
|
|
||||||
|
@ -1481,17 +1486,17 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_accounts_not_executable() {
|
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 mut error_counters = ErrorCounters::default();
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let key0 = keypair.pubkey();
|
let key0 = keypair.pubkey();
|
||||||
let key1 = Pubkey::new(&[5u8; 32]);
|
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));
|
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));
|
accounts.push((key1, account));
|
||||||
|
|
||||||
let instructions = vec![CompiledInstruction::new(1, &(), vec![0])];
|
let instructions = vec![CompiledInstruction::new(1, &(), vec![0])];
|
||||||
|
@ -1515,7 +1520,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_accounts_multiple_loaders() {
|
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 mut error_counters = ErrorCounters::default();
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
|
@ -1523,17 +1528,17 @@ mod tests {
|
||||||
let key1 = Pubkey::new(&[5u8; 32]);
|
let key1 = Pubkey::new(&[5u8; 32]);
|
||||||
let key2 = Pubkey::new(&[6u8; 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;
|
account.rent_epoch = 1;
|
||||||
accounts.push((key0, account));
|
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.executable = true;
|
||||||
account.rent_epoch = 1;
|
account.rent_epoch = 1;
|
||||||
account.owner = native_loader::id();
|
account.owner = native_loader::id();
|
||||||
accounts.push((key1, account));
|
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.executable = true;
|
||||||
account.rent_epoch = 1;
|
account.rent_epoch = 1;
|
||||||
account.owner = key1;
|
account.owner = key1;
|
||||||
|
@ -1580,13 +1585,13 @@ mod tests {
|
||||||
|
|
||||||
// Load accounts owned by various programs into AccountsDb
|
// Load accounts owned by various programs into AccountsDb
|
||||||
let pubkey0 = solana_sdk::pubkey::new_rand();
|
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);
|
accounts.store_slow_uncached(0, &pubkey0, &account0);
|
||||||
let pubkey1 = solana_sdk::pubkey::new_rand();
|
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);
|
accounts.store_slow_uncached(0, &pubkey1, &account1);
|
||||||
let pubkey2 = solana_sdk::pubkey::new_rand();
|
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);
|
accounts.store_slow_uncached(0, &pubkey2, &account2);
|
||||||
|
|
||||||
let loaded = accounts.load_by_program_slot(0, Some(&Pubkey::new(&[2; 32])));
|
let loaded = accounts.load_by_program_slot(0, Some(&Pubkey::new(&[2; 32])));
|
||||||
|
@ -1630,10 +1635,10 @@ mod tests {
|
||||||
let keypair2 = Keypair::new();
|
let keypair2 = Keypair::new();
|
||||||
let keypair3 = Keypair::new();
|
let keypair3 = Keypair::new();
|
||||||
|
|
||||||
let account0 = Account::new(1, 0, &Pubkey::default());
|
let account0 = AccountSharedData::new(1, 0, &Pubkey::default());
|
||||||
let account1 = Account::new(2, 0, &Pubkey::default());
|
let account1 = AccountSharedData::new(2, 0, &Pubkey::default());
|
||||||
let account2 = Account::new(3, 0, &Pubkey::default());
|
let account2 = AccountSharedData::new(3, 0, &Pubkey::default());
|
||||||
let account3 = Account::new(4, 0, &Pubkey::default());
|
let account3 = AccountSharedData::new(4, 0, &Pubkey::default());
|
||||||
|
|
||||||
let accounts =
|
let accounts =
|
||||||
Accounts::new_with_config(Vec::new(), &ClusterType::Development, HashSet::new(), false);
|
Accounts::new_with_config(Vec::new(), &ClusterType::Development, HashSet::new(), false);
|
||||||
|
@ -1738,9 +1743,9 @@ mod tests {
|
||||||
let keypair1 = Keypair::new();
|
let keypair1 = Keypair::new();
|
||||||
let keypair2 = Keypair::new();
|
let keypair2 = Keypair::new();
|
||||||
|
|
||||||
let account0 = Account::new(1, 0, &Pubkey::default());
|
let account0 = AccountSharedData::new(1, 0, &Pubkey::default());
|
||||||
let account1 = Account::new(2, 0, &Pubkey::default());
|
let account1 = AccountSharedData::new(2, 0, &Pubkey::default());
|
||||||
let account2 = Account::new(3, 0, &Pubkey::default());
|
let account2 = AccountSharedData::new(3, 0, &Pubkey::default());
|
||||||
|
|
||||||
let accounts =
|
let accounts =
|
||||||
Accounts::new_with_config(Vec::new(), &ClusterType::Development, HashSet::new(), false);
|
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 loaders = vec![(Ok(()), None), (Ok(()), None)];
|
||||||
|
|
||||||
let account0 = Account::new(1, 0, &Pubkey::default());
|
let account0 = AccountSharedData::new(1, 0, &Pubkey::default());
|
||||||
let account1 = Account::new(2, 0, &Pubkey::default());
|
let account1 = AccountSharedData::new(2, 0, &Pubkey::default());
|
||||||
let account2 = Account::new(3, 0, &Pubkey::default());
|
let account2 = AccountSharedData::new(3, 0, &Pubkey::default());
|
||||||
|
|
||||||
let transaction_accounts0 = vec![account0, account2.clone()];
|
let transaction_accounts0 = vec![account0, account2.clone()];
|
||||||
let transaction_loaders0 = vec![];
|
let transaction_loaders0 = vec![];
|
||||||
|
@ -1923,11 +1928,12 @@ mod tests {
|
||||||
let accounts =
|
let accounts =
|
||||||
Accounts::new_with_config(Vec::new(), &ClusterType::Development, HashSet::new(), false);
|
Accounts::new_with_config(Vec::new(), &ClusterType::Development, HashSet::new(), false);
|
||||||
let mut old_pubkey = Pubkey::default();
|
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..");
|
info!("storing..");
|
||||||
for i in 0..2_000 {
|
for i in 0..2_000 {
|
||||||
let pubkey = solana_sdk::pubkey::new_rand();
|
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, &pubkey, &account);
|
||||||
accounts.store_slow_uncached(i, &old_pubkey, &zero_account);
|
accounts.store_slow_uncached(i, &old_pubkey, &zero_account);
|
||||||
old_pubkey = pubkey;
|
old_pubkey = pubkey;
|
||||||
|
@ -1984,17 +1990,17 @@ mod tests {
|
||||||
|
|
||||||
fn create_accounts_prepare_if_nonce_account() -> (
|
fn create_accounts_prepare_if_nonce_account() -> (
|
||||||
Pubkey,
|
Pubkey,
|
||||||
Account,
|
AccountSharedData,
|
||||||
Account,
|
AccountSharedData,
|
||||||
Hash,
|
Hash,
|
||||||
FeeCalculator,
|
FeeCalculator,
|
||||||
Option<Account>,
|
Option<AccountSharedData>,
|
||||||
) {
|
) {
|
||||||
let data = nonce::state::Versions::new_current(nonce::State::Initialized(
|
let data = nonce::state::Versions::new_current(nonce::State::Initialized(
|
||||||
nonce::state::Data::default(),
|
nonce::state::Data::default(),
|
||||||
));
|
));
|
||||||
let account = Account::new_data(42, &data, &system_program::id()).unwrap();
|
let account = AccountSharedData::new_data(42, &data, &system_program::id()).unwrap();
|
||||||
let pre_account = Account {
|
let pre_account = AccountSharedData {
|
||||||
lamports: 43,
|
lamports: 43,
|
||||||
..account.clone()
|
..account.clone()
|
||||||
};
|
};
|
||||||
|
@ -2011,12 +2017,12 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_prepare_if_nonce_account_test(
|
fn run_prepare_if_nonce_account_test(
|
||||||
account: &mut Account,
|
account: &mut AccountSharedData,
|
||||||
account_pubkey: &Pubkey,
|
account_pubkey: &Pubkey,
|
||||||
tx_result: &Result<()>,
|
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),
|
last_blockhash_with_fee_calculator: &(Hash, FeeCalculator),
|
||||||
expect_account: &Account,
|
expect_account: &AccountSharedData,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
// Verify expect_account's relationship
|
// Verify expect_account's relationship
|
||||||
match maybe_nonce_rollback {
|
match maybe_nonce_rollback {
|
||||||
|
@ -2088,7 +2094,7 @@ mod tests {
|
||||||
) = create_accounts_prepare_if_nonce_account();
|
) = create_accounts_prepare_if_nonce_account();
|
||||||
let post_account_pubkey = pre_account_pubkey;
|
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();
|
let expect_account = post_account.clone();
|
||||||
assert!(run_prepare_if_nonce_account_test(
|
assert!(run_prepare_if_nonce_account_test(
|
||||||
&mut post_account,
|
&mut post_account,
|
||||||
|
@ -2192,8 +2198,9 @@ mod tests {
|
||||||
blockhash,
|
blockhash,
|
||||||
fee_calculator: FeeCalculator::default(),
|
fee_calculator: FeeCalculator::default(),
|
||||||
}));
|
}));
|
||||||
let nonce_account_pre = Account::new_data(42, &nonce_state, &system_program::id()).unwrap();
|
let nonce_account_pre =
|
||||||
let from_account_pre = Account::new(4242, 0, &Pubkey::default());
|
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(
|
let nonce_rollback = Some(NonceRollbackFull::new(
|
||||||
nonce_address,
|
nonce_address,
|
||||||
|
@ -2215,12 +2222,12 @@ mod tests {
|
||||||
fee_calculator: FeeCalculator::default(),
|
fee_calculator: FeeCalculator::default(),
|
||||||
}));
|
}));
|
||||||
let nonce_account_post =
|
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 from_account_post = AccountSharedData::new(4199, 0, &Pubkey::default());
|
||||||
let to_account = Account::new(2, 0, &Pubkey::default());
|
let to_account = AccountSharedData::new(2, 0, &Pubkey::default());
|
||||||
let nonce_authority_account = Account::new(3, 0, &Pubkey::default());
|
let nonce_authority_account = AccountSharedData::new(3, 0, &Pubkey::default());
|
||||||
let recent_blockhashes_sysvar_account = Account::new(4, 0, &Pubkey::default());
|
let recent_blockhashes_sysvar_account = AccountSharedData::new(4, 0, &Pubkey::default());
|
||||||
|
|
||||||
let transaction_accounts = vec![
|
let transaction_accounts = vec![
|
||||||
from_account_post,
|
from_account_post,
|
||||||
|
@ -2303,7 +2310,8 @@ mod tests {
|
||||||
blockhash,
|
blockhash,
|
||||||
fee_calculator: FeeCalculator::default(),
|
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(
|
let nonce_rollback = Some(NonceRollbackFull::new(
|
||||||
nonce_address,
|
nonce_address,
|
||||||
|
@ -2325,12 +2333,12 @@ mod tests {
|
||||||
fee_calculator: FeeCalculator::default(),
|
fee_calculator: FeeCalculator::default(),
|
||||||
}));
|
}));
|
||||||
let nonce_account_post =
|
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 from_account_post = AccountSharedData::new(4200, 0, &Pubkey::default());
|
||||||
let to_account = Account::new(2, 0, &Pubkey::default());
|
let to_account = AccountSharedData::new(2, 0, &Pubkey::default());
|
||||||
let nonce_authority_account = Account::new(3, 0, &Pubkey::default());
|
let nonce_authority_account = AccountSharedData::new(3, 0, &Pubkey::default());
|
||||||
let recent_blockhashes_sysvar_account = Account::new(4, 0, &Pubkey::default());
|
let recent_blockhashes_sysvar_account = AccountSharedData::new(4, 0, &Pubkey::default());
|
||||||
|
|
||||||
let transaction_accounts = vec![
|
let transaction_accounts = vec![
|
||||||
from_account_post,
|
from_account_post,
|
||||||
|
|
|
@ -424,7 +424,7 @@ mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::genesis_utils::create_genesis_config;
|
use crate::genesis_utils::create_genesis_config;
|
||||||
use crossbeam_channel::unbounded;
|
use crossbeam_channel::unbounded;
|
||||||
use solana_sdk::{account::Account, pubkey::Pubkey};
|
use solana_sdk::{account::AccountSharedData, pubkey::Pubkey};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_accounts_background_service_remove_dead_slots() {
|
fn test_accounts_background_service_remove_dead_slots() {
|
||||||
|
@ -438,7 +438,10 @@ mod test {
|
||||||
|
|
||||||
// Store an account in slot 0
|
// Store an account in slot 0
|
||||||
let account_key = Pubkey::new_unique();
|
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());
|
assert!(bank0.get_account(&account_key).is_some());
|
||||||
pruned_banks_sender.send(0).unwrap();
|
pruned_banks_sender.send(0).unwrap();
|
||||||
AccountsBackgroundService::remove_dead_slots(&bank0, &request_handler, &mut 0, &mut 0);
|
AccountsBackgroundService::remove_dead_slots(&bank0, &request_handler, &mut 0, &mut 0);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use dashmap::DashMap;
|
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::{
|
use std::{
|
||||||
collections::BTreeSet,
|
collections::BTreeSet,
|
||||||
ops::Deref,
|
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) {
|
if self.cache.contains_key(pubkey) {
|
||||||
self.same_account_writes.fetch_add(1, Ordering::Relaxed);
|
self.same_account_writes.fetch_add(1, Ordering::Relaxed);
|
||||||
self.same_account_writes_size
|
self.same_account_writes_size
|
||||||
|
@ -86,7 +86,7 @@ impl Deref for SlotCacheInner {
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct CachedAccount {
|
pub struct CachedAccount {
|
||||||
pub account: Account,
|
pub account: AccountSharedData,
|
||||||
pub hash: Hash,
|
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(||
|
let slot_cache = self.slot_cache(slot).unwrap_or_else(||
|
||||||
// DashMap entry.or_insert() returns a RefMut, essentially a write lock,
|
// DashMap entry.or_insert() returns a RefMut, essentially a write lock,
|
||||||
// which is dropped after this block ends, minimizing time held by the lock.
|
// which is dropped after this block ends, minimizing time held by the lock.
|
||||||
|
@ -235,7 +235,7 @@ pub mod tests {
|
||||||
cache.store(
|
cache.store(
|
||||||
inserted_slot,
|
inserted_slot,
|
||||||
&Pubkey::new_unique(),
|
&Pubkey::new_unique(),
|
||||||
Account::new(1, 0, &Pubkey::default()),
|
AccountSharedData::new(1, 0, &Pubkey::default()),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
// If the cache is told the size limit is 0, it should return the one slot
|
// 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(
|
cache.store(
|
||||||
inserted_slot,
|
inserted_slot,
|
||||||
&Pubkey::new_unique(),
|
&Pubkey::new_unique(),
|
||||||
Account::new(1, 0, &Pubkey::default()),
|
AccountSharedData::new(1, 0, &Pubkey::default()),
|
||||||
Hash::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);
|
self.program_id_index.insert(account_owner, pubkey, slot);
|
||||||
}
|
}
|
||||||
// Note because of the below check below on the account data length, when an
|
// 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.
|
// the below updates to the secondary indexes.
|
||||||
//
|
//
|
||||||
// Skipping means not updating secondary index to mark the account as missing.
|
// 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:
|
// removed from the secondary index, the scan function will:
|
||||||
// 1) consult the primary index via `get(&pubkey, Some(ancestors), max_root)`
|
// 1) consult the primary index via `get(&pubkey, Some(ancestors), max_root)`
|
||||||
// and find the zero-lamport version
|
// 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
|
// (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()`.
|
// filtered out by post-scan filters, like in `get_filtered_spl_token_accounts_by_owner()`.
|
||||||
if *account_owner == inline_spl_token_v2_0::id()
|
if *account_owner == inline_spl_token_v2_0::id()
|
||||||
|
|
|
@ -5,7 +5,7 @@ use log::*;
|
||||||
use memmap2::MmapMut;
|
use memmap2::MmapMut;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
clock::{Epoch, Slot},
|
clock::{Epoch, Slot},
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
|
@ -57,8 +57,8 @@ pub struct AccountMeta {
|
||||||
pub rent_epoch: Epoch,
|
pub rent_epoch: Epoch,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a Account> for AccountMeta {
|
impl<'a> From<&'a AccountSharedData> for AccountMeta {
|
||||||
fn from(account: &'a Account) -> Self {
|
fn from(account: &'a AccountSharedData) -> Self {
|
||||||
Self {
|
Self {
|
||||||
lamports: account.lamports,
|
lamports: account.lamports,
|
||||||
owner: account.owner,
|
owner: account.owner,
|
||||||
|
@ -83,8 +83,8 @@ pub struct StoredAccountMeta<'a> {
|
||||||
|
|
||||||
impl<'a> StoredAccountMeta<'a> {
|
impl<'a> StoredAccountMeta<'a> {
|
||||||
/// Return a new Account by copying all the data referenced by the `StoredAccountMeta`.
|
/// Return a new Account by copying all the data referenced by the `StoredAccountMeta`.
|
||||||
pub fn clone_account(&self) -> Account {
|
pub fn clone_account(&self) -> AccountSharedData {
|
||||||
Account {
|
AccountSharedData {
|
||||||
lamports: self.account_meta.lamports,
|
lamports: self.account_meta.lamports,
|
||||||
owner: self.account_meta.owner,
|
owner: self.account_meta.owner,
|
||||||
executable: self.account_meta.executable,
|
executable: self.account_meta.executable,
|
||||||
|
@ -103,8 +103,8 @@ impl<'a> StoredAccountMeta<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sanitize_lamports(&self) -> bool {
|
fn sanitize_lamports(&self) -> bool {
|
||||||
// Sanitize 0 lamports to ensure to be same as Account::default()
|
// Sanitize 0 lamports to ensure to be same as AccountSharedData::default()
|
||||||
self.account_meta.lamports != 0 || self.clone_account() == Account::default()
|
self.account_meta.lamports != 0 || self.clone_account() == AccountSharedData::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ref_executable_byte(&self) -> &u8 {
|
fn ref_executable_byte(&self) -> &u8 {
|
||||||
|
@ -431,7 +431,7 @@ impl AppendVec {
|
||||||
next,
|
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 (stored_account, _) = self.get_account(offset)?;
|
||||||
let meta = stored_account.meta.clone();
|
let meta = stored_account.meta.clone();
|
||||||
Some((meta, stored_account.clone_account()))
|
Some((meta, stored_account.clone_account()))
|
||||||
|
@ -457,7 +457,7 @@ impl AppendVec {
|
||||||
/// and will be available to other threads.
|
/// and will be available to other threads.
|
||||||
pub fn append_accounts(
|
pub fn append_accounts(
|
||||||
&self,
|
&self,
|
||||||
accounts: &[(StoredMeta, &Account)],
|
accounts: &[(StoredMeta, &AccountSharedData)],
|
||||||
hashes: &[Hash],
|
hashes: &[Hash],
|
||||||
) -> Vec<usize> {
|
) -> Vec<usize> {
|
||||||
let _lock = self.append_lock.lock().unwrap();
|
let _lock = self.append_lock.lock().unwrap();
|
||||||
|
@ -496,7 +496,7 @@ impl AppendVec {
|
||||||
pub fn append_account(
|
pub fn append_account(
|
||||||
&self,
|
&self,
|
||||||
storage_meta: StoredMeta,
|
storage_meta: StoredMeta,
|
||||||
account: &Account,
|
account: &AccountSharedData,
|
||||||
hash: Hash,
|
hash: Hash,
|
||||||
) -> Option<usize> {
|
) -> Option<usize> {
|
||||||
let res = self.append_accounts(&[(storage_meta, account)], &[hash]);
|
let res = self.append_accounts(&[(storage_meta, account)], &[hash]);
|
||||||
|
@ -512,7 +512,7 @@ pub mod test_utils {
|
||||||
use super::StoredMeta;
|
use super::StoredMeta;
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::AccountSharedData;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use std::fs::create_dir_all;
|
use std::fs::create_dir_all;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -543,9 +543,9 @@ pub mod test_utils {
|
||||||
TempFile { path: buf }
|
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 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();
|
account.data = (0..data_len).map(|_| data_len as u8).collect();
|
||||||
let stored_meta = StoredMeta {
|
let stored_meta = StoredMeta {
|
||||||
write_version: 0,
|
write_version: 0,
|
||||||
|
@ -566,7 +566,7 @@ pub mod tests {
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
impl AppendVec {
|
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())
|
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 pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let owner = Pubkey::default();
|
let owner = Pubkey::default();
|
||||||
let data_len = 3_u64;
|
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();
|
account.data = b"abc".to_vec();
|
||||||
let stored_meta = StoredMeta {
|
let stored_meta = StoredMeta {
|
||||||
write_version: 0,
|
write_version: 0,
|
||||||
|
|
|
@ -31,7 +31,7 @@ use rayon::ThreadPool;
|
||||||
use solana_measure::measure::Measure;
|
use solana_measure::measure::Measure;
|
||||||
use solana_metrics::{datapoint_debug, inc_new_counter_debug, inc_new_counter_info};
|
use solana_metrics::{datapoint_debug, inc_new_counter_debug, inc_new_counter_info};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{create_account, from_account, Account},
|
account::{create_account_shared_data as create_account, from_account, AccountSharedData},
|
||||||
clock::{
|
clock::{
|
||||||
Epoch, Slot, SlotCount, SlotIndex, UnixTimestamp, DEFAULT_TICKS_PER_SECOND,
|
Epoch, Slot, SlotCount, SlotIndex, UnixTimestamp, DEFAULT_TICKS_PER_SECOND,
|
||||||
MAX_PROCESSING_AGE, MAX_RECENT_BLOCKHASHES, MAX_TRANSACTION_FORWARDING_DELAY,
|
MAX_PROCESSING_AGE, MAX_RECENT_BLOCKHASHES, MAX_TRANSACTION_FORWARDING_DELAY,
|
||||||
|
@ -113,9 +113,9 @@ impl ExecuteTimings {
|
||||||
type BankStatusCache = StatusCache<Result<()>>;
|
type BankStatusCache = StatusCache<Result<()>>;
|
||||||
#[frozen_abi(digest = "EcB9J7sm37t1R47vLcvGuNeiRciB4Efq1EDWDWL6Bp5h")]
|
#[frozen_abi(digest = "EcB9J7sm37t1R47vLcvGuNeiRciB4Efq1EDWDWL6Bp5h")]
|
||||||
pub type BankSlotDelta = SlotDelta<Result<()>>;
|
pub type BankSlotDelta = SlotDelta<Result<()>>;
|
||||||
type TransactionAccountRefCells = Vec<Rc<RefCell<Account>>>;
|
type TransactionAccountRefCells = Vec<Rc<RefCell<AccountSharedData>>>;
|
||||||
type TransactionAccountDepRefCells = Vec<(Pubkey, RefCell<Account>)>;
|
type TransactionAccountDepRefCells = Vec<(Pubkey, RefCell<AccountSharedData>)>;
|
||||||
type TransactionLoaderRefCells = Vec<Vec<(Pubkey, RefCell<Account>)>>;
|
type TransactionLoaderRefCells = Vec<Vec<(Pubkey, RefCell<AccountSharedData>)>>;
|
||||||
|
|
||||||
// Eager rent collection repeats in cyclic manner.
|
// Eager rent collection repeats in cyclic manner.
|
||||||
// Each cycle is composed of <partition_count> number of tiny pubkey subranges
|
// Each cycle is composed of <partition_count> number of tiny pubkey subranges
|
||||||
|
@ -444,19 +444,19 @@ pub struct TransactionLogCollector {
|
||||||
|
|
||||||
pub trait NonceRollbackInfo {
|
pub trait NonceRollbackInfo {
|
||||||
fn nonce_address(&self) -> &Pubkey;
|
fn nonce_address(&self) -> &Pubkey;
|
||||||
fn nonce_account(&self) -> &Account;
|
fn nonce_account(&self) -> &AccountSharedData;
|
||||||
fn fee_calculator(&self) -> Option<FeeCalculator>;
|
fn fee_calculator(&self) -> Option<FeeCalculator>;
|
||||||
fn fee_account(&self) -> Option<&Account>;
|
fn fee_account(&self) -> Option<&AccountSharedData>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq)]
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
pub struct NonceRollbackPartial {
|
pub struct NonceRollbackPartial {
|
||||||
nonce_address: Pubkey,
|
nonce_address: Pubkey,
|
||||||
nonce_account: Account,
|
nonce_account: AccountSharedData,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NonceRollbackPartial {
|
impl NonceRollbackPartial {
|
||||||
pub fn new(nonce_address: Pubkey, nonce_account: Account) -> Self {
|
pub fn new(nonce_address: Pubkey, nonce_account: AccountSharedData) -> Self {
|
||||||
Self {
|
Self {
|
||||||
nonce_address,
|
nonce_address,
|
||||||
nonce_account,
|
nonce_account,
|
||||||
|
@ -468,13 +468,13 @@ impl NonceRollbackInfo for NonceRollbackPartial {
|
||||||
fn nonce_address(&self) -> &Pubkey {
|
fn nonce_address(&self) -> &Pubkey {
|
||||||
&self.nonce_address
|
&self.nonce_address
|
||||||
}
|
}
|
||||||
fn nonce_account(&self) -> &Account {
|
fn nonce_account(&self) -> &AccountSharedData {
|
||||||
&self.nonce_account
|
&self.nonce_account
|
||||||
}
|
}
|
||||||
fn fee_calculator(&self) -> Option<FeeCalculator> {
|
fn fee_calculator(&self) -> Option<FeeCalculator> {
|
||||||
nonce_account::fee_calculator_of(&self.nonce_account)
|
nonce_account::fee_calculator_of(&self.nonce_account)
|
||||||
}
|
}
|
||||||
fn fee_account(&self) -> Option<&Account> {
|
fn fee_account(&self) -> Option<&AccountSharedData> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -482,16 +482,16 @@ impl NonceRollbackInfo for NonceRollbackPartial {
|
||||||
#[derive(Clone, Debug, Default, PartialEq)]
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
pub struct NonceRollbackFull {
|
pub struct NonceRollbackFull {
|
||||||
nonce_address: Pubkey,
|
nonce_address: Pubkey,
|
||||||
nonce_account: Account,
|
nonce_account: AccountSharedData,
|
||||||
fee_account: Option<Account>,
|
fee_account: Option<AccountSharedData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NonceRollbackFull {
|
impl NonceRollbackFull {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
nonce_address: Pubkey,
|
nonce_address: Pubkey,
|
||||||
nonce_account: Account,
|
nonce_account: AccountSharedData,
|
||||||
fee_account: Option<Account>,
|
fee_account: Option<AccountSharedData>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
nonce_address,
|
nonce_address,
|
||||||
|
@ -502,7 +502,7 @@ impl NonceRollbackFull {
|
||||||
pub fn from_partial(
|
pub fn from_partial(
|
||||||
partial: NonceRollbackPartial,
|
partial: NonceRollbackPartial,
|
||||||
message: &Message,
|
message: &Message,
|
||||||
accounts: &[Account],
|
accounts: &[AccountSharedData],
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let NonceRollbackPartial {
|
let NonceRollbackPartial {
|
||||||
nonce_address,
|
nonce_address,
|
||||||
|
@ -538,13 +538,13 @@ impl NonceRollbackInfo for NonceRollbackFull {
|
||||||
fn nonce_address(&self) -> &Pubkey {
|
fn nonce_address(&self) -> &Pubkey {
|
||||||
&self.nonce_address
|
&self.nonce_address
|
||||||
}
|
}
|
||||||
fn nonce_account(&self) -> &Account {
|
fn nonce_account(&self) -> &AccountSharedData {
|
||||||
&self.nonce_account
|
&self.nonce_account
|
||||||
}
|
}
|
||||||
fn fee_calculator(&self) -> Option<FeeCalculator> {
|
fn fee_calculator(&self) -> Option<FeeCalculator> {
|
||||||
nonce_account::fee_calculator_of(&self.nonce_account)
|
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()
|
self.fee_account.as_ref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1328,7 +1328,7 @@ impl Bank {
|
||||||
|
|
||||||
fn update_sysvar_account<F>(&self, pubkey: &Pubkey, updater: F)
|
fn update_sysvar_account<F>(&self, pubkey: &Pubkey, updater: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Option<Account>) -> Account,
|
F: Fn(&Option<AccountSharedData>) -> AccountSharedData,
|
||||||
{
|
{
|
||||||
let old_account = self.get_sysvar_account(pubkey);
|
let old_account = self.get_sysvar_account(pubkey);
|
||||||
let new_account = updater(&old_account);
|
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)
|
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| {
|
self.update_sysvar_account(&sysvar::slot_history::id(), |account| {
|
||||||
let mut slot_history = account
|
let mut slot_history = account
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|account| from_account::<SlotHistory>(&account).unwrap())
|
.map(|account| from_account::<SlotHistory, _>(account).unwrap())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
slot_history.add(self.slot());
|
slot_history.add(self.slot());
|
||||||
create_account(
|
create_account(
|
||||||
|
@ -1445,7 +1448,7 @@ impl Bank {
|
||||||
self.update_sysvar_account(&sysvar::slot_hashes::id(), |account| {
|
self.update_sysvar_account(&sysvar::slot_hashes::id(), |account| {
|
||||||
let mut slot_hashes = account
|
let mut slot_hashes = account
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|account| from_account::<SlotHashes>(&account).unwrap())
|
.map(|account| from_account::<SlotHashes, _>(account).unwrap())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
slot_hashes.add(self.parent_slot, self.parent_hash);
|
slot_hashes.add(self.parent_slot, self.parent_hash);
|
||||||
create_account(
|
create_account(
|
||||||
|
@ -1720,7 +1723,7 @@ impl Bank {
|
||||||
fn stake_delegation_accounts(
|
fn stake_delegation_accounts(
|
||||||
&self,
|
&self,
|
||||||
reward_calc_tracer: &mut Option<impl FnMut(&RewardCalculationEvent)>,
|
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();
|
let mut accounts = HashMap::new();
|
||||||
|
|
||||||
self.stakes
|
self.stakes
|
||||||
|
@ -2101,7 +2104,7 @@ impl Bank {
|
||||||
if self.get_account(&pubkey).is_some() {
|
if self.get_account(&pubkey).is_some() {
|
||||||
panic!("{} repeated in genesis config", pubkey);
|
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);
|
self.capitalization.fetch_add(account.lamports, Relaxed);
|
||||||
}
|
}
|
||||||
// updating sysvars (the fees sysvar in this case) now depends on feature activations in
|
// 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() {
|
if self.get_account(&pubkey).is_some() {
|
||||||
panic!("{} repeated in genesis config", pubkey);
|
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
|
// highest staked node is the first collector
|
||||||
|
@ -2560,7 +2563,7 @@ impl Bank {
|
||||||
.check_hash_age(hash, max_age)
|
.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)
|
transaction::uses_durable_nonce(&tx)
|
||||||
.and_then(|nonce_ix| transaction::get_nonce_pubkey_from_instruction(&nonce_ix, &tx))
|
.and_then(|nonce_ix| transaction::get_nonce_pubkey_from_instruction(&nonce_ix, &tx))
|
||||||
.and_then(|nonce_pubkey| {
|
.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
|
/// ownership by draining the source
|
||||||
fn accounts_to_refcells(
|
fn accounts_to_refcells(
|
||||||
accounts: &mut TransactionAccounts,
|
accounts: &mut TransactionAccounts,
|
||||||
|
@ -2734,7 +2737,7 @@ impl Bank {
|
||||||
(account_refcells, account_dep_refcells, loader_refcells)
|
(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
|
/// ownership by draining the sources
|
||||||
fn refcells_to_accounts(
|
fn refcells_to_accounts(
|
||||||
accounts: &mut TransactionAccounts,
|
accounts: &mut TransactionAccounts,
|
||||||
|
@ -2771,7 +2774,7 @@ impl Bank {
|
||||||
fn get_executors(
|
fn get_executors(
|
||||||
&self,
|
&self,
|
||||||
message: &Message,
|
message: &Message,
|
||||||
loaders: &[Vec<(Pubkey, Account)>],
|
loaders: &[Vec<(Pubkey, AccountSharedData)>],
|
||||||
) -> Rc<RefCell<Executors>> {
|
) -> Rc<RefCell<Executors>> {
|
||||||
let mut num_executors = message.account_keys.len();
|
let mut num_executors = message.account_keys.len();
|
||||||
for instruction_loaders in loaders.iter() {
|
for instruction_loaders in loaders.iter() {
|
||||||
|
@ -3352,7 +3355,7 @@ impl Bank {
|
||||||
fn run_incinerator(&self) {
|
fn run_incinerator(&self) {
|
||||||
if let Some((account, _)) = self.get_account_modified_since_parent(&incinerator::id()) {
|
if let Some((account, _)) = self.get_account_modified_since_parent(&incinerator::id()) {
|
||||||
self.capitalization.fetch_sub(account.lamports, Relaxed);
|
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)
|
self.process_transaction(&tx).map(|_| signature)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_balance(account: &Account) -> u64 {
|
pub fn read_balance(account: &AccountSharedData) -> u64 {
|
||||||
account.lamports
|
account.lamports
|
||||||
}
|
}
|
||||||
/// Each program would need to be able to introspect its own state
|
/// Each program would need to be able to introspect its own state
|
||||||
|
@ -3838,7 +3841,7 @@ impl Bank {
|
||||||
parents
|
parents
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn store_account(&self, pubkey: &Pubkey, account: &Account) {
|
pub fn store_account(&self, pubkey: &Pubkey, account: &AccountSharedData) {
|
||||||
assert!(!self.freeze_started());
|
assert!(!self.freeze_started());
|
||||||
self.rc
|
self.rc
|
||||||
.accounts
|
.accounts
|
||||||
|
@ -3872,7 +3875,11 @@ impl Bank {
|
||||||
self.rc.accounts.accounts_db.expire_old_recycle_stores()
|
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) {
|
if let Some(old_account) = self.get_account(&pubkey) {
|
||||||
match new_account.lamports.cmp(&old_account.lamports) {
|
match new_account.lamports.cmp(&old_account.lamports) {
|
||||||
std::cmp::Ordering::Greater => {
|
std::cmp::Ordering::Greater => {
|
||||||
|
@ -3969,12 +3976,12 @@ impl Bank {
|
||||||
self.hard_forks.clone()
|
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)
|
self.get_account_modified_slot(pubkey)
|
||||||
.map(|(acc, _slot)| acc)
|
.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)
|
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.
|
// multiple times with the same parent_slot in the case of forking.
|
||||||
//
|
//
|
||||||
// Generally, all of sysvar update granularity should be slot boundaries.
|
// 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();
|
let mut ancestors = self.ancestors.clone();
|
||||||
ancestors.remove(&self.slot());
|
ancestors.remove(&self.slot());
|
||||||
self.rc
|
self.rc
|
||||||
|
@ -3994,40 +4001,40 @@ impl Bank {
|
||||||
.map(|(acc, _slot)| acc)
|
.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
|
self.rc
|
||||||
.accounts
|
.accounts
|
||||||
.load_by_program(&self.ancestors, program_id)
|
.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,
|
&self,
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
filter: F,
|
filter: F,
|
||||||
) -> Vec<(Pubkey, Account)> {
|
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||||
self.rc
|
self.rc
|
||||||
.accounts
|
.accounts
|
||||||
.load_by_program_with_filter(&self.ancestors, program_id, filter)
|
.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,
|
&self,
|
||||||
index_key: &IndexKey,
|
index_key: &IndexKey,
|
||||||
filter: F,
|
filter: F,
|
||||||
) -> Vec<(Pubkey, Account)> {
|
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||||
self.rc
|
self.rc
|
||||||
.accounts
|
.accounts
|
||||||
.load_by_index_key_with_filter(&self.ancestors, index_key, filter)
|
.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)
|
self.rc.accounts.load_all(&self.ancestors)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_program_accounts_modified_since_parent(
|
pub fn get_program_accounts_modified_since_parent(
|
||||||
&self,
|
&self,
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
) -> Vec<(Pubkey, Account)> {
|
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||||
self.rc
|
self.rc
|
||||||
.accounts
|
.accounts
|
||||||
.load_by_program_slot(self.slot(), Some(program_id))
|
.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)
|
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();
|
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 let Some((account, slot)) = self.rc.accounts.load_slow(&just_self, pubkey) {
|
||||||
if slot == self.slot() {
|
if slot == self.slot() {
|
||||||
|
@ -4765,7 +4775,7 @@ impl Bank {
|
||||||
// Clear new token account
|
// Clear new token account
|
||||||
self.store_account(
|
self.store_account(
|
||||||
&inline_spl_token_v2_0::new_token_program::id(),
|
&inline_spl_token_v2_0::new_token_program::id(),
|
||||||
&Account::default(),
|
&AccountSharedData::default(),
|
||||||
);
|
);
|
||||||
|
|
||||||
self.remove_executor(&inline_spl_token_v2_0::id());
|
self.remove_executor(&inline_spl_token_v2_0::id());
|
||||||
|
@ -4815,7 +4825,7 @@ impl Bank {
|
||||||
};
|
};
|
||||||
|
|
||||||
if reconfigure_token2_native_mint {
|
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(),
|
owner: inline_spl_token_v2_0::id(),
|
||||||
data: inline_spl_token_v2_0::native_mint::ACCOUNT_DATA.to_vec(),
|
data: inline_spl_token_v2_0::native_mint::ACCOUNT_DATA.to_vec(),
|
||||||
lamports: sol_to_lamports(1.),
|
lamports: sol_to_lamports(1.),
|
||||||
|
@ -4952,6 +4962,7 @@ pub(crate) mod tests {
|
||||||
};
|
};
|
||||||
use crossbeam_channel::bounded;
|
use crossbeam_channel::bounded;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
|
account::Account,
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
clock::{DEFAULT_SLOTS_PER_EPOCH, DEFAULT_TICKS_PER_SLOT},
|
clock::{DEFAULT_SLOTS_PER_EPOCH, DEFAULT_TICKS_PER_SLOT},
|
||||||
epoch_schedule::MINIMUM_SLOTS_PER_EPOCH,
|
epoch_schedule::MINIMUM_SLOTS_PER_EPOCH,
|
||||||
|
@ -4993,7 +5004,7 @@ pub(crate) mod tests {
|
||||||
blockhash: Hash::new_unique(),
|
blockhash: Hash::new_unique(),
|
||||||
fee_calculator: fee_calculator.clone(),
|
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
|
// NonceRollbackPartial create + NonceRollbackInfo impl
|
||||||
let partial = NonceRollbackPartial::new(nonce_address, nonce_account.clone());
|
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 message = Message::new(&instructions, Some(&from_address));
|
||||||
|
|
||||||
let from_account = Account::new(44, 0, &Pubkey::default());
|
let from_account = AccountSharedData::new(44, 0, &Pubkey::default());
|
||||||
let to_account = Account::new(45, 0, &Pubkey::default());
|
let to_account = AccountSharedData::new(45, 0, &Pubkey::default());
|
||||||
let recent_blockhashes_sysvar_account = Account::new(4, 0, &Pubkey::default());
|
let recent_blockhashes_sysvar_account = AccountSharedData::new(4, 0, &Pubkey::default());
|
||||||
let accounts = [
|
let accounts = [
|
||||||
from_account.clone(),
|
from_account.clone(),
|
||||||
nonce_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_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.burn_percent, 5);
|
||||||
assert_eq!(rent.exemption_threshold, 1.2);
|
assert_eq!(rent.exemption_threshold, 1.2);
|
||||||
|
@ -5240,12 +5251,12 @@ pub(crate) mod tests {
|
||||||
assert_eq!(bank.last_blockhash(), genesis_config.hash());
|
assert_eq!(bank.last_blockhash(), genesis_config.hash());
|
||||||
|
|
||||||
// Initialize credit-debit and credit only accounts
|
// Initialize credit-debit and credit only accounts
|
||||||
let account1 = Account::new(264, 0, &Pubkey::default());
|
let account1 = AccountSharedData::new(264, 0, &Pubkey::default());
|
||||||
let account2 = Account::new(264, 1, &Pubkey::default());
|
let account2 = AccountSharedData::new(264, 1, &Pubkey::default());
|
||||||
let account3 = Account::new(264, 0, &Pubkey::default());
|
let account3 = AccountSharedData::new(264, 0, &Pubkey::default());
|
||||||
let account4 = Account::new(264, 1, &Pubkey::default());
|
let account4 = AccountSharedData::new(264, 1, &Pubkey::default());
|
||||||
let account5 = Account::new(10, 0, &Pubkey::default());
|
let account5 = AccountSharedData::new(10, 0, &Pubkey::default());
|
||||||
let account6 = Account::new(10, 1, &Pubkey::default());
|
let account6 = AccountSharedData::new(10, 1, &Pubkey::default());
|
||||||
|
|
||||||
bank.store_account(&keypair1.pubkey(), &account1);
|
bank.store_account(&keypair1.pubkey(), &account1);
|
||||||
bank.store_account(&keypair2.pubkey(), &account2);
|
bank.store_account(&keypair2.pubkey(), &account2);
|
||||||
|
@ -5359,10 +5370,11 @@ pub(crate) mod tests {
|
||||||
mock_program_id: Pubkey,
|
mock_program_id: Pubkey,
|
||||||
generic_rent_due_for_system_account: u64,
|
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((
|
account_pairs.push((
|
||||||
keypairs[0].pubkey(),
|
keypairs[0].pubkey(),
|
||||||
Account::new(
|
AccountSharedData::new(
|
||||||
generic_rent_due_for_system_account + 2,
|
generic_rent_due_for_system_account + 2,
|
||||||
0,
|
0,
|
||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
|
@ -5370,7 +5382,7 @@ pub(crate) mod tests {
|
||||||
));
|
));
|
||||||
account_pairs.push((
|
account_pairs.push((
|
||||||
keypairs[1].pubkey(),
|
keypairs[1].pubkey(),
|
||||||
Account::new(
|
AccountSharedData::new(
|
||||||
generic_rent_due_for_system_account + 2,
|
generic_rent_due_for_system_account + 2,
|
||||||
0,
|
0,
|
||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
|
@ -5378,7 +5390,7 @@ pub(crate) mod tests {
|
||||||
));
|
));
|
||||||
account_pairs.push((
|
account_pairs.push((
|
||||||
keypairs[2].pubkey(),
|
keypairs[2].pubkey(),
|
||||||
Account::new(
|
AccountSharedData::new(
|
||||||
generic_rent_due_for_system_account + 2,
|
generic_rent_due_for_system_account + 2,
|
||||||
0,
|
0,
|
||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
|
@ -5386,7 +5398,7 @@ pub(crate) mod tests {
|
||||||
));
|
));
|
||||||
account_pairs.push((
|
account_pairs.push((
|
||||||
keypairs[3].pubkey(),
|
keypairs[3].pubkey(),
|
||||||
Account::new(
|
AccountSharedData::new(
|
||||||
generic_rent_due_for_system_account + 2,
|
generic_rent_due_for_system_account + 2,
|
||||||
0,
|
0,
|
||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
|
@ -5394,15 +5406,15 @@ pub(crate) mod tests {
|
||||||
));
|
));
|
||||||
account_pairs.push((
|
account_pairs.push((
|
||||||
keypairs[4].pubkey(),
|
keypairs[4].pubkey(),
|
||||||
Account::new(10, 0, &Pubkey::default()),
|
AccountSharedData::new(10, 0, &Pubkey::default()),
|
||||||
));
|
));
|
||||||
account_pairs.push((
|
account_pairs.push((
|
||||||
keypairs[5].pubkey(),
|
keypairs[5].pubkey(),
|
||||||
Account::new(10, 0, &Pubkey::default()),
|
AccountSharedData::new(10, 0, &Pubkey::default()),
|
||||||
));
|
));
|
||||||
account_pairs.push((
|
account_pairs.push((
|
||||||
keypairs[6].pubkey(),
|
keypairs[6].pubkey(),
|
||||||
Account::new(
|
AccountSharedData::new(
|
||||||
(2 * generic_rent_due_for_system_account) + 24,
|
(2 * generic_rent_due_for_system_account) + 24,
|
||||||
0,
|
0,
|
||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
|
@ -5411,7 +5423,7 @@ pub(crate) mod tests {
|
||||||
|
|
||||||
account_pairs.push((
|
account_pairs.push((
|
||||||
keypairs[8].pubkey(),
|
keypairs[8].pubkey(),
|
||||||
Account::new(
|
AccountSharedData::new(
|
||||||
generic_rent_due_for_system_account + 2 + 929,
|
generic_rent_due_for_system_account + 2 + 929,
|
||||||
0,
|
0,
|
||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
|
@ -5419,13 +5431,13 @@ pub(crate) mod tests {
|
||||||
));
|
));
|
||||||
account_pairs.push((
|
account_pairs.push((
|
||||||
keypairs[9].pubkey(),
|
keypairs[9].pubkey(),
|
||||||
Account::new(10, 0, &Pubkey::default()),
|
AccountSharedData::new(10, 0, &Pubkey::default()),
|
||||||
));
|
));
|
||||||
|
|
||||||
// Feeding to MockProgram to test read only rent behaviour
|
// Feeding to MockProgram to test read only rent behaviour
|
||||||
account_pairs.push((
|
account_pairs.push((
|
||||||
keypairs[10].pubkey(),
|
keypairs[10].pubkey(),
|
||||||
Account::new(
|
AccountSharedData::new(
|
||||||
generic_rent_due_for_system_account + 3,
|
generic_rent_due_for_system_account + 3,
|
||||||
0,
|
0,
|
||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
|
@ -5433,15 +5445,15 @@ pub(crate) mod tests {
|
||||||
));
|
));
|
||||||
account_pairs.push((
|
account_pairs.push((
|
||||||
keypairs[11].pubkey(),
|
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((
|
account_pairs.push((
|
||||||
keypairs[12].pubkey(),
|
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((
|
account_pairs.push((
|
||||||
keypairs[13].pubkey(),
|
keypairs[13].pubkey(),
|
||||||
Account::new(14, 22, &mock_program_id),
|
AccountSharedData::new(14, 22, &mock_program_id),
|
||||||
));
|
));
|
||||||
|
|
||||||
for account_pair in account_pairs.iter() {
|
for account_pair in account_pairs.iter() {
|
||||||
|
@ -5497,7 +5509,7 @@ pub(crate) mod tests {
|
||||||
let pubkey = solana_sdk::pubkey::new_rand();
|
let pubkey = solana_sdk::pubkey::new_rand();
|
||||||
|
|
||||||
let some_lamports = 400;
|
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(
|
assert_capitalization_diff(
|
||||||
&bank,
|
&bank,
|
||||||
|
@ -5515,7 +5527,7 @@ pub(crate) mod tests {
|
||||||
let pubkey = mint_keypair.pubkey();
|
let pubkey = mint_keypair.pubkey();
|
||||||
|
|
||||||
let new_lamports = 500;
|
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(
|
assert_capitalization_diff(
|
||||||
&bank,
|
&bank,
|
||||||
|
@ -5533,7 +5545,7 @@ pub(crate) mod tests {
|
||||||
let pubkey = mint_keypair.pubkey();
|
let pubkey = mint_keypair.pubkey();
|
||||||
|
|
||||||
let new_lamports = 100;
|
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(
|
assert_capitalization_diff(
|
||||||
&bank,
|
&bank,
|
||||||
|
@ -5550,7 +5562,7 @@ pub(crate) mod tests {
|
||||||
let bank = Bank::new(&genesis_config);
|
let bank = Bank::new(&genesis_config);
|
||||||
let pubkey = mint_keypair.pubkey();
|
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(
|
assert_capitalization_diff(
|
||||||
&bank,
|
&bank,
|
||||||
|
@ -5613,11 +5625,11 @@ pub(crate) mod tests {
|
||||||
);
|
);
|
||||||
genesis_config.accounts.insert(
|
genesis_config.accounts.insert(
|
||||||
validator_1_staking_keypair.pubkey(),
|
validator_1_staking_keypair.pubkey(),
|
||||||
validator_1_stake_account,
|
Account::from(validator_1_stake_account),
|
||||||
);
|
);
|
||||||
genesis_config.accounts.insert(
|
genesis_config.accounts.insert(
|
||||||
validator_1_voting_keypair.pubkey(),
|
validator_1_voting_keypair.pubkey(),
|
||||||
validator_1_vote_account,
|
Account::from(validator_1_vote_account),
|
||||||
);
|
);
|
||||||
|
|
||||||
let validator_2_pubkey = solana_sdk::pubkey::new_rand();
|
let validator_2_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
|
@ -5646,11 +5658,11 @@ pub(crate) mod tests {
|
||||||
);
|
);
|
||||||
genesis_config.accounts.insert(
|
genesis_config.accounts.insert(
|
||||||
validator_2_staking_keypair.pubkey(),
|
validator_2_staking_keypair.pubkey(),
|
||||||
validator_2_stake_account,
|
Account::from(validator_2_stake_account),
|
||||||
);
|
);
|
||||||
genesis_config.accounts.insert(
|
genesis_config.accounts.insert(
|
||||||
validator_2_voting_keypair.pubkey(),
|
validator_2_voting_keypair.pubkey(),
|
||||||
validator_2_vote_account,
|
Account::from(validator_2_vote_account),
|
||||||
);
|
);
|
||||||
|
|
||||||
let validator_3_pubkey = solana_sdk::pubkey::new_rand();
|
let validator_3_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
|
@ -5679,11 +5691,11 @@ pub(crate) mod tests {
|
||||||
);
|
);
|
||||||
genesis_config.accounts.insert(
|
genesis_config.accounts.insert(
|
||||||
validator_3_staking_keypair.pubkey(),
|
validator_3_staking_keypair.pubkey(),
|
||||||
validator_3_stake_account,
|
Account::from(validator_3_stake_account),
|
||||||
);
|
);
|
||||||
genesis_config.accounts.insert(
|
genesis_config.accounts.insert(
|
||||||
validator_3_voting_keypair.pubkey(),
|
validator_3_voting_keypair.pubkey(),
|
||||||
validator_3_vote_account,
|
Account::from(validator_3_vote_account),
|
||||||
);
|
);
|
||||||
|
|
||||||
genesis_config.rent = Rent {
|
genesis_config.rent = Rent {
|
||||||
|
@ -5699,11 +5711,11 @@ pub(crate) mod tests {
|
||||||
bank.rent_collector.slots_per_year = 192.0;
|
bank.rent_collector.slots_per_year = 192.0;
|
||||||
|
|
||||||
let payer = Keypair::new();
|
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);
|
bank.store_account_and_update_capitalization(&payer.pubkey(), &payer_account);
|
||||||
|
|
||||||
let payee = Keypair::new();
|
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);
|
bank.store_account_and_update_capitalization(&payee.pubkey(), &payee_account);
|
||||||
|
|
||||||
let bootstrap_validator_initial_balance = bank.get_balance(&bootstrap_validator_pubkey);
|
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_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let account_balance = 1;
|
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;
|
account.executable = true;
|
||||||
bank.store_account(&account_pubkey, &account);
|
bank.store_account(&account_pubkey, &account);
|
||||||
|
|
||||||
|
@ -6710,15 +6723,15 @@ pub(crate) mod tests {
|
||||||
|
|
||||||
bank.store_account(
|
bank.store_account(
|
||||||
&zero_lamport_pubkey,
|
&zero_lamport_pubkey,
|
||||||
&Account::new(zero_lamports, 0, &Pubkey::default()),
|
&AccountSharedData::new(zero_lamports, 0, &Pubkey::default()),
|
||||||
);
|
);
|
||||||
bank.store_account(
|
bank.store_account(
|
||||||
&rent_due_pubkey,
|
&rent_due_pubkey,
|
||||||
&Account::new(little_lamports, 0, &Pubkey::default()),
|
&AccountSharedData::new(little_lamports, 0, &Pubkey::default()),
|
||||||
);
|
);
|
||||||
bank.store_account(
|
bank.store_account(
|
||||||
&rent_exempt_pubkey,
|
&rent_exempt_pubkey,
|
||||||
&Account::new(large_lamports, 0, &Pubkey::default()),
|
&AccountSharedData::new(large_lamports, 0, &Pubkey::default()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let genesis_slot = 0;
|
let genesis_slot = 0;
|
||||||
|
@ -6788,7 +6801,7 @@ pub(crate) mod tests {
|
||||||
let bank1_without_zero = Arc::new(new_from_parent(&genesis_bank2));
|
let bank1_without_zero = Arc::new(new_from_parent(&genesis_bank2));
|
||||||
let zero_lamports = 0;
|
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_with_zero.store_account(&zero_lamport_pubkey, &account);
|
||||||
bank1_without_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
|
let rewards = bank1
|
||||||
.get_account(&sysvar::rewards::id())
|
.get_account(&sysvar::rewards::id())
|
||||||
.map(|account| from_account::<Rewards>(&account).unwrap())
|
.map(|account| from_account::<Rewards, _>(&account).unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// verify the stake and vote accounts are the right size
|
// 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 min_balance = bank.get_minimum_balance_for_rent_exemption(nonce::State::size());
|
||||||
let nonce = Keypair::new();
|
let nonce = Keypair::new();
|
||||||
let nonce_account = Account::new_data(
|
let nonce_account = AccountSharedData::new_data(
|
||||||
min_balance + 42,
|
min_balance + 42,
|
||||||
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
||||||
nonce::state::Data::default(),
|
nonce::state::Data::default(),
|
||||||
|
@ -8235,7 +8248,7 @@ pub(crate) mod tests {
|
||||||
let current_account = bank1.get_account(&dummy_clock_id).unwrap();
|
let current_account = bank1.get_account(&dummy_clock_id).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
expected_previous_slot,
|
expected_previous_slot,
|
||||||
from_account::<Clock>(¤t_account).unwrap().slot
|
from_account::<Clock, _>(¤t_account).unwrap().slot
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|old, new| {
|
|old, new| {
|
||||||
|
@ -8275,7 +8288,7 @@ pub(crate) mod tests {
|
||||||
&bank2,
|
&bank2,
|
||||||
|| {
|
|| {
|
||||||
bank2.update_sysvar_account(&dummy_clock_id, |optional_account| {
|
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()
|
.unwrap()
|
||||||
.slot
|
.slot
|
||||||
+ 1;
|
+ 1;
|
||||||
|
@ -8291,7 +8304,7 @@ pub(crate) mod tests {
|
||||||
let current_account = bank2.get_account(&dummy_clock_id).unwrap();
|
let current_account = bank2.get_account(&dummy_clock_id).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
expected_next_slot,
|
expected_next_slot,
|
||||||
from_account::<Clock>(¤t_account).unwrap().slot
|
from_account::<Clock, _>(¤t_account).unwrap().slot
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|old, new| {
|
|old, new| {
|
||||||
|
@ -8306,7 +8319,7 @@ pub(crate) mod tests {
|
||||||
&bank2,
|
&bank2,
|
||||||
|| {
|
|| {
|
||||||
bank2.update_sysvar_account(&dummy_clock_id, |optional_account| {
|
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()
|
.unwrap()
|
||||||
.slot
|
.slot
|
||||||
+ 1;
|
+ 1;
|
||||||
|
@ -8322,7 +8335,7 @@ pub(crate) mod tests {
|
||||||
let current_account = bank2.get_account(&dummy_clock_id).unwrap();
|
let current_account = bank2.get_account(&dummy_clock_id).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
expected_next_slot,
|
expected_next_slot,
|
||||||
from_account::<Clock>(¤t_account).unwrap().slot
|
from_account::<Clock, _>(¤t_account).unwrap().slot
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|old, new| {
|
|old, new| {
|
||||||
|
@ -8685,7 +8698,7 @@ pub(crate) mod tests {
|
||||||
let bank = Arc::new(Bank::new(&genesis_config));
|
let bank = Arc::new(Bank::new(&genesis_config));
|
||||||
|
|
||||||
let fees_account = bank.get_account(&sysvar::fees::id()).unwrap();
|
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!(
|
assert_eq!(
|
||||||
bank.fee_calculator.lamports_per_signature,
|
bank.fee_calculator.lamports_per_signature,
|
||||||
fees.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 bank0 = Arc::new(new_from_parent(&parent));
|
||||||
let pubkey0 = solana_sdk::pubkey::new_rand();
|
let pubkey0 = solana_sdk::pubkey::new_rand();
|
||||||
let program_id = Pubkey::new(&[2; 32]);
|
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);
|
bank0.store_account(&pubkey0, &account0);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -8776,11 +8789,11 @@ pub(crate) mod tests {
|
||||||
|
|
||||||
let bank2 = Arc::new(new_from_parent(&bank1));
|
let bank2 = Arc::new(new_from_parent(&bank1));
|
||||||
let pubkey1 = solana_sdk::pubkey::new_rand();
|
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);
|
bank2.store_account(&pubkey1, &account1);
|
||||||
// Accounts with 0 lamports should be filtered out by Accounts::load_by_program()
|
// Accounts with 0 lamports should be filtered out by Accounts::load_by_program()
|
||||||
let pubkey2 = solana_sdk::pubkey::new_rand();
|
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);
|
bank2.store_account(&pubkey2, &account2);
|
||||||
|
|
||||||
let bank3 = Arc::new(new_from_parent(&bank2));
|
let bank3 = Arc::new(new_from_parent(&bank2));
|
||||||
|
@ -8802,7 +8815,7 @@ pub(crate) mod tests {
|
||||||
|
|
||||||
let address = Pubkey::new_unique();
|
let address = Pubkey::new_unique();
|
||||||
let program_id = 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);
|
bank.store_account(&address, &account);
|
||||||
|
|
||||||
let indexed_accounts =
|
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
|
// it is still present in the index under the original program id as well. This
|
||||||
// demonstrates the need for a redundant post-processing filter.
|
// demonstrates the need for a redundant post-processing filter.
|
||||||
let another_program_id = Pubkey::new_unique();
|
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));
|
let bank = Arc::new(new_from_parent(&bank));
|
||||||
bank.store_account(&address, &new_account);
|
bank.store_account(&address, &new_account);
|
||||||
let indexed_accounts =
|
let indexed_accounts =
|
||||||
|
@ -9042,7 +9055,7 @@ pub(crate) mod tests {
|
||||||
for i in 1..5 {
|
for i in 1..5 {
|
||||||
let bhq_account = bank.get_account(&sysvar::recent_blockhashes::id()).unwrap();
|
let bhq_account = bank.get_account(&sysvar::recent_blockhashes::id()).unwrap();
|
||||||
let recent_blockhashes =
|
let recent_blockhashes =
|
||||||
from_account::<sysvar::recent_blockhashes::RecentBlockhashes>(&bhq_account)
|
from_account::<sysvar::recent_blockhashes::RecentBlockhashes, _>(&bhq_account)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// Check length
|
// Check length
|
||||||
assert_eq!(recent_blockhashes.len(), i);
|
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 bhq_account = bank.get_account(&sysvar::recent_blockhashes::id()).unwrap();
|
||||||
let recent_blockhashes =
|
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 sysvar_recent_blockhash = recent_blockhashes[0].blockhash;
|
||||||
let bank_last_blockhash = bank.last_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 (genesis_config, _mint_keypair) = create_genesis_config(100_000_000);
|
||||||
let bank = Arc::new(Bank::new(&genesis_config));
|
let bank = Arc::new(Bank::new(&genesis_config));
|
||||||
let nonce = Keypair::new();
|
let nonce = Keypair::new();
|
||||||
let nonce_account = Account::new_data(
|
let nonce_account = AccountSharedData::new_data(
|
||||||
42_424_242,
|
42_424_242,
|
||||||
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
||||||
nonce::state::Data::default(),
|
nonce::state::Data::default(),
|
||||||
|
@ -9606,9 +9619,9 @@ pub(crate) mod tests {
|
||||||
let pubkey0 = solana_sdk::pubkey::new_rand();
|
let pubkey0 = solana_sdk::pubkey::new_rand();
|
||||||
let pubkey1 = solana_sdk::pubkey::new_rand();
|
let pubkey1 = solana_sdk::pubkey::new_rand();
|
||||||
let program_id = Pubkey::new(&[2; 32]);
|
let program_id = Pubkey::new(&[2; 32]);
|
||||||
let keypair_account = Account::new(8, 0, &program_id);
|
let keypair_account = AccountSharedData::new(8, 0, &program_id);
|
||||||
let account0 = Account::new(11, 0, &program_id);
|
let account0 = AccountSharedData::new(11, 0, &program_id);
|
||||||
let program_account = Account::new(1, 10, &Pubkey::default());
|
let program_account = AccountSharedData::new(1, 10, &Pubkey::default());
|
||||||
bank0.store_account(&keypair.pubkey(), &keypair_account);
|
bank0.store_account(&keypair.pubkey(), &keypair_account);
|
||||||
bank0.store_account(&pubkey0, &account0);
|
bank0.store_account(&pubkey0, &account0);
|
||||||
bank0.store_account(&program_id, &program_account);
|
bank0.store_account(&program_id, &program_account);
|
||||||
|
@ -9658,9 +9671,9 @@ pub(crate) mod tests {
|
||||||
let pubkey0 = solana_sdk::pubkey::new_rand();
|
let pubkey0 = solana_sdk::pubkey::new_rand();
|
||||||
let pubkey1 = solana_sdk::pubkey::new_rand();
|
let pubkey1 = solana_sdk::pubkey::new_rand();
|
||||||
let pubkey2 = solana_sdk::pubkey::new_rand();
|
let pubkey2 = solana_sdk::pubkey::new_rand();
|
||||||
let keypair0_account = Account::new(8, 0, &Pubkey::default());
|
let keypair0_account = AccountSharedData::new(8, 0, &Pubkey::default());
|
||||||
let keypair1_account = Account::new(9, 0, &Pubkey::default());
|
let keypair1_account = AccountSharedData::new(9, 0, &Pubkey::default());
|
||||||
let account0 = Account::new(11, 0, &&Pubkey::default());
|
let account0 = AccountSharedData::new(11, 0, &&Pubkey::default());
|
||||||
bank0.store_account(&keypair0.pubkey(), &keypair0_account);
|
bank0.store_account(&keypair0.pubkey(), &keypair0_account);
|
||||||
bank0.store_account(&keypair1.pubkey(), &keypair1_account);
|
bank0.store_account(&keypair1.pubkey(), &keypair1_account);
|
||||||
bank0.store_account(&pubkey0, &account0);
|
bank0.store_account(&pubkey0, &account0);
|
||||||
|
@ -9735,8 +9748,8 @@ pub(crate) mod tests {
|
||||||
let from_pubkey = solana_sdk::pubkey::new_rand();
|
let from_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let to_pubkey = solana_sdk::pubkey::new_rand();
|
let to_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let dup_pubkey = from_pubkey;
|
let dup_pubkey = from_pubkey;
|
||||||
let from_account = Account::new(100, 1, &mock_program_id);
|
let from_account = AccountSharedData::new(100, 1, &mock_program_id);
|
||||||
let to_account = Account::new(0, 1, &mock_program_id);
|
let to_account = AccountSharedData::new(0, 1, &mock_program_id);
|
||||||
bank.store_account(&from_pubkey, &from_account);
|
bank.store_account(&from_pubkey, &from_account);
|
||||||
bank.store_account(&to_pubkey, &to_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 from_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let to_pubkey = solana_sdk::pubkey::new_rand();
|
let to_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let dup_pubkey = from_pubkey;
|
let dup_pubkey = from_pubkey;
|
||||||
let from_account = Account::new(100, 1, &mock_program_id);
|
let from_account = AccountSharedData::new(100, 1, &mock_program_id);
|
||||||
let to_account = Account::new(0, 1, &mock_program_id);
|
let to_account = AccountSharedData::new(0, 1, &mock_program_id);
|
||||||
bank.store_account(&from_pubkey, &from_account);
|
bank.store_account(&from_pubkey, &from_account);
|
||||||
bank.store_account(&to_pubkey, &to_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 space = thread_rng().gen_range(0, 10);
|
||||||
let owner = Pubkey::default();
|
let owner = Pubkey::default();
|
||||||
let account = Account::new(lamports, space, &owner);
|
let account = AccountSharedData::new(lamports, space, &owner);
|
||||||
bank.store_account(&key, &account);
|
bank.store_account(&key, &account);
|
||||||
lamports
|
lamports
|
||||||
} else {
|
} else {
|
||||||
|
@ -10160,7 +10173,7 @@ pub(crate) mod tests {
|
||||||
let mut genesis_config = GenesisConfig::new(
|
let mut genesis_config = GenesisConfig::new(
|
||||||
&[(
|
&[(
|
||||||
Pubkey::new(&[42; 32]),
|
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
|
// Add a new program owned by the first
|
||||||
let program2_pubkey = solana_sdk::pubkey::new_rand();
|
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;
|
program2_account.executable = true;
|
||||||
bank.store_account(&program2_pubkey, &program2_account);
|
bank.store_account(&program2_pubkey, &program2_account);
|
||||||
|
|
||||||
|
@ -10283,7 +10296,7 @@ pub(crate) mod tests {
|
||||||
|
|
||||||
let pubkey0_size = get_shrink_account_size();
|
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);
|
bank0.store_account(&pubkey0, &account0);
|
||||||
|
|
||||||
goto_end_of_slot(Arc::<Bank>::get_mut(&mut bank0).unwrap());
|
goto_end_of_slot(Arc::<Bank>::get_mut(&mut bank0).unwrap());
|
||||||
|
@ -10909,8 +10922,11 @@ pub(crate) mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
let loaders = &[
|
let loaders = &[
|
||||||
vec![(key3, Account::default()), (key4, Account::default())],
|
vec![
|
||||||
vec![(key1, Account::default())],
|
(key3, AccountSharedData::default()),
|
||||||
|
(key4, AccountSharedData::default()),
|
||||||
|
],
|
||||||
|
vec![(key1, AccountSharedData::default())],
|
||||||
];
|
];
|
||||||
|
|
||||||
// don't do any work if not dirty
|
// don't do any work if not dirty
|
||||||
|
@ -10972,7 +10988,10 @@ pub(crate) mod tests {
|
||||||
let key2 = solana_sdk::pubkey::new_rand();
|
let key2 = solana_sdk::pubkey::new_rand();
|
||||||
let executor: Arc<dyn Executor> = Arc::new(TestExecutor {});
|
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
|
// add one to root bank
|
||||||
let mut executors = Executors::default();
|
let mut executors = Executors::default();
|
||||||
|
@ -11071,19 +11090,19 @@ pub(crate) mod tests {
|
||||||
// Setup original token account
|
// Setup original token account
|
||||||
bank.store_account_and_update_capitalization(
|
bank.store_account_and_update_capitalization(
|
||||||
&inline_spl_token_v2_0::id(),
|
&inline_spl_token_v2_0::id(),
|
||||||
&Account {
|
&AccountSharedData {
|
||||||
lamports: 100,
|
lamports: 100,
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
assert_eq!(bank.get_balance(&inline_spl_token_v2_0::id()), 100);
|
assert_eq!(bank.get_balance(&inline_spl_token_v2_0::id()), 100);
|
||||||
|
|
||||||
// Setup new token account
|
// Setup new token account
|
||||||
let new_token_account = Account {
|
let new_token_account = AccountSharedData {
|
||||||
lamports: 123,
|
lamports: 123,
|
||||||
data: vec![1, 2, 3],
|
data: vec![1, 2, 3],
|
||||||
executable: true,
|
executable: true,
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
};
|
};
|
||||||
bank.store_account_and_update_capitalization(
|
bank.store_account_and_update_capitalization(
|
||||||
&inline_spl_token_v2_0::new_token_program::id(),
|
&inline_spl_token_v2_0::new_token_program::id(),
|
||||||
|
@ -11138,12 +11157,12 @@ pub(crate) mod tests {
|
||||||
// inhibit deprecated rewards sysvar creation altogether
|
// inhibit deprecated rewards sysvar creation altogether
|
||||||
genesis_config.accounts.insert(
|
genesis_config.accounts.insert(
|
||||||
feature_set::deprecate_rewards_sysvar::id(),
|
feature_set::deprecate_rewards_sysvar::id(),
|
||||||
feature::create_account(
|
Account::from(feature::create_account(
|
||||||
&Feature {
|
&Feature {
|
||||||
activated_at: Some(0),
|
activated_at: Some(0),
|
||||||
},
|
},
|
||||||
feature_balance,
|
feature_balance,
|
||||||
),
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
let bank0 = Bank::new(&genesis_config);
|
let bank0 = Bank::new(&genesis_config);
|
||||||
|
@ -11591,7 +11610,7 @@ pub(crate) mod tests {
|
||||||
.collect();
|
.collect();
|
||||||
let program_id = system_program::id();
|
let program_id = system_program::id();
|
||||||
let starting_lamports = 1;
|
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
|
// Write accounts to the store
|
||||||
for key in &all_pubkeys {
|
for key in &all_pubkeys {
|
||||||
|
@ -11696,7 +11715,7 @@ pub(crate) mod tests {
|
||||||
&solana_sdk::pubkey::new_rand(),
|
&solana_sdk::pubkey::new_rand(),
|
||||||
current_minor_fork_bank.slot() + 2,
|
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
|
// 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.
|
// get cleaned up, there will be keys with the wrong account value/missing.
|
||||||
for key in pubkeys_to_modify {
|
for key in pubkeys_to_modify {
|
||||||
|
@ -11722,7 +11741,7 @@ pub(crate) mod tests {
|
||||||
current_minor_fork_bank.slot() - 1,
|
current_minor_fork_bank.slot() - 1,
|
||||||
));
|
));
|
||||||
let lamports = current_major_fork_bank.slot() + starting_lamports + 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() {
|
for key in pubkeys_to_modify.iter() {
|
||||||
// Store rooted updates to these pubkeys such that the minor
|
// Store rooted updates to these pubkeys such that the minor
|
||||||
// fork updates to the same keys will be deleted by clean
|
// fork updates to the same keys will be deleted by clean
|
||||||
|
@ -11768,7 +11787,7 @@ pub(crate) mod tests {
|
||||||
let mut prev_bank = bank0;
|
let mut prev_bank = bank0;
|
||||||
loop {
|
loop {
|
||||||
let lamports_this_round = current_bank.slot() + starting_lamports + 1;
|
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() {
|
for key in pubkeys_to_modify.iter() {
|
||||||
current_bank.store_account(key, &account);
|
current_bank.store_account(key, &account);
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ impl SyncClient for BankClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_account(&self, pubkey: &Pubkey) -> Result<Option<Account>> {
|
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(
|
fn get_account_with_commitment(
|
||||||
|
@ -125,7 +125,7 @@ impl SyncClient for BankClient {
|
||||||
pubkey: &Pubkey,
|
pubkey: &Pubkey,
|
||||||
_commitment_config: CommitmentConfig,
|
_commitment_config: CommitmentConfig,
|
||||||
) -> Result<Option<Account>> {
|
) -> 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> {
|
fn get_balance(&self, pubkey: &Pubkey) -> Result<u64> {
|
||||||
|
|
|
@ -116,13 +116,13 @@ impl EpochStakes {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod tests {
|
pub(crate) mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::AccountSharedData;
|
||||||
use solana_vote_program::vote_state::create_account_with_authorized;
|
use solana_vote_program::vote_state::create_account_with_authorized;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
struct VoteAccountInfo {
|
struct VoteAccountInfo {
|
||||||
vote_account: Pubkey,
|
vote_account: Pubkey,
|
||||||
account: Account,
|
account: AccountSharedData,
|
||||||
authorized_voter: Pubkey,
|
authorized_voter: Pubkey,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::Account,
|
||||||
|
account::AccountSharedData,
|
||||||
feature::{self, Feature},
|
feature::{self, Feature},
|
||||||
feature_set::FeatureSet,
|
feature_set::FeatureSet,
|
||||||
fee_calculator::FeeRateGovernor,
|
fee_calculator::FeeRateGovernor,
|
||||||
|
@ -110,13 +111,15 @@ pub fn create_genesis_config_with_vote_accounts_and_cluster_type(
|
||||||
// Create accounts
|
// Create accounts
|
||||||
let node_account = Account::new(VALIDATOR_LAMPORTS, 0, &system_program::id());
|
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 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,
|
&stake_pubkey,
|
||||||
&vote_pubkey,
|
&vote_pubkey,
|
||||||
&vote_account,
|
&vote_account,
|
||||||
&genesis_config_info.genesis_config.rent,
|
&genesis_config_info.genesis_config.rent,
|
||||||
*stake,
|
*stake,
|
||||||
);
|
));
|
||||||
|
|
||||||
|
let vote_account = Account::from(vote_account);
|
||||||
|
|
||||||
// Put newly created accounts into genesis
|
// Put newly created accounts into genesis
|
||||||
genesis_config_info.genesis_config.accounts.extend(vec![
|
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 {
|
for feature_id in FeatureSet::default().inactive {
|
||||||
genesis_config.accounts.insert(
|
genesis_config.accounts.insert(
|
||||||
feature_id,
|
feature_id,
|
||||||
feature::create_account(
|
Account::from(feature::create_account(
|
||||||
&Feature {
|
&Feature {
|
||||||
activated_at: Some(0),
|
activated_at: Some(0),
|
||||||
},
|
},
|
||||||
std::cmp::max(genesis_config.rent.minimum_balance(Feature::size_of()), 1),
|
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,
|
fee_rate_governor: FeeRateGovernor,
|
||||||
rent: Rent,
|
rent: Rent,
|
||||||
cluster_type: ClusterType,
|
cluster_type: ClusterType,
|
||||||
mut initial_accounts: Vec<(Pubkey, Account)>,
|
mut initial_accounts: Vec<(Pubkey, AccountSharedData)>,
|
||||||
) -> GenesisConfig {
|
) -> GenesisConfig {
|
||||||
let validator_vote_account = vote_state::create_account(
|
let validator_vote_account = vote_state::create_account(
|
||||||
&validator_vote_account_pubkey,
|
&validator_vote_account_pubkey,
|
||||||
|
@ -204,17 +207,21 @@ pub fn create_genesis_config_with_leader_ex(
|
||||||
|
|
||||||
initial_accounts.push((
|
initial_accounts.push((
|
||||||
*mint_pubkey,
|
*mint_pubkey,
|
||||||
Account::new(mint_lamports, 0, &system_program::id()),
|
AccountSharedData::new(mint_lamports, 0, &system_program::id()),
|
||||||
));
|
));
|
||||||
initial_accounts.push((
|
initial_accounts.push((
|
||||||
*validator_pubkey,
|
*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_vote_account_pubkey, validator_vote_account));
|
||||||
initial_accounts.push((*validator_stake_account_pubkey, validator_stake_account));
|
initial_accounts.push((*validator_stake_account_pubkey, validator_stake_account));
|
||||||
|
|
||||||
let mut genesis_config = GenesisConfig {
|
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,
|
fee_rate_governor,
|
||||||
rent,
|
rent,
|
||||||
cluster_type,
|
cluster_type,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
use log::*;
|
use log::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
||||||
feature_set::{instructions_sysvar_enabled, track_writable_deescalation, FeatureSet},
|
feature_set::{instructions_sysvar_enabled, track_writable_deescalation, FeatureSet},
|
||||||
|
@ -83,11 +83,11 @@ impl ExecuteDetailsTimings {
|
||||||
pub struct PreAccount {
|
pub struct PreAccount {
|
||||||
key: Pubkey,
|
key: Pubkey,
|
||||||
is_writable: bool,
|
is_writable: bool,
|
||||||
account: RefCell<Account>,
|
account: RefCell<AccountSharedData>,
|
||||||
changed: bool,
|
changed: bool,
|
||||||
}
|
}
|
||||||
impl PreAccount {
|
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 {
|
Self {
|
||||||
key: *key,
|
key: *key,
|
||||||
is_writable,
|
is_writable,
|
||||||
|
@ -101,7 +101,7 @@ impl PreAccount {
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
is_writable: Option<bool>,
|
is_writable: Option<bool>,
|
||||||
rent: &Rent,
|
rent: &Rent,
|
||||||
post: &Account,
|
post: &AccountSharedData,
|
||||||
timings: &mut ExecuteDetailsTimings,
|
timings: &mut ExecuteDetailsTimings,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
let pre = self.account.borrow();
|
let pre = self.account.borrow();
|
||||||
|
@ -207,7 +207,7 @@ impl PreAccount {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, account: &Account) {
|
pub fn update(&mut self, account: &AccountSharedData) {
|
||||||
let mut pre = self.account.borrow_mut();
|
let mut pre = self.account.borrow_mut();
|
||||||
|
|
||||||
pre.lamports = account.lamports;
|
pre.lamports = account.lamports;
|
||||||
|
@ -262,7 +262,7 @@ pub struct ThisInvokeContext<'a> {
|
||||||
program_ids: Vec<Pubkey>,
|
program_ids: Vec<Pubkey>,
|
||||||
rent: Rent,
|
rent: Rent,
|
||||||
pre_accounts: Vec<PreAccount>,
|
pre_accounts: Vec<PreAccount>,
|
||||||
account_deps: &'a [(Pubkey, RefCell<Account>)],
|
account_deps: &'a [(Pubkey, RefCell<AccountSharedData>)],
|
||||||
programs: &'a [(Pubkey, ProcessInstructionWithContext)],
|
programs: &'a [(Pubkey, ProcessInstructionWithContext)],
|
||||||
logger: Rc<RefCell<dyn Logger>>,
|
logger: Rc<RefCell<dyn Logger>>,
|
||||||
bpf_compute_budget: BpfComputeBudget,
|
bpf_compute_budget: BpfComputeBudget,
|
||||||
|
@ -278,7 +278,7 @@ impl<'a> ThisInvokeContext<'a> {
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
rent: Rent,
|
rent: Rent,
|
||||||
pre_accounts: Vec<PreAccount>,
|
pre_accounts: Vec<PreAccount>,
|
||||||
account_deps: &'a [(Pubkey, RefCell<Account>)],
|
account_deps: &'a [(Pubkey, RefCell<AccountSharedData>)],
|
||||||
programs: &'a [(Pubkey, ProcessInstructionWithContext)],
|
programs: &'a [(Pubkey, ProcessInstructionWithContext)],
|
||||||
log_collector: Option<Rc<LogCollector>>,
|
log_collector: Option<Rc<LogCollector>>,
|
||||||
bpf_compute_budget: BpfComputeBudget,
|
bpf_compute_budget: BpfComputeBudget,
|
||||||
|
@ -328,7 +328,7 @@ impl<'a> InvokeContext for ThisInvokeContext<'a> {
|
||||||
&mut self,
|
&mut self,
|
||||||
message: &Message,
|
message: &Message,
|
||||||
instruction: &CompiledInstruction,
|
instruction: &CompiledInstruction,
|
||||||
accounts: &[Rc<RefCell<Account>>],
|
accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||||
caller_privileges: Option<&[bool]>,
|
caller_privileges: Option<&[bool]>,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
let track_writable_deescalation =
|
let track_writable_deescalation =
|
||||||
|
@ -379,7 +379,7 @@ impl<'a> InvokeContext for ThisInvokeContext<'a> {
|
||||||
fn is_feature_active(&self, feature_id: &Pubkey) -> bool {
|
fn is_feature_active(&self, feature_id: &Pubkey) -> bool {
|
||||||
self.feature_set.is_active(feature_id)
|
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 let Some(account) = self.pre_accounts.iter().find_map(|pre| {
|
||||||
if pre.key == *pubkey {
|
if pre.key == *pubkey {
|
||||||
Some(pre.account.clone())
|
Some(pre.account.clone())
|
||||||
|
@ -519,8 +519,8 @@ impl MessageProcessor {
|
||||||
fn create_keyed_accounts<'a>(
|
fn create_keyed_accounts<'a>(
|
||||||
message: &'a Message,
|
message: &'a Message,
|
||||||
instruction: &'a CompiledInstruction,
|
instruction: &'a CompiledInstruction,
|
||||||
executable_accounts: &'a [(Pubkey, RefCell<Account>)],
|
executable_accounts: &'a [(Pubkey, RefCell<AccountSharedData>)],
|
||||||
accounts: &'a [Rc<RefCell<Account>>],
|
accounts: &'a [Rc<RefCell<AccountSharedData>>],
|
||||||
) -> Vec<KeyedAccount<'a>> {
|
) -> Vec<KeyedAccount<'a>> {
|
||||||
let mut keyed_accounts = create_keyed_readonly_accounts(&executable_accounts);
|
let mut keyed_accounts = create_keyed_readonly_accounts(&executable_accounts);
|
||||||
let mut keyed_accounts2: Vec<_> = instruction
|
let mut keyed_accounts2: Vec<_> = instruction
|
||||||
|
@ -811,8 +811,8 @@ impl MessageProcessor {
|
||||||
/// This method calls the instruction's program entrypoint function
|
/// This method calls the instruction's program entrypoint function
|
||||||
pub fn process_cross_program_instruction(
|
pub fn process_cross_program_instruction(
|
||||||
message: &Message,
|
message: &Message,
|
||||||
executable_accounts: &[(Pubkey, RefCell<Account>)],
|
executable_accounts: &[(Pubkey, RefCell<AccountSharedData>)],
|
||||||
accounts: &[Rc<RefCell<Account>>],
|
accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||||
caller_privileges: &[bool],
|
caller_privileges: &[bool],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
|
@ -863,7 +863,7 @@ impl MessageProcessor {
|
||||||
pub fn create_pre_accounts(
|
pub fn create_pre_accounts(
|
||||||
message: &Message,
|
message: &Message,
|
||||||
instruction: &CompiledInstruction,
|
instruction: &CompiledInstruction,
|
||||||
accounts: &[Rc<RefCell<Account>>],
|
accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||||
) -> Vec<PreAccount> {
|
) -> Vec<PreAccount> {
|
||||||
let mut pre_accounts = Vec::with_capacity(instruction.accounts.len());
|
let mut pre_accounts = Vec::with_capacity(instruction.accounts.len());
|
||||||
{
|
{
|
||||||
|
@ -881,7 +881,7 @@ impl MessageProcessor {
|
||||||
|
|
||||||
/// Verify there are no outstanding borrows
|
/// Verify there are no outstanding borrows
|
||||||
pub fn verify_account_references(
|
pub fn verify_account_references(
|
||||||
accounts: &[(Pubkey, RefCell<Account>)],
|
accounts: &[(Pubkey, RefCell<AccountSharedData>)],
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
for (_, account) in accounts.iter() {
|
for (_, account) in accounts.iter() {
|
||||||
account
|
account
|
||||||
|
@ -896,8 +896,8 @@ impl MessageProcessor {
|
||||||
message: &Message,
|
message: &Message,
|
||||||
instruction: &CompiledInstruction,
|
instruction: &CompiledInstruction,
|
||||||
pre_accounts: &[PreAccount],
|
pre_accounts: &[PreAccount],
|
||||||
executable_accounts: &[(Pubkey, RefCell<Account>)],
|
executable_accounts: &[(Pubkey, RefCell<AccountSharedData>)],
|
||||||
accounts: &[Rc<RefCell<Account>>],
|
accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||||
rent: &Rent,
|
rent: &Rent,
|
||||||
timings: &mut ExecuteDetailsTimings,
|
timings: &mut ExecuteDetailsTimings,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
|
@ -939,7 +939,7 @@ impl MessageProcessor {
|
||||||
message: &Message,
|
message: &Message,
|
||||||
instruction: &CompiledInstruction,
|
instruction: &CompiledInstruction,
|
||||||
pre_accounts: &mut [PreAccount],
|
pre_accounts: &mut [PreAccount],
|
||||||
accounts: &[Rc<RefCell<Account>>],
|
accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
rent: &Rent,
|
rent: &Rent,
|
||||||
track_writable_deescalation: bool,
|
track_writable_deescalation: bool,
|
||||||
|
@ -1000,9 +1000,9 @@ impl MessageProcessor {
|
||||||
&self,
|
&self,
|
||||||
message: &Message,
|
message: &Message,
|
||||||
instruction: &CompiledInstruction,
|
instruction: &CompiledInstruction,
|
||||||
executable_accounts: &[(Pubkey, RefCell<Account>)],
|
executable_accounts: &[(Pubkey, RefCell<AccountSharedData>)],
|
||||||
accounts: &[Rc<RefCell<Account>>],
|
accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||||
account_deps: &[(Pubkey, RefCell<Account>)],
|
account_deps: &[(Pubkey, RefCell<AccountSharedData>)],
|
||||||
rent_collector: &RentCollector,
|
rent_collector: &RentCollector,
|
||||||
log_collector: Option<Rc<LogCollector>>,
|
log_collector: Option<Rc<LogCollector>>,
|
||||||
executors: Rc<RefCell<Executors>>,
|
executors: Rc<RefCell<Executors>>,
|
||||||
|
@ -1071,9 +1071,9 @@ impl MessageProcessor {
|
||||||
pub fn process_message(
|
pub fn process_message(
|
||||||
&self,
|
&self,
|
||||||
message: &Message,
|
message: &Message,
|
||||||
loaders: &[Vec<(Pubkey, RefCell<Account>)>],
|
loaders: &[Vec<(Pubkey, RefCell<AccountSharedData>)>],
|
||||||
accounts: &[Rc<RefCell<Account>>],
|
accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||||
account_deps: &[(Pubkey, RefCell<Account>)],
|
account_deps: &[(Pubkey, RefCell<AccountSharedData>)],
|
||||||
rent_collector: &RentCollector,
|
rent_collector: &RentCollector,
|
||||||
log_collector: Option<Rc<LogCollector>>,
|
log_collector: Option<Rc<LogCollector>>,
|
||||||
executors: Rc<RefCell<Executors>>,
|
executors: Rc<RefCell<Executors>>,
|
||||||
|
@ -1126,14 +1126,14 @@ mod tests {
|
||||||
for i in 0..MAX_DEPTH {
|
for i in 0..MAX_DEPTH {
|
||||||
program_ids.push(solana_sdk::pubkey::new_rand());
|
program_ids.push(solana_sdk::pubkey::new_rand());
|
||||||
keys.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,
|
i as u64,
|
||||||
1,
|
1,
|
||||||
&program_ids[i],
|
&program_ids[i],
|
||||||
))));
|
))));
|
||||||
pre_accounts.push(PreAccount::new(&keys[i], &accounts[i].borrow(), false))
|
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() {
|
for program_id in program_ids.iter() {
|
||||||
pre_accounts.push(PreAccount::new(program_id, &account.clone(), false));
|
pre_accounts.push(PreAccount::new(program_id, &account.clone(), false));
|
||||||
}
|
}
|
||||||
|
@ -1181,7 +1181,7 @@ mod tests {
|
||||||
// modify account owned by the program
|
// modify account owned by the program
|
||||||
accounts[owned_index].borrow_mut().data[0] = (MAX_DEPTH + owned_index) as u8;
|
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();
|
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,
|
||||||
1,
|
1,
|
||||||
&solana_sdk::pubkey::Pubkey::default(),
|
&solana_sdk::pubkey::Pubkey::default(),
|
||||||
|
@ -1248,7 +1248,7 @@ mod tests {
|
||||||
fn test_verify_account_references() {
|
fn test_verify_account_references() {
|
||||||
let accounts = vec![(
|
let accounts = vec![(
|
||||||
solana_sdk::pubkey::new_rand(),
|
solana_sdk::pubkey::new_rand(),
|
||||||
RefCell::new(Account::default()),
|
RefCell::new(AccountSharedData::default()),
|
||||||
)];
|
)];
|
||||||
|
|
||||||
assert!(MessageProcessor::verify_account_references(&accounts).is_ok());
|
assert!(MessageProcessor::verify_account_references(&accounts).is_ok());
|
||||||
|
@ -1265,7 +1265,7 @@ mod tests {
|
||||||
is_writable: bool,
|
is_writable: bool,
|
||||||
rent: Rent,
|
rent: Rent,
|
||||||
pre: PreAccount,
|
pre: PreAccount,
|
||||||
post: Account,
|
post: AccountSharedData,
|
||||||
}
|
}
|
||||||
impl Change {
|
impl Change {
|
||||||
pub fn new(owner: &Pubkey, program_id: &Pubkey) -> Self {
|
pub fn new(owner: &Pubkey, program_id: &Pubkey) -> Self {
|
||||||
|
@ -1275,18 +1275,18 @@ mod tests {
|
||||||
is_writable: true,
|
is_writable: true,
|
||||||
pre: PreAccount::new(
|
pre: PreAccount::new(
|
||||||
&solana_sdk::pubkey::new_rand(),
|
&solana_sdk::pubkey::new_rand(),
|
||||||
&Account {
|
&AccountSharedData {
|
||||||
owner: *owner,
|
owner: *owner,
|
||||||
lamports: std::u64::MAX,
|
lamports: std::u64::MAX,
|
||||||
data: vec![],
|
data: vec![],
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
post: Account {
|
post: AccountSharedData {
|
||||||
owner: *owner,
|
owner: *owner,
|
||||||
lamports: std::u64::MAX,
|
lamports: std::u64::MAX,
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1686,13 +1686,13 @@ mod tests {
|
||||||
let mut message_processor = MessageProcessor::default();
|
let mut message_processor = MessageProcessor::default();
|
||||||
message_processor.add_program(mock_system_program_id, mock_system_process_instruction);
|
message_processor.add_program(mock_system_program_id, mock_system_process_instruction);
|
||||||
|
|
||||||
let mut accounts: Vec<Rc<RefCell<Account>>> = Vec::new();
|
let mut accounts: Vec<Rc<RefCell<AccountSharedData>>> = Vec::new();
|
||||||
let account = Account::new_ref(100, 1, &mock_system_program_id);
|
let account = AccountSharedData::new_ref(100, 1, &mock_system_program_id);
|
||||||
accounts.push(account);
|
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);
|
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));
|
let account = RefCell::new(create_loadable_account("mock_system_program", 1));
|
||||||
loaders.push(vec![(mock_system_program_id, account)]);
|
loaders.push(vec![(mock_system_program_id, account)]);
|
||||||
|
|
||||||
|
@ -1853,13 +1853,13 @@ mod tests {
|
||||||
let mut message_processor = MessageProcessor::default();
|
let mut message_processor = MessageProcessor::default();
|
||||||
message_processor.add_program(mock_program_id, mock_system_process_instruction);
|
message_processor.add_program(mock_program_id, mock_system_process_instruction);
|
||||||
|
|
||||||
let mut accounts: Vec<Rc<RefCell<Account>>> = Vec::new();
|
let mut accounts: Vec<Rc<RefCell<AccountSharedData>>> = Vec::new();
|
||||||
let account = Account::new_ref(100, 1, &mock_program_id);
|
let account = AccountSharedData::new_ref(100, 1, &mock_program_id);
|
||||||
accounts.push(account);
|
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);
|
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));
|
let account = RefCell::new(create_loadable_account("mock_system_program", 1));
|
||||||
loaders.push(vec![(mock_program_id, account)]);
|
loaders.push(vec![(mock_program_id, account)]);
|
||||||
|
|
||||||
|
@ -2001,17 +2001,17 @@ mod tests {
|
||||||
let caller_program_id = solana_sdk::pubkey::new_rand();
|
let caller_program_id = solana_sdk::pubkey::new_rand();
|
||||||
let callee_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;
|
program_account.executable = true;
|
||||||
let executable_preaccount = PreAccount::new(&callee_program_id, &program_account, 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 executable_accounts = vec![(callee_program_id, RefCell::new(program_account.clone()))];
|
||||||
|
|
||||||
let owned_key = solana_sdk::pubkey::new_rand();
|
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 owned_preaccount = PreAccount::new(&owned_key, &owned_account, true);
|
||||||
|
|
||||||
let not_owned_key = solana_sdk::pubkey::new_rand();
|
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);
|
let not_owned_preaccount = PreAccount::new(¬_owned_key, ¬_owned_account, true);
|
||||||
|
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! calculate and collect rent from Accounts
|
//! calculate and collect rent from Accounts
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account, clock::Epoch, epoch_schedule::EpochSchedule, genesis_config::GenesisConfig,
|
account::AccountSharedData, clock::Epoch, epoch_schedule::EpochSchedule,
|
||||||
incinerator, pubkey::Pubkey, rent::Rent, sysvar,
|
genesis_config::GenesisConfig, incinerator, pubkey::Pubkey, rent::Rent, sysvar,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, AbiExample)]
|
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, AbiExample)]
|
||||||
|
@ -50,7 +50,11 @@ impl RentCollector {
|
||||||
// the account rent collected, if any
|
// the account rent collected, if any
|
||||||
//
|
//
|
||||||
#[must_use = "add to Bank::collected_rent"]
|
#[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
|
if account.executable
|
||||||
|| account.rent_epoch > self.epoch
|
|| account.rent_epoch > self.epoch
|
||||||
|| sysvar::check_id(&account.owner)
|
|| sysvar::check_id(&account.owner)
|
||||||
|
@ -88,7 +92,7 @@ impl RentCollector {
|
||||||
rent_due
|
rent_due
|
||||||
} else {
|
} else {
|
||||||
let rent_charged = account.lamports;
|
let rent_charged = account.lamports;
|
||||||
*account = Account::default();
|
*account = AccountSharedData::default();
|
||||||
rent_charged
|
rent_charged
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -99,7 +103,11 @@ impl RentCollector {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use = "add to Bank::collected_rent"]
|
#[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
|
// initialize rent_epoch as created at this epoch
|
||||||
account.rent_epoch = self.epoch;
|
account.rent_epoch = self.epoch;
|
||||||
self.collect_from_existing_account(address, account)
|
self.collect_from_existing_account(address, account)
|
||||||
|
@ -117,10 +125,10 @@ mod tests {
|
||||||
let new_epoch = 3;
|
let new_epoch = 3;
|
||||||
|
|
||||||
let (mut created_account, mut existing_account) = {
|
let (mut created_account, mut existing_account) = {
|
||||||
let account = Account {
|
let account = AccountSharedData {
|
||||||
lamports: old_lamports,
|
lamports: old_lamports,
|
||||||
rent_epoch: old_epoch,
|
rent_epoch: old_epoch,
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
(account.clone(), account)
|
(account.clone(), account)
|
||||||
|
@ -149,7 +157,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rent_exempt_temporal_escape() {
|
fn test_rent_exempt_temporal_escape() {
|
||||||
let mut account = Account::default();
|
let mut account = AccountSharedData::default();
|
||||||
let epoch = 3;
|
let epoch = 3;
|
||||||
let huge_lamports = 123_456_789_012;
|
let huge_lamports = 123_456_789_012;
|
||||||
let tiny_lamports = 789_012;
|
let tiny_lamports = 789_012;
|
||||||
|
|
|
@ -9,7 +9,7 @@ use {
|
||||||
bincode::serialize_into,
|
bincode::serialize_into,
|
||||||
rand::{thread_rng, Rng},
|
rand::{thread_rng, Rng},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
clock::Slot,
|
clock::Slot,
|
||||||
genesis_config::{create_genesis_config, ClusterType},
|
genesis_config::{create_genesis_config, ClusterType},
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
|
@ -45,7 +45,7 @@ fn check_accounts(accounts: &Accounts, pubkeys: &[Pubkey], num: usize) {
|
||||||
let ancestors = vec![(0, 0)].into_iter().collect();
|
let ancestors = vec![(0, 0)].into_iter().collect();
|
||||||
let account = accounts.load_slow(&ancestors, &pubkeys[idx]);
|
let account = accounts.load_slow(&ancestors, &pubkeys[idx]);
|
||||||
let account1 = Some((
|
let account1 = Some((
|
||||||
Account::new((idx + 1) as u64, 0, &Account::default().owner),
|
AccountSharedData::new((idx + 1) as u64, 0, &AccountSharedData::default().owner),
|
||||||
0,
|
0,
|
||||||
));
|
));
|
||||||
assert_eq!(account, account1);
|
assert_eq!(account, account1);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//! node stakes
|
//! node stakes
|
||||||
use crate::vote_account::{ArcVoteAccount, VoteAccounts};
|
use crate::vote_account::{ArcVoteAccount, VoteAccounts};
|
||||||
use solana_sdk::{
|
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_stake_program::stake_state::{new_stake_history_entry, Delegation, StakeState};
|
||||||
use solana_vote_program::vote_state::VoteState;
|
use solana_vote_program::vote_state::VoteState;
|
||||||
|
@ -106,7 +106,7 @@ impl Stakes {
|
||||||
.sum::<u64>()
|
.sum::<u64>()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_stake(account: &Account) -> bool {
|
pub fn is_stake(account: &AccountSharedData) -> bool {
|
||||||
solana_vote_program::check_id(&account.owner)
|
solana_vote_program::check_id(&account.owner)
|
||||||
|| solana_stake_program::check_id(&account.owner)
|
|| solana_stake_program::check_id(&account.owner)
|
||||||
&& account.data.len() >= std::mem::size_of::<StakeState>()
|
&& account.data.len() >= std::mem::size_of::<StakeState>()
|
||||||
|
@ -115,7 +115,7 @@ impl Stakes {
|
||||||
pub fn store(
|
pub fn store(
|
||||||
&mut self,
|
&mut self,
|
||||||
pubkey: &Pubkey,
|
pubkey: &Pubkey,
|
||||||
account: &Account,
|
account: &AccountSharedData,
|
||||||
fix_stake_deactivate: bool,
|
fix_stake_deactivate: bool,
|
||||||
check_vote_init: bool,
|
check_vote_init: bool,
|
||||||
) -> Option<ArcVoteAccount> {
|
) -> Option<ArcVoteAccount> {
|
||||||
|
@ -232,7 +232,9 @@ pub mod tests {
|
||||||
use solana_vote_program::vote_state::{self, VoteState, VoteStateVersions};
|
use solana_vote_program::vote_state::{self, VoteState, VoteStateVersions};
|
||||||
|
|
||||||
// set up some dummies for a staked node (( vote ) ( stake ))
|
// 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_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let vote_account =
|
let vote_account =
|
||||||
vote_state::create_account(&vote_pubkey, &solana_sdk::pubkey::new_rand(), 0, 1);
|
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 )
|
// 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();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
(
|
(
|
||||||
stake_pubkey,
|
stake_pubkey,
|
||||||
|
@ -260,7 +262,7 @@ pub mod tests {
|
||||||
pub fn create_warming_staked_node_accounts(
|
pub fn create_warming_staked_node_accounts(
|
||||||
stake: u64,
|
stake: u64,
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
) -> ((Pubkey, Account), (Pubkey, Account)) {
|
) -> ((Pubkey, AccountSharedData), (Pubkey, AccountSharedData)) {
|
||||||
let vote_pubkey = solana_sdk::pubkey::new_rand();
|
let vote_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let vote_account =
|
let vote_account =
|
||||||
vote_state::create_account(&vote_pubkey, &solana_sdk::pubkey::new_rand(), 0, 1);
|
vote_state::create_account(&vote_pubkey, &solana_sdk::pubkey::new_rand(), 0, 1);
|
||||||
|
@ -275,7 +277,7 @@ pub mod tests {
|
||||||
stake: u64,
|
stake: u64,
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
vote_pubkey: &Pubkey,
|
vote_pubkey: &Pubkey,
|
||||||
) -> (Pubkey, Account) {
|
) -> (Pubkey, AccountSharedData) {
|
||||||
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
let stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
(
|
(
|
||||||
stake_pubkey,
|
stake_pubkey,
|
||||||
|
@ -557,7 +559,7 @@ pub mod tests {
|
||||||
// not a stake account, and whacks above entry
|
// not a stake account, and whacks above entry
|
||||||
stakes.store(
|
stakes.store(
|
||||||
&stake_pubkey,
|
&stake_pubkey,
|
||||||
&Account::new(1, 0, &solana_stake_program::id()),
|
&AccountSharedData::new(1, 0, &solana_stake_program::id()),
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use log::*;
|
use log::*;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
ic_msg,
|
ic_msg,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
|
@ -62,7 +62,7 @@ impl Address {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn allocate(
|
fn allocate(
|
||||||
account: &mut Account,
|
account: &mut AccountSharedData,
|
||||||
address: &Address,
|
address: &Address,
|
||||||
space: u64,
|
space: u64,
|
||||||
signers: &HashSet<Pubkey>,
|
signers: &HashSet<Pubkey>,
|
||||||
|
@ -104,7 +104,7 @@ fn allocate(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assign(
|
fn assign(
|
||||||
account: &mut Account,
|
account: &mut AccountSharedData,
|
||||||
address: &Address,
|
address: &Address,
|
||||||
owner: &Pubkey,
|
owner: &Pubkey,
|
||||||
signers: &HashSet<Pubkey>,
|
signers: &HashSet<Pubkey>,
|
||||||
|
@ -131,7 +131,7 @@ fn assign(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn allocate_and_assign(
|
fn allocate_and_assign(
|
||||||
to: &mut Account,
|
to: &mut AccountSharedData,
|
||||||
to_address: &Address,
|
to_address: &Address,
|
||||||
space: u64,
|
space: u64,
|
||||||
owner: &Pubkey,
|
owner: &Pubkey,
|
||||||
|
@ -421,7 +421,7 @@ pub enum SystemAccountKind {
|
||||||
Nonce,
|
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 system_program::check_id(&account.owner) {
|
||||||
if account.data.is_empty() {
|
if account.data.is_empty() {
|
||||||
Some(SystemAccountKind::System)
|
Some(SystemAccountKind::System)
|
||||||
|
@ -446,7 +446,7 @@ mod tests {
|
||||||
use crate::{bank::Bank, bank_client::BankClient};
|
use crate::{bank::Bank, bank_client::BankClient};
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{self, Account},
|
account::{self, AccountSharedData},
|
||||||
client::SyncClient,
|
client::SyncClient,
|
||||||
fee_calculator::FeeCalculator,
|
fee_calculator::FeeCalculator,
|
||||||
genesis_config::create_genesis_config,
|
genesis_config::create_genesis_config,
|
||||||
|
@ -486,10 +486,10 @@ mod tests {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_default_account() -> RefCell<Account> {
|
fn create_default_account() -> RefCell<AccountSharedData> {
|
||||||
RefCell::new(Account::default())
|
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(
|
RefCell::new(recent_blockhashes_account::create_account_with_data(
|
||||||
1,
|
1,
|
||||||
vec![
|
vec![
|
||||||
|
@ -499,8 +499,8 @@ mod tests {
|
||||||
.into_iter(),
|
.into_iter(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
fn create_default_rent_account() -> RefCell<Account> {
|
fn create_default_rent_account() -> RefCell<AccountSharedData> {
|
||||||
RefCell::new(account::create_account(&Rent::free(), 1))
|
RefCell::new(account::create_account_shared_data(&Rent::free(), 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -508,8 +508,8 @@ mod tests {
|
||||||
let new_owner = Pubkey::new(&[9; 32]);
|
let new_owner = Pubkey::new(&[9; 32]);
|
||||||
let from = solana_sdk::pubkey::new_rand();
|
let from = solana_sdk::pubkey::new_rand();
|
||||||
let to = solana_sdk::pubkey::new_rand();
|
let to = 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_account = Account::new_ref(0, 0, &Pubkey::default());
|
let to_account = AccountSharedData::new_ref(0, 0, &Pubkey::default());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
process_instruction(
|
process_instruction(
|
||||||
|
@ -540,8 +540,8 @@ mod tests {
|
||||||
let seed = "shiny pepper";
|
let seed = "shiny pepper";
|
||||||
let to = Pubkey::create_with_seed(&from, seed, &new_owner).unwrap();
|
let to = Pubkey::create_with_seed(&from, seed, &new_owner).unwrap();
|
||||||
|
|
||||||
let from_account = Account::new_ref(100, 0, &system_program::id());
|
let from_account = AccountSharedData::new_ref(100, 0, &system_program::id());
|
||||||
let to_account = Account::new_ref(0, 0, &Pubkey::default());
|
let to_account = AccountSharedData::new_ref(0, 0, &Pubkey::default());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
process_instruction(
|
process_instruction(
|
||||||
|
@ -575,9 +575,9 @@ mod tests {
|
||||||
let seed = "shiny pepper";
|
let seed = "shiny pepper";
|
||||||
let to = Pubkey::create_with_seed(&base, seed, &new_owner).unwrap();
|
let to = Pubkey::create_with_seed(&base, seed, &new_owner).unwrap();
|
||||||
|
|
||||||
let from_account = Account::new_ref(100, 0, &system_program::id());
|
let from_account = AccountSharedData::new_ref(100, 0, &system_program::id());
|
||||||
let to_account = Account::new_ref(0, 0, &Pubkey::default());
|
let to_account = AccountSharedData::new_ref(0, 0, &Pubkey::default());
|
||||||
let base_account = Account::new_ref(0, 0, &Pubkey::default());
|
let base_account = AccountSharedData::new_ref(0, 0, &Pubkey::default());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
process_instruction(
|
process_instruction(
|
||||||
|
@ -628,8 +628,8 @@ mod tests {
|
||||||
let seed = "dull boy";
|
let seed = "dull boy";
|
||||||
let to = Pubkey::create_with_seed(&from, seed, &new_owner).unwrap();
|
let to = Pubkey::create_with_seed(&from, seed, &new_owner).unwrap();
|
||||||
|
|
||||||
let from_account = Account::new_ref(100, 0, &system_program::id());
|
let from_account = AccountSharedData::new_ref(100, 0, &system_program::id());
|
||||||
let to_account = Account::new_ref(0, 0, &Pubkey::default());
|
let to_account = AccountSharedData::new_ref(0, 0, &Pubkey::default());
|
||||||
let to_address = Address::create(
|
let to_address = Address::create(
|
||||||
&to,
|
&to,
|
||||||
Some((&from, seed, &new_owner)),
|
Some((&from, seed, &new_owner)),
|
||||||
|
@ -651,7 +651,7 @@ mod tests {
|
||||||
Err(InstructionError::MissingRequiredSignature)
|
Err(InstructionError::MissingRequiredSignature)
|
||||||
);
|
);
|
||||||
assert_eq!(from_account.borrow().lamports, 100);
|
assert_eq!(from_account.borrow().lamports, 100);
|
||||||
assert_eq!(*to_account.borrow(), Account::default());
|
assert_eq!(*to_account.borrow(), AccountSharedData::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -659,10 +659,10 @@ mod tests {
|
||||||
// create account with zero lamports transferred
|
// create account with zero lamports transferred
|
||||||
let new_owner = Pubkey::new(&[9; 32]);
|
let new_owner = Pubkey::new(&[9; 32]);
|
||||||
let from = solana_sdk::pubkey::new_rand();
|
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 = 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!(
|
assert_eq!(
|
||||||
create_account(
|
create_account(
|
||||||
|
@ -693,10 +693,10 @@ mod tests {
|
||||||
// Attempt to create account with more lamports than remaining in from_account
|
// Attempt to create account with more lamports than remaining in from_account
|
||||||
let new_owner = Pubkey::new(&[9; 32]);
|
let new_owner = Pubkey::new(&[9; 32]);
|
||||||
let from = solana_sdk::pubkey::new_rand();
|
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 = 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(
|
let result = create_account(
|
||||||
&KeyedAccount::new(&from, true, &from_account),
|
&KeyedAccount::new(&from, true, &from_account),
|
||||||
|
@ -713,9 +713,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_request_more_than_allowed_data_length() {
|
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 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 to = solana_sdk::pubkey::new_rand();
|
||||||
|
|
||||||
let signers = &[from, to].iter().cloned().collect::<HashSet<_>>();
|
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
|
// Attempt to create system account in account already owned by another program
|
||||||
let new_owner = Pubkey::new(&[9; 32]);
|
let new_owner = Pubkey::new(&[9; 32]);
|
||||||
let from = solana_sdk::pubkey::new_rand();
|
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 original_program_owner = Pubkey::new(&[5; 32]);
|
||||||
let owned_key = solana_sdk::pubkey::new_rand();
|
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 unchanged_account = owned_account.clone();
|
||||||
|
|
||||||
let signers = &[from, owned_key].iter().cloned().collect::<HashSet<_>>();
|
let signers = &[from, owned_key].iter().cloned().collect::<HashSet<_>>();
|
||||||
|
@ -789,7 +789,7 @@ mod tests {
|
||||||
assert_eq!(owned_account, unchanged_account);
|
assert_eq!(owned_account, unchanged_account);
|
||||||
|
|
||||||
// Attempt to create system account in account that already has data
|
// 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 unchanged_account = owned_account.borrow().clone();
|
||||||
let result = create_account(
|
let result = create_account(
|
||||||
&KeyedAccount::new(&from, true, &from_account),
|
&KeyedAccount::new(&from, true, &from_account),
|
||||||
|
@ -807,7 +807,7 @@ mod tests {
|
||||||
assert_eq!(*owned_account.borrow(), unchanged_account);
|
assert_eq!(*owned_account.borrow(), unchanged_account);
|
||||||
|
|
||||||
// Attempt to create an account that already has lamports
|
// 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 unchanged_account = owned_account.borrow().clone();
|
||||||
let result = create_account(
|
let result = create_account(
|
||||||
&KeyedAccount::new(&from, true, &from_account),
|
&KeyedAccount::new(&from, true, &from_account),
|
||||||
|
@ -829,10 +829,10 @@ mod tests {
|
||||||
// Attempt to create an account without signing the transfer
|
// Attempt to create an account without signing the transfer
|
||||||
let new_owner = Pubkey::new(&[9; 32]);
|
let new_owner = Pubkey::new(&[9; 32]);
|
||||||
let from = solana_sdk::pubkey::new_rand();
|
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_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();
|
let owned_address = owned_key.into();
|
||||||
|
|
||||||
|
@ -850,7 +850,7 @@ mod tests {
|
||||||
assert_eq!(result, Err(InstructionError::MissingRequiredSignature));
|
assert_eq!(result, Err(InstructionError::MissingRequiredSignature));
|
||||||
|
|
||||||
// Haven't signed to account
|
// 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(
|
let result = create_account(
|
||||||
&KeyedAccount::new(&from, true, &from_account),
|
&KeyedAccount::new(&from, true, &from_account),
|
||||||
&KeyedAccount::new(&owned_key, true, &owned_account),
|
&KeyedAccount::new(&owned_key, true, &owned_account),
|
||||||
|
@ -864,7 +864,7 @@ mod tests {
|
||||||
assert_eq!(result, Err(InstructionError::MissingRequiredSignature));
|
assert_eq!(result, Err(InstructionError::MissingRequiredSignature));
|
||||||
|
|
||||||
// support creation/assignment with zero lamports (ephemeral account)
|
// 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(
|
let result = create_account(
|
||||||
&KeyedAccount::new(&from, false, &from_account),
|
&KeyedAccount::new(&from, false, &from_account),
|
||||||
&KeyedAccount::new(&owned_key, false, &owned_account),
|
&KeyedAccount::new(&owned_key, false, &owned_account),
|
||||||
|
@ -882,10 +882,10 @@ mod tests {
|
||||||
fn test_create_sysvar_invalid_id() {
|
fn test_create_sysvar_invalid_id() {
|
||||||
// Attempt to create system account in account already owned by another program
|
// Attempt to create system account in account already owned by another program
|
||||||
let from = solana_sdk::pubkey::new_rand();
|
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 = 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 signers = [from, to].iter().cloned().collect::<HashSet<_>>();
|
||||||
let to_address = to.into();
|
let to_address = to.into();
|
||||||
|
@ -910,12 +910,12 @@ mod tests {
|
||||||
// Attempt to create system account in account with populated data
|
// Attempt to create system account in account with populated data
|
||||||
let new_owner = Pubkey::new(&[9; 32]);
|
let new_owner = Pubkey::new(&[9; 32]);
|
||||||
let from = solana_sdk::pubkey::new_rand();
|
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_key = solana_sdk::pubkey::new_rand();
|
||||||
let populated_account = Account {
|
let populated_account = AccountSharedData {
|
||||||
data: vec![0, 1, 2, 3],
|
data: vec![0, 1, 2, 3],
|
||||||
..Account::default()
|
..AccountSharedData::default()
|
||||||
}
|
}
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
|
@ -941,7 +941,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_from_account_is_nonce_fail() {
|
fn test_create_from_account_is_nonce_fail() {
|
||||||
let nonce = solana_sdk::pubkey::new_rand();
|
let nonce = solana_sdk::pubkey::new_rand();
|
||||||
let nonce_account = Account::new_ref_data(
|
let nonce_account = AccountSharedData::new_ref_data(
|
||||||
42,
|
42,
|
||||||
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
||||||
nonce::state::Data::default(),
|
nonce::state::Data::default(),
|
||||||
|
@ -952,7 +952,7 @@ mod tests {
|
||||||
let from = KeyedAccount::new(&nonce, true, &nonce_account);
|
let from = KeyedAccount::new(&nonce, true, &nonce_account);
|
||||||
let new = solana_sdk::pubkey::new_rand();
|
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 signers = [nonce, new].iter().cloned().collect::<HashSet<_>>();
|
||||||
let new_address = new.into();
|
let new_address = new.into();
|
||||||
|
@ -978,7 +978,7 @@ mod tests {
|
||||||
let new_owner = Pubkey::new(&[9; 32]);
|
let new_owner = Pubkey::new(&[9; 32]);
|
||||||
|
|
||||||
let pubkey = solana_sdk::pubkey::new_rand();
|
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!(
|
assert_eq!(
|
||||||
assign(
|
assign(
|
||||||
|
@ -1018,7 +1018,7 @@ mod tests {
|
||||||
let new_owner = sysvar::id();
|
let new_owner = sysvar::id();
|
||||||
|
|
||||||
let from = solana_sdk::pubkey::new_rand();
|
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!(
|
assert_eq!(
|
||||||
assign(
|
assign(
|
||||||
|
@ -1043,7 +1043,7 @@ mod tests {
|
||||||
assert_eq!(result, Err(InstructionError::NotEnoughAccountKeys));
|
assert_eq!(result, Err(InstructionError::NotEnoughAccountKeys));
|
||||||
|
|
||||||
let from = solana_sdk::pubkey::new_rand();
|
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
|
// Attempt to transfer with no destination
|
||||||
let instruction = SystemInstruction::Transfer { lamports: 0 };
|
let instruction = SystemInstruction::Transfer { lamports: 0 };
|
||||||
let data = serialize(&instruction).unwrap();
|
let data = serialize(&instruction).unwrap();
|
||||||
|
@ -1058,9 +1058,9 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transfer_lamports() {
|
fn test_transfer_lamports() {
|
||||||
let from = solana_sdk::pubkey::new_rand();
|
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 = 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 from_keyed_account = KeyedAccount::new(&from, true, &from_account);
|
||||||
let to_keyed_account = KeyedAccount::new(&to, false, &to_account);
|
let to_keyed_account = KeyedAccount::new(&to, false, &to_account);
|
||||||
transfer(
|
transfer(
|
||||||
|
@ -1104,14 +1104,14 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transfer_with_seed() {
|
fn test_transfer_with_seed() {
|
||||||
let base = solana_sdk::pubkey::new_rand();
|
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_base_keyed_account = KeyedAccount::new(&base, true, &base_account);
|
||||||
let from_seed = "42";
|
let from_seed = "42";
|
||||||
let from_owner = system_program::id();
|
let from_owner = system_program::id();
|
||||||
let from = Pubkey::create_with_seed(&base, from_seed, &from_owner).unwrap();
|
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 = 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 from_keyed_account = KeyedAccount::new(&from, true, &from_account);
|
||||||
let to_keyed_account = KeyedAccount::new(&to, false, &to_account);
|
let to_keyed_account = KeyedAccount::new(&to, false, &to_account);
|
||||||
transfer_with_seed(
|
transfer_with_seed(
|
||||||
|
@ -1163,7 +1163,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transfer_lamports_from_nonce_account_fail() {
|
fn test_transfer_lamports_from_nonce_account_fail() {
|
||||||
let from = solana_sdk::pubkey::new_rand();
|
let from = solana_sdk::pubkey::new_rand();
|
||||||
let from_account = Account::new_ref_data(
|
let from_account = AccountSharedData::new_ref_data(
|
||||||
100,
|
100,
|
||||||
&nonce::state::Versions::new_current(nonce::State::Initialized(nonce::state::Data {
|
&nonce::state::Versions::new_current(nonce::State::Initialized(nonce::state::Data {
|
||||||
authority: from,
|
authority: from,
|
||||||
|
@ -1178,7 +1178,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let to = Pubkey::new(&[3; 32]);
|
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!(
|
assert_eq!(
|
||||||
transfer(
|
transfer(
|
||||||
&KeyedAccount::new(&from, true, &from_account),
|
&KeyedAccount::new(&from, true, &from_account),
|
||||||
|
@ -1377,9 +1377,9 @@ mod tests {
|
||||||
RefCell::new(if sysvar::recent_blockhashes::check_id(&meta.pubkey) {
|
RefCell::new(if sysvar::recent_blockhashes::check_id(&meta.pubkey) {
|
||||||
create_default_recent_blockhashes_account().into_inner()
|
create_default_recent_blockhashes_account().into_inner()
|
||||||
} else if sysvar::rent::check_id(&meta.pubkey) {
|
} else if sysvar::rent::check_id(&meta.pubkey) {
|
||||||
account::create_account(&Rent::free(), 1)
|
account::create_account_shared_data(&Rent::free(), 1)
|
||||||
} else {
|
} else {
|
||||||
Account::default()
|
AccountSharedData::default()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -1752,7 +1752,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_system_account_kind_system_ok() {
|
fn test_get_system_account_kind_system_ok() {
|
||||||
let system_account = Account::default();
|
let system_account = AccountSharedData::default();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_system_account_kind(&system_account),
|
get_system_account_kind(&system_account),
|
||||||
Some(SystemAccountKind::System)
|
Some(SystemAccountKind::System)
|
||||||
|
@ -1761,7 +1761,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_system_account_kind_nonce_ok() {
|
fn test_get_system_account_kind_nonce_ok() {
|
||||||
let nonce_account = Account::new_data(
|
let nonce_account = AccountSharedData::new_data(
|
||||||
42,
|
42,
|
||||||
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
||||||
nonce::state::Data::default(),
|
nonce::state::Data::default(),
|
||||||
|
@ -1785,13 +1785,14 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_system_account_kind_system_owner_nonzero_nonnonce_data_fail() {
|
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);
|
assert_eq!(get_system_account_kind(&other_data_account), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_system_account_kind_nonsystem_owner_with_nonce_data_fail() {
|
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,
|
42,
|
||||||
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
&nonce::state::Versions::new_current(nonce::State::Initialized(
|
||||||
nonce::state::Data::default(),
|
nonce::state::Data::default(),
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use serde::de::{Deserialize, Deserializer};
|
use serde::de::{Deserialize, Deserializer};
|
||||||
use serde::ser::{Serialize, Serializer};
|
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 solana_vote_program::vote_state::VoteState;
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Borrow,
|
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 {
|
impl From<Account> for ArcVoteAccount {
|
||||||
fn from(account: Account) -> Self {
|
fn from(account: Account) -> Self {
|
||||||
Self(Arc::new(VoteAccount::from(account)))
|
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 {
|
impl From<Account> for VoteAccount {
|
||||||
fn from(account: Account) -> Self {
|
fn from(account: Account) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -299,7 +316,7 @@ mod tests {
|
||||||
fn new_rand_vote_account<R: Rng>(
|
fn new_rand_vote_account<R: Rng>(
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
node_pubkey: Option<Pubkey>,
|
node_pubkey: Option<Pubkey>,
|
||||||
) -> (Account, VoteState) {
|
) -> (AccountSharedData, VoteState) {
|
||||||
let vote_init = VoteInit {
|
let vote_init = VoteInit {
|
||||||
node_pubkey: node_pubkey.unwrap_or_else(Pubkey::new_unique),
|
node_pubkey: node_pubkey.unwrap_or_else(Pubkey::new_unique),
|
||||||
authorized_voter: Pubkey::new_unique(),
|
authorized_voter: Pubkey::new_unique(),
|
||||||
|
@ -314,7 +331,7 @@ mod tests {
|
||||||
unix_timestamp: rng.gen(),
|
unix_timestamp: rng.gen(),
|
||||||
};
|
};
|
||||||
let vote_state = VoteState::new(&vote_init, &clock);
|
let vote_state = VoteState::new(&vote_init, &clock);
|
||||||
let account = Account::new_data(
|
let account = AccountSharedData::new_data(
|
||||||
rng.gen(), // lamports
|
rng.gen(), // lamports
|
||||||
&VoteStateVersions::new_current(vote_state.clone()),
|
&VoteStateVersions::new_current(vote_state.clone()),
|
||||||
&Pubkey::new_unique(), // owner
|
&Pubkey::new_unique(), // owner
|
||||||
|
|
|
@ -3,7 +3,7 @@ use rand::{thread_rng, Rng};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use solana_runtime::{accounts_db::AccountsDb, accounts_index::Ancestors};
|
use solana_runtime::{accounts_db::AccountsDb, accounts_index::Ancestors};
|
||||||
use solana_sdk::genesis_config::ClusterType;
|
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::collections::HashSet;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -37,7 +37,7 @@ fn test_shrink_and_clean() {
|
||||||
while alive_accounts.len() <= 10 {
|
while alive_accounts.len() <= 10 {
|
||||||
alive_accounts.push((
|
alive_accounts.push((
|
||||||
solana_sdk::pubkey::new_rand(),
|
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 key = Keypair::new().pubkey();
|
||||||
let lamports = thread_rng().gen_range(0, 100);
|
let lamports = thread_rng().gen_range(0, 100);
|
||||||
let some_data_len = thread_rng().gen_range(0, 1000);
|
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)
|
(key, account)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -77,7 +77,7 @@ fn warmed_up(bank: &Bank, stake_pubkey: &Pubkey) -> bool {
|
||||||
== stake.stake(
|
== stake.stake(
|
||||||
bank.epoch(),
|
bank.epoch(),
|
||||||
Some(
|
Some(
|
||||||
&from_account::<StakeHistory>(
|
&from_account::<StakeHistory, _>(
|
||||||
&bank.get_account(&sysvar::stake_history::id()).unwrap(),
|
&bank.get_account(&sysvar::stake_history::id()).unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
|
@ -92,7 +92,7 @@ fn get_staked(bank: &Bank, stake_pubkey: &Pubkey) -> u64 {
|
||||||
.stake(
|
.stake(
|
||||||
bank.epoch(),
|
bank.epoch(),
|
||||||
Some(
|
Some(
|
||||||
&from_account::<StakeHistory>(
|
&from_account::<StakeHistory, _>(
|
||||||
&bank.get_account(&sysvar::stake_history::id()).unwrap(),
|
&bank.get_account(&sysvar::stake_history::id()).unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
|
|
|
@ -16,6 +16,6 @@ fn bench_to_from_account(b: &mut Bencher) {
|
||||||
}
|
}
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let account = create_account(&slot_hashes, 0);
|
let account = create_account(&slot_hashes, 0);
|
||||||
slot_hashes = from_account::<SlotHashes>(&account).unwrap();
|
slot_hashes = from_account::<SlotHashes, _>(&account).unwrap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ fn bench_to_from_account(b: &mut Bencher) {
|
||||||
|
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let account = create_account(&slot_history, 0);
|
let account = create_account(&slot_history, 0);
|
||||||
slot_history = from_account::<SlotHistory>(&account).unwrap();
|
slot_history = from_account::<SlotHistory, _>(&account).unwrap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{clock::Epoch, pubkey::Pubkey};
|
use crate::{clock::Epoch, pubkey::Pubkey};
|
||||||
use solana_program::{account_info::AccountInfo, sysvar::Sysvar};
|
use solana_program::{account_info::AccountInfo, sysvar::Sysvar};
|
||||||
use std::{cell::RefCell, cmp, fmt, rc::Rc};
|
use std::{cell::Ref, cell::RefCell, cmp, fmt, rc::Rc};
|
||||||
|
|
||||||
/// An Account with data that is stored on chain
|
/// An Account with data that is stored on chain
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
@ -21,72 +21,361 @@ pub struct Account {
|
||||||
pub rent_epoch: Epoch,
|
pub rent_epoch: Epoch,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Account {
|
/// An Account with data that is stored on chain
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
/// This will become a new in-memory representation of the 'Account' struct data.
|
||||||
let data_len = cmp::min(64, self.data.len());
|
/// The existing 'Account' structure cannot easily change due to downstream projects.
|
||||||
|
/// This struct will shortly rely on something like the ReadableAccount trait for access to the fields.
|
||||||
|
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Default, AbiExample)]
|
||||||
|
pub struct AccountSharedData {
|
||||||
|
/// lamports in the account
|
||||||
|
pub lamports: u64,
|
||||||
|
/// data held in this account
|
||||||
|
#[serde(with = "serde_bytes")]
|
||||||
|
pub data: Vec<u8>, // will be: Arc<Vec<u8>>,
|
||||||
|
/// the program that owns this account. If executable, the program that loads this account.
|
||||||
|
pub owner: Pubkey,
|
||||||
|
/// this account's data contains a loaded program (and is now read-only)
|
||||||
|
pub executable: bool,
|
||||||
|
/// the epoch at which this account will next owe rent
|
||||||
|
pub rent_epoch: Epoch,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Compares two ReadableAccounts
|
||||||
|
///
|
||||||
|
/// Returns true if accounts are essentially equivalent as in all fields are equivalent.
|
||||||
|
pub fn accounts_equal<T: ReadableAccount, U: ReadableAccount>(me: &T, other: &U) -> bool {
|
||||||
|
me.lamports() == other.lamports()
|
||||||
|
&& me.data() == other.data()
|
||||||
|
&& me.owner() == other.owner()
|
||||||
|
&& me.executable() == other.executable()
|
||||||
|
&& me.rent_epoch() == other.rent_epoch()
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<AccountSharedData> for Account {
|
||||||
|
fn from(other: AccountSharedData) -> Self {
|
||||||
|
Self {
|
||||||
|
lamports: other.lamports,
|
||||||
|
data: other.data,
|
||||||
|
owner: other.owner,
|
||||||
|
executable: other.executable,
|
||||||
|
rent_epoch: other.rent_epoch,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Account> for AccountSharedData {
|
||||||
|
fn from(other: Account) -> Self {
|
||||||
|
Self {
|
||||||
|
lamports: other.lamports,
|
||||||
|
data: other.data,
|
||||||
|
owner: other.owner,
|
||||||
|
executable: other.executable,
|
||||||
|
rent_epoch: other.rent_epoch,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait WritableAccount: ReadableAccount {
|
||||||
|
fn set_lamports(&mut self, lamports: u64);
|
||||||
|
fn data_as_mut_slice(&mut self) -> &mut [u8];
|
||||||
|
fn set_owner(&mut self, owner: Pubkey);
|
||||||
|
fn set_executable(&mut self, executable: bool);
|
||||||
|
fn set_rent_epoch(&mut self, epoch: Epoch);
|
||||||
|
fn create(
|
||||||
|
lamports: u64,
|
||||||
|
data: Vec<u8>,
|
||||||
|
owner: Pubkey,
|
||||||
|
executable: bool,
|
||||||
|
rent_epoch: Epoch,
|
||||||
|
) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait ReadableAccount: Sized {
|
||||||
|
fn lamports(&self) -> u64;
|
||||||
|
fn data(&self) -> &Vec<u8>;
|
||||||
|
fn owner(&self) -> &Pubkey;
|
||||||
|
fn executable(&self) -> bool;
|
||||||
|
fn rent_epoch(&self) -> Epoch;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReadableAccount for Account {
|
||||||
|
fn lamports(&self) -> u64 {
|
||||||
|
self.lamports
|
||||||
|
}
|
||||||
|
fn data(&self) -> &Vec<u8> {
|
||||||
|
&self.data
|
||||||
|
}
|
||||||
|
fn owner(&self) -> &Pubkey {
|
||||||
|
&self.owner
|
||||||
|
}
|
||||||
|
fn executable(&self) -> bool {
|
||||||
|
self.executable
|
||||||
|
}
|
||||||
|
fn rent_epoch(&self) -> Epoch {
|
||||||
|
self.rent_epoch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WritableAccount for Account {
|
||||||
|
fn set_lamports(&mut self, lamports: u64) {
|
||||||
|
self.lamports = lamports;
|
||||||
|
}
|
||||||
|
fn data_as_mut_slice(&mut self) -> &mut [u8] {
|
||||||
|
&mut self.data
|
||||||
|
}
|
||||||
|
fn set_owner(&mut self, owner: Pubkey) {
|
||||||
|
self.owner = owner;
|
||||||
|
}
|
||||||
|
fn set_executable(&mut self, executable: bool) {
|
||||||
|
self.executable = executable;
|
||||||
|
}
|
||||||
|
fn set_rent_epoch(&mut self, epoch: Epoch) {
|
||||||
|
self.rent_epoch = epoch;
|
||||||
|
}
|
||||||
|
fn create(
|
||||||
|
lamports: u64,
|
||||||
|
data: Vec<u8>,
|
||||||
|
owner: Pubkey,
|
||||||
|
executable: bool,
|
||||||
|
rent_epoch: Epoch,
|
||||||
|
) -> Self {
|
||||||
|
Account {
|
||||||
|
lamports,
|
||||||
|
data,
|
||||||
|
owner,
|
||||||
|
executable,
|
||||||
|
rent_epoch,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WritableAccount for AccountSharedData {
|
||||||
|
fn set_lamports(&mut self, lamports: u64) {
|
||||||
|
self.lamports = lamports;
|
||||||
|
}
|
||||||
|
fn data_as_mut_slice(&mut self) -> &mut [u8] {
|
||||||
|
&mut self.data
|
||||||
|
}
|
||||||
|
fn set_owner(&mut self, owner: Pubkey) {
|
||||||
|
self.owner = owner;
|
||||||
|
}
|
||||||
|
fn set_executable(&mut self, executable: bool) {
|
||||||
|
self.executable = executable;
|
||||||
|
}
|
||||||
|
fn set_rent_epoch(&mut self, epoch: Epoch) {
|
||||||
|
self.rent_epoch = epoch;
|
||||||
|
}
|
||||||
|
fn create(
|
||||||
|
lamports: u64,
|
||||||
|
data: Vec<u8>,
|
||||||
|
owner: Pubkey,
|
||||||
|
executable: bool,
|
||||||
|
rent_epoch: Epoch,
|
||||||
|
) -> Self {
|
||||||
|
AccountSharedData {
|
||||||
|
lamports,
|
||||||
|
data,
|
||||||
|
owner,
|
||||||
|
executable,
|
||||||
|
rent_epoch,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReadableAccount for AccountSharedData {
|
||||||
|
fn lamports(&self) -> u64 {
|
||||||
|
self.lamports
|
||||||
|
}
|
||||||
|
fn data(&self) -> &Vec<u8> {
|
||||||
|
&self.data
|
||||||
|
}
|
||||||
|
fn owner(&self) -> &Pubkey {
|
||||||
|
&self.owner
|
||||||
|
}
|
||||||
|
fn executable(&self) -> bool {
|
||||||
|
self.executable
|
||||||
|
}
|
||||||
|
fn rent_epoch(&self) -> Epoch {
|
||||||
|
self.rent_epoch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReadableAccount for Ref<'_, AccountSharedData> {
|
||||||
|
fn lamports(&self) -> u64 {
|
||||||
|
self.lamports
|
||||||
|
}
|
||||||
|
fn data(&self) -> &Vec<u8> {
|
||||||
|
&self.data
|
||||||
|
}
|
||||||
|
fn owner(&self) -> &Pubkey {
|
||||||
|
&self.owner
|
||||||
|
}
|
||||||
|
fn executable(&self) -> bool {
|
||||||
|
self.executable
|
||||||
|
}
|
||||||
|
fn rent_epoch(&self) -> Epoch {
|
||||||
|
self.rent_epoch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReadableAccount for Ref<'_, Account> {
|
||||||
|
fn lamports(&self) -> u64 {
|
||||||
|
self.lamports
|
||||||
|
}
|
||||||
|
fn data(&self) -> &Vec<u8> {
|
||||||
|
&self.data
|
||||||
|
}
|
||||||
|
fn owner(&self) -> &Pubkey {
|
||||||
|
&self.owner
|
||||||
|
}
|
||||||
|
fn executable(&self) -> bool {
|
||||||
|
self.executable
|
||||||
|
}
|
||||||
|
fn rent_epoch(&self) -> Epoch {
|
||||||
|
self.rent_epoch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn debug_fmt<T: ReadableAccount>(item: &T, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let data_len = cmp::min(64, item.data().len());
|
||||||
let data_str = if data_len > 0 {
|
let data_str = if data_len > 0 {
|
||||||
format!(" data: {}", hex::encode(self.data[..data_len].to_vec()))
|
format!(" data: {}", hex::encode(item.data()[..data_len].to_vec()))
|
||||||
} else {
|
} else {
|
||||||
"".to_string()
|
"".to_string()
|
||||||
};
|
};
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"Account {{ lamports: {} data.len: {} owner: {} executable: {} rent_epoch: {}{} }}",
|
"Account {{ lamports: {} data.len: {} owner: {} executable: {} rent_epoch: {}{} }}",
|
||||||
self.lamports,
|
item.lamports(),
|
||||||
self.data.len(),
|
data_len,
|
||||||
self.owner,
|
item.owner(),
|
||||||
self.executable,
|
item.executable(),
|
||||||
self.rent_epoch,
|
item.rent_epoch(),
|
||||||
data_str,
|
data_str,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for Account {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
debug_fmt(self, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for AccountSharedData {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
debug_fmt(self, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shared_new<T: WritableAccount>(lamports: u64, space: usize, owner: &Pubkey) -> T {
|
||||||
|
T::create(
|
||||||
|
lamports,
|
||||||
|
vec![0u8; space],
|
||||||
|
*owner,
|
||||||
|
bool::default(),
|
||||||
|
Epoch::default(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shared_new_ref<T: WritableAccount>(
|
||||||
|
lamports: u64,
|
||||||
|
space: usize,
|
||||||
|
owner: &Pubkey,
|
||||||
|
) -> Rc<RefCell<T>> {
|
||||||
|
Rc::new(RefCell::new(shared_new::<T>(lamports, space, owner)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shared_new_data<T: serde::Serialize, U: WritableAccount>(
|
||||||
|
lamports: u64,
|
||||||
|
state: &T,
|
||||||
|
owner: &Pubkey,
|
||||||
|
) -> Result<U, bincode::Error> {
|
||||||
|
let data = bincode::serialize(state)?;
|
||||||
|
Ok(U::create(
|
||||||
|
lamports,
|
||||||
|
data,
|
||||||
|
*owner,
|
||||||
|
bool::default(),
|
||||||
|
Epoch::default(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
fn shared_new_ref_data<T: serde::Serialize, U: WritableAccount>(
|
||||||
|
lamports: u64,
|
||||||
|
state: &T,
|
||||||
|
owner: &Pubkey,
|
||||||
|
) -> Result<RefCell<U>, bincode::Error> {
|
||||||
|
Ok(RefCell::new(shared_new_data::<T, U>(
|
||||||
|
lamports, state, owner,
|
||||||
|
)?))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shared_new_data_with_space<T: serde::Serialize, U: WritableAccount>(
|
||||||
|
lamports: u64,
|
||||||
|
state: &T,
|
||||||
|
space: usize,
|
||||||
|
owner: &Pubkey,
|
||||||
|
) -> Result<U, bincode::Error> {
|
||||||
|
let mut account = shared_new::<U>(lamports, space, owner);
|
||||||
|
|
||||||
|
shared_serialize_data(&mut account, state)?;
|
||||||
|
|
||||||
|
Ok(account)
|
||||||
|
}
|
||||||
|
fn shared_new_ref_data_with_space<T: serde::Serialize, U: WritableAccount>(
|
||||||
|
lamports: u64,
|
||||||
|
state: &T,
|
||||||
|
space: usize,
|
||||||
|
owner: &Pubkey,
|
||||||
|
) -> Result<RefCell<U>, bincode::Error> {
|
||||||
|
Ok(RefCell::new(shared_new_data_with_space::<T, U>(
|
||||||
|
lamports, state, space, owner,
|
||||||
|
)?))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shared_deserialize_data<T: serde::de::DeserializeOwned, U: ReadableAccount>(
|
||||||
|
account: &U,
|
||||||
|
) -> Result<T, bincode::Error> {
|
||||||
|
bincode::deserialize(account.data())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shared_serialize_data<T: serde::Serialize, U: WritableAccount>(
|
||||||
|
account: &mut U,
|
||||||
|
state: &T,
|
||||||
|
) -> Result<(), bincode::Error> {
|
||||||
|
if bincode::serialized_size(state)? > account.data().len() as u64 {
|
||||||
|
return Err(Box::new(bincode::ErrorKind::SizeLimit));
|
||||||
|
}
|
||||||
|
bincode::serialize_into(&mut account.data_as_mut_slice(), state)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Account {
|
impl Account {
|
||||||
pub fn new(lamports: u64, space: usize, owner: &Pubkey) -> Self {
|
pub fn new(lamports: u64, space: usize, owner: &Pubkey) -> Self {
|
||||||
Self {
|
shared_new(lamports, space, owner)
|
||||||
lamports,
|
|
||||||
data: vec![0u8; space],
|
|
||||||
owner: *owner,
|
|
||||||
..Self::default()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn new_ref(lamports: u64, space: usize, owner: &Pubkey) -> Rc<RefCell<Self>> {
|
pub fn new_ref(lamports: u64, space: usize, owner: &Pubkey) -> Rc<RefCell<Self>> {
|
||||||
Rc::new(RefCell::new(Self::new(lamports, space, owner)))
|
shared_new_ref(lamports, space, owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_data<T: serde::Serialize>(
|
pub fn new_data<T: serde::Serialize>(
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
state: &T,
|
state: &T,
|
||||||
owner: &Pubkey,
|
owner: &Pubkey,
|
||||||
) -> Result<Self, bincode::Error> {
|
) -> Result<Self, bincode::Error> {
|
||||||
let data = bincode::serialize(state)?;
|
shared_new_data(lamports, state, owner)
|
||||||
Ok(Self {
|
|
||||||
lamports,
|
|
||||||
data,
|
|
||||||
owner: *owner,
|
|
||||||
..Self::default()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
pub fn new_ref_data<T: serde::Serialize>(
|
pub fn new_ref_data<T: serde::Serialize>(
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
state: &T,
|
state: &T,
|
||||||
owner: &Pubkey,
|
owner: &Pubkey,
|
||||||
) -> Result<RefCell<Self>, bincode::Error> {
|
) -> Result<RefCell<Self>, bincode::Error> {
|
||||||
Ok(RefCell::new(Self::new_data(lamports, state, owner)?))
|
shared_new_ref_data(lamports, state, owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_data_with_space<T: serde::Serialize>(
|
pub fn new_data_with_space<T: serde::Serialize>(
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
state: &T,
|
state: &T,
|
||||||
space: usize,
|
space: usize,
|
||||||
owner: &Pubkey,
|
owner: &Pubkey,
|
||||||
) -> Result<Self, bincode::Error> {
|
) -> Result<Self, bincode::Error> {
|
||||||
let mut account = Self::new(lamports, space, owner);
|
shared_new_data_with_space(lamports, state, space, owner)
|
||||||
|
|
||||||
account.serialize_data(state)?;
|
|
||||||
|
|
||||||
Ok(account)
|
|
||||||
}
|
}
|
||||||
pub fn new_ref_data_with_space<T: serde::Serialize>(
|
pub fn new_ref_data_with_space<T: serde::Serialize>(
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
|
@ -94,20 +383,58 @@ impl Account {
|
||||||
space: usize,
|
space: usize,
|
||||||
owner: &Pubkey,
|
owner: &Pubkey,
|
||||||
) -> Result<RefCell<Self>, bincode::Error> {
|
) -> Result<RefCell<Self>, bincode::Error> {
|
||||||
Ok(RefCell::new(Self::new_data_with_space(
|
shared_new_ref_data_with_space(lamports, state, space, owner)
|
||||||
lamports, state, space, owner,
|
|
||||||
)?))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deserialize_data<T: serde::de::DeserializeOwned>(&self) -> Result<T, bincode::Error> {
|
pub fn deserialize_data<T: serde::de::DeserializeOwned>(&self) -> Result<T, bincode::Error> {
|
||||||
bincode::deserialize(&self.data)
|
shared_deserialize_data(self)
|
||||||
|
}
|
||||||
|
pub fn serialize_data<T: serde::Serialize>(&mut self, state: &T) -> Result<(), bincode::Error> {
|
||||||
|
shared_serialize_data(self, state)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn serialize_data<T: serde::Serialize>(&mut self, state: &T) -> Result<(), bincode::Error> {
|
impl AccountSharedData {
|
||||||
if bincode::serialized_size(state)? > self.data.len() as u64 {
|
pub fn new(lamports: u64, space: usize, owner: &Pubkey) -> Self {
|
||||||
return Err(Box::new(bincode::ErrorKind::SizeLimit));
|
shared_new(lamports, space, owner)
|
||||||
}
|
}
|
||||||
bincode::serialize_into(&mut self.data[..], state)
|
pub fn new_ref(lamports: u64, space: usize, owner: &Pubkey) -> Rc<RefCell<Self>> {
|
||||||
|
shared_new_ref(lamports, space, owner)
|
||||||
|
}
|
||||||
|
pub fn new_data<T: serde::Serialize>(
|
||||||
|
lamports: u64,
|
||||||
|
state: &T,
|
||||||
|
owner: &Pubkey,
|
||||||
|
) -> Result<Self, bincode::Error> {
|
||||||
|
shared_new_data(lamports, state, owner)
|
||||||
|
}
|
||||||
|
pub fn new_ref_data<T: serde::Serialize>(
|
||||||
|
lamports: u64,
|
||||||
|
state: &T,
|
||||||
|
owner: &Pubkey,
|
||||||
|
) -> Result<RefCell<Self>, bincode::Error> {
|
||||||
|
shared_new_ref_data(lamports, state, owner)
|
||||||
|
}
|
||||||
|
pub fn new_data_with_space<T: serde::Serialize>(
|
||||||
|
lamports: u64,
|
||||||
|
state: &T,
|
||||||
|
space: usize,
|
||||||
|
owner: &Pubkey,
|
||||||
|
) -> Result<Self, bincode::Error> {
|
||||||
|
shared_new_data_with_space(lamports, state, space, owner)
|
||||||
|
}
|
||||||
|
pub fn new_ref_data_with_space<T: serde::Serialize>(
|
||||||
|
lamports: u64,
|
||||||
|
state: &T,
|
||||||
|
space: usize,
|
||||||
|
owner: &Pubkey,
|
||||||
|
) -> Result<RefCell<Self>, bincode::Error> {
|
||||||
|
shared_new_ref_data_with_space(lamports, state, space, owner)
|
||||||
|
}
|
||||||
|
pub fn deserialize_data<T: serde::de::DeserializeOwned>(&self) -> Result<T, bincode::Error> {
|
||||||
|
shared_deserialize_data(self)
|
||||||
|
}
|
||||||
|
pub fn serialize_data<T: serde::Serialize>(&mut self, state: &T) -> Result<(), bincode::Error> {
|
||||||
|
shared_serialize_data(self, state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,18 +442,37 @@ impl Account {
|
||||||
pub fn create_account<S: Sysvar>(sysvar: &S, lamports: u64) -> Account {
|
pub fn create_account<S: Sysvar>(sysvar: &S, lamports: u64) -> Account {
|
||||||
let data_len = S::size_of().max(bincode::serialized_size(sysvar).unwrap() as usize);
|
let data_len = S::size_of().max(bincode::serialized_size(sysvar).unwrap() as usize);
|
||||||
let mut account = Account::new(lamports, data_len, &solana_program::sysvar::id());
|
let mut account = Account::new(lamports, data_len, &solana_program::sysvar::id());
|
||||||
to_account::<S>(sysvar, &mut account).unwrap();
|
to_account::<S, Account>(sysvar, &mut account).unwrap();
|
||||||
account
|
account
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create an `Account` from a `Sysvar`.
|
||||||
|
pub fn create_account_shared_data<S: Sysvar>(sysvar: &S, lamports: u64) -> AccountSharedData {
|
||||||
|
AccountSharedData::from(create_account(sysvar, lamports))
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a `Sysvar` from an `Account`'s data.
|
/// Create a `Sysvar` from an `Account`'s data.
|
||||||
pub fn from_account<S: Sysvar>(account: &Account) -> Option<S> {
|
pub fn from_account<S: Sysvar, T: ReadableAccount>(account: &T) -> Option<S> {
|
||||||
bincode::deserialize(&account.data).ok()
|
bincode::deserialize(account.data()).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serialize a `Sysvar` into an `Account`'s data.
|
/// Serialize a `Sysvar` into an `Account`'s data.
|
||||||
pub fn to_account<S: Sysvar>(sysvar: &S, account: &mut Account) -> Option<()> {
|
pub fn to_account<S: Sysvar, T: WritableAccount>(sysvar: &S, account: &mut T) -> Option<()> {
|
||||||
bincode::serialize_into(&mut account.data[..], sysvar).ok()
|
bincode::serialize_into(account.data_as_mut_slice(), sysvar).ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the information required to construct an `AccountInfo`. Used by the
|
||||||
|
/// `AccountInfo` conversion implementations.
|
||||||
|
impl solana_program::account_info::Account for AccountSharedData {
|
||||||
|
fn get(&mut self) -> (&mut u64, &mut [u8], &Pubkey, bool, Epoch) {
|
||||||
|
(
|
||||||
|
&mut self.lamports,
|
||||||
|
&mut self.data,
|
||||||
|
&self.owner,
|
||||||
|
self.executable,
|
||||||
|
self.rent_epoch,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the information required to construct an `AccountInfo`. Used by the
|
/// Return the information required to construct an `AccountInfo`. Used by the
|
||||||
|
@ -144,7 +490,7 @@ impl solana_program::account_info::Account for Account {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create `AccountInfo`s
|
/// Create `AccountInfo`s
|
||||||
pub fn create_account_infos(accounts: &mut [(Pubkey, Account)]) -> Vec<AccountInfo> {
|
pub fn create_account_infos(accounts: &mut [(Pubkey, AccountSharedData)]) -> Vec<AccountInfo> {
|
||||||
accounts.iter_mut().map(Into::into).collect()
|
accounts.iter_mut().map(Into::into).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,3 +514,292 @@ pub fn create_is_signer_account_infos<'a>(
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn make_two_accounts(key: &Pubkey) -> (Account, AccountSharedData) {
|
||||||
|
let mut account1 = Account::new(1, 2, &key);
|
||||||
|
account1.executable = true;
|
||||||
|
account1.rent_epoch = 4;
|
||||||
|
let mut account2 = AccountSharedData::new(1, 2, key);
|
||||||
|
account2.executable = true;
|
||||||
|
account2.rent_epoch = 4;
|
||||||
|
assert!(accounts_equal(&account1, &account2));
|
||||||
|
(account1, account2)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic(
|
||||||
|
expected = "called `Result::unwrap()` on an `Err` value: Io(Kind(UnexpectedEof))"
|
||||||
|
)]
|
||||||
|
fn test_account_deserialize() {
|
||||||
|
let key = Pubkey::new_unique();
|
||||||
|
let (account1, _account2) = make_two_accounts(&key);
|
||||||
|
account1.deserialize_data::<String>().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic(expected = "called `Result::unwrap()` on an `Err` value: SizeLimit")]
|
||||||
|
fn test_account_serialize() {
|
||||||
|
let key = Pubkey::new_unique();
|
||||||
|
let (mut account1, _account2) = make_two_accounts(&key);
|
||||||
|
account1.serialize_data(&"hello world").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic(
|
||||||
|
expected = "called `Result::unwrap()` on an `Err` value: Io(Kind(UnexpectedEof))"
|
||||||
|
)]
|
||||||
|
fn test_account_shared_data_deserialize() {
|
||||||
|
let key = Pubkey::new_unique();
|
||||||
|
let (_account1, account2) = make_two_accounts(&key);
|
||||||
|
account2.deserialize_data::<String>().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic(expected = "called `Result::unwrap()` on an `Err` value: SizeLimit")]
|
||||||
|
fn test_account_shared_data_serialize() {
|
||||||
|
let key = Pubkey::new_unique();
|
||||||
|
let (_account1, mut account2) = make_two_accounts(&key);
|
||||||
|
account2.serialize_data(&"hello world").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_account_shared_data() {
|
||||||
|
let key = Pubkey::new_unique();
|
||||||
|
let (account1, account2) = make_two_accounts(&key);
|
||||||
|
assert!(accounts_equal(&account1, &account2));
|
||||||
|
let account = account1;
|
||||||
|
assert_eq!(account.lamports, 1);
|
||||||
|
assert_eq!(account.lamports(), 1);
|
||||||
|
assert_eq!(account.data.len(), 2);
|
||||||
|
assert_eq!(account.data().len(), 2);
|
||||||
|
assert_eq!(account.owner, key);
|
||||||
|
assert_eq!(account.owner(), &key);
|
||||||
|
assert_eq!(account.executable, true);
|
||||||
|
assert_eq!(account.executable(), true);
|
||||||
|
assert_eq!(account.rent_epoch, 4);
|
||||||
|
assert_eq!(account.rent_epoch(), 4);
|
||||||
|
let account = account2;
|
||||||
|
assert_eq!(account.lamports, 1);
|
||||||
|
assert_eq!(account.lamports(), 1);
|
||||||
|
assert_eq!(account.data.len(), 2);
|
||||||
|
assert_eq!(account.data().len(), 2);
|
||||||
|
assert_eq!(account.owner, key);
|
||||||
|
assert_eq!(account.owner(), &key);
|
||||||
|
assert_eq!(account.executable, true);
|
||||||
|
assert_eq!(account.executable(), true);
|
||||||
|
assert_eq!(account.rent_epoch, 4);
|
||||||
|
assert_eq!(account.rent_epoch(), 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// test clone and from for both types against expected
|
||||||
|
fn test_equal(
|
||||||
|
should_be_equal: bool,
|
||||||
|
account1: &Account,
|
||||||
|
account2: &AccountSharedData,
|
||||||
|
account_expected: &Account,
|
||||||
|
) {
|
||||||
|
assert_eq!(should_be_equal, accounts_equal(account1, account2));
|
||||||
|
if should_be_equal {
|
||||||
|
assert!(accounts_equal(account_expected, account2));
|
||||||
|
}
|
||||||
|
assert_eq!(
|
||||||
|
accounts_equal(account_expected, account1),
|
||||||
|
accounts_equal(account_expected, &account1.clone())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
accounts_equal(account_expected, account2),
|
||||||
|
accounts_equal(account_expected, &account2.clone())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
accounts_equal(account_expected, account1),
|
||||||
|
accounts_equal(account_expected, &AccountSharedData::from(account1.clone()))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
accounts_equal(account_expected, account2),
|
||||||
|
accounts_equal(account_expected, &Account::from(account2.clone()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[allow(clippy::redundant_clone)]
|
||||||
|
fn test_account_shared_data_all_fields() {
|
||||||
|
let key = Pubkey::new_unique();
|
||||||
|
let key2 = Pubkey::new_unique();
|
||||||
|
let key3 = Pubkey::new_unique();
|
||||||
|
let (mut account1, mut account2) = make_two_accounts(&key);
|
||||||
|
assert!(accounts_equal(&account1, &account2));
|
||||||
|
|
||||||
|
let mut account_expected = account1.clone();
|
||||||
|
assert!(accounts_equal(&account1, &account_expected));
|
||||||
|
assert!(accounts_equal(&account1, &account2.clone())); // test the clone here
|
||||||
|
|
||||||
|
for field_index in 0..5 {
|
||||||
|
for pass in 0..4 {
|
||||||
|
if field_index == 0 {
|
||||||
|
if pass == 0 {
|
||||||
|
account1.lamports += 1;
|
||||||
|
} else if pass == 1 {
|
||||||
|
account_expected.lamports += 1;
|
||||||
|
account2.set_lamports(account2.lamports + 1);
|
||||||
|
} else if pass == 2 {
|
||||||
|
account1.set_lamports(account1.lamports + 1);
|
||||||
|
} else if pass == 3 {
|
||||||
|
account_expected.lamports += 1;
|
||||||
|
account2.lamports += 1;
|
||||||
|
}
|
||||||
|
} else if field_index == 1 {
|
||||||
|
if pass == 0 {
|
||||||
|
account1.data[0] += 1;
|
||||||
|
} else if pass == 1 {
|
||||||
|
account_expected.data[0] += 1;
|
||||||
|
account2.data_as_mut_slice()[0] = account2.data[0] + 1;
|
||||||
|
} else if pass == 2 {
|
||||||
|
account1.data_as_mut_slice()[0] = account1.data[0] + 1;
|
||||||
|
} else if pass == 3 {
|
||||||
|
account_expected.data[0] += 1;
|
||||||
|
account2.data[0] += 1;
|
||||||
|
}
|
||||||
|
} else if field_index == 2 {
|
||||||
|
if pass == 0 {
|
||||||
|
account1.owner = key2;
|
||||||
|
} else if pass == 1 {
|
||||||
|
account_expected.owner = key2;
|
||||||
|
account2.set_owner(key2);
|
||||||
|
} else if pass == 2 {
|
||||||
|
account1.set_owner(key3);
|
||||||
|
} else if pass == 3 {
|
||||||
|
account_expected.owner = key3;
|
||||||
|
account2.owner = key3;
|
||||||
|
}
|
||||||
|
} else if field_index == 3 {
|
||||||
|
if pass == 0 {
|
||||||
|
account1.executable = !account1.executable;
|
||||||
|
} else if pass == 1 {
|
||||||
|
account_expected.executable = !account_expected.executable;
|
||||||
|
account2.set_executable(!account2.executable);
|
||||||
|
} else if pass == 2 {
|
||||||
|
account1.set_executable(!account1.executable);
|
||||||
|
} else if pass == 3 {
|
||||||
|
account_expected.executable = !account_expected.executable;
|
||||||
|
account2.executable = !account2.executable;
|
||||||
|
}
|
||||||
|
} else if field_index == 4 {
|
||||||
|
if pass == 0 {
|
||||||
|
account1.rent_epoch += 1;
|
||||||
|
} else if pass == 1 {
|
||||||
|
account_expected.rent_epoch += 1;
|
||||||
|
account2.set_rent_epoch(account2.rent_epoch + 1);
|
||||||
|
} else if pass == 2 {
|
||||||
|
account1.set_rent_epoch(account1.rent_epoch + 1);
|
||||||
|
} else if pass == 3 {
|
||||||
|
account_expected.rent_epoch += 1;
|
||||||
|
account2.rent_epoch += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let should_be_equal = pass == 1 || pass == 3;
|
||||||
|
test_equal(should_be_equal, &account1, &account2, &account_expected);
|
||||||
|
|
||||||
|
// test new_ref
|
||||||
|
if should_be_equal {
|
||||||
|
assert!(accounts_equal(
|
||||||
|
&Account::new_ref(
|
||||||
|
account_expected.lamports(),
|
||||||
|
account_expected.data().len(),
|
||||||
|
account_expected.owner()
|
||||||
|
)
|
||||||
|
.borrow(),
|
||||||
|
&AccountSharedData::new_ref(
|
||||||
|
account_expected.lamports(),
|
||||||
|
account_expected.data().len(),
|
||||||
|
account_expected.owner()
|
||||||
|
)
|
||||||
|
.borrow()
|
||||||
|
));
|
||||||
|
|
||||||
|
{
|
||||||
|
// test new_data
|
||||||
|
let account1_with_data = Account::new_data(
|
||||||
|
account_expected.lamports(),
|
||||||
|
&account_expected.data()[0],
|
||||||
|
account_expected.owner(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let account2_with_data = AccountSharedData::new_data(
|
||||||
|
account_expected.lamports(),
|
||||||
|
&account_expected.data()[0],
|
||||||
|
account_expected.owner(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert!(accounts_equal(&account1_with_data, &account2_with_data));
|
||||||
|
assert_eq!(
|
||||||
|
account1_with_data.deserialize_data::<u8>().unwrap(),
|
||||||
|
account2_with_data.deserialize_data::<u8>().unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// test new_data_with_space
|
||||||
|
assert!(accounts_equal(
|
||||||
|
&Account::new_data_with_space(
|
||||||
|
account_expected.lamports(),
|
||||||
|
&account_expected.data()[0],
|
||||||
|
1,
|
||||||
|
account_expected.owner()
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
&AccountSharedData::new_data_with_space(
|
||||||
|
account_expected.lamports(),
|
||||||
|
&account_expected.data()[0],
|
||||||
|
1,
|
||||||
|
account_expected.owner()
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
));
|
||||||
|
|
||||||
|
// test new_ref_data
|
||||||
|
assert!(accounts_equal(
|
||||||
|
&Account::new_ref_data(
|
||||||
|
account_expected.lamports(),
|
||||||
|
&account_expected.data()[0],
|
||||||
|
account_expected.owner()
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.borrow(),
|
||||||
|
&AccountSharedData::new_ref_data(
|
||||||
|
account_expected.lamports(),
|
||||||
|
&account_expected.data()[0],
|
||||||
|
account_expected.owner()
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.borrow()
|
||||||
|
));
|
||||||
|
|
||||||
|
//new_ref_data_with_space
|
||||||
|
assert!(accounts_equal(
|
||||||
|
&Account::new_ref_data_with_space(
|
||||||
|
account_expected.lamports(),
|
||||||
|
&account_expected.data()[0],
|
||||||
|
1,
|
||||||
|
account_expected.owner()
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.borrow(),
|
||||||
|
&AccountSharedData::new_ref_data_with_space(
|
||||||
|
account_expected.lamports(),
|
||||||
|
&account_expected.data()[0],
|
||||||
|
1,
|
||||||
|
account_expected.owner()
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.borrow()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! useful extras for Account state
|
//! useful extras for Account state
|
||||||
use crate::{account::Account, instruction::InstructionError};
|
use crate::{account::Account, account::AccountSharedData, instruction::InstructionError};
|
||||||
use bincode::ErrorKind;
|
use bincode::ErrorKind;
|
||||||
|
use std::cell::Ref;
|
||||||
|
|
||||||
/// Convenience trait to covert bincode errors to instruction errors.
|
/// Convenience trait to covert bincode errors to instruction errors.
|
||||||
pub trait StateMut<T> {
|
pub trait StateMut<T> {
|
||||||
|
@ -28,20 +29,49 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> StateMut<T> for AccountSharedData
|
||||||
|
where
|
||||||
|
T: serde::Serialize + serde::de::DeserializeOwned,
|
||||||
|
{
|
||||||
|
fn state(&self) -> Result<T, InstructionError> {
|
||||||
|
self.deserialize_data()
|
||||||
|
.map_err(|_| InstructionError::InvalidAccountData)
|
||||||
|
}
|
||||||
|
fn set_state(&mut self, state: &T) -> Result<(), InstructionError> {
|
||||||
|
self.serialize_data(state).map_err(|err| match *err {
|
||||||
|
ErrorKind::SizeLimit => InstructionError::AccountDataTooSmall,
|
||||||
|
_ => InstructionError::GenericError,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> StateMut<T> for Ref<'_, AccountSharedData>
|
||||||
|
where
|
||||||
|
T: serde::Serialize + serde::de::DeserializeOwned,
|
||||||
|
{
|
||||||
|
fn state(&self) -> Result<T, InstructionError> {
|
||||||
|
self.deserialize_data()
|
||||||
|
.map_err(|_| InstructionError::InvalidAccountData)
|
||||||
|
}
|
||||||
|
fn set_state(&mut self, _state: &T) -> Result<(), InstructionError> {
|
||||||
|
panic!("illegal");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{account::Account, pubkey::Pubkey};
|
use crate::{account::AccountSharedData, pubkey::Pubkey};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_account_state() {
|
fn test_account_state() {
|
||||||
let state = 42u64;
|
let state = 42u64;
|
||||||
|
|
||||||
assert!(Account::default().set_state(&state).is_err());
|
assert!(AccountSharedData::default().set_state(&state).is_err());
|
||||||
let res = Account::default().state() as Result<u64, InstructionError>;
|
let res = AccountSharedData::default().state() as Result<u64, InstructionError>;
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
|
|
||||||
let mut account = Account::new(0, std::mem::size_of::<u64>(), &Pubkey::default());
|
let mut account = AccountSharedData::new(0, std::mem::size_of::<u64>(), &Pubkey::default());
|
||||||
|
|
||||||
assert!(account.set_state(&state).is_ok());
|
assert!(account.set_state(&state).is_ok());
|
||||||
let stored_state: u64 = account.state().unwrap();
|
let stored_state: u64 = account.state().unwrap();
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
use crate::account::Account;
|
use crate::account::AccountSharedData;
|
||||||
|
use crate::account::ReadableAccount;
|
||||||
pub use solana_program::feature::*;
|
pub use solana_program::feature::*;
|
||||||
|
|
||||||
pub fn from_account(account: &Account) -> Option<Feature> {
|
pub fn from_account<T: ReadableAccount>(account: &T) -> Option<Feature> {
|
||||||
if account.owner != id() {
|
if account.owner() != &id() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
bincode::deserialize(&account.data).ok()
|
bincode::deserialize(account.data()).ok()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_account(feature: &Feature, account: &mut Account) -> Option<()> {
|
pub fn to_account(feature: &Feature, account: &mut AccountSharedData) -> Option<()> {
|
||||||
bincode::serialize_into(&mut account.data[..], feature).ok()
|
bincode::serialize_into(&mut account.data[..], feature).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_account(feature: &Feature, lamports: u64) -> Account {
|
pub fn create_account(feature: &Feature, lamports: u64) -> AccountSharedData {
|
||||||
let data_len = Feature::size_of().max(bincode::serialized_size(feature).unwrap() as usize);
|
let data_len = Feature::size_of().max(bincode::serialized_size(feature).unwrap() as usize);
|
||||||
let mut account = Account::new(lamports, data_len, &id());
|
let mut account = AccountSharedData::new(lamports, data_len, &id());
|
||||||
to_account(feature, &mut account).unwrap();
|
to_account(feature, &mut account).unwrap();
|
||||||
account
|
account
|
||||||
}
|
}
|
||||||
|
@ -26,7 +27,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn feature_deserialize_none() {
|
fn feature_deserialize_none() {
|
||||||
let just_initialized = Account::new(42, Feature::size_of(), &id());
|
let just_initialized = AccountSharedData::new(42, Feature::size_of(), &id());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
from_account(&just_initialized),
|
from_account(&just_initialized),
|
||||||
Some(Feature { activated_at: None })
|
Some(Feature { activated_at: None })
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
account::Account,
|
account::Account,
|
||||||
|
account::AccountSharedData,
|
||||||
clock::{UnixTimestamp, DEFAULT_TICKS_PER_SLOT},
|
clock::{UnixTimestamp, DEFAULT_TICKS_PER_SLOT},
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
fee_calculator::FeeRateGovernor,
|
fee_calculator::FeeRateGovernor,
|
||||||
|
@ -98,7 +99,7 @@ pub fn create_genesis_config(lamports: u64) -> (GenesisConfig, Keypair) {
|
||||||
GenesisConfig::new(
|
GenesisConfig::new(
|
||||||
&[(
|
&[(
|
||||||
faucet_keypair.pubkey(),
|
faucet_keypair.pubkey(),
|
||||||
Account::new(lamports, 0, &system_program::id()),
|
AccountSharedData::new(lamports, 0, &system_program::id()),
|
||||||
)],
|
)],
|
||||||
&[],
|
&[],
|
||||||
),
|
),
|
||||||
|
@ -131,13 +132,14 @@ impl Default for GenesisConfig {
|
||||||
|
|
||||||
impl GenesisConfig {
|
impl GenesisConfig {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
accounts: &[(Pubkey, Account)],
|
accounts: &[(Pubkey, AccountSharedData)],
|
||||||
native_instruction_processors: &[(String, Pubkey)],
|
native_instruction_processors: &[(String, Pubkey)],
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
accounts: accounts
|
accounts: accounts
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
|
.map(|(key, account)| (key, Account::from(account)))
|
||||||
.collect::<BTreeMap<Pubkey, Account>>(),
|
.collect::<BTreeMap<Pubkey, Account>>(),
|
||||||
native_instruction_processors: native_instruction_processors.to_vec(),
|
native_instruction_processors: native_instruction_processors.to_vec(),
|
||||||
..GenesisConfig::default()
|
..GenesisConfig::default()
|
||||||
|
@ -201,8 +203,8 @@ impl GenesisConfig {
|
||||||
file.write_all(&serialized)
|
file.write_all(&serialized)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_account(&mut self, pubkey: Pubkey, account: Account) {
|
pub fn add_account(&mut self, pubkey: Pubkey, account: AccountSharedData) {
|
||||||
self.accounts.insert(pubkey, account);
|
self.accounts.insert(pubkey, Account::from(account));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_native_instruction_processor(&mut self, name: String, program_id: Pubkey) {
|
pub fn add_native_instruction_processor(&mut self, name: String, program_id: Pubkey) {
|
||||||
|
@ -318,11 +320,11 @@ mod tests {
|
||||||
let mut config = GenesisConfig::default();
|
let mut config = GenesisConfig::default();
|
||||||
config.add_account(
|
config.add_account(
|
||||||
faucet_keypair.pubkey(),
|
faucet_keypair.pubkey(),
|
||||||
Account::new(10_000, 0, &Pubkey::default()),
|
AccountSharedData::new(10_000, 0, &Pubkey::default()),
|
||||||
);
|
);
|
||||||
config.add_account(
|
config.add_account(
|
||||||
solana_sdk::pubkey::new_rand(),
|
solana_sdk::pubkey::new_rand(),
|
||||||
Account::new(1, 0, &Pubkey::default()),
|
AccountSharedData::new(1, 0, &Pubkey::default()),
|
||||||
);
|
);
|
||||||
config.add_native_instruction_processor("hi".to_string(), solana_sdk::pubkey::new_rand());
|
config.add_native_instruction_processor("hi".to_string(), solana_sdk::pubkey::new_rand());
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
account::{from_account, Account},
|
account::{from_account, AccountSharedData},
|
||||||
account_utils::{State, StateMut},
|
account_utils::{State, StateMut},
|
||||||
};
|
};
|
||||||
use solana_program::{clock::Epoch, instruction::InstructionError, pubkey::Pubkey, sysvar::Sysvar};
|
use solana_program::{clock::Epoch, instruction::InstructionError, pubkey::Pubkey, sysvar::Sysvar};
|
||||||
|
@ -14,7 +14,7 @@ pub struct KeyedAccount<'a> {
|
||||||
is_signer: bool, // Transaction was signed by this account's key
|
is_signer: bool, // Transaction was signed by this account's key
|
||||||
is_writable: bool,
|
is_writable: bool,
|
||||||
key: &'a Pubkey,
|
key: &'a Pubkey,
|
||||||
pub account: &'a RefCell<Account>,
|
pub account: &'a RefCell<AccountSharedData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> KeyedAccount<'a> {
|
impl<'a> KeyedAccount<'a> {
|
||||||
|
@ -58,26 +58,26 @@ impl<'a> KeyedAccount<'a> {
|
||||||
Ok(self.try_borrow()?.rent_epoch)
|
Ok(self.try_borrow()?.rent_epoch)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_account_ref(&'a self) -> Result<Ref<Account>, InstructionError> {
|
pub fn try_account_ref(&'a self) -> Result<Ref<AccountSharedData>, InstructionError> {
|
||||||
self.try_borrow()
|
self.try_borrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_account_ref_mut(&'a self) -> Result<RefMut<Account>, InstructionError> {
|
pub fn try_account_ref_mut(&'a self) -> Result<RefMut<AccountSharedData>, InstructionError> {
|
||||||
self.try_borrow_mut()
|
self.try_borrow_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_borrow(&self) -> Result<Ref<Account>, InstructionError> {
|
fn try_borrow(&self) -> Result<Ref<AccountSharedData>, InstructionError> {
|
||||||
self.account
|
self.account
|
||||||
.try_borrow()
|
.try_borrow()
|
||||||
.map_err(|_| InstructionError::AccountBorrowFailed)
|
.map_err(|_| InstructionError::AccountBorrowFailed)
|
||||||
}
|
}
|
||||||
fn try_borrow_mut(&self) -> Result<RefMut<Account>, InstructionError> {
|
fn try_borrow_mut(&self) -> Result<RefMut<AccountSharedData>, InstructionError> {
|
||||||
self.account
|
self.account
|
||||||
.try_borrow_mut()
|
.try_borrow_mut()
|
||||||
.map_err(|_| InstructionError::AccountBorrowFailed)
|
.map_err(|_| InstructionError::AccountBorrowFailed)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(key: &'a Pubkey, is_signer: bool, account: &'a RefCell<Account>) -> Self {
|
pub fn new(key: &'a Pubkey, is_signer: bool, account: &'a RefCell<AccountSharedData>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
is_signer,
|
is_signer,
|
||||||
is_writable: true,
|
is_writable: true,
|
||||||
|
@ -86,7 +86,11 @@ impl<'a> KeyedAccount<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_readonly(key: &'a Pubkey, is_signer: bool, account: &'a RefCell<Account>) -> Self {
|
pub fn new_readonly(
|
||||||
|
key: &'a Pubkey,
|
||||||
|
is_signer: bool,
|
||||||
|
account: &'a RefCell<AccountSharedData>,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
is_signer,
|
is_signer,
|
||||||
is_writable: false,
|
is_writable: false,
|
||||||
|
@ -102,8 +106,8 @@ impl<'a> PartialEq for KeyedAccount<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<(&'a Pubkey, &'a RefCell<Account>)> for KeyedAccount<'a> {
|
impl<'a> From<(&'a Pubkey, &'a RefCell<AccountSharedData>)> for KeyedAccount<'a> {
|
||||||
fn from((key, account): (&'a Pubkey, &'a RefCell<Account>)) -> Self {
|
fn from((key, account): (&'a Pubkey, &'a RefCell<AccountSharedData>)) -> Self {
|
||||||
Self {
|
Self {
|
||||||
is_signer: false,
|
is_signer: false,
|
||||||
is_writable: true,
|
is_writable: true,
|
||||||
|
@ -113,8 +117,8 @@ impl<'a> From<(&'a Pubkey, &'a RefCell<Account>)> for KeyedAccount<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<(&'a Pubkey, bool, &'a RefCell<Account>)> for KeyedAccount<'a> {
|
impl<'a> From<(&'a Pubkey, bool, &'a RefCell<AccountSharedData>)> for KeyedAccount<'a> {
|
||||||
fn from((key, is_signer, account): (&'a Pubkey, bool, &'a RefCell<Account>)) -> Self {
|
fn from((key, is_signer, account): (&'a Pubkey, bool, &'a RefCell<AccountSharedData>)) -> Self {
|
||||||
Self {
|
Self {
|
||||||
is_signer,
|
is_signer,
|
||||||
is_writable: true,
|
is_writable: true,
|
||||||
|
@ -124,8 +128,8 @@ impl<'a> From<(&'a Pubkey, bool, &'a RefCell<Account>)> for KeyedAccount<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a (&'a Pubkey, &'a RefCell<Account>)> for KeyedAccount<'a> {
|
impl<'a> From<&'a (&'a Pubkey, &'a RefCell<AccountSharedData>)> for KeyedAccount<'a> {
|
||||||
fn from((key, account): &'a (&'a Pubkey, &'a RefCell<Account>)) -> Self {
|
fn from((key, account): &'a (&'a Pubkey, &'a RefCell<AccountSharedData>)) -> Self {
|
||||||
Self {
|
Self {
|
||||||
is_signer: false,
|
is_signer: false,
|
||||||
is_writable: true,
|
is_writable: true,
|
||||||
|
@ -136,13 +140,13 @@ impl<'a> From<&'a (&'a Pubkey, &'a RefCell<Account>)> for KeyedAccount<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_keyed_accounts<'a>(
|
pub fn create_keyed_accounts<'a>(
|
||||||
accounts: &'a [(&'a Pubkey, &'a RefCell<Account>)],
|
accounts: &'a [(&'a Pubkey, &'a RefCell<AccountSharedData>)],
|
||||||
) -> Vec<KeyedAccount<'a>> {
|
) -> Vec<KeyedAccount<'a>> {
|
||||||
accounts.iter().map(Into::into).collect()
|
accounts.iter().map(Into::into).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_keyed_is_signer_accounts<'a>(
|
pub fn create_keyed_is_signer_accounts<'a>(
|
||||||
accounts: &'a [(&'a Pubkey, bool, &'a RefCell<Account>)],
|
accounts: &'a [(&'a Pubkey, bool, &'a RefCell<AccountSharedData>)],
|
||||||
) -> Vec<KeyedAccount<'a>> {
|
) -> Vec<KeyedAccount<'a>> {
|
||||||
accounts
|
accounts
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -156,7 +160,7 @@ pub fn create_keyed_is_signer_accounts<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_keyed_readonly_accounts(
|
pub fn create_keyed_readonly_accounts(
|
||||||
accounts: &[(Pubkey, RefCell<Account>)],
|
accounts: &[(Pubkey, RefCell<AccountSharedData>)],
|
||||||
) -> Vec<KeyedAccount> {
|
) -> Vec<KeyedAccount> {
|
||||||
accounts
|
accounts
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -212,7 +216,8 @@ pub fn from_keyed_account<S: Sysvar>(
|
||||||
if !S::check_id(keyed_account.unsigned_key()) {
|
if !S::check_id(keyed_account.unsigned_key()) {
|
||||||
return Err(InstructionError::InvalidArgument);
|
return Err(InstructionError::InvalidArgument);
|
||||||
}
|
}
|
||||||
from_account::<S>(&*keyed_account.try_account_ref()?).ok_or(InstructionError::InvalidArgument)
|
from_account::<S, AccountSharedData>(&*keyed_account.try_account_ref()?)
|
||||||
|
.ok_or(InstructionError::InvalidArgument)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -244,12 +249,12 @@ mod tests {
|
||||||
let wrong_key = Pubkey::new_unique();
|
let wrong_key = Pubkey::new_unique();
|
||||||
|
|
||||||
let account = create_account(&test_sysvar, 42);
|
let account = create_account(&test_sysvar, 42);
|
||||||
let test_sysvar = from_account::<TestSysvar>(&account).unwrap();
|
let test_sysvar = from_account::<TestSysvar, _>(&account).unwrap();
|
||||||
assert_eq!(test_sysvar, TestSysvar::default());
|
assert_eq!(test_sysvar, TestSysvar::default());
|
||||||
|
|
||||||
let mut account = Account::new(42, TestSysvar::size_of(), &key);
|
let mut account = AccountSharedData::new(42, TestSysvar::size_of(), &key);
|
||||||
to_account(&test_sysvar, &mut account).unwrap();
|
to_account(&test_sysvar, &mut account).unwrap();
|
||||||
let test_sysvar = from_account::<TestSysvar>(&account).unwrap();
|
let test_sysvar = from_account::<TestSysvar, _>(&account).unwrap();
|
||||||
assert_eq!(test_sysvar, TestSysvar::default());
|
assert_eq!(test_sysvar, TestSysvar::default());
|
||||||
|
|
||||||
let account = RefCell::new(account);
|
let account = RefCell::new(account);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::account::Account;
|
use crate::account::AccountSharedData;
|
||||||
|
|
||||||
crate::declare_id!("NativeLoader1111111111111111111111111111111");
|
crate::declare_id!("NativeLoader1111111111111111111111111111111");
|
||||||
|
|
||||||
/// Create an executable account with the given shared object name.
|
/// Create an executable account with the given shared object name.
|
||||||
pub fn create_loadable_account(name: &str, lamports: u64) -> Account {
|
pub fn create_loadable_account(name: &str, lamports: u64) -> AccountSharedData {
|
||||||
Account {
|
AccountSharedData {
|
||||||
lamports,
|
lamports,
|
||||||
owner: id(),
|
owner: id(),
|
||||||
data: name.as_bytes().to_vec(),
|
data: name.as_bytes().to_vec(),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
fee_calculator::FeeCalculator,
|
fee_calculator::FeeCalculator,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
|
@ -7,9 +7,9 @@ use crate::{
|
||||||
};
|
};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
pub fn create_account(lamports: u64) -> RefCell<Account> {
|
pub fn create_account(lamports: u64) -> RefCell<AccountSharedData> {
|
||||||
RefCell::new(
|
RefCell::new(
|
||||||
Account::new_data_with_space(
|
AccountSharedData::new_data_with_space(
|
||||||
lamports,
|
lamports,
|
||||||
&Versions::new_current(State::Uninitialized),
|
&Versions::new_current(State::Uninitialized),
|
||||||
State::size(),
|
State::size(),
|
||||||
|
@ -19,7 +19,7 @@ pub fn create_account(lamports: u64) -> RefCell<Account> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn verify_nonce_account(acc: &Account, hash: &Hash) -> bool {
|
pub fn verify_nonce_account(acc: &AccountSharedData, hash: &Hash) -> bool {
|
||||||
if acc.owner != crate::system_program::id() {
|
if acc.owner != crate::system_program::id() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ pub fn verify_nonce_account(acc: &Account, hash: &Hash) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fee_calculator_of(account: &Account) -> Option<FeeCalculator> {
|
pub fn fee_calculator_of(account: &AccountSharedData) -> Option<FeeCalculator> {
|
||||||
let state = StateMut::<Versions>::state(account)
|
let state = StateMut::<Versions>::state(account)
|
||||||
.ok()?
|
.ok()?
|
||||||
.convert_to_current();
|
.convert_to_current();
|
||||||
|
@ -48,7 +48,7 @@ mod tests {
|
||||||
fn test_verify_bad_account_owner_fails() {
|
fn test_verify_bad_account_owner_fails() {
|
||||||
let program_id = Pubkey::new_unique();
|
let program_id = Pubkey::new_unique();
|
||||||
assert_ne!(program_id, crate::system_program::id());
|
assert_ne!(program_id, crate::system_program::id());
|
||||||
let account = Account::new_data_with_space(
|
let account = AccountSharedData::new_data_with_space(
|
||||||
42,
|
42,
|
||||||
&Versions::new_current(State::Uninitialized),
|
&Versions::new_current(State::Uninitialized),
|
||||||
State::size(),
|
State::size(),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
instruction::{CompiledInstruction, Instruction, InstructionError},
|
instruction::{CompiledInstruction, Instruction, InstructionError},
|
||||||
keyed_account::KeyedAccount,
|
keyed_account::KeyedAccount,
|
||||||
message::Message,
|
message::Message,
|
||||||
|
@ -36,7 +36,7 @@ pub trait InvokeContext {
|
||||||
&mut self,
|
&mut self,
|
||||||
message: &Message,
|
message: &Message,
|
||||||
instruction: &CompiledInstruction,
|
instruction: &CompiledInstruction,
|
||||||
accounts: &[Rc<RefCell<Account>>],
|
accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||||
caller_pivileges: Option<&[bool]>,
|
caller_pivileges: Option<&[bool]>,
|
||||||
) -> Result<(), InstructionError>;
|
) -> Result<(), InstructionError>;
|
||||||
/// Get the program ID of the currently executing program
|
/// Get the program ID of the currently executing program
|
||||||
|
@ -59,7 +59,7 @@ pub trait InvokeContext {
|
||||||
/// Get the bank's active feature set
|
/// Get the bank's active feature set
|
||||||
fn is_feature_active(&self, feature_id: &Pubkey) -> bool;
|
fn is_feature_active(&self, feature_id: &Pubkey) -> bool;
|
||||||
/// Get an account from a pre-account
|
/// Get an account from a pre-account
|
||||||
fn get_account(&self, pubkey: &Pubkey) -> Option<RefCell<Account>>;
|
fn get_account(&self, pubkey: &Pubkey) -> Option<RefCell<AccountSharedData>>;
|
||||||
/// Update timing
|
/// Update timing
|
||||||
fn update_timing(
|
fn update_timing(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -305,7 +305,7 @@ impl InvokeContext for MockInvokeContext {
|
||||||
&mut self,
|
&mut self,
|
||||||
_message: &Message,
|
_message: &Message,
|
||||||
_instruction: &CompiledInstruction,
|
_instruction: &CompiledInstruction,
|
||||||
_accounts: &[Rc<RefCell<Account>>],
|
_accounts: &[Rc<RefCell<AccountSharedData>>],
|
||||||
_caller_pivileges: Option<&[bool]>,
|
_caller_pivileges: Option<&[bool]>,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -333,7 +333,7 @@ impl InvokeContext for MockInvokeContext {
|
||||||
fn is_feature_active(&self, _feature_id: &Pubkey) -> bool {
|
fn is_feature_active(&self, _feature_id: &Pubkey) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
fn get_account(&self, _pubkey: &Pubkey) -> Option<RefCell<Account>> {
|
fn get_account(&self, _pubkey: &Pubkey) -> Option<RefCell<AccountSharedData>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn update_timing(
|
fn update_timing(
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
use crate::account::{create_account, to_account, Account};
|
use crate::account::{create_account_shared_data, to_account, AccountSharedData};
|
||||||
use solana_program::sysvar::recent_blockhashes::{
|
use solana_program::sysvar::recent_blockhashes::{
|
||||||
IntoIterSorted, IterItem, RecentBlockhashes, MAX_ENTRIES,
|
IntoIterSorted, IterItem, RecentBlockhashes, MAX_ENTRIES,
|
||||||
};
|
};
|
||||||
use std::{collections::BinaryHeap, iter::FromIterator};
|
use std::{collections::BinaryHeap, iter::FromIterator};
|
||||||
|
|
||||||
pub fn update_account<'a, I>(account: &mut Account, recent_blockhash_iter: I) -> Option<()>
|
pub fn update_account<'a, I>(
|
||||||
|
account: &mut AccountSharedData,
|
||||||
|
recent_blockhash_iter: I,
|
||||||
|
) -> Option<()>
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = IterItem<'a>>,
|
I: IntoIterator<Item = IterItem<'a>>,
|
||||||
{
|
{
|
||||||
|
@ -15,11 +18,12 @@ where
|
||||||
to_account(&recent_blockhashes, account)
|
to_account(&recent_blockhashes, account)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_account_with_data<'a, I>(lamports: u64, recent_blockhash_iter: I) -> Account
|
pub fn create_account_with_data<'a, I>(lamports: u64, recent_blockhash_iter: I) -> AccountSharedData
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = IterItem<'a>>,
|
I: IntoIterator<Item = IterItem<'a>>,
|
||||||
{
|
{
|
||||||
let mut account = create_account::<RecentBlockhashes>(&RecentBlockhashes::default(), lamports);
|
let mut account =
|
||||||
|
create_account_shared_data::<RecentBlockhashes>(&RecentBlockhashes::default(), lamports);
|
||||||
update_account(&mut account, recent_blockhash_iter).unwrap();
|
update_account(&mut account, recent_blockhash_iter).unwrap();
|
||||||
account
|
account
|
||||||
}
|
}
|
||||||
|
@ -38,7 +42,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_account_empty() {
|
fn test_create_account_empty() {
|
||||||
let account = create_account_with_data(42, vec![].into_iter());
|
let account = create_account_with_data(42, vec![].into_iter());
|
||||||
let recent_blockhashes = from_account::<RecentBlockhashes>(&account).unwrap();
|
let recent_blockhashes = from_account::<RecentBlockhashes, _>(&account).unwrap();
|
||||||
assert_eq!(recent_blockhashes, RecentBlockhashes::default());
|
assert_eq!(recent_blockhashes, RecentBlockhashes::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +54,7 @@ mod tests {
|
||||||
42,
|
42,
|
||||||
vec![IterItem(0u64, &def_hash, &def_fees); MAX_ENTRIES].into_iter(),
|
vec![IterItem(0u64, &def_hash, &def_fees); MAX_ENTRIES].into_iter(),
|
||||||
);
|
);
|
||||||
let recent_blockhashes = from_account::<RecentBlockhashes>(&account).unwrap();
|
let recent_blockhashes = from_account::<RecentBlockhashes, _>(&account).unwrap();
|
||||||
assert_eq!(recent_blockhashes.len(), MAX_ENTRIES);
|
assert_eq!(recent_blockhashes.len(), MAX_ENTRIES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +66,7 @@ mod tests {
|
||||||
42,
|
42,
|
||||||
vec![IterItem(0u64, &def_hash, &def_fees); MAX_ENTRIES + 1].into_iter(),
|
vec![IterItem(0u64, &def_hash, &def_fees); MAX_ENTRIES + 1].into_iter(),
|
||||||
);
|
);
|
||||||
let recent_blockhashes = from_account::<RecentBlockhashes>(&account).unwrap();
|
let recent_blockhashes = from_account::<RecentBlockhashes, _>(&account).unwrap();
|
||||||
assert_eq!(recent_blockhashes.len(), MAX_ENTRIES);
|
assert_eq!(recent_blockhashes.len(), MAX_ENTRIES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +91,7 @@ mod tests {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(i, hash)| IterItem(*i, hash, &def_fees)),
|
.map(|(i, hash)| IterItem(*i, hash, &def_fees)),
|
||||||
);
|
);
|
||||||
let recent_blockhashes = from_account::<RecentBlockhashes>(&account).unwrap();
|
let recent_blockhashes = from_account::<RecentBlockhashes, _>(&account).unwrap();
|
||||||
|
|
||||||
let mut unsorted_recent_blockhashes: Vec<_> = unsorted_blocks
|
let mut unsorted_recent_blockhashes: Vec<_> = unsorted_blocks
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -280,7 +280,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use solana_runtime::{bank::Bank, bank_client::BankClient};
|
use solana_runtime::{bank::Bank, bank_client::BankClient};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
client::SyncClient,
|
client::SyncClient,
|
||||||
genesis_config::create_genesis_config,
|
genesis_config::create_genesis_config,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
|
@ -306,9 +306,13 @@ mod tests {
|
||||||
fee_payer_keypair
|
fee_payer_keypair
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_account_at<C: SyncClient>(client: &C, base_pubkey: &Pubkey, i: usize) -> Account {
|
fn get_account_at<C: SyncClient>(
|
||||||
|
client: &C,
|
||||||
|
base_pubkey: &Pubkey,
|
||||||
|
i: usize,
|
||||||
|
) -> AccountSharedData {
|
||||||
let account_address = derive_stake_account_address(&base_pubkey, i);
|
let account_address = derive_stake_account_address(&base_pubkey, i);
|
||||||
client.get_account(&account_address).unwrap().unwrap()
|
AccountSharedData::from(client.get_account(&account_address).unwrap().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_balances<C: SyncClient>(
|
fn get_balances<C: SyncClient>(
|
||||||
|
@ -332,7 +336,8 @@ mod tests {
|
||||||
(0..num_accounts)
|
(0..num_accounts)
|
||||||
.map(|i| {
|
.map(|i| {
|
||||||
let address = derive_stake_account_address(&base_pubkey, i);
|
let address = derive_stake_account_address(&base_pubkey, i);
|
||||||
let account = client.get_account(&address).unwrap().unwrap();
|
let account =
|
||||||
|
AccountSharedData::from(client.get_account(&address).unwrap().unwrap());
|
||||||
(address, StakeState::lockup_from(&account).unwrap())
|
(address, StakeState::lockup_from(&account).unwrap())
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
|
|
@ -12,7 +12,7 @@ use {
|
||||||
solana_core::rpc::JsonRpcConfig,
|
solana_core::rpc::JsonRpcConfig,
|
||||||
solana_faucet::faucet::{run_local_faucet_with_port, FAUCET_PORT},
|
solana_faucet::faucet::{run_local_faucet_with_port, FAUCET_PORT},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::Account,
|
account::AccountSharedData,
|
||||||
clock::Slot,
|
clock::Slot,
|
||||||
native_token::sol_to_lamports,
|
native_token::sol_to_lamports,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
|
@ -385,7 +385,7 @@ fn main() {
|
||||||
.ledger_path(&ledger_path)
|
.ledger_path(&ledger_path)
|
||||||
.add_account(
|
.add_account(
|
||||||
faucet_pubkey,
|
faucet_pubkey,
|
||||||
Account::new(faucet_lamports, 0, &system_program::id()),
|
AccountSharedData::new(faucet_lamports, 0, &system_program::id()),
|
||||||
)
|
)
|
||||||
.rpc_config(JsonRpcConfig {
|
.rpc_config(JsonRpcConfig {
|
||||||
enable_rpc_transaction_history: true,
|
enable_rpc_transaction_history: true,
|
||||||
|
|
Loading…
Reference in New Issue