diff --git a/native/aetherlight/src/journal.rs b/native/aetherlight/src/journal.rs index de93b50ea..c4ce73c75 100644 --- a/native/aetherlight/src/journal.rs +++ b/native/aetherlight/src/journal.rs @@ -13,6 +13,23 @@ pub(super) const JOURNAL_SCHEMA: &str = "aetherlight.journal.v1"; pub(super) enum JournalError { #[error("world journal is corrupt: {0}")] Corrupt(String), + /// A well-formed commit of another schema generation: not damage, a world + /// this build cannot read. Named apart so a store can tell an old save from + /// a corrupt one. + #[error("commit schema {found} is not the supported {supported}")] + UnsupportedSchema { found: String, supported: &'static str }, +} + +/// The one judge of the schema generation, asked of every commit before any of +/// its other fields is believed. +fn require_commit_schema(commit: &WorldCommit) -> Result<(), JournalError> { + if commit.schema == COMMIT_SCHEMA { + return Ok(()); + } + Err(JournalError::UnsupportedSchema { + found: commit.schema.clone(), + supported: COMMIT_SCHEMA, + }) } /// What an export carries: the schema that names the format, and the commits in @@ -106,6 +123,7 @@ pub(super) fn verify_history(commits: &[WorldCommit]) -> Result Result Result { + assert_eq!(found, "aetherlight.world_commit.v1"); + assert_eq!(supported, COMMIT_SCHEMA); + } + other => panic!("a v1 chain must be refused by name, got {other:?}"), + } + // A later commit of another generation is refused the same way. + let mut mixed = kernel.journal.commits.clone(); + last_commit(&mut mixed).schema = "aetherlight.world_commit.v3".into(); + assert!(matches!( + reopen(&mixed), + Err(JournalError::UnsupportedSchema { .. }) + )); } /// The replay-side future check reads only the subjects the transaction @@ -1032,7 +1062,7 @@ mod tests { forge(&mut forged); forged.digest = commit_digest(&forged).unwrap(); assert!( - matches!(reopen(&[forged]), Err(JournalError::Corrupt(_))), + reopen(&[forged]).is_err(), "a genesis with {what} was admitted" ); } @@ -1134,7 +1164,7 @@ mod tests { }); let error = reopen(&forged) .expect_err("a commit forged to the owner replayed"); - let JournalError::Corrupt(_) = error; + assert!(matches!(error, JournalError::Corrupt(_)), "{error:?}"); } } diff --git a/native/aetherlight/src/lib.rs b/native/aetherlight/src/lib.rs index 30a3c8a12..3918dba55 100644 --- a/native/aetherlight/src/lib.rs +++ b/native/aetherlight/src/lib.rs @@ -916,14 +916,22 @@ pub enum KernelError { Serialization(String), #[error("world journal is corrupt: {0}")] CorruptJournal(String), + /// A well-formed export written under another commit schema generation + /// (a v1 save): not corrupt, but not readable by this build. + #[error("export commit schema {found} is not the supported {supported}")] + UnsupportedSchema { found: String, supported: &'static str }, #[error("private reducer invariant failed: {0}")] Invariant(String), } impl From for KernelError { fn from(error: journal::JournalError) -> Self { - let journal::JournalError::Corrupt(detail) = error; - Self::CorruptJournal(detail) + match error { + journal::JournalError::Corrupt(detail) => Self::CorruptJournal(detail), + journal::JournalError::UnsupportedSchema { found, supported } => { + Self::UnsupportedSchema { found, supported } + } + } } }