Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS] Add get_account() and account_matches_owner() to TieredStorageReader #34968

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 accounts-db/src/tiered_storage/hot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl HotStorageReader {
}

/// Returns the offset to the account given the specified index.
fn get_account_offset(
pub(crate) fn get_account_offset(
brooksprumo marked this conversation as resolved.
Show resolved Hide resolved
&self,
index_offset: IndexOffset,
) -> TieredStorageResult<HotAccountOffset> {
Expand Down
37 changes: 37 additions & 0 deletions accounts-db/src/tiered_storage/readable.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use {
crate::{
account_storage::meta::StoredAccountMeta,
accounts_file::MatchAccountOwnerError,
accounts_hash::AccountHash,
tiered_storage::{
footer::{AccountMetaFormat, TieredStorageFooter},
hot::HotStorageReader,
index::IndexOffset,
meta::TieredAccountMeta,
TieredStorageResult,
},
Expand Down Expand Up @@ -111,4 +114,38 @@ impl TieredStorageReader {
Self::Hot(hot) => hot.num_accounts(),
}
}

/// Returns the account located at the specified index offset.
pub fn get_account(
Comment on lines +118 to +119
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

&self,
index_offset: u32,
) -> TieredStorageResult<Option<(StoredAccountMeta<'_>, usize)>> {
match self {
Self::Hot(hot) => hot.get_account(IndexOffset(index_offset)),
}
}

/// Returns Ok(index_of_matching_owner) if the account owner at
/// `account_offset` is one of the pubkeys in `owners`.
///
/// Returns Err(MatchAccountOwnerError::NoMatch) if the account has 0
/// lamports or the owner is not one of the pubkeys in `owners`.
///
/// Returns Err(MatchAccountOwnerError::UnableToLoad) if there is any internal
/// error that causes the data unable to load, including `account_offset`
/// causes a data overrun.
pub fn account_matches_owners(
&self,
index_offset: u32,
owners: &[Pubkey],
) -> Result<usize, MatchAccountOwnerError> {
match self {
Self::Hot(hot) => {
let account_offset = hot
.get_account_offset(IndexOffset(index_offset))
.map_err(|_| MatchAccountOwnerError::UnableToLoad)?;
hot.account_matches_owners(account_offset, owners)
}
}
}
}
Loading