|
| 1 | +//! Program state types. |
| 2 | +
|
| 3 | +use solana_program::pubkey::Pubkey; |
| 4 | + |
| 5 | +/// Cooldown before a program can be un-/redeployed again |
| 6 | +pub const DEPLOYMENT_COOLDOWN_IN_SLOTS: u64 = 750; |
| 7 | + |
| 8 | +#[repr(u64)] |
| 9 | +#[derive(Debug, PartialEq, Eq, Clone, Copy)] |
| 10 | +pub enum LoaderV4Status { |
| 11 | + /// Program is in maintenance. |
| 12 | + Retracted, |
| 13 | + /// Program is ready to be executed. |
| 14 | + Deployed, |
| 15 | + /// Same as `Deployed`, but can not be retracted anymore. |
| 16 | + Finalized, |
| 17 | +} |
| 18 | + |
| 19 | +/// LoaderV4 account states |
| 20 | +#[repr(C)] |
| 21 | +#[derive(Debug, PartialEq, Eq, Clone, Copy)] |
| 22 | +pub struct LoaderV4State { |
| 23 | + /// Slot in which the program was last deployed, retracted or initialized. |
| 24 | + pub slot: u64, |
| 25 | + /// Address of signer which can send program management instructions when |
| 26 | + /// the status is not finalized. |
| 27 | + /// Otherwise a forwarding to the next version of the finalized program. |
| 28 | + pub authority_address_or_next_version: Pubkey, |
| 29 | + /// Deployment status. |
| 30 | + pub status: LoaderV4Status, |
| 31 | + // The raw program data follows this serialized structure in the |
| 32 | + // account's data. |
| 33 | +} |
| 34 | + |
| 35 | +impl LoaderV4State { |
| 36 | + /// Size of a serialized program account. |
| 37 | + pub const fn program_data_offset() -> usize { |
| 38 | + std::mem::size_of::<Self>() |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +#[cfg(test)] |
| 43 | +mod tests { |
| 44 | + use {super::*, memoffset::offset_of}; |
| 45 | + |
| 46 | + #[test] |
| 47 | + fn test_layout() { |
| 48 | + assert_eq!(offset_of!(LoaderV4State, slot), 0x00); |
| 49 | + assert_eq!( |
| 50 | + offset_of!(LoaderV4State, authority_address_or_next_version), |
| 51 | + 0x08 |
| 52 | + ); |
| 53 | + assert_eq!(offset_of!(LoaderV4State, status), 0x28); |
| 54 | + assert_eq!(LoaderV4State::program_data_offset(), 0x30); |
| 55 | + } |
| 56 | +} |
0 commit comments