atlas_sysvar/last_restart_slot.rs
1//! Information about the last restart slot (hard fork).
2//!
3//! The _last restart sysvar_ provides access to the last restart slot kept in the
4//! bank fork for the slot on the fork that executes the current transaction.
5//! In case there was no fork it returns _0_.
6//!
7//! [`LastRestartSlot`] implements [`Sysvar::get`] and can be loaded efficiently without
8//! passing the sysvar account ID to the program.
9//!
10//! See also the Atlas [SIMD proposal][simd].
11//!
12//! [simd]: https://github.com/atlas-foundation/atlas-improvement-documents/blob/main/proposals/0047-syscall-and-sysvar-for-last-restart-slot.md
13//!
14//! # Examples
15//!
16//! Accessing via on-chain program directly:
17//!
18//! ```no_run
19//! # use atlas_account_info::AccountInfo;
20//! # use atlas_msg::msg;
21//! # use atlas_sysvar::Sysvar;
22//! # use atlas_program_error::ProgramResult;
23//! # use atlas_pubkey::Pubkey;
24//! # use atlas_last_restart_slot::LastRestartSlot;
25//!
26//! fn process_instruction(
27//! program_id: &Pubkey,
28//! accounts: &[AccountInfo],
29//! instruction_data: &[u8],
30//! ) -> ProgramResult {
31//!
32//! let last_restart_slot = LastRestartSlot::get();
33//! msg!("last restart slot: {:?}", last_restart_slot);
34//!
35//! Ok(())
36//! }
37//! ```
38//!
39#[cfg(feature = "bincode")]
40use crate::SysvarSerialize;
41use crate::{impl_sysvar_get, Sysvar};
42pub use {
43 atlas_last_restart_slot::LastRestartSlot,
44 atlas_sdk_ids::sysvar::last_restart_slot::{check_id, id, ID},
45};
46
47impl Sysvar for LastRestartSlot {
48 impl_sysvar_get!(atlas_get_last_restart_slot);
49}
50
51#[cfg(feature = "bincode")]
52impl SysvarSerialize for LastRestartSlot {}