Skip to content

Commit 82c9f5f

Browse files
committed
program state
1 parent 67aa5d5 commit 82c9f5f

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

program/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ solana-program = "~2.0"
2121
thiserror = "^1.0"
2222

2323
[dev-dependencies]
24+
memoffset = "0.9"
2425

2526
[features]
2627
bpf-entrypoint = []

program/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod entrypoint;
66
pub mod error;
77
pub mod instruction;
88
pub mod processor;
9+
pub mod state;
910

1011
// [CORE BPF]: Unfortunately, the runtime still depends pretty heavily on this
1112
// program ID hard-coded, so we can't test with it just yet.

program/src/state.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

Comments
 (0)