From 793e66d7a67692e4243be4a03232decb96e22bd8 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Fri, 26 Jan 2024 05:12:22 -0800 Subject: [PATCH 1/2] [TS] Add get_account() and account_matches_owners() to TieredStorageReader --- accounts-db/src/tiered_storage/hot.rs | 2 +- accounts-db/src/tiered_storage/readable.rs | 37 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/accounts-db/src/tiered_storage/hot.rs b/accounts-db/src/tiered_storage/hot.rs index 730ace5aa310ed..4a1716615acecc 100644 --- a/accounts-db/src/tiered_storage/hot.rs +++ b/accounts-db/src/tiered_storage/hot.rs @@ -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( &self, index_offset: IndexOffset, ) -> TieredStorageResult { diff --git a/accounts-db/src/tiered_storage/readable.rs b/accounts-db/src/tiered_storage/readable.rs index aff29a79fb03ab..647c78d5ca91c1 100644 --- a/accounts-db/src/tiered_storage/readable.rs +++ b/accounts-db/src/tiered_storage/readable.rs @@ -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, }, @@ -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, 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 { + 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) + } + } + } } From fbd259ea3d48f8f52313d6969550c3791aff42ec Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Fri, 26 Jan 2024 13:59:20 -0800 Subject: [PATCH 2/2] Use pub(super) for scope within tiered-storage --- accounts-db/src/tiered_storage/hot.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts-db/src/tiered_storage/hot.rs b/accounts-db/src/tiered_storage/hot.rs index 4a1716615acecc..311da9916785f6 100644 --- a/accounts-db/src/tiered_storage/hot.rs +++ b/accounts-db/src/tiered_storage/hot.rs @@ -326,7 +326,7 @@ impl HotStorageReader { } /// Returns the offset to the account given the specified index. - pub(crate) fn get_account_offset( + pub(super) fn get_account_offset( &self, index_offset: IndexOffset, ) -> TieredStorageResult {