From 7689b7f4e0c57f798557c255eed615a830b357b6 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Wed, 21 Feb 2024 23:23:43 -0800 Subject: [PATCH 1/2] [TieredStorage] Return rent_epoch() 0 for zero-lamport accounts --- accounts-db/src/tiered_storage/readable.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/accounts-db/src/tiered_storage/readable.rs b/accounts-db/src/tiered_storage/readable.rs index 12c4a8224d48ea..df933ece04264f 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, }; @@ -73,11 +76,16 @@ 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. + /// is rent-exempt, and 0 for any zero-lamport account. 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 { + // 0 rent-epoch is used for zero-lamport accounts. + 0 + }) } /// Returns the data associated to this account. From f45aafad8cf7929def41623c15a4ceeb07d7aef1 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Fri, 1 Mar 2024 11:40:36 -0800 Subject: [PATCH 2/2] Improve code comment to explain why Epoch::Default() is used for zero-lamport account. --- accounts-db/src/tiered_storage/readable.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/accounts-db/src/tiered_storage/readable.rs b/accounts-db/src/tiered_storage/readable.rs index df933ece04264f..1801b04fcecd80 100644 --- a/accounts-db/src/tiered_storage/readable.rs +++ b/accounts-db/src/tiered_storage/readable.rs @@ -75,16 +75,22 @@ 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, and 0 for any zero-lamport account. + /// 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(if self.lamports() != 0 { RENT_EXEMPT_RENT_EPOCH } else { - // 0 rent-epoch is used for zero-lamport accounts. - 0 + // 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() }) }