Skip to content

Commit

Permalink
dashmap -> rwlock<hashmap> for rewrites (solana-labs#24327)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Jun 30, 2022
1 parent 8087593 commit 237b96e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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

0 comments on commit 237b96e

Please sign in to comment.