Skip to content

Commit

Permalink
[TieredStorage] rent_epoch() returns 0 for zero-lamport accounts (#35344
Browse files Browse the repository at this point in the history
)

#### Problem
In TieredAccountMeta, RENT_EXEMPT_RENT_EPOCH will be used when
its optional field rent_epoch is None.  However, for legacy reasons, 0
should be used for zero-lamport accounts.

#### Summary of Changes
Return 0 for TieredAccountMeta::rent_epoch() for zero-lamport accounts.

#### Test Plan
accounts_db::tests::test_clean_zero_lamport_and_dead_slot
  • Loading branch information
yhchiang-sol authored Mar 1, 2024
1 parent cb260f1 commit 608329b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions accounts-db/src/tiered_storage/readable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use {
TieredStorageResult,
},
},
solana_sdk::{account::ReadableAccount, pubkey::Pubkey, stake_history::Epoch},
solana_sdk::{
account::ReadableAccount, pubkey::Pubkey, rent_collector::RENT_EXEMPT_RENT_EPOCH,
stake_history::Epoch,
},
std::path::Path,
};

Expand Down Expand Up @@ -72,12 +75,23 @@ impl<'accounts_file, M: TieredAccountMeta> ReadableAccount
}

/// Returns the epoch that this account will next owe rent by parsing
/// the specified account block. Epoch::MAX will be returned if the account
/// is rent-exempt.
/// the specified account block. RENT_EXEMPT_RENT_EPOCH will be returned
/// if the account is rent-exempt.
///
/// For a zero-lamport account, Epoch::default() will be returned to
/// default states of an AccountSharedData.
fn rent_epoch(&self) -> Epoch {
self.meta
.rent_epoch(self.account_block)
.unwrap_or(Epoch::MAX)
.unwrap_or(if self.lamports() != 0 {
RENT_EXEMPT_RENT_EPOCH
} else {
// While there is no valid-values for any fields of a zero
// lamport account, here we return Epoch::default() to
// match the default states of AccountSharedData. Otherwise,
// a hash mismatch will occur.
Epoch::default()
})
}

/// Returns the data associated to this account.
Expand Down

0 comments on commit 608329b

Please sign in to comment.