Skip to content

Commit

Permalink
remove a StorableAccounts impl (solana-labs#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Apr 22, 2024
1 parent ff79531 commit 43e47be
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 39 deletions.
5 changes: 4 additions & 1 deletion accounts-db/benches/bench_accounts_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ fn bench_write_accounts_file(c: &mut Criterion) {
})
.take(accounts_count)
.collect();
let accounts_refs: Vec<_> = accounts.iter().collect();
let accounts_refs: Vec<_> = accounts
.iter()
.map(|(pubkey, account)| (pubkey, account))
.collect();
let storable_accounts = (Slot::MAX, accounts_refs.as_slice());

group.bench_function(BenchmarkId::new("append_vec", accounts_count), |b| {
Expand Down
54 changes: 25 additions & 29 deletions accounts-db/src/storable_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,7 @@ where
}
}

impl<'a: 'b, 'b, T: ReadableAccount + Sync + 'a> StorableAccounts<'a>
for (Slot, &'b [(&'a Pubkey, &'a T)])
where
AccountForStorage<'a>: From<(&'a Pubkey, &'a T)>,
{
impl<'a: 'b, 'b> StorableAccounts<'a> for (Slot, &'b [(&'a Pubkey, &'a AccountSharedData)]) {
fn account<Ret>(
&self,
index: usize,
Expand All @@ -192,29 +188,6 @@ where
self.1.len()
}
}
impl<'a, T: ReadableAccount + Sync> StorableAccounts<'a> for (Slot, &'a [&'a (Pubkey, T)])
where
AccountForStorage<'a>: From<(&'a Pubkey, &'a T)>,
{
fn account<Ret>(
&self,
index: usize,
mut callback: impl for<'local> FnMut(AccountForStorage<'local>) -> Ret,
) -> Ret {
callback((&self.1[index].0, &self.1[index].1).into())
}
fn slot(&self, _index: usize) -> Slot {
// per-index slot is not unique per slot when per-account slot is not included in the source data
self.target_slot()
}
fn target_slot(&self) -> Slot {
self.0
}
fn len(&self) -> usize {
self.1.len()
}
}

impl<'a> StorableAccounts<'a> for (Slot, &'a [&'a StoredAccountMeta<'a>]) {
fn account<Ret>(
&self,
Expand All @@ -234,7 +207,6 @@ impl<'a> StorableAccounts<'a> for (Slot, &'a [&'a StoredAccountMeta<'a>]) {
self.1.len()
}
}

/// holds slices of accounts being moved FROM a common source slot to 'target_slot'
pub struct StorableAccountsBySlot<'a> {
target_slot: Slot,
Expand Down Expand Up @@ -359,6 +331,30 @@ pub mod tests {
},
};

/// this is no longer used. It is very tricky to get these right. There are already tests for this. It is likely worth it to leave this here for a while until everything has settled.
impl<'a, T: ReadableAccount + Sync> StorableAccounts<'a> for (Slot, &'a [&'a (Pubkey, T)])
where
AccountForStorage<'a>: From<(&'a Pubkey, &'a T)>,
{
fn account<Ret>(
&self,
index: usize,
mut callback: impl for<'local> FnMut(AccountForStorage<'local>) -> Ret,
) -> Ret {
callback((&self.1[index].0, &self.1[index].1).into())
}
fn slot(&self, _index: usize) -> Slot {
// per-index slot is not unique per slot when per-account slot is not included in the source data
self.target_slot()
}
fn target_slot(&self) -> Slot {
self.0
}
fn len(&self) -> usize {
self.1.len()
}
}

fn compare<'a>(a: &impl StorableAccounts<'a>, b: &impl StorableAccounts<'a>) {
assert_eq!(a.target_slot(), b.target_slot());
assert_eq!(a.len(), b.len());
Expand Down
12 changes: 3 additions & 9 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ use {
accounts_hash::{
AccountHash, AccountsHash, CalcAccountsHashConfig, HashStats, IncrementalAccountsHash,
},
accounts_index::{AccountSecondaryIndexes, IndexKey, ScanConfig, ScanResult, ZeroLamport},
accounts_index::{AccountSecondaryIndexes, IndexKey, ScanConfig, ScanResult},
accounts_partition::{self, Partition, PartitionIndex},
accounts_update_notifier_interface::AccountsUpdateNotifier,
ancestors::{Ancestors, AncestorsForSerialization},
blockhash_queue::BlockhashQueue,
epoch_accounts_hash::EpochAccountsHash,
sorted_storages::SortedStorages,
stake_rewards::StakeReward,
storable_accounts::{AccountForStorage, StorableAccounts},
storable_accounts::StorableAccounts,
},
solana_bpf_loader_program::syscalls::create_program_runtime_environment_v1,
solana_cost_model::cost_tracker::CostTracker,
Expand Down Expand Up @@ -5062,13 +5062,7 @@ impl Bank {

/// fn store the single `account` with `pubkey`.
/// Uses `store_accounts`, which works on a vector of accounts.
pub fn store_account<'a, T: ReadableAccount + Sync + ZeroLamport + 'a>(
&self,
pubkey: &'a Pubkey,
account: &'a T,
) where
AccountForStorage<'a>: From<(&'a Pubkey, &'a T)>,
{
pub fn store_account(&self, pubkey: &Pubkey, account: &AccountSharedData) {
self.store_accounts((self.slot(), &[(pubkey, account)][..]))
}

Expand Down

0 comments on commit 43e47be

Please sign in to comment.