Skip to content

Commit

Permalink
remove IncludeSlotInHash after feature activation on mnb (solana-labs…
Browse files Browse the repository at this point in the history
…#33816)

* remove IncludeSlotInHash after feature activation on mnb

* fix compile errors

* compile errors

* fix tests

* fix test results
  • Loading branch information
jeffwashington authored Oct 23, 2023
1 parent a099c7a commit b0b4e1f
Show file tree
Hide file tree
Showing 20 changed files with 147 additions and 532 deletions.
3 changes: 1 addition & 2 deletions accounts-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
accounts::Accounts,
accounts_db::{
test_utils::{create_test_accounts, update_accounts_bench},
AccountShrinkThreshold, CalcAccountsHashDataSource, INCLUDE_SLOT_IN_HASH_TESTS,
AccountShrinkThreshold, CalcAccountsHashDataSource,
},
accounts_index::AccountSecondaryIndexes,
ancestors::Ancestors,
Expand Down Expand Up @@ -134,7 +134,6 @@ fn main() {
&EpochSchedule::default(),
&RentCollector::default(),
true,
INCLUDE_SLOT_IN_HASH_TESTS,
);
time_store.stop();
if results != results_store {
Expand Down
3 changes: 1 addition & 2 deletions accounts-db/benches/append_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use {
account_storage::meta::{
StorableAccountsWithHashesAndWriteVersions, StoredAccountInfo, StoredMeta,
},
accounts_db::INCLUDE_SLOT_IN_HASH_TESTS,
accounts_hash::AccountHash,
append_vec::{
test_utils::{create_test_account, get_append_vec_path},
Expand Down Expand Up @@ -39,7 +38,7 @@ fn append_account(
let slot_ignored = Slot::MAX;
let accounts = [(&storage_meta.pubkey, account)];
let slice = &accounts[..];
let accounts = (slot_ignored, slice, INCLUDE_SLOT_IN_HASH_TESTS);
let accounts = (slot_ignored, slice);
let storable_accounts =
StorableAccountsWithHashesAndWriteVersions::new_with_hashes_and_write_versions(
&accounts,
Expand Down
14 changes: 5 additions & 9 deletions accounts-db/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use {
account_overrides::AccountOverrides,
account_rent_state::{check_rent_state_with_account, RentState},
accounts_db::{
AccountShrinkThreshold, AccountsAddRootTiming, AccountsDb, AccountsDbConfig,
IncludeSlotInHash, LoadHint, LoadedAccount, ScanStorageResult,
VerifyAccountsHashAndLamportsConfig, ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS,
ACCOUNTS_DB_CONFIG_FOR_TESTING,
AccountShrinkThreshold, AccountsAddRootTiming, AccountsDb, AccountsDbConfig, LoadHint,
LoadedAccount, ScanStorageResult, VerifyAccountsHashAndLamportsConfig,
ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS, ACCOUNTS_DB_CONFIG_FOR_TESTING,
},
accounts_index::{
AccountSecondaryIndexes, IndexKey, ScanConfig, ScanError, ScanResult, ZeroLamport,
Expand Down Expand Up @@ -1311,7 +1310,6 @@ impl Accounts {
rent_collector: &RentCollector,
durable_nonce: &DurableNonce,
lamports_per_signature: u64,
include_slot_in_hash: IncludeSlotInHash,
) {
let (accounts_to_store, transactions) = self.collect_accounts_to_store(
txs,
Expand All @@ -1321,10 +1319,8 @@ impl Accounts {
durable_nonce,
lamports_per_signature,
);
self.accounts_db.store_cached_inline_update_index(
(slot, &accounts_to_store[..], include_slot_in_hash),
Some(&transactions),
);
self.accounts_db
.store_cached_inline_update_index((slot, &accounts_to_store[..]), Some(&transactions));
}

pub fn store_accounts_cached<'a, T: ReadableAccount + Sync + ZeroLamport + 'a>(
Expand Down
40 changes: 6 additions & 34 deletions accounts-db/src/accounts_cache.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use {
crate::{
accounts_db::{AccountsDb, IncludeSlotInHash},
accounts_hash::AccountHash,
},
crate::{accounts_db::AccountsDb, accounts_hash::AccountHash},
dashmap::DashMap,
seqlock::SeqLock,
solana_sdk::{
Expand Down Expand Up @@ -68,20 +65,12 @@ impl SlotCacheInner {
self.cache.iter().map(|item| *item.key()).collect()
}

pub fn insert(
&self,
pubkey: &Pubkey,
account: AccountSharedData,
slot: Slot,
include_slot_in_hash: IncludeSlotInHash,
) -> CachedAccount {
pub fn insert(&self, pubkey: &Pubkey, account: AccountSharedData) -> CachedAccount {
let data_len = account.data().len() as u64;
let item = Arc::new(CachedAccountInner {
account,
hash: SeqLock::new(None),
slot,
pubkey: *pubkey,
include_slot_in_hash,
});
if let Some(old) = self.cache.insert(*pubkey, item.clone()) {
self.same_account_writes.fetch_add(1, Ordering::Relaxed);
Expand Down Expand Up @@ -145,11 +134,7 @@ pub type CachedAccount = Arc<CachedAccountInner>;
pub struct CachedAccountInner {
pub account: AccountSharedData,
hash: SeqLock<Option<AccountHash>>,
slot: Slot,
pubkey: Pubkey,
/// temporarily here during feature activation
/// since we calculate the hash later, or in the background, we need knowledge of whether this slot uses the slot in the hash or not
pub include_slot_in_hash: IncludeSlotInHash,
}

impl CachedAccountInner {
Expand All @@ -158,12 +143,7 @@ impl CachedAccountInner {
match hash {
Some(hash) => hash,
None => {
let hash = AccountsDb::hash_account(
self.slot,
&self.account,
&self.pubkey,
self.include_slot_in_hash,
);
let hash = AccountsDb::hash_account(&self.account, &self.pubkey);
*self.hash.lock_write() = Some(hash);
hash
}
Expand Down Expand Up @@ -228,13 +208,7 @@ impl AccountsCache {
);
}

pub fn store(
&self,
slot: Slot,
pubkey: &Pubkey,
account: AccountSharedData,
include_slot_in_hash: IncludeSlotInHash,
) -> CachedAccount {
pub fn store(&self, slot: Slot, pubkey: &Pubkey, account: AccountSharedData) -> CachedAccount {
let slot_cache = self.slot_cache(slot).unwrap_or_else(||
// DashMap entry.or_insert() returns a RefMut, essentially a write lock,
// which is dropped after this block ends, minimizing time held by the lock.
Expand All @@ -246,7 +220,7 @@ impl AccountsCache {
.or_insert(self.new_inner())
.clone());

slot_cache.insert(pubkey, account, slot, include_slot_in_hash)
slot_cache.insert(pubkey, account)
}

pub fn load(&self, slot: Slot, pubkey: &Pubkey) -> Option<CachedAccount> {
Expand Down Expand Up @@ -338,7 +312,7 @@ impl AccountsCache {

#[cfg(test)]
pub mod tests {
use {super::*, crate::accounts_db::INCLUDE_SLOT_IN_HASH_TESTS};
use super::*;

#[test]
fn test_remove_slots_le() {
Expand All @@ -350,7 +324,6 @@ pub mod tests {
inserted_slot,
&Pubkey::new_unique(),
AccountSharedData::new(1, 0, &Pubkey::default()),
INCLUDE_SLOT_IN_HASH_TESTS,
);
// If the cache is told the size limit is 0, it should return the one slot
let removed = cache.remove_slots_le(0);
Expand All @@ -368,7 +341,6 @@ pub mod tests {
inserted_slot,
&Pubkey::new_unique(),
AccountSharedData::new(1, 0, &Pubkey::default()),
INCLUDE_SLOT_IN_HASH_TESTS,
);

// If the cache is told the size limit is 0, it should return nothing, because there's no
Expand Down
Loading

0 comments on commit b0b4e1f

Please sign in to comment.