Account->AccountSharedData (#15691)
This commit is contained in:
committed by
GitHub
parent
61c7ce857e
commit
8a3135d17b
@ -253,7 +253,7 @@ mod tests {
|
||||
bank_forks::BankForks,
|
||||
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_vote_program::{
|
||||
vote_state::{self, VoteStateVersions},
|
||||
@ -411,16 +411,20 @@ mod tests {
|
||||
rooted_stake_amount,
|
||||
);
|
||||
|
||||
genesis_config.accounts.extend(vec![
|
||||
(pk1, vote_account1.clone()),
|
||||
(sk1, stake_account1),
|
||||
(pk2, vote_account2.clone()),
|
||||
(sk2, stake_account2),
|
||||
(pk3, vote_account3.clone()),
|
||||
(sk3, stake_account3),
|
||||
(pk4, vote_account4.clone()),
|
||||
(sk4, stake_account4),
|
||||
]);
|
||||
genesis_config.accounts.extend(
|
||||
vec![
|
||||
(pk1, vote_account1.clone()),
|
||||
(sk1, stake_account1),
|
||||
(pk2, vote_account2.clone()),
|
||||
(sk2, stake_account2),
|
||||
(pk3, vote_account3.clone()),
|
||||
(sk3, stake_account3),
|
||||
(pk4, vote_account4.clone()),
|
||||
(sk4, stake_account4),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(key, account)| (key, Account::from(account))),
|
||||
);
|
||||
|
||||
// Create bank
|
||||
let bank = Arc::new(Bank::new(&genesis_config));
|
||||
|
@ -1253,7 +1253,7 @@ pub mod test {
|
||||
},
|
||||
};
|
||||
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,
|
||||
};
|
||||
use solana_vote_program::{
|
||||
@ -1571,10 +1571,10 @@ pub mod test {
|
||||
fn gen_stakes(stake_votes: &[(u64, &[u64])]) -> Vec<(Pubkey, (u64, ArcVoteAccount))> {
|
||||
let mut stakes = vec![];
|
||||
for (lamports, votes) in stake_votes {
|
||||
let mut account = Account {
|
||||
let mut account = AccountSharedData {
|
||||
data: vec![0; VoteState::size_of()],
|
||||
lamports: *lamports,
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
};
|
||||
let mut vote_state = VoteState::default();
|
||||
for slot in *votes {
|
||||
@ -2251,9 +2251,9 @@ pub mod test {
|
||||
#[test]
|
||||
fn test_stake_is_updated_for_entire_branch() {
|
||||
let mut voted_stakes = HashMap::new();
|
||||
let account = Account {
|
||||
let account = AccountSharedData {
|
||||
lamports: 1,
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
};
|
||||
let set: HashSet<u64> = vec![0u64, 1u64].into_iter().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())
|
||||
};
|
||||
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 {
|
||||
StakeState::Initialized(meta) => {
|
||||
if meta.lockup.is_in_force(&clock, None)
|
||||
@ -138,6 +138,7 @@ mod tests {
|
||||
use super::*;
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account::AccountSharedData,
|
||||
epoch_schedule::EpochSchedule,
|
||||
genesis_config::{ClusterType, GenesisConfig},
|
||||
};
|
||||
@ -212,7 +213,10 @@ mod tests {
|
||||
bank = Arc::new(new_from_parent(&bank));
|
||||
let new_balance = 11;
|
||||
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);
|
||||
assert_eq!(
|
||||
|
@ -49,7 +49,7 @@ use solana_runtime::{
|
||||
snapshot_utils::get_highest_snapshot_archive_path,
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account::AccountSharedData,
|
||||
account_utils::StateMut,
|
||||
clock::{Slot, UnixTimestamp, MAX_RECENT_BLOCKHASHES},
|
||||
commitment_config::{CommitmentConfig, CommitmentLevel},
|
||||
@ -1157,7 +1157,7 @@ impl JsonRpcRequestProcessor {
|
||||
.get_account(&stake_history::id())
|
||||
.ok_or_else(Error::internal_error)?;
|
||||
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)?;
|
||||
|
||||
let (active, activating, deactivating) = delegation.stake_activating_and_deactivating(
|
||||
@ -1381,8 +1381,8 @@ impl JsonRpcRequestProcessor {
|
||||
bank: &Arc<Bank>,
|
||||
program_id: &Pubkey,
|
||||
filters: Vec<RpcFilterType>,
|
||||
) -> Vec<(Pubkey, Account)> {
|
||||
let filter_closure = |account: &Account| {
|
||||
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||
let filter_closure = |account: &AccountSharedData| {
|
||||
filters.iter().all(|filter_type| match filter_type {
|
||||
RpcFilterType::DataSize(size) => account.data.len() as u64 == *size,
|
||||
RpcFilterType::Memcmp(compare) => compare.bytes_match(&account.data),
|
||||
@ -1396,7 +1396,7 @@ impl JsonRpcRequestProcessor {
|
||||
bank.get_filtered_indexed_accounts(&IndexKey::ProgramId(*program_id), |account| {
|
||||
// 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
|
||||
// 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
|
||||
// accounts.
|
||||
account.owner == *program_id && filter_closure(account)
|
||||
@ -1412,10 +1412,10 @@ impl JsonRpcRequestProcessor {
|
||||
bank: &Arc<Bank>,
|
||||
owner_key: &Pubkey,
|
||||
mut filters: Vec<RpcFilterType>,
|
||||
) -> Vec<(Pubkey, Account)> {
|
||||
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||
// 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
|
||||
// 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.
|
||||
//
|
||||
// Filter on Token Account state
|
||||
@ -1452,10 +1452,10 @@ impl JsonRpcRequestProcessor {
|
||||
bank: &Arc<Bank>,
|
||||
mint_key: &Pubkey,
|
||||
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.
|
||||
// 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.
|
||||
//
|
||||
// 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(
|
||||
bank: Arc<Bank>,
|
||||
pubkey: &Pubkey,
|
||||
account: Account,
|
||||
account: AccountSharedData,
|
||||
) -> UiAccount {
|
||||
let additional_data = get_token_account_mint(&account.data)
|
||||
.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,
|
||||
) -> impl Iterator<Item = RpcKeyedAccount>
|
||||
where
|
||||
I: Iterator<Item = (Pubkey, Account)>,
|
||||
I: Iterator<Item = (Pubkey, AccountSharedData)>,
|
||||
{
|
||||
let mut mint_decimals: HashMap<Pubkey, u8> = HashMap::new();
|
||||
keyed_accounts.filter_map(move |(pubkey, account)| {
|
||||
@ -3216,7 +3216,10 @@ pub mod tests {
|
||||
.unwrap()
|
||||
.set_root(*root, &AbsRequestSender::default(), Some(0));
|
||||
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
|
||||
.read()
|
||||
.unwrap()
|
||||
@ -3822,7 +3825,7 @@ pub mod tests {
|
||||
|
||||
let address = solana_sdk::pubkey::new_rand();
|
||||
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();
|
||||
bank.store_account(&address, &account);
|
||||
|
||||
@ -3879,7 +3882,7 @@ pub mod tests {
|
||||
|
||||
let address = Pubkey::new(&[9; 32]);
|
||||
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();
|
||||
bank.store_account(&address, &account);
|
||||
|
||||
@ -5611,11 +5614,11 @@ pub mod tests {
|
||||
close_authority: COption::Some(owner),
|
||||
};
|
||||
TokenAccount::pack(token_account, &mut account_data).unwrap();
|
||||
let token_account = Account {
|
||||
let token_account = AccountSharedData {
|
||||
lamports: 111,
|
||||
data: account_data.to_vec(),
|
||||
owner: spl_token_id_v2_0(),
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
};
|
||||
let token_account_pubkey = solana_sdk::pubkey::new_rand();
|
||||
bank.store_account(&token_account_pubkey, &token_account);
|
||||
@ -5630,11 +5633,11 @@ pub mod tests {
|
||||
freeze_authority: COption::Some(owner),
|
||||
};
|
||||
Mint::pack(mint_state, &mut mint_data).unwrap();
|
||||
let mint_account = Account {
|
||||
let mint_account = AccountSharedData {
|
||||
lamports: 111,
|
||||
data: mint_data.to_vec(),
|
||||
owner: spl_token_id_v2_0(),
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
};
|
||||
bank.store_account(&Pubkey::from_str(&mint.to_string()).unwrap(), &mint_account);
|
||||
|
||||
@ -5707,11 +5710,11 @@ pub mod tests {
|
||||
close_authority: COption::Some(owner),
|
||||
};
|
||||
TokenAccount::pack(token_account, &mut account_data).unwrap();
|
||||
let token_account = Account {
|
||||
let token_account = AccountSharedData {
|
||||
lamports: 111,
|
||||
data: account_data.to_vec(),
|
||||
owner: spl_token_id_v2_0(),
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
};
|
||||
let token_with_different_mint_pubkey = solana_sdk::pubkey::new_rand();
|
||||
bank.store_account(&token_with_different_mint_pubkey, &token_account);
|
||||
@ -5926,11 +5929,11 @@ pub mod tests {
|
||||
freeze_authority: COption::Some(owner),
|
||||
};
|
||||
Mint::pack(mint_state, &mut mint_data).unwrap();
|
||||
let mint_account = Account {
|
||||
let mint_account = AccountSharedData {
|
||||
lamports: 111,
|
||||
data: mint_data.to_vec(),
|
||||
owner: spl_token_id_v2_0(),
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
};
|
||||
bank.store_account(
|
||||
&Pubkey::from_str(&new_mint.to_string()).unwrap(),
|
||||
@ -5948,11 +5951,11 @@ pub mod tests {
|
||||
close_authority: COption::Some(owner),
|
||||
};
|
||||
TokenAccount::pack(token_account, &mut account_data).unwrap();
|
||||
let token_account = Account {
|
||||
let token_account = AccountSharedData {
|
||||
lamports: 111,
|
||||
data: account_data.to_vec(),
|
||||
owner: spl_token_id_v2_0(),
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
};
|
||||
let token_with_smaller_balance = solana_sdk::pubkey::new_rand();
|
||||
bank.store_account(&token_with_smaller_balance, &token_account);
|
||||
@ -6012,11 +6015,11 @@ pub mod tests {
|
||||
close_authority: COption::Some(owner),
|
||||
};
|
||||
TokenAccount::pack(token_account, &mut account_data).unwrap();
|
||||
let token_account = Account {
|
||||
let token_account = AccountSharedData {
|
||||
lamports: 111,
|
||||
data: account_data.to_vec(),
|
||||
owner: spl_token_id_v2_0(),
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
};
|
||||
let token_account_pubkey = solana_sdk::pubkey::new_rand();
|
||||
bank.store_account(&token_account_pubkey, &token_account);
|
||||
@ -6031,11 +6034,11 @@ pub mod tests {
|
||||
freeze_authority: COption::Some(owner),
|
||||
};
|
||||
Mint::pack(mint_state, &mut mint_data).unwrap();
|
||||
let mint_account = Account {
|
||||
let mint_account = AccountSharedData {
|
||||
lamports: 111,
|
||||
data: mint_data.to_vec(),
|
||||
owner: spl_token_id_v2_0(),
|
||||
..Account::default()
|
||||
..AccountSharedData::default()
|
||||
};
|
||||
bank.store_account(&Pubkey::from_str(&mint.to_string()).unwrap(), &mint_account);
|
||||
|
||||
|
@ -28,7 +28,7 @@ use solana_runtime::{
|
||||
commitment::{BlockCommitmentCache, CommitmentSlots},
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account::AccountSharedData,
|
||||
clock::{Slot, UnixTimestamp},
|
||||
commitment_config::CommitmentConfig,
|
||||
pubkey::Pubkey,
|
||||
@ -276,7 +276,7 @@ impl RpcNotifier {
|
||||
}
|
||||
|
||||
fn filter_account_result(
|
||||
result: Option<(Account, Slot)>,
|
||||
result: Option<(AccountSharedData, Slot)>,
|
||||
pubkey: &Pubkey,
|
||||
last_notified_slot: Slot,
|
||||
encoding: Option<UiAccountEncoding>,
|
||||
@ -320,7 +320,7 @@ fn filter_signature_result(
|
||||
}
|
||||
|
||||
fn filter_program_results(
|
||||
accounts: Vec<(Pubkey, Account)>,
|
||||
accounts: Vec<(Pubkey, AccountSharedData)>,
|
||||
program_id: &Pubkey,
|
||||
last_notified_slot: Slot,
|
||||
config: Option<ProgramConfig>,
|
||||
|
@ -321,7 +321,7 @@ mod test {
|
||||
create_genesis_config_with_vote_accounts, GenesisConfigInfo, ValidatorVoteKeypairs,
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account::AccountSharedData,
|
||||
fee_calculator::FeeCalculator,
|
||||
genesis_config::create_genesis_config,
|
||||
nonce,
|
||||
@ -529,7 +529,8 @@ mod test {
|
||||
blockhash: durable_nonce,
|
||||
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);
|
||||
|
||||
let working_bank = Arc::new(Bank::new_from_parent(&root_bank, &Pubkey::default(), 2));
|
||||
@ -753,7 +754,8 @@ mod test {
|
||||
blockhash: new_durable_nonce,
|
||||
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);
|
||||
let result = SendTransactionService::process_transactions(
|
||||
&working_bank,
|
||||
|
@ -13,7 +13,7 @@ use {
|
||||
hardened_unpack::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
|
||||
},
|
||||
solana_sdk::{
|
||||
account::Account,
|
||||
account::AccountSharedData,
|
||||
clock::{Slot, DEFAULT_MS_PER_SLOT},
|
||||
commitment_config::CommitmentConfig,
|
||||
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
||||
@ -50,7 +50,7 @@ pub struct TestValidatorGenesis {
|
||||
rpc_ports: Option<(u16, u16)>, // (JsonRpc, JsonRpcPubSub), None == random ports
|
||||
warp_slot: Option<Slot>,
|
||||
no_bpf_jit: bool,
|
||||
accounts: HashMap<Pubkey, Account>,
|
||||
accounts: HashMap<Pubkey, AccountSharedData>,
|
||||
programs: Vec<ProgramInfo>,
|
||||
pub validator_exit: Arc<RwLock<ValidatorExit>>,
|
||||
pub start_progress: Arc<RwLock<ValidatorStartProgress>>,
|
||||
@ -93,14 +93,14 @@ impl TestValidatorGenesis {
|
||||
}
|
||||
|
||||
/// 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
|
||||
}
|
||||
|
||||
pub fn add_accounts<T>(&mut self, accounts: T) -> &mut Self
|
||||
where
|
||||
T: IntoIterator<Item = (Pubkey, Account)>,
|
||||
T: IntoIterator<Item = (Pubkey, AccountSharedData)>,
|
||||
{
|
||||
for (address, account) in accounts {
|
||||
self.add_account(address, account);
|
||||
@ -118,7 +118,7 @@ impl TestValidatorGenesis {
|
||||
error!("Failed to fetch {}: {}", address, err);
|
||||
crate::validator::abort();
|
||||
});
|
||||
self.add_account(address, account);
|
||||
self.add_account(address, AccountSharedData::from(account));
|
||||
}
|
||||
self
|
||||
}
|
||||
@ -133,7 +133,7 @@ impl TestValidatorGenesis {
|
||||
) -> &mut Self {
|
||||
self.add_account(
|
||||
address,
|
||||
Account {
|
||||
AccountSharedData {
|
||||
lamports,
|
||||
data: solana_program_test::read_file(
|
||||
solana_program_test::find_file(filename).unwrap_or_else(|| {
|
||||
@ -158,7 +158,7 @@ impl TestValidatorGenesis {
|
||||
) -> &mut Self {
|
||||
self.add_account(
|
||||
address,
|
||||
Account {
|
||||
AccountSharedData {
|
||||
lamports,
|
||||
data: base64::decode(data_base64)
|
||||
.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);
|
||||
accounts.insert(
|
||||
program.program_id,
|
||||
Account {
|
||||
AccountSharedData {
|
||||
lamports: Rent::default().minimum_balance(data.len()).min(1),
|
||||
data,
|
||||
owner: program.loader,
|
||||
|
@ -868,7 +868,7 @@ impl Validator {
|
||||
|
||||
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(vote_state) = VoteState::from(&account) {
|
||||
if let Some(vote_state) = VoteState::from(account) {
|
||||
return !vote_state.votes.is_empty();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user