solana_program/sysvar/
slot_hashes.rs

1//! named accounts for synthesized data accounts for bank state, etc.
2//!
3//! this account carries the Bank's most recent bank hashes for some N parents
4//!
5pub use crate::slot_hashes::SlotHashes;
6use crate::{account_info::AccountInfo, program_error::ProgramError, sysvar::Sysvar};
7
8crate::declare_sysvar_id!("SysvarS1otHashes111111111111111111111111111", SlotHashes);
9
10impl Sysvar for SlotHashes {
11    // override
12    fn size_of() -> usize {
13        // hard-coded so that we don't have to construct an empty
14        20_488 // golden, update if MAX_ENTRIES changes
15    }
16    fn from_account_info(_account_info: &AccountInfo) -> Result<Self, ProgramError> {
17        // This sysvar is too large to bincode::deserialize in-program
18        Err(ProgramError::UnsupportedSysvar)
19    }
20}
21
22#[cfg(test)]
23mod tests {
24    use {
25        super::*,
26        crate::{clock::Slot, hash::Hash, slot_hashes::MAX_ENTRIES},
27    };
28
29    #[test]
30    fn test_size_of() {
31        assert_eq!(
32            SlotHashes::size_of(),
33            bincode::serialized_size(
34                &(0..MAX_ENTRIES)
35                    .map(|slot| (slot as Slot, Hash::default()))
36                    .collect::<SlotHashes>()
37            )
38            .unwrap() as usize
39        );
40    }
41}