Skip to content

Commit

Permalink
[TieredStorage] HotStorageReader::get_owner_address (solana-labs#34053)
Browse files Browse the repository at this point in the history
#### Problem
The HotStorageReader does not have an API to obtain owners_address.

#### Summary of Changes
This PR adds HotStorageReader::get_owner_address().

#### Test Plan
A new unit-test is added to this PR.
  • Loading branch information
yhchiang-sol committed Feb 13, 2024
1 parent d164ac4 commit f64d124
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions accounts-db/src/tiered_storage/hot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use {
index::{AccountOffset, IndexBlockFormat, IndexOffset},
meta::{AccountMetaFlags, AccountMetaOptionalFields, TieredAccountMeta},
mmap_utils::get_type,
owners::{OwnerOffset, OwnersBlock},
TieredStorageFormat, TieredStorageResult,
},
},
Expand Down Expand Up @@ -244,6 +245,12 @@ impl HotStorageReader {
.index_block_format
.get_account_address(&self.mmap, &self.footer, index)
}

/// Returns the address of the account owner given the specified
/// owner_offset.
fn get_owner_address(&self, owner_offset: OwnerOffset) -> TieredStorageResult<&Pubkey> {
OwnersBlock::get_owner_address(&self.mmap, &self.footer, owner_offset)
}
}

#[cfg(test)]
Expand Down Expand Up @@ -531,4 +538,42 @@ pub mod tests {
assert_eq!(account_address, index_writer_entry.address);
}
}

#[test]
fn test_hot_storage_get_owner_address() {
// Generate a new temp path that is guaranteed to NOT already have a file.
let temp_dir = TempDir::new().unwrap();
let path = temp_dir.path().join("test_hot_storage_get_owner_address");
const NUM_OWNERS: usize = 10;

let addresses: Vec<_> = std::iter::repeat_with(Pubkey::new_unique)
.take(NUM_OWNERS)
.collect();

let footer = TieredStorageFooter {
account_meta_format: AccountMetaFormat::Hot,
// Set owners_block_offset to 0 as we didn't write any account
// meta/data nor index block in this test
owners_block_offset: 0,
..TieredStorageFooter::default()
};

{
let file = TieredStorageFile::new_writable(&path).unwrap();

OwnersBlock::write_owners_block(&file, &addresses).unwrap();

// while the test only focuses on account metas, writing a footer
// here is necessary to make it a valid tiered-storage file.
footer.write_footer_block(&file).unwrap();
}

let hot_storage = HotStorageReader::new_from_path(&path).unwrap();
for (i, address) in addresses.iter().enumerate() {
assert_eq!(
hot_storage.get_owner_address(OwnerOffset(i)).unwrap(),
address,
);
}
}
}

0 comments on commit f64d124

Please sign in to comment.