get_stored_account_meta_callback returns Option (#847)

* get_stored_account_meta_callback returns Option

* Update accounts-db/src/accounts_file.rs

Co-authored-by: Brooks <brooks@prumo.org>

---------

Co-authored-by: Brooks <brooks@prumo.org>
This commit is contained in:
Jeff Washington (jwash) 2024-04-17 08:12:32 -05:00 committed by GitHub
parent 97c56ac0e2
commit 63d4278cae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 27 deletions

View File

@ -137,24 +137,23 @@ impl AccountsFile {
}
/// calls `callback` with the account located at the specified index offset.
pub fn get_stored_account_meta_callback<'a>(
pub fn get_stored_account_meta_callback<'a, Ret>(
&'a self,
offset: usize,
callback: impl FnMut(StoredAccountMeta<'a>),
) {
callback: impl FnMut(StoredAccountMeta<'a>) -> Ret,
) -> Option<Ret> {
match self {
Self::AppendVec(av) => av.get_stored_account_meta_callback(offset, callback),
// Note: The conversion here is needed as the AccountsDB currently
// assumes all offsets are multiple of 8 while TieredStorage uses
// IndexOffset that is equivalent to AccountInfo::reduced_offset.
Self::TieredStorage(ts) => {
if let Some(reader) = ts.reader() {
_ = reader.get_stored_account_meta_callback(
IndexOffset(AccountInfo::get_reduced_offset(offset)),
callback,
);
}
}
Self::TieredStorage(ts) => ts
.reader()?
.get_stored_account_meta_callback(
IndexOffset(AccountInfo::get_reduced_offset(offset)),
callback,
)
.ok()?,
}
}

View File

@ -542,14 +542,13 @@ impl AppendVec {
}
/// calls `callback` with the account located at the specified index offset.
pub fn get_stored_account_meta_callback<'a>(
pub fn get_stored_account_meta_callback<'a, Ret>(
&'a self,
offset: usize,
mut callback: impl FnMut(StoredAccountMeta<'a>),
) {
if let Some((account, _offset)) = self.get_stored_account_meta(offset) {
callback(account)
}
mut callback: impl FnMut(StoredAccountMeta<'a>) -> Ret,
) -> Option<Ret> {
self.get_stored_account_meta(offset)
.map(|(account, _offset)| callback(account))
}
/// return an `AccountSharedData` for an account at `offset`.

View File

@ -527,15 +527,13 @@ impl HotStorageReader {
}
/// calls `callback` with the account located at the specified index offset.
pub fn get_stored_account_meta_callback<'a>(
pub fn get_stored_account_meta_callback<'a, Ret>(
&'a self,
index_offset: IndexOffset,
mut callback: impl FnMut(StoredAccountMeta<'a>),
) -> TieredStorageResult<()> {
if let Some((account, _offset)) = self.get_stored_account_meta(index_offset)? {
callback(account)
}
Ok(())
mut callback: impl FnMut(StoredAccountMeta<'a>) -> Ret,
) -> TieredStorageResult<Option<Ret>> {
let account = self.get_stored_account_meta(index_offset)?;
Ok(account.map(|(account, _offset)| callback(account)))
}
/// Returns the account located at the specified index offset.

View File

@ -86,11 +86,11 @@ impl TieredStorageReader {
}
/// calls `callback` with the account located at the specified index offset.
pub fn get_stored_account_meta_callback<'a>(
pub fn get_stored_account_meta_callback<'a, Ret>(
&'a self,
index_offset: IndexOffset,
callback: impl FnMut(StoredAccountMeta<'a>),
) -> TieredStorageResult<()> {
callback: impl FnMut(StoredAccountMeta<'a>) -> Ret,
) -> TieredStorageResult<Option<Ret>> {
match self {
Self::Hot(hot) => hot.get_stored_account_meta_callback(index_offset, callback),
}