Skip to content

Commit

Permalink
checkpoint: add comments to struct, correct version comment (#115)
Browse files Browse the repository at this point in the history
* checkpoint: add comments to struct, correct version comment

* remove BTmeta, add snapshot version constant
  • Loading branch information
litlep-nibbyt authored Jan 14, 2025
1 parent 568b6fe commit e2589a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
14 changes: 14 additions & 0 deletions crown/src/kernel/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ use tracing::{debug, error, info, warn};

#[derive(Clone)]
pub struct Checkpoint {
/// Magic bytes to identify checkpoint format
pub magic_bytes: u64,
/// Version of checkpoint
pub version: u32,
/// The buffer that this checkpoint was saved to, either 0 or 1.
pub buff_index: bool,
/// Hash of the boot kernel
pub ker_hash: Hash,
/// Event number
pub event_num: u64,
/// State of the kernel
pub ker_state: Noun,
/// Cold state
pub cold: Cold,
}

Expand All @@ -45,14 +52,21 @@ impl Checkpoint {

#[derive(Encode, Decode, PartialEq, Debug)]
pub struct JammedCheckpoint {
/// Magic bytes to identify checkpoint format
pub magic_bytes: u64,
/// Version of checkpoint
pub version: u32,
/// The buffer this checkpoint was saved to, either 0 or 1
pub buff_index: bool,
/// Hash of the boot kernel
#[bincode(with_serde)]
pub ker_hash: Hash,
/// Checksum derived from event_num and jam (the entries below)
#[bincode(with_serde)]
pub checksum: Hash,
/// Event number
pub event_num: u64,
/// Jammed noun of [kernel_state cold_state]
pub jam: JammedNoun,
}

Expand Down
11 changes: 3 additions & 8 deletions crown/src/kernel/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ const LOAD_AXIS: u64 = 4;
const PEEK_AXIS: u64 = 22;
const POKE_AXIS: u64 = 23;

/// Enum representing the Sword snapshot metadata fields.
#[repr(usize)]
enum BTMetaField {
SnapshotVersion = 0,
Snapshot = 1,
}
const SNAPSHOT_VERSION: u32 = 0;

/// Represents a Sword kernel, containing a Serf and snapshot location.
pub struct Kernel {
Expand Down Expand Up @@ -470,7 +465,7 @@ impl Kernel {
/// Represents the Serf, which maintains context and provides an interface to
/// the Sword.
pub struct Serf {
/// Version number of arvo
/// Version number of snapshot
pub version: u32,
/// Hash of boot kernel
pub ker_hash: Hash,
Expand Down Expand Up @@ -540,7 +535,7 @@ impl Serf {

let version = checkpoint
.as_ref()
.map_or_else(|| 0, |snapshot| snapshot.version);
.map_or_else(|| SNAPSHOT_VERSION, |snapshot| snapshot.version);

let mut hasher = Hasher::new();
hasher.update(kernel_bytes);
Expand Down

0 comments on commit e2589a9

Please sign in to comment.