Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

dashmap -> rwlock<hashmap> for rewrites #24327

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,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<Pubkey, Hash>;
pub type Rewrites = RwLock<HashMap<Pubkey, Hash>>;

#[derive(Clone, Debug, PartialEq)]
pub struct RentDebit {
Expand Down
14 changes: 10 additions & 4 deletions runtime/src/expected_rent_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down