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

[TieredStorage] rent_epoch() returns 0 for zero-lamport accounts #35344

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
brooksprumo marked this conversation as resolved.
Show resolved Hide resolved
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()
})
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writing a 0 lamport account would currently store the rent_epoch as a 0 u64

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writing a 0 lamport account would currently store the rent_epoch as a 0 u64

It shouldn't be the case because zero lamport account will be None:
https://github.com/jeffwashington/solana/blob/ef6c506ab673c570220f39ba2830cd3ce942a40d/accounts-db/src/account_storage/meta.rs#L81

And, for None case, we will write None for the rent_epoch
https://github.com/jeffwashington/solana/blob/ef6c506ab673c570220f39ba2830cd3ce942a40d/accounts-db/src/tiered_storage/hot.rs#L597


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