hash_account_with_rent_epoch (#24104)

This commit is contained in:
Jeff Washington (jwash) 2022-04-05 08:10:31 -05:00 committed by GitHub
parent ba92ba0e06
commit 4a11fa072f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 0 deletions

View File

@ -4402,6 +4402,23 @@ impl AccountsDb {
} }
} }
pub fn hash_account_with_rent_epoch<T: ReadableAccount>(
slot: Slot,
account: &T,
pubkey: &Pubkey,
rent_epoch: Epoch,
) -> Hash {
Self::hash_account_data(
slot,
account.lamports(),
account.owner(),
account.executable(),
rent_epoch,
account.data(),
pubkey,
)
}
pub fn hash_account<T: ReadableAccount>(slot: Slot, account: &T, pubkey: &Pubkey) -> Hash { pub fn hash_account<T: ReadableAccount>(slot: Slot, account: &T, pubkey: &Pubkey) -> Hash {
Self::hash_account_data( Self::hash_account_data(
slot, slot,
@ -13742,4 +13759,19 @@ pub mod tests {
}); });
} }
} }
#[test]
fn test_hash_account_with_rent_epoch() {
let owner = solana_sdk::pubkey::new_rand();
let pubkey = solana_sdk::pubkey::new_rand();
let slot = 9;
let mut account = AccountSharedData::new(2, 1, &owner);
for rent in 0..3 {
account.set_rent_epoch(rent);
assert_eq!(
AccountsDb::hash_account(slot, &account, &pubkey),
AccountsDb::hash_account_with_rent_epoch(slot, &account, &pubkey, rent)
);
}
}
} }