From 608329b9740467da3c42e0c109573b7d261b89e4 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang <93241502+yhchiang-sol@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:18:12 -0800 Subject: [PATCH] [TieredStorage] rent_epoch() returns 0 for zero-lamport accounts (#35344) #### 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 --- accounts-db/src/tiered_storage/readable.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/accounts-db/src/tiered_storage/readable.rs b/accounts-db/src/tiered_storage/readable.rs index 12c4a8224..1801b04fc 100644 --- a/accounts-db/src/tiered_storage/readable.rs +++ b/accounts-db/src/tiered_storage/readable.rs @@ -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, }; @@ -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.