Skip to content

Commit

Permalink
allow index update to change storage slot #
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Feb 22, 2022
1 parent 8b32e80 commit d525ef3
Show file tree
Hide file tree
Showing 7 changed files with 442 additions and 288 deletions.
2 changes: 2 additions & 0 deletions runtime/benches/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fn bench_accounts_index(bencher: &mut Bencher) {
for f in 0..NUM_FORKS {
for pubkey in pubkeys.iter().take(NUM_PUBKEYS) {
index.upsert(
f,
f,
pubkey,
&Pubkey::default(),
Expand All @@ -44,6 +45,7 @@ fn bench_accounts_index(bencher: &mut Bencher) {
for _p in 0..NUM_PUBKEYS {
let pubkey = thread_rng().gen_range(0, NUM_PUBKEYS);
index.upsert(
fork,
fork,
&pubkeys[pubkey],
&Pubkey::default(),
Expand Down
31 changes: 19 additions & 12 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,11 +953,13 @@ impl Accounts {
/// WARNING: This noncached version is only to be used for tests/benchmarking
/// as bypassing the cache in general is not supported
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, slot)]);
}

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, slot)]);
}

fn lock_account(
Expand Down Expand Up @@ -1122,6 +1124,7 @@ impl Accounts {
blockhash,
lamports_per_signature,
leave_nonce_on_success,
slot,
);
self.accounts_db.store_cached(slot, &accounts_to_store);
}
Expand All @@ -1148,7 +1151,8 @@ impl Accounts {
blockhash: &Hash,
lamports_per_signature: u64,
leave_nonce_on_success: bool,
) -> Vec<(&'a Pubkey, &'a AccountSharedData)> {
slot: Slot,
) -> Vec<(&'a Pubkey, &'a AccountSharedData, Slot)> {
let mut accounts = Vec::with_capacity(load_results.len());
for (i, ((tx_load_result, nonce), tx)) in load_results.iter_mut().zip(txs).enumerate() {
if tx_load_result.is_err() {
Expand Down Expand Up @@ -1217,7 +1221,7 @@ impl Accounts {
}

// Add to the accounts to store
accounts.push((&*address, &*account));
accounts.push((&*address, &*account, slot));
}
}
}
Expand Down Expand Up @@ -2937,14 +2941,15 @@ mod tests {
&Hash::default(),
0,
true, // leave_nonce_on_success
0,
);
assert_eq!(collected_accounts.len(), 2);
assert!(collected_accounts
.iter()
.any(|(pubkey, _account)| *pubkey == &keypair0.pubkey()));
.any(|(pubkey, _account, _slot)| *pubkey == &keypair0.pubkey()));
assert!(collected_accounts
.iter()
.any(|(pubkey, _account)| *pubkey == &keypair1.pubkey()));
.any(|(pubkey, _account, _slot)| *pubkey == &keypair1.pubkey()));

// Ensure readonly_lock reflects lock
assert_eq!(
Expand Down Expand Up @@ -3366,21 +3371,22 @@ mod tests {
&next_blockhash,
0,
true, // leave_nonce_on_success
0,
);
assert_eq!(collected_accounts.len(), 2);
assert_eq!(
collected_accounts
.iter()
.find(|(pubkey, _account)| *pubkey == &from_address)
.map(|(_pubkey, account)| *account)
.find(|(pubkey, _account, _slot)| *pubkey == &from_address)
.map(|(_pubkey, account, _slot)| *account)
.cloned()
.unwrap(),
from_account_pre,
);
let collected_nonce_account = collected_accounts
.iter()
.find(|(pubkey, _account)| *pubkey == &nonce_address)
.map(|(_pubkey, account)| *account)
.find(|(pubkey, _account, _slot)| *pubkey == &nonce_address)
.map(|(_pubkey, account, _slot)| *account)
.cloned()
.unwrap();
assert_eq!(
Expand Down Expand Up @@ -3475,12 +3481,13 @@ mod tests {
&next_blockhash,
0,
true, // leave_nonce_on_success
0,
);
assert_eq!(collected_accounts.len(), 1);
let collected_nonce_account = collected_accounts
.iter()
.find(|(pubkey, _account)| *pubkey == &nonce_address)
.map(|(_pubkey, account)| *account)
.find(|(pubkey, _account, _slot)| *pubkey == &nonce_address)
.map(|(_pubkey, account, _slot)| *account)
.cloned()
.unwrap();
assert_eq!(
Expand Down
Loading

0 comments on commit d525ef3

Please sign in to comment.