From c5c2b44ecc69555567a41cc23fdc48e41fa17cae Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Wed, 22 Jun 2022 15:11:25 -0500 Subject: [PATCH] adjust cached stake account compare for rent_epoch (#26135) --- runtime/src/bank.rs | 22 +++++++++++++++++++++- runtime/src/stake_account.rs | 6 ++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 5563131f53..bb88135c4d 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -2794,7 +2794,27 @@ impl Bank { } }; if cached_stake_account != &stake_account { - invalid_cached_stake_accounts.fetch_add(1, Relaxed); + let mut cached_account = cached_stake_account.account().clone(); + // We could have collected rent on the loaded account already in this new epoch (we could be at partition_index 12, for example). + // So, we may need to adjust the rent_epoch of the cached account. So, update rent_epoch and compare just the accounts. + ExpectedRentCollection::maybe_update_rent_epoch_on_load( + &mut cached_account, + &SlotInfoInEpoch::new_small(self.slot()), + &SlotInfoInEpoch::new_small(self.slot()), + self.epoch_schedule(), + self.rent_collector(), + stake_pubkey, + &self.rewrites_skipped_this_slot, + ); + if &cached_account != stake_account.account() { + info!( + "cached stake account mismatch: {}: {:?}, {:?}", + stake_pubkey, + cached_account, + stake_account.account() + ); + invalid_cached_stake_accounts.fetch_add(1, Relaxed); + } } let stake_delegation = (*stake_pubkey, stake_account); let mut vote_delegations = if let Some(vote_delegations) = diff --git a/runtime/src/stake_account.rs b/runtime/src/stake_account.rs index 0cfd8b5fd3..e13b16efa4 100644 --- a/runtime/src/stake_account.rs +++ b/runtime/src/stake_account.rs @@ -103,6 +103,12 @@ impl From> for (AccountSharedData, StakeState) { } } +impl StakeAccount { + pub fn account(&self) -> &AccountSharedData { + &self.account + } +} + impl PartialEq> for StakeAccount { fn eq(&self, other: &StakeAccount) -> bool { let StakeAccount {