Skip to content

Commit

Permalink
[TS] Add get_account() and account_matches_owner() to TieredStorageRe…
Browse files Browse the repository at this point in the history
…ader (solana-labs#34968)

#### Problem
TieredStorageReader is a wrapper enum that works for
both Hot and Cold storage readers, but its get_account()
and account_matches_owner() API are missing.

#### Summary of Changes
Add get_account() and account_matches_owner() to
TieredStorageReader.

#### Test Plan
hot.rs offers similar coverage for HotStorageReader.
  • Loading branch information
yhchiang-sol committed Feb 13, 2024
1 parent cf51382 commit 15132d6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
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 @@ -318,7 +318,7 @@ impl HotStorageReader {
}

/// Returns the offset to the account given the specified index.
fn get_account_offset(
pub(super) fn get_account_offset(
&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(
&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)
}
}
}
}

0 comments on commit 15132d6

Please sign in to comment.