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