protect access to rent paying account vec (#26919)

This commit is contained in:
Jeff Washington (jwash) 2022-08-05 08:19:46 -05:00 committed by GitHub
parent 5b879067e6
commit 73fe400407
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -5,6 +5,10 @@ use {
std::collections::HashSet,
};
lazy_static! {
pub static ref EMPTY_HASHSET: HashSet<Pubkey> = HashSet::default();
}
/// populated at startup with the accounts that were found that are rent paying.
/// These are the 'possible' rent paying accounts.
/// This set can never grow during runtime since it is not possible to create rent paying accounts now.
@ -45,7 +49,9 @@ impl RentPayingAccountsByPartition {
&self,
partition_end_index: PartitionIndex,
) -> &HashSet<Pubkey> {
&self.accounts[partition_end_index as usize]
self.accounts
.get(partition_end_index as usize)
.unwrap_or(&EMPTY_HASHSET)
}
pub fn is_initialized(&self) -> bool {
self.partition_count != 0