From 237b96eebd3d62cb26b6f21ceca7a0c73e571563 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Thu, 14 Apr 2022 11:55:58 -0500 Subject: [PATCH] dashmap -> rwlock for rewrites (#24327) --- runtime/src/bank.rs | 2 +- runtime/src/expected_rent_collection.rs | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index b1b23cfe9e9c9b..f1abbeca3cda64 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -179,7 +179,7 @@ pub const SECONDS_PER_YEAR: f64 = 365.25 * 24.0 * 60.0 * 60.0; pub const MAX_LEADER_SCHEDULE_STAKES: Epoch = 5; -pub type Rewrites = DashMap; +pub type Rewrites = RwLock>; #[derive(Clone, Debug, PartialEq)] pub struct RentDebit { diff --git a/runtime/src/expected_rent_collection.rs b/runtime/src/expected_rent_collection.rs index 68639fb32e027f..25f63c07492b21 100644 --- a/runtime/src/expected_rent_collection.rs +++ b/runtime/src/expected_rent_collection.rs @@ -284,7 +284,10 @@ impl ExpectedRentCollection { if possibly_update && rent_epoch == 0 && current_epoch > 1 - && !rewrites_skipped_this_slot.contains_key(pubkey) + && !rewrites_skipped_this_slot + .read() + .unwrap() + .contains_key(pubkey) { // we know we're done return None; @@ -293,7 +296,10 @@ impl ExpectedRentCollection { // if an account was written >= its rent collection slot within the last epoch worth of slots, then we don't want to update it here if possibly_update && rent_epoch < current_epoch { let new_rent_epoch = if partition_from_pubkey < partition_from_current_slot - || rewrites_skipped_this_slot.contains_key(pubkey) + || rewrites_skipped_this_slot + .read() + .unwrap() + .contains_key(pubkey) { // partition_from_pubkey < partition_from_current_slot: // we already would have done a rewrite on this account IN this epoch @@ -310,7 +316,7 @@ impl ExpectedRentCollection { } } else if !possibly_update { // This is a non-trivial lookup. Would be nice to skip this. - assert!(!rewrites_skipped_this_slot.contains_key(pubkey), "did not update rent_epoch: {}, new value for rent_epoch: {}, old: {}, current epoch: {}", pubkey, rent_epoch, next_epoch, current_epoch); + assert!(!rewrites_skipped_this_slot.read().unwrap().contains_key(pubkey), "did not update rent_epoch: {}, new value for rent_epoch: {}, old: {}, current epoch: {}", pubkey, rent_epoch, next_epoch, current_epoch); } } None @@ -1131,7 +1137,7 @@ pub mod tests { continue; } - rewrites.insert(pubkey, Hash::default()); + rewrites.write().unwrap().insert(pubkey, Hash::default()); } let expected_new_rent_epoch = if partition_index_bank_slot > partition_from_pubkey