Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkgs/id/src/world/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ impl WorldCore {
}
JournalEntry::Committed { event } => {
ensure!(
event.sequence == core.sequence.saturating_add(1),
core.sequence.checked_add(1) == Some(event.sequence),
"journal sequence jumps from {} to {}",
core.sequence,
event.sequence
Expand Down
52 changes: 52 additions & 0 deletions pkgs/id/src/world/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,58 @@ mod tests {
assert_eq!(restored.core.sequence, u64::MAX);
}

#[test]
fn restore_committed_sequence_does_not_wrap_at_u64_max() {
// #8370 (design #4000 decision 2): the Committed arm's succession
// predicate must be checked_add. With saturating_add, a core
// already at u64::MAX would accept a further committed event with
// sequence MAX — the saturated successor equals the current
// sequence, so the "advance by one" check passes without
// advancing, and repeated MAX events would each pass it again.
// Oracle: the succession contract itself — after a checkpoint at
// MAX, no committed event can legitimately follow.
fn chat(sequence: u64) -> WorldEvent {
WorldEvent {
sequence,
participant_id: 0,
kind: WorldEventKind::Chat("committed boundary test".to_owned()),
}
}

let journal = |committed: WorldEvent| {
[
JournalEntry::Created {
world_id: "w".to_owned(),
version: JOURNAL_VERSION,
},
JournalEntry::Checkpoint {
sequence: u64::MAX,
module_hash: "h".to_owned(),
seed: 1,
provenance: None,
execution_profile: None,
caps_ceiling: None,
schedules: None,
transfers: None,
lease: None,
snapshot: "s".to_owned(),
events: vec![chat(u64::MAX - 1), chat(u64::MAX)],
open_presence: None,
admin_history: None,
},
JournalEntry::Committed { event: committed },
]
};

let error = WorldCore::restore("w", WorldLimits::default(), journal(chat(u64::MAX)))
.err()
.expect("a committed event at u64::MAX must not pass as the successor of MAX");
assert!(
error.to_string().contains("journal sequence jumps"),
"{error:#}"
);
}

#[test]
fn restore_accepts_v1_through_v6_headers_and_refuses_newer_at_the_header() {
// The issue-#227 rollback contract: this binary reads versions
Expand Down
Loading