diff --git a/CHANGELOG.md b/CHANGELOG.md index 88c6c06..fb5ee76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Start a propagation node without rereading and flushing every stored message, so restarts with large stores no longer delay announces and hosting. Each message is still verified when it is served. + ## 1.4.0 - 2026-10-12 - Preserve each signed message exactly as received, including binary text and custom fields, and reject ambiguous field definitions. diff --git a/api/migrations/relay-store-v2.md b/api/migrations/relay-store-v2.md index 84a1e14..d92d74b 100644 --- a/api/migrations/relay-store-v2.md +++ b/api/migrations/relay-store-v2.md @@ -13,7 +13,10 @@ explicit offline migration. An incomplete migration, invalid committed record, unsupported filesystem, or unavailable storage prevents hosting. Daemons fail startup when required relay storage is unavailable. Applications retain the user's hosting preference but show hosting as unavailable until recovery succeeds. -There is no automatic in-memory fallback for a durable host. +There is no automatic in-memory fallback for a durable host. Startup checks each +committed record's index, provenance, size and destination without rereading +whole message bodies; every read verifies the full body, and a body that fails +is not served. Stop every process that can write the store, including service supervisors and scheduled restarts. Then run the candidate daemon against the correct config: diff --git a/crates/lxmf-core/src/propagation_node.rs b/crates/lxmf-core/src/propagation_node.rs index ab835eb..041935a 100644 --- a/crates/lxmf-core/src/propagation_node.rs +++ b/crates/lxmf-core/src/propagation_node.rs @@ -1000,7 +1000,7 @@ impl PropagationNode { continue; } let (meta, _) = crate::propagation_store_v2::read_manifest(&object)?; - crate::propagation_store_v2::verify_committed_object(&object)?; + crate::propagation_store_v2::check_committed_on_load(&object, &meta)?; if self.store.contains(&meta.transient_id) { return Err(std::io::Error::other("duplicate relay TID")); } diff --git a/crates/lxmf-core/src/propagation_store_v2.rs b/crates/lxmf-core/src/propagation_store_v2.rs index 188cf7a..3ccd1a6 100644 --- a/crates/lxmf-core/src/propagation_store_v2.rs +++ b/crates/lxmf-core/src/propagation_store_v2.rs @@ -308,6 +308,25 @@ pub(crate) fn verify_committed_object(path: &Path) -> io::Result<()> { check_index(path, &meta, &encoded) } +/// Startup check for an indexed record: readable, committed size and +/// destination prefix. Publication completed its barriers before any proof, +/// duplicates renew them, and every read revalidates the body, so restart must +/// not reread and re-flush the whole store. +pub(crate) fn check_committed_on_load(path: &Path, meta: &EntryManifest) -> io::Result<()> { + let metadata = fs::symlink_metadata(path)?; + if !metadata.is_file() || metadata.len() != meta.size as u64 { + return Err(invalid("relay object does not match its committed size")); + } + let mut destination = [0u8; 16]; + File::open(path)?.read_exact(&mut destination)?; + if destination != meta.destination { + return Err(invalid( + "relay object does not match its committed destination", + )); + } + Ok(()) +} + /// Both the manifest and complete bytes are checked at the final read boundary. /// An unresolved durable deletion always defeats a previously prepared read. pub(crate) fn read_validated_file(path: &Path) -> io::Result> { diff --git a/crates/lxmf-core/tests/relay_store_v2.rs b/crates/lxmf-core/tests/relay_store_v2.rs index 8cda71e..f73e658 100644 --- a/crates/lxmf-core/tests/relay_store_v2.rs +++ b/crates/lxmf-core/tests/relay_store_v2.rs @@ -1,7 +1,7 @@ use bytes::Bytes; use lxmf_core::propagation_node::{ PropagationAdmission, PropagationAdmissionOutcome, PropagationNode, PropagationNodeConfig, - ValidatedOpaquePropagationBlob, + ValidatedOpaquePropagationBlob, read_planned_messages, }; use rmpv::Value; fn payload(destination: [u8; 16]) -> Bytes { @@ -68,6 +68,27 @@ async fn duplicate_waits_for_exact_commit_and_rechecks_retained_files() { drop(node); assert!(PropagationNode::with_storage(PropagationNodeConfig::default(), [1; 16], old).is_err()); } +#[test] +fn restart_skips_body_rereads_and_never_serves_a_damaged_body() { + let dir = tempfile::tempdir().unwrap(); + let store = dir.path().join("store"); + let mut node = + PropagationNode::with_storage(PropagationNodeConfig::default(), [1; 16], store.clone()) + .unwrap(); + let bytes = payload([2; 16]); + let tid = validated(bytes.clone()).transient_id(); + let plan = reserve(&mut node, bytes); + assert!(node.commit_store_write(plan.persist().unwrap())); + let path = node.plan_message_reads(&[tid]).pop().unwrap().path; + drop(node); + let mut damaged = std::fs::read(&path).unwrap(); + *damaged.last_mut().unwrap() ^= 0xff; + std::fs::write(&path, &damaged).unwrap(); + let reopened = + PropagationNode::with_storage(PropagationNodeConfig::default(), [1; 16], store).unwrap(); + assert_eq!(reopened.message_count(), 1); + assert!(read_planned_messages(&reopened.plan_message_reads(&[tid])).is_empty()); +} #[tokio::test] async fn cancelled_reservation_releases_waiters_without_authority_and_can_retry() { let dir = tempfile::tempdir().unwrap();