Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit ca0e3b1

Browse files
committed
handle account with 0 lamports
1 parent 4f178a3 commit ca0e3b1

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

runtime/src/accounts_db.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -821,9 +821,9 @@ impl<'a> LoadedAccountAccessor<'a> {
821821
LoadedAccountAccessor::Cached(cached_account) => cached_account
822822
.as_ref()
823823
.and_then(|cached_account| {
824-
owners
825-
.contains(&cached_account.account.owner())
826-
.then_some(())
824+
(!cached_account.account.is_zero_lamport()
825+
&& owners.contains(&cached_account.account.owner()))
826+
.then_some(())
827827
})
828828
.ok_or(MatchAccountOwnerError::NoMatch),
829829
LoadedAccountAccessor::Stored(maybe_storage_entry) => {
@@ -4957,8 +4957,7 @@ impl AccountsDb {
49574957
if !storage_location.is_cached() {
49584958
let result = self.read_only_accounts_cache.load(*account, slot);
49594959
if let Some(account) = result {
4960-
return owners
4961-
.contains(&account.owner())
4960+
return (!account.is_zero_lamport() && owners.contains(&account.owner()))
49624961
.then_some(())
49634962
.ok_or(MatchAccountOwnerError::NoMatch);
49644963
}
@@ -14148,13 +14147,19 @@ pub mod tests {
1414814147
let account3_key = Pubkey::new_unique();
1414914148
let account3 = AccountSharedData::new(1, 1, &Pubkey::new_unique());
1415014149

14150+
// Account with 0 lamports
14151+
let account4_key = Pubkey::new_unique();
14152+
let account4 = AccountSharedData::new(0, 1, &owners[1]);
14153+
1415114154
db.store_cached((0, &[(&account1_key, &account1)][..]), None);
1415214155
db.store_cached((1, &[(&account2_key, &account2)][..]), None);
1415314156
db.store_cached((2, &[(&account3_key, &account3)][..]), None);
14157+
db.store_cached((3, &[(&account4_key, &account4)][..]), None);
1415414158

1415514159
db.add_root(0);
1415614160
db.add_root(1);
1415714161
db.add_root(2);
14162+
db.add_root(3);
1415814163

1415914164
// Flush the cache so that the account meta will be read from the storage
1416014165
db.flush_accounts_cache(true, None);
@@ -14172,6 +14177,10 @@ pub mod tests {
1417214177
db.account_matches_owners(&Ancestors::default(), &account3_key, &owners_refs),
1417314178
Err(MatchAccountOwnerError::NoMatch)
1417414179
);
14180+
assert_eq!(
14181+
db.account_matches_owners(&Ancestors::default(), &account4_key, &owners_refs),
14182+
Err(MatchAccountOwnerError::NoMatch)
14183+
);
1417514184
assert_eq!(
1417614185
db.account_matches_owners(&Ancestors::default(), &Pubkey::new_unique(), &owners_refs),
1417714186
Err(MatchAccountOwnerError::UnableToLoad)
@@ -14202,6 +14211,10 @@ pub mod tests {
1420214211
db.account_matches_owners(&Ancestors::default(), &account3_key, &owners_refs),
1420314212
Err(MatchAccountOwnerError::NoMatch)
1420414213
);
14214+
assert_eq!(
14215+
db.account_matches_owners(&Ancestors::default(), &account4_key, &owners_refs),
14216+
Err(MatchAccountOwnerError::NoMatch)
14217+
);
1420514218
assert_eq!(
1420614219
db.account_matches_owners(&Ancestors::default(), &Pubkey::new_unique(), &owners_refs),
1420714220
Err(MatchAccountOwnerError::UnableToLoad)

runtime/src/append_vec.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ impl AppendVec {
603603
))
604604
}
605605

606-
fn get_account_meta<'a>(&'a self, offset: usize) -> Option<&'a AccountMeta> {
606+
fn get_account_meta<'a>(&self, offset: usize) -> Option<&'a AccountMeta> {
607607
// Skip over StoredMeta data in the account
608608
let offset = offset.checked_add(mem::size_of::<StoredMeta>())?;
609609
// u64_align! does an unchecked add for alignment. Check that it won't cause an overflow.
@@ -623,8 +623,7 @@ impl AppendVec {
623623
let account_meta = self
624624
.get_account_meta(offset)
625625
.ok_or(MatchAccountOwnerError::UnableToLoad)?;
626-
owners
627-
.contains(&&account_meta.owner)
626+
(account_meta.lamports != 0 && owners.contains(&&account_meta.owner))
628627
.then_some(())
629628
.ok_or(MatchAccountOwnerError::NoMatch)
630629
}

0 commit comments

Comments
 (0)